À©µµ¿ì ÇÁ·Î±×·¡¹Ö ÀÚ·á |
---|
Á¦¸ñ | [API] hello.cpp 1998/07/14 (08:54) |
À̸§ | ±èÈ¿¿ø |
¹øÈ£ | 20 |
Á¶È¸ | 368 |
º»¹® |
1. WinMainÇÔ¼ö´Â ÇÁ·Î±×·¥ÀÇ Entry Point¸¦ °¡Áö´Â Ç¥ÁØ C MainÇÔ¼ö¿Í µ¿ÀÏÇÑ °³³äÀÇ ÇÔ¼öÀÌ´Ù. WndProcÀº À©µµ¿ì ÇÁ·Î½ÃÀú·Î¼, Å°º¸µå¿Í ¸¶¿ì½º¸¦ ÅëÇÑ ÀԷ¿¡ ÀÀ´äÇÏ°í, ȸ鿡 ±×·¡ÇÈ Ãâ·ÂÀ» Ç¥ÇöÇÏ´Â ¿ä¾àÄÚµåÀÇ ÇÑ ¹æ¹ýÀÌ´Ù. Áï, À©µµ¿ì¿¡ ´ëÇÑ ¸Þ½ÃÁö¸¦ ó¸®ÇÑ´Ù. 2. ¾î¶² ¼Ò½º¿¡¼µµ WndProc¸¦ Á÷Á¢ È£ÃâÇÏÁö´Â ¾Ê´Â´Ù. WndProcÀº À©µµ¿ì·ÎºÎÅ͸¸ È£ÃâµÇÁö¸¸, WndMain¿¡¼ WndProc¿¡ ´ëÇÑ ÂüÁ¶°¡ Çѹø Àִµ¥ ÀÌ°ÍÀÌ WndProcÇÔ¼ö°¡ WinMainÀü¿¡ ÇÁ·Î±×·¥ÀÇ ½ÃÀÛ ºÎºÐ¿¡¼ ¼±¾ðµÇ¾î¾ß ÇÏ´Â ÀÌÀ¯ÀÌ´Ù. 3. GetStockObject() ±×·¡ÇÈ °³Ã¼(¿©±â¼´Â À©µµ¿ì ¹è°æÀ» Ä¥Çϴµ¥ »ç¿ëµÇ´Â ºê·¯½Ã)¸¦ ¾ò´Â´Ù. 4. RegisterClassEx() ÇÁ·Î±×·¥ÀÇ À©µµ¿ì¸¦ À§ÇÑ À©µµ¿ì Ŭ·¡½º¸¦ µî·ÏÇÑ´Ù. 5. CreateWindow() À©µµ¿ì Ŭ·¡½º¿¡ ±â¹ÝÇÏ¿© À©µµ¿ì »ý¼º 6. ShowWindow() À©µµ¿ì¸¦ ȸ鿡 Ç¥½Ã 7. UpdateWindow() À©µµ¿ì¿¡°Ô ÀÚ½ÅÀ» ´Ù½Ã ±×¸®µµ·Ï ÇÑ´Ù. 8. GetMessage() ¸Þ½ÃÁö Å¥¿¡¼ ÇϳªÀÇ ¸Þ½ÃÁö¸¦ ¾ò´Â´Ù. 9. TranslateMessage() Å°º¸µå ¸Þ½ÃÁö¸¦ º¯È¯ÇÑ´Ù. 10. DispatchMessage() ¸Þ½ÃÁö¸¦ À©µµ¿ì ÇÁ·Î½ÃÀú¿¡ º¸³½´Ù. 11. PostQuitMessage() ¸¶Ä§ ¸Þ½ÃÁö(WM_QUIT)¸¦ ¸Þ½ÃÁö Å¥¿¡ »ðÀÔÇÑ´Ù. 12. DefWindowProc() default¸Þ½ÃÁö 󸮸¦ ¼öÇàÇÑ´Ù. /*------------------------------------------------------------ HELLOWIN.C -- Displays "Hello, Windows 95!" in client area ------------------------------------------------------------*/ #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) // hIstance´Â instance handle·Î ÇÁ·Î±×·¥À» // À¯ÀÏÇÏ°Ô ½Äº°ÇÏ´Â ¹øÈ£ÀÌ´Ù. // hPrevInstance´Â Ç×»ó NULLÀÌ´Ù. // ¿¹Àü¿¡´Â º¹»çº»ÀÇ ÀûÀç ¿©ºÎ¿¡ µû¶ó¼, // NULL°ªÀ» °¡Áø´Ù. // szCmdLine ½ÇÇà½ÃÀÇ ¸í·ÉÁÙ ÀÎÀÚÀÌ´Ù. // ¹®ÀÚ¿¿¡ ´ëÇÑ Æ÷ÀÎÅÍÀÌ´Ù. // iCmdShow ÇØ´ç À©µµ¿ì°¡ À©µµ¿ìÁî¿¡¼ // óÀ½À¸·Î Ç¥½ÃµÇ´Â ¹æ¹ýÀ» Áö½ÃÇÏ´Â ¹øÈ£ÀÌ´Ù. // 1(SW_SHOWNORMAL), 7(SW_SHOWMINNOACTIVE) // ÀÇ °ªÀ» °¡Áø´Ù. { static char szAppName[] = "HelloWin" ; HWND hwnd ; MSG msg ; WNDCLASSEX wndclass ; wndclass.cbSize = sizeof (wndclass) ; wndclass.style = CS_HREDRAW | CS_VREDRAW ; wndclass.lpfnWndProc = WndProc ; // lpfn : long pointer to a function wndclass.cbClsExtra = 0 ; // cb : count of bytes wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ; wndclass.lpszMenuName = NULL ; wndclass.lpszClassName = szAppName ; wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION) ; RegisterClassEx (&wndclass) ; hwnd = CreateWindow (szAppName, // window class name "The Hello Program", // window caption WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position CW_USEDEFAULT, // initial x size CW_USEDEFAULT, // initial y size NULL, // parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ; // creation parameters ShowWindow (hwnd, iCmdShow) ; UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, 0, 0)) // WM_QUIT°¡ ¾Æ´Ñ ¸ðµç ¸Þ½ÃÁöÀÇ °æ¿ì¿¡ // 0ÀÌ ¾Æ´Ñ °ªÀ» ¹ÝȯÇÑ´Ù. // WM_QUIT´Â ¸Þ½ÃÁö´Â ¸Þ½ÃÁö ·çÇÁ¸¦ ºüÁ® // ³ª¿Í¼ ÇÁ·Î±×·¥ÀÌ Á¾·áµÈ´Ù. { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } return msg.wParam ; } LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (iMsg) { case WM_CREATE : PlaySound ("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT : hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, "Hello, Windows 95!", -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; } |