   Creating a window without WinMain
  Driven purely by curiosity, I have been trying to create a Win32 app that starts with int main() rather than WinMain and doesn't require the Windows App switch to my compiler. Here's what I have so far:#include <windows.h>LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam);bool Register(HINSTANCE HIn);int main(int,const char **av){    HMODULE HIn=GetModuleHandle(NULL);    FreeConsole();    HWND Hw;    MSG Msg;    DWORD TCount;    if(!Register(HIn)) return 0;    Hw=CreateWindowEx(WS_EX_TOPMOST,"MyWin","",WS_OVERLAPPEDWINDOW,  0,0,640,480,  GetDesktopWindow(),NULL,HIn,NULL);    if(Hw==NULL) return 0;    ShowWindow(Hw,SW_SHOW); UpdateWindow(Hw); SetFocus(Hw);    PeekMessage(&Msg,NULL,0,0,PM_NOREMOVE);    while(Msg.message!=WM_QUIT)   {   if(PeekMessage(&Msg,NULL,0,0,PM_REMOVE))  {  TranslateMessage(&Msg);  DispatchMessage(&Msg);  }   }    return Msg.wParam;}LRESULT CALLBACK WndProc(HWND Hw,UINT Msg,WPARAM wParam,LPARAM lParam){    switch(Msg)   {   default: return DefWindowProc(Hw,Msg,wParam,lParam);   }}bool Register(HINSTANCE HIn){    WNDCLASSEX Wc;    Wc.cbSize=sizeof(WNDCLASSEX);    Wc.style=0;    Wc.lpfnWndProc=WndProc;    Wc.cbClsExtra=0;    Wc.cbWndExtra=0;    Wc.hInstance=HIn;    Wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);    Wc.hCursor=LoadCursor(NULL,IDC_ARROW);    Wc.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);    Wc.lpszMenuName=NULL;    Wc.lpszClassName="MyWin";    Wc.hIconSm=LoadIcon(NULL,IDI_APPLICATION);    return RegisterClassEx(&Wc);}It sort of works, but if I run it from Explorer, it still creates a DOS window first, that then vanishes shortly after the Windows window appears.Is there any way to do this without that happening? I'm sort of toying with the idea of putting the window creation code in a library so my DirectX apps can just start at main() instead of having to copy paste the big old WinMain functions into each project.Ta. Paul   
  If you are starting from a Win32 console app, you are going to get the console.  You are just creating a window from within the console.Also as long as you are running from within Windows 2000 or XP, you don't need to worry about getting the HINSTANCE value.  You can just make this null.   ;  If you create a console subsystem application it will always create a console window when run from Explorer or otherwise run normally. Ironically, if you create a windows subsystem application it can create a console window if it wants one, but it doesn't need to.   ;  That's a shame. I had a feeling that might be the case.How do things like SDL and GLUT work then? I don't know much about them but from code I've seen, it appears to me you start with int main(etc).   ;  EasilyConfused,I'm not sure about those libraries, but with FLTK you can use 'int main' only if you link statically.  What is happening is that they have declared a 'WinMain' in their library, which calls your main and passes the arguments to it.  Its a pretty cool little trick, but it doesn't work with dynamically linked libraries.  I'm not sure if thats possible, but someone else might know.-brad   ;  What you want to do is possible, although not recommended.WinMain is actually only a layer ontop of other code that is called.  The function WinMainCRTStartup is actually called before WinMain, gets the instance, gets the parameters, etc.  What you could do is change the entry point to the program (in the linker tab), and handle it that way.  But this still gets somewhat ugly.Creating a library which handles the initialization is probably the safer way of handling things, and just include the library, and have your main function called that way.   ;  @GalapaegosAha.That is a neat trick but not really what I was looking for. Never mind. I suppose it was quite a lot to expect really.Cheers for the info.@NytegardI appreciate the suggestion, but I don't want to do it that badly [grin]. Looks like my idea can join the majority of the others in the bin then.   ;  I'm pretty sure that MinGW allows you to use main() (i.e. it will do the right thing if you use main()) instead of WinMain() for windows applications.