Reputation:
I am trying to display a combobox window as you can see I set hWndComboBox
as my second window and I am using ShowWindow()
function and it does not really show anything when I compile and run the code? What should I add more?
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstace, LPSTR lpCommand, int nCmdLine)
{
HWND window;
int xpos = 100; // Horizontal position of the window.
int ypos = 100; // Vertical position of the window.
int nwidth = 200; // Width of the window
int nheight = 200; // Height of the window
HWND hwndParent = window; // Handle to the parent window
MSG message;
WNDCLASSEX wndClass;
wndClass.cbSize = sizeof(WNDCLASSEX);
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.style = 0;
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = wndCll;
wndClass.lpszClassName = classNoOne;
wndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MYMENU);
wndClass.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PENGUIN_ICON));
wndClass.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PENGUIN_ICON), IMAGE_ICON, LR_DEFAULTSIZE, LR_DEFAULTSIZE, 0);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW-1);
if(!RegisterClassEx(&wndClass)){
printf("No wndclass");
}
window = CreateWindowEx(WS_EX_CLIENTEDGE, classNoOne, "Start Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 500, NULL, NULL, hInstance, NULL);
//create the window
HWND hWndComboBox = CreateWindow(WC_COMBOBOX, "name of the combobox", CBS_DROPDOWN | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE , xpos, ypos, nwidth, nheight, hwndParent, NULL, hInstance, NULL);
TCHAR Planets[9][10] = {
TEXT("MERCURY"), TEXT("VENUS"), TEXT("Terra"), TEXT("MARS"), TEXT("JUPITER"), TEXT("SATURN"), TEXT("URANUS"), TEXT("NEPTUNE"), TEXT("PLUTO")
};
//these are the list elements
TCHAR A[16];
int k = 0;
memset(&A, 0, sizeof(A));
//allocate memory
for(k = 0; k<=8; k+=1){
strcpy(A, (TCHAR *)Planets[k]);
SendMessage(hWndComboBox,(UINT) CB_ADDSTRING,(WPARAM) 0,(LPARAM) A);
}
SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)2, (LPARAM)0);
ShowWindow(hWndComboBox, nCmdLine);
//ShowWindow(window, nCmdLine);
if(window == NULL){
printf("window is NULL");
}
while(GetMessage(&message, NULL, 0, 0) > 0){
if(!IsDialogMessage(dialogSmall, &message)){
TranslateMessage(&message);
DispatchMessage(&message);
}
}
return message.wParam;
}
Upvotes: 0
Views: 106
Reputation: 61969
Programming languages do not work like mathematics. In mathematics you can say x = y; and then say y = 5; and then you can infer that x must be 5.
In programming languages however, when you say HWND hwndParent = window;
then hwndParent
takes the value that window
had at the moment of the assignment, so if you later actually initialize window
with window = ...
you cannot expect the value of hwndParent
to suddenly become meaningful. It will stay uninitialized, since window
was uninitialized at the time of the assignment.
Hint: if you have been able to do HWND hwndParent = window;
when window
was uninitialized, this means that you received no warning about it. Which in turn means that you have not configured your compiler to issue warnings when you do things like that. Do not try to program without warnings. You will never accomplish much this way.
Upvotes: 1