Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Creating a window without WinMain


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 methinks   Members   -  Reputation: 221

Like
0Likes
Like

Posted 27 June 2006 - 01:40 PM

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

Sponsor:

#2 nullsquared   Members   -  Reputation: 122

Like
0Likes
Like

Posted 27 June 2006 - 01:43 PM

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.

#3 Boder   Members   -  Reputation: 937

Like
0Likes
Like

Posted 27 June 2006 - 01:46 PM

Just use the classic signature

int main()

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

#4 Ximmer   Members   -  Reputation: 314

Like
0Likes
Like

Posted 27 June 2006 - 01:48 PM

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)

#5 SirKnight   Members   -  Reputation: 316

Like
0Likes
Like

Posted 27 June 2006 - 01:49 PM

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

#6 taby   Members   -  Reputation: 380

Like
0Likes
Like

Posted 27 June 2006 - 01:57 PM

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. :)

#7 tendifo   Members   -  Reputation: 146

Like
0Likes
Like

Posted 27 June 2006 - 04:40 PM

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.

#8 Mike2343   Members   -  Reputation: 482

Like
0Likes
Like

Posted 27 June 2006 - 05:35 PM

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.

#9 methinks   Members   -  Reputation: 221

Like
0Likes
Like

Posted 28 June 2006 - 03:24 PM

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?

#10 Shiny   Members   -  Reputation: 456

Like
0Likes
Like

Posted 28 June 2006 - 03:33 PM

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
------------'C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg.' -Bjarne Stroustrup

#11 methinks   Members   -  Reputation: 221

Like
0Likes
Like

Posted 28 June 2006 - 03:51 PM

I tried that (I think...), but I get the following error message:

argument of type `LRESULT (dWindowsCommon::)(HWND__*, UINT, WPARAM, LPARAM)' does not match `LRESULT (*)(HWND__*, UINT, WPARAM, LPARAM)'

Again, this looks like a descreptancy between a plain function pointer and a pointer to a member of a class, even if it's the same class.

the function's name is "wndProc", declared as public of the class "dWindowsCommon"

Compiled using Code::blocks (ming compiler)

#12 Sr_Guapo   Members   -  Reputation: 876

Like
0Likes
Like

Posted 28 June 2006 - 04:04 PM

this may help.

#13 yckx   Prime Members   -  Reputation: 1291

Like
0Likes
Like

Posted 29 June 2006 - 03:37 AM

Quote:
Original post by methinks
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?


In addition to Sr_Guapo's link, there's also these (1, 2) on The Code Project, that can guide you in keeping your WNDPROC in a class.

#14 Rattrap   Members   -  Reputation: 2018

Like
0Likes
Like

Posted 29 June 2006 - 04:17 AM

The WndProc can only be a member if it is declared static. Also as long as your in 2000/XP, you don't actually need an HINSTANCE. It is ignored. This isn't true for 9x/ME.

[edit]

What you can do then is use the CREATESTRUCT and its lpCreateParams to pass the this pointer to WM_CREATE message (since hWnd doesn't exist yet). In every other case you can use allocate extra space using WNDCLASSEX's cbWndExtra and use SetWindowLongPtr/GetWindowLongPtr function and the GWLP_USERDATA to do this (plus some casting). You just need to allocate enough space to store a pointer. This is how I've been doing it in my windows class. This is because the static member WndProc wont have direct access to your member variables (unless they too are static).

#15 Colin Jeanne   Members   -  Reputation: 1114

Like
0Likes
Like

Posted 29 June 2006 - 04:46 PM

GWLP_USERDATA accesses the pointer-sized block of memory associated with each and every window. Using 0 in Set/GetWindowLongPtr() will access cbWndExtra.

#16 Rattrap   Members   -  Reputation: 2018

Like
0Likes
Like

Posted 30 June 2006 - 02:15 PM

Wow your right, I completely miss read the MSDN text on Get/Set WindowsLongPtr.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS