[Cmake] WinMain

William A. Hoffman billlist at nycap.rr.com
Mon Jun 7 11:11:36 EDT 2004


I found a QT example that did this:



int main( int argc, char **argv )
{
    QApplication app( argc, argv );
                MainMenu win;
                win.setCaption("titol de la finestra");
                win.setMaximumSize(0,0);
                //win.setMargin(0);
                app.setMainWidget( &win );
                win.show();
    return app.exec();
}


#if WINDOWS
#include <windows.h>
int APIENTRY WinMain( HINSTANCE hInstance,
                                          HINSTANCE hPrevInstance,
                                          LPSTR lpCmdLine,
                                          int nCmdShow)
{
        return main(nCmdShow, &lpCmdLine);
}




At 10:41 AM 6/7/2004, Nick Arini wrote:

>Hi Andy, 
>
>Thanks for your prompt reply. 
>
>I modified my main.cpp file based on the example you sent me. The resulting code is below. I am now getting strange compiler errors: 
>
>What am I missing? Sorry if this is not strictly a cmake question. 
>
>Nick 
>
>
>------ Build started: Project: viewer, Configuration: Release Win32 ------ 
>
>Compiling... 
>main.cpp 
>C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(143) : warning C4091: 'typedef ' : ignored on left of 'unsigned char' when no variable is declared 
>C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(143) : error C2143: syntax error : missing ';' before 'constant' 
>C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(143) : fatal error C1075: end of file found before the left brace '{' at 'C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinDef.h(30)' was matched 
>
>
>
><begin code> 
>
>#include "ImageViewer.h" 
>
>#include <qapplication.h> 
>
>
>int MyMain(int argc, char* argv[]) 
>{ 
>  QApplication myapp(argc, argv); 
>  
>  if ( argc <= 1 ) 
>    { 
>      // Create a window which looks after its own existance 
>      ImageViewer *mywidget = new ImageViewer(); 
>      QString title = "Image Viewer: "; 
>      title += "No image loaded"; 
>      mywidget->setCaption(title); 
>      mywidget->loadFile( "Resources/background.png" ); 
>          mywidget->setGeometry(50+(20), 50+(20), 256, 256); 
>      mywidget->setInitSize();  // snaps the window to the size of the image 
>      mywidget->show(); 
>
>    } else { 
>      for( int i=1; i< argc; i++ ) 
>        { 
>          ImageViewer *mywidget = new ImageViewer(); 
>          QString title = "Image Viewer: "; 
>          title += argv[i]; 
>          mywidget->setCaption(title); 
>          mywidget->loadFile( argv[i] ); 
>          mywidget->setGeometry(50+(i*20), 50+(i*20), 1000, 1000); 
>          mywidget->setInitSize();  // snaps the window to the size of the image 
>          
>          mywidget->show(); 
>        } 
>    } 
>
>  // handles shutdown of all windows 
>  QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit())); 
>
>
>  //  myapp.setMainWidget( mywidget ); 
>
>  // remember to show the widget 
>  //  mywidget->show(); 
>
>  return myapp.exec(); 
>
>} 
>
>
>// Now we need to set up the bits for the windows OS 
>    
>#ifdef _WIN32 
>#include <windows.h> 
>
>int __stdcall WinMain(HINSTANCE hInstance, 
>                      HINSTANCE hPrevInstance, 
>                      LPSTR lpCmdLine, int nShowCmd) 
>{ 
>  int          argc; 
>  int          retVal; 
>  char**       argv; 
>  unsigned int i; 
>  int          j; 
>
>  // parse a few of the command line arguments 
>  // a space delimites an argument except when it is inside a quote 
>
>  argc = 1; 
>  int pos = 0; 
>  for (i = 0; i < strlen(lpCmdLine); i++) 
>    { 
>    while (lpCmdLine[i] == ' ' && i < strlen(lpCmdLine)) 
>      { 
>      i++; 
>      } 
>    if (lpCmdLine[i] == '\"') 
>      { 
>      i++; 
>      while (lpCmdLine[i] != '\"' && i < strlen(lpCmdLine)) 
>        { 
>        i++; 
>        pos++; 
>        } 
>      argc++; 
>      pos = 0; 
>      } 
>    else 
>      { 
>      while (lpCmdLine[i] != ' ' && i < strlen(lpCmdLine)) 
>        { 
>        i++; 
>        pos++; 
>        } 
>      argc++; 
>      pos = 0; 
>      } 
>    } 
>
>  argv = (char**)malloc(sizeof(char*)* (argc+1)); 
>
>  argv[0] = (char*)malloc(1024); 
>  ::GetModuleFileName(0, argv[0],1024); 
>
>  for(j=1; j<argc; j++) 
>    { 
>    argv[j] = (char*)malloc(strlen(lpCmdLine)+10); 
>    } 
>  argv[argc] = 0; 
>
>  argc = 1; 
>  pos = 0; 
>  for (i = 0; i < strlen(lpCmdLine); i++) 
>    { 
>    while (lpCmdLine[i] == ' ' && i < strlen(lpCmdLine)) 
>      { 
>      i++; 
>      } 
>    if (lpCmdLine[i] == '\"') 
>      { 
>      i++; 
>      while (lpCmdLine[i] != '\"' && i < strlen(lpCmdLine)) 
>        { 
>        argv[argc][pos] = lpCmdLine[i]; 
>        i++; 
>        pos++; 
>        } 
>      argv[argc][pos] = '\0'; 
>      argc++; 
>      pos = 0; 
>      } 
>    else 
>      { 
>      while (lpCmdLine[i] != ' ' && i < strlen(lpCmdLine)) 
>        { 
>        argv[argc][pos] = lpCmdLine[i]; 
>        i++; 
>        pos++; 
>        } 
>      argv[argc][pos] = '\0'; 
>      argc++; 
>      pos = 0; 
>      } 
>    } 
>  argv[argc] = 0; 
>
>
>  // Initialize the processes and start the application. 
>  retVal = MyMain(argc, argv); 
>
>  // Delete arguments 
>  for(j=0; j<argc; j++) 
>    { 
>    free(argv[j]); 
>    } 
>  free(argv); 
>
>  return retVal;; 
>} 
>#else 
>int main(int argc, char *argv[]) 
>{ 
>  return MyMain(argc, argv); 
>} 
>#endif 
>
><end code> 
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake



More information about the Cmake mailing list