본문 바로가기
프로그래밍/Windows

C++ WinForm Frame

by 즉흥 2014. 7. 4.
728x90
반응형

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <windows.h>
 
//콜백함수
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam);
LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam);
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam);
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam);
LRESULT OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam);
 
HINSTANCE g_hInst;
PAINTSTRUCT ps;
HDC hdc;
 
 
typedef struct MESSAGEMAP{
    UINT iMessage;
    LRESULT(*lpfnMsgProc)(HWND, WPARAM, LPARAM);
}MESSAGEMAP;
 
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow){
    HWND hWnd;
    MSG Message;
    WNDCLASS WndClass;
    g_hInst = hInstance;
 
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hInstance = hInstance;
    WndClass.lpfnWndProc = (WNDPROC)WndProc;
    WndClass.lpszClassName = L"Reversing #2";
    WndClass.lpszMenuName = NULL;
    WndClass.style = CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&WndClass);
 
    hWnd = CreateWindow(L"Reversing #2", L"Reversing #2", WS_OVERLAPPEDWINDOW,
        7070490510,
        NULL, (HMENU)NULL, hInstance, NULL);
    ShowWindow(hWnd, nCmdShow);
 
 
    //메시지 루프
    while (GetMessage(&Message, NULL, 00)) {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    return Message.wParam;
}
 
//운영체제가 호출하는 CALLBACK함수 (메시지 처리)
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam){
    int i;
    static MESSAGEMAP MessageMaps[] = {    //콜백 함수 정리
        { WM_CREATE, OnCreate },
        { WM_COMMAND, OnCommand },
        { WM_PAINT, OnPaint },
        { WM_DESTROY, OnDestroy },
        { WM_SIZE, OnSize },
    };
    for (i = 0; i < sizeof(MessageMaps) / sizeof(MessageMaps[0]); ++i){
        if (MessageMaps[i].iMessage == iMessage){
            return (*MessageMaps[i].lpfnMsgProc)(hWnd, wParam, lParam);
        }
    }
    return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
 
LRESULT OnCreate(HWND hWnd, WPARAM wParam, LPARAM lParam){
    return 0;
}
 
LRESULT OnSize(HWND hWnd, WPARAM wParam, LPARAM lParam){
    return 0;
}
 
LRESULT OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam){
    switch (LOWORD(wParam)){
    }
    return 0;
}
 
LRESULT OnPaint(HWND hWnd, WPARAM wParam, LPARAM lParam){
    hdc = BeginPaint(hWnd, &ps);
    EndPaint(hWnd, &ps);
    return 0;
}
 
LRESULT OnDestroy(HWND hWnd, WPARAM wParam, LPARAM lParam){
    PostQuitMessage(0);
    return 0;
}
cs




#define WS_OVERLAPPEDWINDOW (WS_OVERLAPPED     | \
                             WS_CAPTION        | \
                             WS_SYSMENU        | \
                             WS_THICKFRAME     | \
                             WS_MINIMIZEBOX    | \
                             WS_MAXIMIZEBOX)



1
2
3
4
5
6
7
8
9
10
11
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
    switch (iMessage)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
 
    return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
cs




출처 : soen.kr 외 다수

728x90
반응형

'프로그래밍 > Windows' 카테고리의 다른 글

아스키코드 -> 유니코드 문자열 변환 함수  (0) 2015.06.03
WinAPI 콤보박스 생성 / ComboBox  (0) 2015.06.01
process list 출력  (2) 2015.05.20
how to create ListView on Visual C++  (0) 2015.05.20
사용자 입력 글자수 제한하기  (0) 2014.07.04
쓰레드 동기화와 WAIT_ABANDONED  (7) 2014.06.02
GetExitCodeProcess  (0) 2014.05.25
(싱글 더블 와이드) 함수 정리  (0) 2014.05.25
IPC MailSlot 메일 슬롯  (0) 2014.05.25
tchar.h  (1) 2014.05.13

댓글