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

simpled 2013.06.23 16:01 조회 수 : 5888

1130815947126971346215836.jpg

04.exe



API를 이용한 popup 프로그램을 완성했다. (2011.09.22 10:07)

첫번째로 소개할 것은 head.h의 내용이다.

head.h를 만드는 버릇은 내가 api를 시작고 코드가 길어지면서 부터 길들여지게 되었다.

나는 API를 할 때 마다 stdafx.h(미리선언된 헤더파일)와 head.h만 선언함으로써, cpp코드의 선언부분를 깔끔하게 하려 노력했다.


각설하고, 바로 아래 보이는 것이 첫번째로 head.h의 내용이다.


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


// 리소스

#include "04.h"


// 변수클래스

#include "clValue_popup.h"

 

// 전역변수

#define MAX_LOADSTRING 100

HINSTANCE hInst;                                     // 현재인스턴스입니다.

HWND hWnd_popup, hWnd_Original;                      // hWnd 객체 변수 (각 윈도우의 개별적인 주소를 갖습니다.)

TCHAR szTitle[MAX_LOADSTRING];                       // 제목표시줄텍스트입니다.

TCHAR szWindowClass[MAX_LOADSTRING];                 // 기본창클래스이름입니다.

 

#include "WindFunc_popup.h"

#include "WindFunc_Original.h"



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


다음으로 바로 보여줄 코드는 clValue_popup.h 의 내용이다.

 

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



class clValue_popup

{

public:

        // popup 화면을중앙에띄우는역할을합니다.

        HWND hWnds;

        RECT reBase, rePopup;

 

public:

        // popup 화면의크기를결정합니다.

        int iPopup_Vertical;

        int iPopup_Horizontal;

       

public:

        // popup 화면에비트맵을띄우는역할을합니다.

        HDC MemDC;

        HBITMAP MyBitmap, OldBitmap;

        BITMAP bit;

        HFONT hFont, OldFont;

 

public:

        // popup 화면의비트맵개수와카운터를저장합니다.

        int iTimer_miliCount;

        int iTimer_Count;

        int iBitmap_Count;

        int iBitmapOfNumber;

 

public:

        TCHAR tcMessage[128];

        TCHAR tcCounter[128];

 

public:

        clValue_popup();

        clValue_popup(int _iBitmapOfNumber);

};

clValue_popup::clValue_popup()

{

        iTimer_miliCount=0;

        iTimer_Count=0;

        iBitmap_Count=0;

        iBitmapOfNumber=0;

}

 

clValue_popup::clValue_popup(int _iBitmapOfNumber)

{

        iTimer_miliCount=0;

        iTimer_Count=0;

        iBitmap_Count=0;

        iBitmapOfNumber=_iBitmapOfNumber;

}



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


다음으로 보여줄 코드는 WindFunc_popup.h 의 내용이다.

 

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



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

ATOM                          MyRegisterClass_popup(HINSTANCE hInstance);

BOOL                          InitInstance_popup(HINSTANCE, int);

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

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

 

 

ATOM MyRegisterClass_popup(HINSTANCE hInstance)

{

        WNDCLASSEX wcex;

 

        wcex.cbSize = sizeof(WNDCLASSEX);

 

        wcex.style                    = CS_HREDRAW | CS_VREDRAW;

        wcex.lpfnWndProc       = WndProc_popup;

        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     = szWindowClass;

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

 

        return RegisterClassEx(&wcex);

}

 

//

//   함수: InitInstance_popup(HINSTANCE, int)

//

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

//

//   설명:

//

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

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

//

BOOL InitInstance_popup(HINSTANCE hInstance, int nCmdShow)

{

   HWND hWnd;

       

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

       

   hWnd = CreateWindow(szWindowClass, szTitle, WS_POPUP,

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

       

   hWnd_popup = hWnd;

       

   if (!hWnd)

   {

      return FALSE;

   }

       

   ShowWindow(hWnd, nCmdShow);

   UpdateWindow(hWnd);

       

   return TRUE;

}

 

 

LRESULT CALLBACK WndProc_popup(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:

                       val.hWnds = GetDesktopWindow();

                       GetClientRect(val.hWnds, &val.reBase);

                       val.iPopup_Vertical=350;

                       val.iPopup_Horizontal=500;

                       SetRect(&val.rePopup,

                              -(val.iPopup_Horizontal),

                              -(val.iPopup_Vertical) ,

                              val.iPopup_Horizontal,

                              val.iPopup_Vertical);

                       SetWindowPos(hWnd, HWND_TOPMOST,

                              int((val.reBase.right/2.0)-(val.iPopup_Horizontal/2)),

                              int((val.reBase.bottom/2.0)-(val.iPopup_Vertical/2)),

                              int(val.rePopup.right),

                              int(val.rePopup.bottom), NULL);

                       SetTimer(hWnd, 1, 1, NULL);                  // 비트맵과텍스트를출력한다.

                       SetTimer(hWnd, 2, 1000, NULL);        // 1초단위를체크한다.

                       SendMessage(hWnd, WM_TIMER, 1, 1);

                       //SendMessage(hWnd, WM_TIMER, 2, 2);

                       break;

              

               case WM_SYSKEYDOWN:

                       break;

              

               case WM_KEYDOWN:

                       switch(wParam)

                       {

                              case VK_ESCAPE:

                                      PostQuitMessage(0);

                                      break;

                       }

                       break;

              

               case WM_TIMER:

                       switch(wParam)

                       {

                              case 1:

                                      hdc=GetDC(hWnd);

                                      val.MemDC=CreateCompatibleDC(hdc);

                                      val.MyBitmap=LoadBitmap(hInst,

                                             MAKEINTRESOURCE(IDB_BITMAP1+2));

                                      val.OldBitmap=(HBITMAP)SelectObject(val.MemDC, val.MyBitmap);

                                      GetObject(val.MyBitmap, sizeof(BITMAP), &val.bit);

                                      StretchBlt(hdc, 0, 0,val.rePopup.right, val.rePopup.bottom,

                                                             val.MemDC, 0, 0, val.bit.bmWidth, val.bit.bmHeight, SRCCOPY);

 

                                      val.hFont=CreateFont(15, 0,0,0, 0,0,0,0, HANGEUL_CHARSET, 0,0,0,

                                             VARIABLE_PITCH | FF_ROMAN, TEXT("돋움"));

                                      val.OldFont=(HFONT)SelectObject(hdc, val.hFont);

                                      SetBkMode(hdc, TRANSPARENT);

                                     

                                      wsprintf(val.tcCounter, TEXT("KNU :: Lab. for Manufacturing system"), val.iTimer_Count);

                                      TextOut(hdc, 10, 10, val.tcCounter, lstrlen(val.tcCounter));

                                     

                                      if(0<=val.iBitmap_Count && val.iBitmap_Count<1)

                                             wsprintf(val.tcCounter, TEXT("[%d][%d] Now Loading."), val.iTimer_miliCount, val.iTimer_Count);

                                      if(1<=val.iBitmap_Count && val.iBitmap_Count<2)

                                             wsprintf(val.tcCounter, TEXT("[%d][%d] Now Loading.."), val.iTimer_miliCount, val.iTimer_Count);

                                      if(2<=val.iBitmap_Count && val.iBitmap_Count<3)

                                             wsprintf(val.tcCounter, TEXT("[%d][%d] Now Loading..."), val.iTimer_miliCount, val.iTimer_Count);

                                     

                                      TextOut(hdc, 10, 30, val.tcCounter, lstrlen(val.tcCounter));

                                     

                                      SelectObject(hdc, val.OldFont);

                                      SelectObject(val.MemDC, val.OldBitmap);

                                      DeleteObject(val.hFont);

                                      DeleteObject(val.MyBitmap);

                                      DeleteDC(val.MemDC);

                                      ReleaseDC(hWnd, hdc);

                                      val.iBitmap_Count++;

                                      val.iTimer_miliCount++;

                                      if(val.iBitmap_Count > val.iBitmapOfNumber-1)

                                             val.iBitmap_Count=0;  

                                      break;

 

                              case 2:

                                      val.iTimer_Count++;

                                      if(val.iTimer_Count==5)

                                      {

                                             // SendMessage(hWnd, WM_DESTROY, 0, 0);

                                             ShowWindow(hWnd_popup, HIDE_WINDOW);

                                             ShowWindow(hWnd_Original, SHOW_OPENWINDOW);

                                             SetWindowPos(hWnd_Original, HWND_TOPMOST,

                                                     int((val.reBase.right/2.0)-(val.iPopup_Horizontal/2)),

                                                     int((val.reBase.bottom/2.0)-(val.iPopup_Vertical/2)),

                                                     int(val.rePopup.right),

                                                     int(val.rePopup.bottom), NULL);

                                      }

                                      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);

                       EndPaint(hWnd, &ps);

                       break;

               case WM_DESTROY:

                       KillTimer(hWnd, 2);

                       KillTimer(hWnd, 1);

                       PostQuitMessage(0);

                       break;

               default:

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

        }

        return 0;

}

 

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)

{

        UNREFERENCED_PARAMETER(lParam);

        switch (message)

        {

               case WM_INITDIALOG:

                       return (INT_PTR)TRUE;

 

               case WM_COMMAND:

                       if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)

                       {

                              EndDialog(hDlg, LOWORD(wParam));

                              return (INT_PTR)TRUE;

                       }

                       break;

        }

        return (INT_PTR)FALSE;

}