All pastes #290611 Raw Edit

Miscellany

public text v1 · immutable
#290611 ·published 2006-12-24 04:46 UTC
rendered paste body
#include <windows.h>




//Function Prototypes
LRESULT WINAPI WndProc(HWND,UINT,WPARAM,LPARAM); //main windows function
void RegisterWindowClass(HINSTANCE hInstance);
void CreateAppWindow(HINSTANCE hInstance);
WPARAM StartMessageLoop();

//Global Varibles
HWND g_hWnd;


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

	RegisterWindowClass(hInstance);
	CreateAppWindow(hInstance);
	ShowWindow(g_hWnd , SW_SHOWDEFAULT);
	UpdateWindow(g_hWnd);
	INT result = StartMessageLoop();
	return result;
}


LRESULT CALLBACK WndProc(HWND hWnd  ,UINT msg , WPARAM wParam , LPARAM lParam)
{
	
	switch(msg)
	{
	case WM_CREATE:
		return 0;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	case WM_PAINT:
		ValidateRect(g_hWnd, NULL);
		return 0;
	}

	return DefWindowProc(g_hWnd , msg , wParam , lParam);
	
}

void RegisterWindowClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL , IDI_APPLICATION); 
wc.hCursor = (HCURSOR)LoadCursor(NULL , IDC_ARROW); //Mouse Cursor 
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //background window colour
wc.lpszMenuName = NULL;
wc.lpszClassName = "WinApp";
wc.hIconSm = NULL;

RegisterClassEx(&wc);
}

void CreateAppWindow(HINSTANCE hInstance)
{

g_hWnd = CreateWindowEx(
					 NULL, 
					 "WinApp",
					 "Basic Windows Application",
                     WS_OVERLAPPEDWINDOW , 
					 100, 
					 100,
					 648,
					 514,
					 GetDesktopWindow(),
					 NULL,
					 hInstance,
					 NULL
					 );
}


WPARAM StartMessageLoop()
{
MSG msg;

while(1)
{
	if(PeekMessage(&msg , NULL , 0 , 0 , PM_REMOVE))
	{
		if(msg.message == WM_QUIT)
		break;
        TranslateMessage(&msg);
	    DispatchMessage(&msg);
	}
	else
	{
      //use idle time here
	}
}

return msg.wParam;
}