//--------------------------------------- // Win32 API Programming //--------------------------------------- #include // ÇÔ¼ö ¼±¾ð void InitInstance(HINSTANCE hInstance, int nCmdShow); void InitApplication(HINSTANCE hInstance); int MessageLoop(); LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // WinMain ÇÔ¼ö int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // ¾îÇø®ÄÉÀÌ¼Ç ÃʱâÈ­ InitApplication(hInstance); // ÀνºÅϽº ÃʱâÈ­ InitInstance(hInstance, nCmdShow); // ¸Þ½ÃÁö ·çÇÁ return MessageLoop(); } // ¾îÇø®ÄÉÀÌ¼Ç ÃʱâÈ­: À©µµ¿ì Ŭ·¡½º µî·Ï void InitApplication(HINSTANCE hInstance) { WNDCLASS wc; wc.style = CS_HREDRAW|CS_VREDRAW; wc.lpfnWndProc = WndProc; // À©µµ¿ì ÇÁ·Î½ÃÀú ¼³Á¤. wc.hInstance = hInstance; // ÇÁ·Î±×·¥ ÇÚµé wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = NULL; wc.lpszClassName = "ExampleClass"; // µî·ÏÇÒ À©µµ¿ìŬ·¡½º¸í wc.cbClsExtra = 0; wc.cbWndExtra = 0; RegisterClass(&wc); } // ÀνºÅϽº ÃʱâÈ­: À©µµ¿ì »ý¼º void InitInstance(HINSTANCE hInstance, int nCmdShow) { HWND hWnd; hWnd = CreateWindow("ExampleClass", // µî·ÏµÈ À©µµ¿ì Ŭ·¡½º "Caption : Win32 API", WS_OVERLAPPEDWINDOW, // Style : ½Ã½ºÅÛ ¸Þ´º, ... CW_USEDEFAULT, CW_USEDEFAULT, // x,y CW_USEDEFAULT, CW_USEDEFAULT, // xSize, ySize NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); // SW_SHOW, SW_SHOWMAXIMIZED UpdateWindow(hWnd); } // ¸Þ½ÃÁö ·çÇÁ int MessageLoop() { MSG msg; while(GetMessage(&msg, NULL, NULL, NULL)) { DispatchMessage(&msg); } return msg.wParam; } // À©µµ¿ì ÇÁ·Î½ÃÀú: ¸Þ½ÃÁö ó¸® LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: // â(Window) ´ÝÈû. PostQuitMessage(0); // WM_QUIT ¸Þ½ÃÁö Àü¼Û -> ÇÁ·Î±×·¥ Á¾·á break; } return DefWindowProc(hWnd, message, wParam, lParam); } //-------------------------- // ¸Þ½ÃÁö ±¸Á¶ //-------------------------- typedef struct tagMSG { HWND hWnd; // ¸Þ½ÃÁö¸¦ ¹ÞÀ» À©µµ¿ìÀÇ ÇÚµé UINT message; // ¸Þ½ÃÁö Á¾·ù ex) WM_PAINT WPARAM wParam; // Ãß°¡Á¤º¸ LPARAM lParam; // Ãß°¡Á¤º¸ DWORD time; // ¹ß»ý½Ã°¢ POINT pt; // ¸Þ½ÃÁö°¡ ¹ß»ýÇÑ È­¸é À§Ä¡ } MSG;