본문 바로가기
Code review

[WinApi]Dialog base start 2

by cafrisun 2009. 5. 27.
 
Dialog base application을 조금 변형..

#include
<windows.h>
#include <windowsx.h>   // for use the "HANDLE_MSG" macro
#include "resource.h"


//*** Global variable define ***//
HINSTANCE hInstance;
HWND hMainWnd;


//*** Function prototype define ***//
LRESULT CALLBACK MainDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
VOID OnCommand (HWND hWnd, int id,HWND hwndCtl, UINT codeNotify);
BOOL OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam);
VOID OnClose(HWND hWnd);


//*** CreteMainWindow() ***//
BOOL CreateMainWindow(int nCmdShow)
{
        RECT rc;

        hMainWnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MainDlg), NULL, (DLGPROC)MainDlgProc);

        GetWindowRect(hMainWnd, &rc);

        ShowWindow(hMainWnd, nCmdShow);

        UpdateWindow(hMainWnd);

        return TRUE;
}


//*** Entry point ***//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
        MSG message;
        HACCEL hAccel;

        hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCEL));

        CreateMainWindow(nShowCmd);

        while (GetMessage(&message, NULL, 0, 0))
        {
                if(!TranslateAccelerator(hMainWnd, hAccel, &message) && !IsDialogMessage(hMainWnd, &message))
                {
                        TranslateMessage(&message);
                        DispatchMessage(&message);
                }
        }

        return 0;
}


//*** Process the window messages ***//
LRESULT CALLBACK MainDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
        switch (uMsg)
        {
                HANDLE_MSG(hWnd, WM_INITDIALOG, OnInitDialog);
                HANDLE_MSG(hWnd, WM_COMMAND, OnCommand);
                HANDLE_MSG(hWnd, WM_CLOSE, OnClose);
        }
        return 0;
}


BOOL OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam)
{
        // initializing the dialog
        return FALSE;
}


VOID OnCommand (HWND hWnd, int id, HWND hwndCtl, UINT codeNotify)
{
        switch(id)
        {
                case IDOK :
                case IDCANCEL :
                        PostQuitMessage(0);
                        EndDialog(hWnd, 0);
                        break;
        }
}


VOID OnClose(HWND hWnd)
{
        PostQuitMessage(0);
        EndDialog(hWnd, 0);
}

반응형

'Code review' 카테고리의 다른 글

[WinApi]self deleting executables  (0) 2009.05.27
[C]time functions  (0) 2009.05.27
[WinApi]Dialog base start  (0) 2009.05.27