Click here to Skip to main content
12,352,573 members (61,823 online)
Click here to Skip to main content

Stats

102.6K views
1.9K downloads
69 bookmarked
Posted

Win32 Window Minimal

, 14 Aug 2012 CPOL
Getting started with Win32 programming through creating a window with minimum code and complexity
winbase
winbase.vcproj.merlin-PC.merlin.user
winbase.cbp
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

 MSG msg          = {0};
 WNDCLASS wc      = {0};
 wc.lpfnWndProc   = WndProc;
 wc.hInstance     = hInstance;
 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
 wc.lpszClassName = L"minwindowsapp";
 if( !RegisterClass(&wc) )
   return 1;

 if( !CreateWindow(	wc.lpszClassName,
                    "Minimal Windows Application",
                    WS_OVERLAPPEDWINDOW|WS_VISIBLE,
                    0,0,640,480,0,0,hInstance,NULL))
    return 2;

    while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
    {
        DispatchMessage( &msg );
    }

    return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

 switch(message)
 {
   case WM_CLOSE:
     PostQuitMessage(0);
     break;
   default:
     return DefWindowProc(hWnd, message, wParam, lParam);
 }
 return 0;

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Jani Mäkinen
Software Developer (Senior) Frozenbyte
Finland Finland
I've programmed since the 90's QBasic times and love programming tight and slick code.

Here are some links for my 'off the clock' programming: http://www.gfx0.com

Specialties: C, C++, Game Programming

I was born in the middle of Finland into a small farming town. Moved to Helsinki, then to Germany and am now back in Helsinki programming in the game industry Smile | :)

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160621.1 | Last Updated 14 Aug 2012
Article Copyright 2011 by Jani Mäkinen
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid