Simplifying Win32.
...or one aspect of it.
Basically, I''m a Win32 newb and I''m finding myself typing a lot of redundant stuff every time I fill out the WNDCLASSEX struct. For example, cbSize is always sizeof(WNDCLASSEX) and cbWndExtra and cbClsExtra are always 0. So, instead of typing this all out each and every time, I''ve decided to make a function that does it for me, which asks for only the pertanent data, and then registers and creates my window. I know that I may appreciate the flexability of specifying each of these later on, but while I''m in my newb stage I''d better-appreciate the lack of extraneous typing.
I start with creating the WNDCLASSEX struct, and then I pass it to the function by reference. I''m not too familiar with resources yet, so I''ve decided to use LoadIcon() for specifying the icons. I''d like to pass the IDI_FOO to my function (rather than passing LoadIcon()), but I don''t know what datatype it is. Will any number data type suffice? An unsigned int?
Also, will I have any trouble calling registering this class and showing the window within this same function? I can pass the HWND to my function by reference as well, and then assign it to the return value of CreateWindowEx(), so that even when my function returns and everything within is out of scope, the calling function (WinMain() or whatever) will still have a handle to the window that was created.
Do you forsee any problems with this plan?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Fisrt, it''s unnessicary to keep the WNDCLASSEX structure around, make it local to the function.
For the icon, I don''t think it is possible to just pass IDI_x to it. I''ve always used LoadIcon().
You plan for creating the window and the class in the same function is will work fine.
For the icon, I don''t think it is possible to just pass IDI_x to it. I''ve always used LoadIcon().
You plan for creating the window and the class in the same function is will work fine.
Awesome. Thanks.
That makes things simpler. I'll just create the WNDCLASSEX in my function.
Here's what my plan was for the IDI_FOO:
void MakeWind(UINT iconID)
{
...
myclass.hIconSm = LoadIcon(NULL, iconID);
...
} // end MakeWind
Would that work? Is UINT a valid datatype?
[edited by - utwo on December 6, 2002 11:46:30 AM]
That makes things simpler. I'll just create the WNDCLASSEX in my function.
Here's what my plan was for the IDI_FOO:
void MakeWind(UINT iconID)
{
...
myclass.hIconSm = LoadIcon(NULL, iconID);
...
} // end MakeWind
Would that work? Is UINT a valid datatype?
[edited by - utwo on December 6, 2002 11:46:30 AM]
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Make the datatype HICON or something and have your function like this:
fillwndclass(&window_class, LoadIcon(blah) );
That way, you can load the icon any way you want.
[edited by - Kurioes on December 6, 2002 11:49:02 AM]
fillwndclass(&window_class, LoadIcon(blah) );
That way, you can load the icon any way you want.
[edited by - Kurioes on December 6, 2002 11:49:02 AM]
Ok, good deal. I was hoping to avoid having to make a function call within the function call, only because I think it looks ugly, but I suppose it makes more sense. Using your method, I can take advantage of resources when I get to that point, no?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
LoadIcon''s prototype:
HICON LoadIcon( HINSTANCE hInstance, char *IconName );
For hInstance, you''d generally use GetModuleHandle(0), so instaed of a HICON parameter, a char* would do.
WndClassFilInStuff(WNDCLASSEX &wc, char *Icon, stuff...)
{
wc.hIcon = LoadIcon(GetModuleHandle(0), Icon);
}
You could of course pass the hInstance parameter to WndClassFillStuff as well but that''ll be a mess.
HICON LoadIcon( HINSTANCE hInstance, char *IconName );
For hInstance, you''d generally use GetModuleHandle(0), so instaed of a HICON parameter, a char* would do.
WndClassFilInStuff(WNDCLASSEX &wc, char *Icon, stuff...)
{
wc.hIcon = LoadIcon(GetModuleHandle(0), Icon);
}
You could of course pass the hInstance parameter to WndClassFillStuff as well but that''ll be a mess.
Awesome. Thanks for the help, guys.
I actually enjoy discussing it, more than anything else. It helps to solidify the concepts into my mind.
I actually enjoy discussing it, more than anything else. It helps to solidify the concepts into my mind.
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
I''ve never used GetModuleHandle(0) before. Is it just a function that returns the handle to the instance of the application? Can it be used for CreateWindowEx() as well?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
quote: Original post by Utwo
I''ve never used GetModuleHandle(0) before. Is it just a function that returns the handle to the instance of the application? Can it be used for CreateWindowEx() as well?
No, GetModuleHandle returns an HMODULE, CreateWindowEx needs an HINSTANCE. There might be a function that lets you get the HINSTANCE, but I''ve never found it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement