Jump to content
  • Advertisement
Sign in to follow this  
methinks

Creating a window without WinMain

This topic is 4520 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

How would I create a window without using the winmain function? I know it can be done, libraries like SDL and GLUT do it, but I can't seem to find anything on it...

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by methinks
How would I create a window without using the winmain function? I know it can be done, libraries like SDL and GLUT do it, but I can't seem to find anything on it...


SDL DOES have a WinMain. Your tradition main(int, char*[]) is actually replaced by SDL (with a #define) to SDL_Main(int, char**), which gets called by SDL's own WinMain (if you don't believe me replace main with SDL_Main and see your code compile without erros). That's what SDLmain.lib is for - WinMain.

I'm not sure about GLUT, or the fact if you can make a window without WinMain. But maybe it's possible - I don't know.

Share this post


Link to post
Share on other sites
Just use the classic signature

int main()

and call the appropriate windowing functions. And then you get the console in the background.

Share this post


Link to post
Share on other sites
you make a window using main the same way you make a window using WinMain, except you need to get your HINSTANCE handle using GetModuleHandle(NULL)

Share this post


Link to post
Share on other sites
I think you can also close the console window while leaving your other window up. Can't remember what the api call for that is though....

Share this post


Link to post
Share on other sites
Quote:
Original post by Ximmer
you make a window using main the same way you make a window using WinMain, except you need to get your HINSTANCE handle using GetModuleHandle(NULL)


You stole the words right out of my mouth. :)

Share this post


Link to post
Share on other sites
It's not that hard to make a window. If you're worried about all the messy code, just throw all the code in another file and call it from the WinMain function. But SDL has some nice encapsulated windows stuff, so I'd go with that.

Share this post


Link to post
Share on other sites
Quote:
Original post by SirKnight
I think you can also close the console window while leaving your other window up. Can't remember what the api call for that is though....


FreeConsole() I do believe.

My engine, to be multiplatform, has WinMain in the lib file, inside that I call main which is user created.

Share this post


Link to post
Share on other sites
I think I have most of it figured out, but now I'm stuck with the WNDPROC
I think the problem is that the WNDPROC, being a callback function, shouldn't be a member of a class, as that messes up the pointer to it. How then do I go about declaring it?

Share this post


Link to post
Share on other sites
Say for example you have a class that creates your windowing stuff -- if you allow that when creating your window class you need to assign a function pointer to say which WNDPROC style callback is going to handle messages -- then you simply make your custom class take a function pointer which you then assign when you create the window class.

Eg. if you have a main() -- each unit that creates its own window needs its own wndproc, thus declare the wndproc locally and when you create your window class, pass in a pointer to the wndproc function and voila!

pseudo code like:

pre-declare wndproc;

int main(int argc, char **argv)
{
// do stuff.

createWindow("Window Name",pointer_to_local_wndproc,width,height,etc);
}

Making any sense? :)

~Shiny.

Note: if anything here sounds dodgy, let me know -- I don't want to give out bad advice :S

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!