Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Utwo

Simplifying Win32.

This topic is 5736 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

...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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Awesome. Thanks for the help, guys.

I actually enjoy discussing it, more than anything else. It helps to solidify the concepts into my mind.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!