앞에서 까지는 Frame(윈도우 창)에서 표현하는 것이라고 한다면, 이번에는 새로운 창

에서 띄우는 Dialog 형태로 처리가 된다.


 메시지 박스는 새 창을 띄워서 어떤 선택을 하거나, 경고문을 보여주는 용도로 쓰인다.


 함수 원본.

 MessageBox(

HWDN hwnd, // 윈도우 핸들

LPCTSTR lpText, // 메세지창의 명칭

LPCTSTR lpCaption, // 메세지창 타이틀바

UINT uType); // 메세지창 종류.



  메시지 창을 띄우는 예제


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
#include <stdlib.h>
 
#include <tchar.h>
#include <windows.h>
 
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
 
WNDCLASS WndClass;
 
int numbers = 0;
 
int WINAPI WinMain(HINSTANCE hInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpszCmdParam,
            int nCmdShow)
{
    HWND hWnd;
    MSG Message;
    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="ApiBase";
    WndClass.lpszMenuName=NULL;
    WndClass.style=CS_HREDRAW|CS_VREDRAW;
 
    RegisterClass(&WndClass);
    
    hWnd = CreateWindow("ApiBase",
                        "Test",
                        WS_OVERLAPPEDWINDOW,
                        10,// X
                        100,// Y
                        400,// Width
                        400,// Height
                        NULL,
                        (HMENU)NULL,
                        hInstance,
                        NULL);
 
                        
    ShowWindow(hWnd,nCmdShow);
    
    while(GetMessage(&Message,0,0,0))
    {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    
    return Message.wParam;
}
 
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    long dwStyle;
    
    POINT polyline[5= {60,50,40,30,20};
    POINT polygon[5= {10,20,30,40,50};
    
    switch(iMessage)
    {
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_LBUTTONDOWN:
            hdc = GetDC(hWnd);
            if(MessageBox(hWnd, "시스템을 종료 하시겠습니까?""시스템 끄기", MB_YESNO) == IDYES)
            {
                MessageBox(hWnd, "시스템을 종료합니다.""시스템 종료.", MB_OK);
            }
            else
            {
                MessageBox(hWnd, "시스템 종료가 취소 되었습니다.""원래대로", MB_OK);
            }
            ReleaseDC(hWnd, hdc);
            break;
        case WM_PAINT:
            hdc = GetDC(hWnd);
            TextOut(hdc, 10050"Hello World",11);
            ReleaseDC(hWnd, hdc);
            break;
    }
    return DefWindowProc(hWnd,iMessage,wParam, lParam);
}
 
cs


Posted by JunkMam
,