[API] 로딩 화면(팝업(popup)) 완성 - 2

simpled 2013.06.23 16:03 조회 수 : 5872

04 (1).exe



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


다음에 보여줄 코드는 WindFunc_Original.h 의 내용이다.

WindFunc_popup.h 의 내용과는 사뭇 다르다. 

각각의 차이를 나열하자면,

1. 일단 윈도우클래스를 다르게 입력했다.

2. 전역 변수 hWnd_Original과 hWnd_popup의 초기화를 각각 InitInstance, IntiInstance_popup 함수에서 해주고 있다.

3. POPUP윈도우는 비트맵과 텍스트를 몇 밀리초 단위로 미친듯이 쓰고 지우지만,

   Original Window는 메뉴가 보이며, 작은 사각형 하나만 그릴 뿐이다. 

4. WindFunc_popup의 프로시저 함수의 WM_TIMER의 2번째 타이머 항목을 보면 hWnd_popup과 hWnd_Original을 이용하여

   각각의 윈도우를 숨기고, 보여지게 하는 기술이 담겨져 있다. 쓰여진 함수는 ShowWindow 함수와 SetWindowPos 함수이다.


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



// 이코드모듈에들어있는함수의정방향선언입니다.

 

ATOM                          MyRegisterClass(HINSTANCE hInstance);

BOOL                           InitInstance(HINSTANCE, int);

LRESULT CALLBACK        WndProc(HWND, UINT, WPARAM, LPARAM);

INT_PTR CALLBACK        About(HWND, UINT, WPARAM, LPARAM);

 

ATOM MyRegisterClass(HINSTANCE hInstance)

{

        WNDCLASSEX wcex;

 

        wcex.cbSize = sizeof(WNDCLASSEX);

 

        wcex.style                    = CS_HREDRAW | CS_VREDRAW;

        wcex.lpfnWndProc       = WndProc;

        wcex.cbClsExtra               = 0;

        wcex.cbWndExtra               = 0;

        wcex.hInstance         = hInstance;

        wcex.hIcon                    = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MY04));

        wcex.hCursor           = LoadCursor(NULL, IDC_ARROW);

        wcex.hbrBackground     = (HBRUSH)(COLOR_WINDOW+1);

        wcex.lpszMenuName      = MAKEINTRESOURCE(IDC_MY04);

        // wcex.lpszMenuName   = NULL;

        wcex.lpszClassName     = TEXT("Orignal");

        wcex.hIconSm           = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

 

        return RegisterClassEx(&wcex);

}

 

//

//   함수: InitInstance(HINSTANCE, int)

//

//   목적인스턴스핸들을저장하고주창을만듭니다.

//

//   설명:

//

//        이함수를통해인스턴스핸들을전역변수에저장하고

//        주프로그램창을만든다음표시합니다.

//

 

 

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

{

   HWND hWnd;

 

   hInst = hInstance; // 인스턴스핸들을전역변수에저장합니다.

 

   hWnd = CreateWindow(TEXT("Orignal"), TEXT("Orignal"), WS_POPUP,

      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

       

   hWnd_Original = hWnd;

       

   if (!hWnd)

   {

      return FALSE;

   }

       

   ShowWindow(hWnd, HIDE_WINDOW);

   UpdateWindow(hWnd);

 

   return TRUE;

}

 

 

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

{

        int wmId, wmEvent;

        PAINTSTRUCT ps;

        HDC hdc;

 

        static clValue_popup val(3); // 비트맵의개수를입력해줘야한다.

 

        switch (message)

        {

               case WM_CREATE:

                       break;

 

               case WM_SIZE:

                      

                       break;

 

               case WM_SYSKEYDOWN:

                       break;

 

               case WM_KEYDOWN:

                       switch(wParam)

                       {

                              case VK_ESCAPE:

                                      PostQuitMessage(0);

                                      break;

                       }

                       break;

 

               case WM_TIMER:

                       switch(wParam)

                       {

                              case 1:

                                      break;

                              case 2:

                                      break;

                       }

                       break;

              

               case WM_COMMAND:

                       wmId    = LOWORD(wParam);

                       wmEvent = HIWORD(wParam);

                       // 메뉴의선택영역을구문분석합니다.

                       switch (wmId)

                       {

                              case IDM_ABOUT:

                                      DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);

                                      break;

                              case IDM_EXIT:

                                      DestroyWindow(hWnd);

                                      break;

                              default:

                                      return DefWindowProc(hWnd, message, wParam, lParam);

                       }

                       break;

               case WM_PAINT:

                       hdc = BeginPaint(hWnd, &ps);

                       Rectangle(hdc, 20, 20, 40, 40);

                       EndPaint(hWnd, &ps);

                       break;

               case WM_DESTROY:

                       PostQuitMessage(0);

                       break;

               default:

                       return DefWindowProc(hWnd, message, wParam, lParam);

        }

        return 0;

}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


다음은 우리가 가장 궁금해 할 만한 WinMain함수이다.

의외로 간단하다.


MyRegisterClass 함수와 MyRegisterClass_popup함수를 선언한 다음,

InitInstance, InitInstance_popup함수를 선언하고


메시지 루프를 돌리면 된다.


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// 04.cpp : 응용프로그램에대한진입점을정의합니다.

//

 

#include "stdafx.h"

#include "head.h"

 

int APIENTRY _tWinMain(HINSTANCE hInstance,

                     HINSTANCE hPrevInstance,

                     LPTSTR    lpCmdLine,

                     int       nCmdShow)

{

        UNREFERENCED_PARAMETER(hPrevInstance);

        UNREFERENCED_PARAMETER(lpCmdLine);

 

        // TODO: 여기에코드를입력합니다.

        MSG msg;

        HACCEL hAccelTable;

 

        // 전역문자열을초기화합니다.

        LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

        LoadString(hInstance, IDC_MY04, szWindowClass, MAX_LOADSTRING);

 

        MyRegisterClass_popup(hInstance);

        MyRegisterClass(hInstance);

 

        // 응용프로그램초기화를수행합니다.

        if (InitInstance_popup (hInstance, nCmdShow)==false || InitInstance (hInstance, nCmdShow)==false)

        {

               return FALSE;

        }

       

        hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MY04));

 

        // 기본메시지루프입니다.

        while (GetMessage(&msg, NULL, 0, 0))

        {

               if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

               {

                       TranslateMessage(&msg);

                       DispatchMessage(&msg);

               }

        }

 

        return (int) msg.wParam;

}