본문 바로가기

프로그래밍/시스템

[윈도우 프로그래밍] 다이얼로그박스 만들기

반응형

 

<취미와 성별정보를 입력받는 다이얼로그>

 

더보기
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
#include <windows.h>
#include <tchar.h>
#include "resource.h"
 
BOOL CALLBACK DlgProc(HWND hwnd,
    UINT iMsg, WPARAM wParam, LPARAM lParam);
 
 
 
int WINAPI _tWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow
)
{
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG3), NULL, DlgProc);
    return 0;
}
 
BOOL CALLBACK DlgProc(HWND hwnd,
    UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    TCHAR word[100];
 
    switch (iMsg)
    {
    case WM_INITDIALOG:
        return 1;
 
    case WM_COMMAND:
 
        switch (LOWORD(wParam))
        {
        
        case ID_BUTTON_COPY:
            GetDlgItemText(hwnd, IDD_EDIT_SOURCE, word, 100);
            SetDlgItemText(hwnd, IDC_EDIT_COPY, word);
            break;
 
        case ID_BUTTON_CLEAR:
            SetDlgItemText(hwnd, IDD_EDIT_SOURCE, _T(""));
            SetDlgItemText(hwnd, IDC_EDIT_COPY, _T(""));
            break;
 
        case ID_BUTTON_END:
            EndDialog(hwnd, 0);
            break;
 
        case IDCANCEL:
            EndDialog(hwnd, 0);
            break;
            
        }
        break;
    }
 
    return 0;
}
 
cs

 

 

 

 

 

 

 

<콤보 박스 컨트롤로 회원 명단 관리하기>

 

더보기
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
95
96
97
98
#include <windows.h>
#include <tchar.h>
#include "resource.h"
BOOL CALLBACK
DlgProc(HWND hwnd,
    UINT iMsg, WPARAM wParam,
    LPARAM lParam);
 
LRESULT CALLBACK
WndProc(HWND hwnd,
    UINT iMsg, WPARAM wParam,
    LPARAM lParam);
 
HINSTANCE hInst;
int WINAPI _tWinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow
)
{
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
    return 0;
}
LRESULT CALLBACK
WndProc(HWND hwnd,
    UINT iMsg, WPARAM wParam,
    LPARAM lParam)
{
    switch (iMsg)
    {
    case WM_LBUTTONDOWN:
        //다이얼로그박스를 띄우게
        DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1),
            hwnd, DlgProc);
        break;
    case WM_CREATE:
        break;
        //x버튼을 누르는 순간 발생
    case WM_DESTROY:
        //WM_QUIT보냄
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hwnd,
        iMsg, wParam, lParam);
}
 
BOOL CALLBACK
DlgProc(HWND hDlg,
    UINT iMsg, WPARAM wParam,
    LPARAM lParam)
{
    static HWND hCombo;
    static int selection;
    TCHAR name[20];
 
 
    switch (iMsg)
    {
 
 
    case WM_INITDIALOG:
        hCombo = GetDlgItem(hDlg, IDC_COMBO_LIST);
        return 1;
        
    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case IDC_BUTTON_INSERT:
                GetDlgItemText(hDlg, IDC_EDIT_NAME, name, 20);
                if ( _tcscmp(name, _T("")) )
                    SendMessage(hCombo, CB_ADDSTRING, 0, (LPARAM)name);
                
                return 0;
    
        case IDC_BUTTON_DELETE:
            SendMessage(hCombo, CB_DELETESTRING, selection, 0);
            return 0;
 
        case IDC_COMBO_LIST:
            if (HIWORD(wParam) == CBN_SELCHANGE)
                selection = SendMessage(hCombo, CB_GETCURSEL, 00);
            break;
 
        case IDCLOSE:
            EndDialog(hDlg, 0);
            return 0;
 
        case IDCANCEL: //x버튼이 발생시킴
            EndDialog(hDlg, 0);
            break;
        }
        break;
    }
    return 0;
}
 
cs

 

반응형