In my basic windows application I have a parent window and a window class. Does windows 'tie' the window class and the main window together when registerclass is called?
In my basic windows application I have a parent window and a window class. Does windows 'tie' the window class and the main window together when registerclass is called?
I may be understanding the question wrong so bear with me. RegisterClass ties the name of the class to the HINSTANCE unless otherwise told not to. When you create your main window you are creating a window that fits the specification of your WNDCLASS/WNDCLASSEX structure. As soon as the HINSTANCE that registered a class is no more that class is freed. A registered class works exactly the same as the pre-existing window type (i.e edit, combo, edit, tab, etc.). The only difference is that yours is temporary, and will only exist as long as the thread that created it. Understand?
CreateWindow and CreateWindowEx take a class name as a parameter. that's what ties it in. unless I understood you wrong.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
No no you guys answered perfectly, you're both awesome, thanks for clarifying that for me.
What are the differences between the WNDCLASS structure and the WNDCLASSEX structure?
LOL...you need to ask!!?
WNDCLASSEX is an extended WNDCLASS
Code:typedef struct _WNDCLASS { UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HANDLE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; } WNDCLASS; typedef struct _WNDCLASSEX { UINT cbSize; UINT style; WNDPROC lpfnWndProc; int cbClsExtra; int cbWndExtra; HANDLE hInstance; HICON hIcon; HCURSOR hCursor; HBRUSH hbrBackground; LPCTSTR lpszMenuName; LPCTSTR lpszClassName; HICON hIconSm; } WNDCLASSEX;
Though you might want to look into UnregisterClass() to make sure everything is freed as it should be.Originally posted by master5001
As soon as the HINSTANCE that registered a class is no more that class is freed.
"Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C
You are absolutely correct johnnie. Like a had mensioned earlier you can make classes that are not dependant on the hinstance. If you use the option CS_GLOBALCLASS for the style member of your WNDCLASS/WNDCLASSEX structure you will have to use UnregisterClass() to do cleanup. Also when a program ends abnormally (like a seg fault or something) windows isn't always able to clean up your classes. So it is a good idea for you to control your program, not the os.
FYI, for any parameter asking for an HINSTANCE you can substitute a stored HINSTANCE with GetModuleHandle(NULL).
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }