Автор: HNKTO
Дата сообщения: 23.04.2013 14:39
Можно вопрос от тупого чайника?
Не могу понять как использовать стандартный элемент управления Windows "Combo Box".
Кто-нибудь объяснит, что я делаю не так.
Код моей программы:
Код:
main.cpp
===================================
#include <windows.h>
#include "resource.h"
HINSTANCE hinst;
INT_PTR WINAPI MdlgFunc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndCombo, hwndList;
LRESULT lResult = 0;
char StrBuffer[300] = {0};
switch (uMsg)
{
case WM_INITDIALOG:
hwndList = CreateWindow("listbox", NULL, WS_CHILD | WS_VISIBLE | LBS_STANDARD, 20, 80, 200, 300, hDlg,(HMENU) 1, hinst, NULL);
hwndCombo = CreateWindow("COMBOBOX", NULL, CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE, 20, 20, 200, 30, hDlg, 0, hinst, NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL :
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
break;
case IDC_BUTTON1 :
GetDlgItemText(hDlg, IDC_EDIT1, StrBuffer, sizeof(StrBuffer));
if(StrBuffer != 0)
lResult = SendMessage(hwndCombo, LB_ADDSTRING, 0,(LPARAM) &StrBuffer);
break;
case IDC_BUTTON2 :
GetDlgItemText(hDlg, IDC_EDIT1, StrBuffer, sizeof(StrBuffer));
if(StrBuffer != 0)
lResult = SendMessage(hwndList, LB_ADDSTRING, 0,(LPARAM) &StrBuffer);
break;
case IDC_BUTTON3 :
break;
}
//сообщения самого комбобокса
if((HWND) lParam == hwndCombo)
{
switch (HIWORD(wParam))
{
case CBN_EDITCHANGE :
SendMessage(hwndCombo, WM_GETTEXT, sizeof(StrBuffer), (LPARAM) &StrBuffer);
SetDlgItemText(hDlg, IDC_EDIT1, StrBuffer);
break;
case CBN_DROPDOWN :
StrBuffer[0] = StrBuffer[0];
//none
break;
}
}
break;
case WM_NOTIFY:
break;
default:
break;
}
return(FALSE);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
hinst = hInstance;
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MdlgFunc);
}
============================================
resource.h //Собственно это и далее - сгенерено самой студией и я не вмешивался.
============================================
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by resource.rc
//
#define IDD_MAIN 101
#define IDC_EDIT1 1001
#define IDC_BUTTON1 1002
#define IDC_BUTTON2 1003
#define IDC_BUTTON3 1004
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1005
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
=============================================
resource.rc
=============================================
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Русский (Россия) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOGEX 0, 0, 317, 181
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_OVERLAPPEDWINDOW
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "ОК",IDOK,206,160,50,14
PUSHBUTTON "Отмена",IDCANCEL,260,160,50,14
EDITTEXT IDC_EDIT1,210,12,84,12,ES_AUTOHSCROLL
PUSHBUTTON "Button1",IDC_BUTTON1,210,30,72,12
PUSHBUTTON "Button2",IDC_BUTTON2,210,48,72,12
PUSHBUTTON "Button3",IDC_BUTTON3,210,66,72,12
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 310
TOPMARGIN, 7
BOTTOMMARGIN, 174
END
END
#endif // APSTUDIO_INVOKED
#endif // Русский (Россия) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED