Sie sind auf Seite 1von 2

#include <windows.

h> char g_szClassName[] = "myWindowClass";//Name of window class // Step 4: the Window Procedure - This is the brain LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_PAINT: //WM=Windows Message hdc = BeginPaint(hwnd, &ps); //BeginPaint must have En dPaint TextOut(hdc, 15, 20, "Hello, Windows!", 50); //0, 0= Co ordinate EndPaint(hwnd, &ps); return 0L; case WM_CLOSE: DestroyWindow(hwnd);//sends the WM_DESTROY message to th e window //(hwnd) getting destroyed, break; case WM_DESTROY: PostQuitMessage(0);//This posts the WM_QUIT message to t he message loop //This window will never receive this message, because // it causes GetMessage() to return FALSE break; default: return DefWindowProc(hwnd, msg, wParam, lParam);//allows //window to, like be sized, maximised, etc... } return 0; } // int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) //Entry of program { WNDCLASSEX wc; //Create WNDCLASSEX object //Step 1: Registering the Window Class wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc;// Window Procedure: mandatory wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance;// owner of the class: mandatory wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW);// optional wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);// optional wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName;// Name of window class:mandatory wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) //Registering successful { MessageBox(NULL, "Window Registration Failed!", "Error!" , MB_ICONEXCLAMATION | MB_OK); return 0; }

else { MessageBox(NULL, "Window Registration Succeed!", "OK", MB_ICONEXCLAMATION | MB_OK); } //Step 2: Creating the Window HWND hwnd; //Create variable hwnd to store handle of Instance (process) hwnd = CreateWindowEx( WS_EX_APPWINDOW, g_szClassName,// name of a registered window class "The title of my window",// window caption WS_OVERLAPPEDWINDOW,// window style CW_USEDEFAULT, CW_USEDEFAULT,//w and y position, 240, 120,// width and height NULL, // handle to parent window NULL, // handle to menu hInstance, // application instance NULL);// window creation data if(hwnd==0) //If window creation failed { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } else { MessageBox(NULL, "Window Creation Succeed!", "OK!", MB_ICONEXCLAMATION | MB_OK); } ShowWindow(hwnd, nCmdShow);//Show window iden tified by hwnd using //parameter passed by the last parameter in WinMain()(nCmdShow) UpdateWindow(hwnd);//then update it to ensure that it has properly //redrawn itself on the screen //Step 3: The Message Loop - This is the heart MSG Msg; //Create MSG structure to store data for windows message // Keep pumping messages--they end up in our Window Procedure while(GetMessage(&Msg, NULL, 0, 0) > 0)//while (message from // application's message queue)>0) { TranslateMessage(&Msg);//do some additional processing on //keyboard events like generating WM_CHAR messages to //go along with WM_KEYDOWN messages DispatchMessage(&Msg);//sends the message out to the //windows procedure } return Msg.wParam; }

Das könnte Ihnen auch gefallen