Why does creating a static window from a console app cause havok?
-
Why does the following code, when running, causes some programs to hang while starting (before presenting any UI), including Windows Explorer/Internet Explorer (when double-clicking an HTML file in Windows Explorer) and the AnalogX PacketMon installer[^]?
#include <iostream>
#include <tchar.h>
#include <windows.h>int _tmain(int argc, _TCHAR* argv[])
{
HWND gWnd = CreateWindow(_T("STATIC"), _T("SomeWindow"), WS_POPUP, 20, 20, 200, 200, 0, 0, 0, 0);
getchar();
return 0;
} -
Why does the following code, when running, causes some programs to hang while starting (before presenting any UI), including Windows Explorer/Internet Explorer (when double-clicking an HTML file in Windows Explorer) and the AnalogX PacketMon installer[^]?
#include <iostream>
#include <tchar.h>
#include <windows.h>int _tmain(int argc, _TCHAR* argv[])
{
HWND gWnd = CreateWindow(_T("STATIC"), _T("SomeWindow"), WS_POPUP, 20, 20, 200, 200, 0, 0, 0, 0);
getchar();
return 0;
}Why are you trying to create a GUI component in a console application?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
Why are you trying to create a GUI component in a console application?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.
What exactly is it that you are trying to do?
CreateWindow()
is a GUI, not a console, function that creates a window. It also sends messages (something that a console application knows nothing about) to the window's procedure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
I'm using a library (not easily modified) that does that call. If I change "STATIC" to "STATIC_" (or probably anything else), the problem disappears.
It sounds like the problem is to do with resource IDs. The tigress is here :-D
-
What exactly is it that you are trying to do?
CreateWindow()
is a GUI, not a console, function that creates a window. It also sends messages (something that a console application knows nothing about) to the window's procedure.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
I know it's not proper, but it's in a (internal) library that would be hard to modify. Because using something other than STATIC doesn't appear to cause problems, it seems like there might be a way to get it to work (a define? another header file?). I basically just want to understand why using STATIC causes problems and using anything else doesn't cause problems. I like to know the causes of problems, not just the solutions.
-
It sounds like the problem is to do with resource IDs. The tigress is here :-D
-
I know it's not proper, but it's in a (internal) library that would be hard to modify. Because using something other than STATIC doesn't appear to cause problems, it seems like there might be a way to get it to work (a define? another header file?). I basically just want to understand why using STATIC causes problems and using anything else doesn't cause problems. I like to know the causes of problems, not just the solutions.
IGx89 wrote: Because using something other than STATIC doesn't appear to cause problems... Have you entertained the thought that "doesn't appear" might be the key phrase here? Just because you do not see a problem does not mean a problem ceases to exist. IGx89 wrote: I like to know the causes of problems, not just the solutions. Unless you have not shown all of the code, you're trying to solve something that is the product of a bad design. Why are you trying, or even thinking that it's possible, to create a static window from within a console application? Much the same result can be achieved by trying to use
getch()
orprintf()
in a GUI application. Yes it might compile/link fine, but a "crash" of some sort is emminent.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D
-
It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D
:confused: "STATIC" is the type (e.g., listbox, button, edit) of window that is to be created. It is one of many predefined system classes. In his call to
CreateWindow()
, 0 (the 9th parameter) was used as the control id.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
-
It is to do with resource ID numbers, STATIC is used to define the resource id for static labels on forms. The tigress is here :-D
I don't believe that resource-ids are the problem: The control/resource-id is specified as the 10th parameter to CreateWindowEx. The STATIC you are seeing is the name of the window-class to create a window from - in this case, a static-control - so no problem there. Changing the text to _STATIC_ results in an invalid class-name and CreateWindowEx fails (returns NULL) so no window is created. I think the problem with the program is that a console-program does not run a message-pump, so it cannot receive or process windows messages. So all messages destined for the STATIC control do not get processed and the program/Windows hangs indefinitely. Solution: create separate thread to handle the GUI and create a message-pump (GetMessage/DispatchMessage) to handle GUI messages. or better yet, use a GUI program that's what they're meant for. James
http://www.catch22.net -
I don't believe that resource-ids are the problem: The control/resource-id is specified as the 10th parameter to CreateWindowEx. The STATIC you are seeing is the name of the window-class to create a window from - in this case, a static-control - so no problem there. Changing the text to _STATIC_ results in an invalid class-name and CreateWindowEx fails (returns NULL) so no window is created. I think the problem with the program is that a console-program does not run a message-pump, so it cannot receive or process windows messages. So all messages destined for the STATIC control do not get processed and the program/Windows hangs indefinitely. Solution: create separate thread to handle the GUI and create a message-pump (GetMessage/DispatchMessage) to handle GUI messages. or better yet, use a GUI program that's what they're meant for. James
http://www.catch22.net