|
-
November 30th, 2012, 04:38 AM
#3
Re: Combobox Problem, new Window, new Combobox
i hope this works
Code:
#include <windows.h>
#define ID_LIST 1
#define ID_TEXT 2
HINSTANCE hChildInst = 0;
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "ComboBox App";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
WNDCLASSEX wincl2;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
/* The Window structure */
wincl2.hInstance = hChildInst;
wincl2.lpszClassName = "Proc2";
wincl2.lpfnWndProc = WindowProcedure;
wincl2.style = CS_DBLCLKS;
wincl2.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl2.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl2.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl2.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl2.lpszMenuName = NULL;
wincl2.cbClsExtra = 0;
wincl2.cbWndExtra = 0;
wincl2.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl2))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"ComboBox App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nFunsterStil);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
void FillListBox(HWND hwndList)
{
CHAR *pVarName[] = {"Item1", "Item2", "Item3", "Item4", "Item5"};
for(int i=0; i<5; i++)
SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM)pVarName[i]);
}
HWND hwndtest;
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndList, hwndText, hwndComboWindow;
int iIndex, iLength, cxChar, cyChar;
CHAR pVarName[30];
switch (message)
{
case WM_CREATE:
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits());
//Create Display Window
hwndText = CreateWindow(TEXT("static"),NULL, WS_CHILD | WS_VISIBLE |
SS_LEFT, cxChar, cyChar,
GetSystemMetrics(SM_CXSCREEN), cyChar,
hwnd, (HMENU)ID_TEXT,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
//Create ComboBox
hwndList = CreateWindow(TEXT("Combobox"), NULL, WS_CHILD | WS_VISIBLE |
LBS_STANDARD, cxChar, cyChar*3,
cxChar*16 + GetSystemMetrics(SM_CXVSCROLL),
cyChar*5, hwnd, (HMENU)ID_LIST,
(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
NULL);
//Populate ComboBox
FillListBox(hwndList);
//Set a Default Selection
SendMessage(hwndList, CB_SETCURSEL, 0, 0);
GetWindowText(hwndList, pVarName, 30);
SetWindowText(hwndText, pVarName);
return 0;
case WM_COMMAND:
if( LOWORD(wParam)==ID_LIST && HIWORD(wParam)==CBN_SELCHANGE )
{
GetWindowText(hwndList, pVarName, 30);
SetWindowText(hwndText, pVarName);
if( strcmp(pVarName,"Item3") == 0 ){
CreateWindowEx( WS_EX_CLIENTEDGE,
"Proc2",
(LPCSTR) pVarName,
WS_OVERLAPPEDWINDOW | WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS,
760,
0,
400,
440,
0,
NULL,
hChildInst,
NULL );
if( hwnd == NULL ){
MessageBox( NULL, "Create Window failed", "Error", MB_OK );
}
// UpdateWindow( hwndComboWindow );
}
if( strcmp(pVarName,"Item4") == 0 ){
CreateWindowEx( WS_EX_CLIENTEDGE,
"Proc2",
(LPCSTR) pVarName,
WS_OVERLAPPEDWINDOW | WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS,
760,
0,
400,
440,
hwnd,
NULL,
hChildInst,
NULL );
if( hwnd == NULL ){
MessageBox( NULL, "Create Window failed", "Error", MB_OK );
}
// UpdateWindow( hwndComboWindow );
}
}
break;
return 0;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|