Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / running a window in a console-application Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
d3lphi

May 27, 2005, 03:17 AM

Hello.

I need to set up a window (receiving an OpenGL-RC) in a console-application (main ... ).

Does anyone know if there is a way to do that without converting it to a windowed application (WinMain ... ). I'm extending an existing tool that i may not redesign in that fashion.

(I'm over using GLUT, but still searching for alternatives.

Thanks in advance.
d3lphi

 
Japigeman

May 27, 2005, 03:37 AM

Yes, you can make as many windows as you want in a console app.

  1.  
  2. #include "stdafx.h"
  3. #include "windows.h"
  4. int main(int argc, char* argv[])
  5. {
  6.  
  7.         HWND h = CreateWindowEx(0, "BUTTON","TEST",WS_TILED,0,0,100,100,0,0,0,0);
  8.  
  9.         ShowWindow(h, SW_NORMAL);
  10.  
  11.         MSG msg;
  12.  
  13.         while(GetMessage(&msg, 0,0,0))
  14.         {
  15.                 DispatchMessage(&msg);
  16.                 if(msg.message==WM_LBUTTONDOWN) PostQuitMessage(0);
  17.         }
  18.  
  19.         return 0;
  20. }
  21.  


This code compiles and runs on a console app in MSVC++ 6.0
Be sure to include windows.h

(It creates a floating button, which isn't very helpfull, but still :p)

 
d3lphi

May 27, 2005, 03:54 AM

So it is ok to leave the hInstance-parameter hungry?

d3lphi

 
Japigeman

May 27, 2005, 03:59 AM

oops, no not really, but you can use GetModuleHandle(0) to get the parameter.
I believe this is also how WinMain gets it.

(Altough this example works without it)

 
d3lphi

May 27, 2005, 04:15 AM

Cool, i will test that.
(Why do i always skip to try the most straighforward things to do ..?)

Big tnx, Japigeman
delphi

 
Roel

May 27, 2005, 06:21 AM

note that there is no real difference made by the OS for console and windows programs regarding the entrypoint. WinMain(..) for windowed and main(args) for console are just called by some default library code your linker puts there for you. the code in the library calls a GetModuleHandle(NULL) (not 0, but NULL) indeed, among several other things.

 
Reedbeta

May 28, 2005, 01:23 AM

0 and NULL are the same in C++.

 
Roel

May 28, 2005, 04:49 AM

you are right :)

 
This thread contains 8 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.