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
|
BOOL CALLBACK
MsgDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
// Text buffer to be filled with string user entered
// into edit control.
char msgText[256];
// Handles to the combo box controls.
static HWND hComboBox = 0; // question : ****must static??****
static HWND hEditBox = 0; // question :****must static??****
static HWND hAddButton = 0; // question :****must static??****
int index = 0;
//========================================
// below are no error
//========================================
switch( msg )
{
case WM_INITDIALOG:
// Controls are child windows to the dialog they lie on.
// In order to get and send information to and from a
// control we will need a handle to it. So save a handle
// to the controls as the dialog is being initialized.
// Recall that we get a handle to a child control on a
// dialog box with the GetDlgItem.
hComboBox = GetDlgItem(hDlg, IDC_COMBOBOX);
hEditBox = GetDlgItem(hDlg, IDC_EDIT_MSG);
hAddButton = GetDlgItem(hDlg, IDB_ADD_BUTTON);
return true;
case WM_COMMAND:
switch(HIWORD(wParam)) {
case CBN_SELENDOK:
index = SendMessage(hComboBox, CB_GETCURSEL, 0, 0);
SendMessage(hComboBox, CB_GETLBTEXT, (WPARAM)index, (LPARAM)msgText);
MessageBox(0, msgText, "Combo Box", MB_OK);
return true;
}
switch(LOWORD(wParam)) {
case IDB_ADD_BUTTON:
GetWindowText(hEditBox, msgText, 256);
if(strlen(msgText) > 0)
SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)msgText);
return true;
}
return true;
case WM_CLOSE:
DestroyWindow(hDlg);
return true;
case WM_DESTROY:
PostQuitMessage(0);
return true;
}
return false;
}
|