[Cmake] WinMain

Julien Jomier jjomier at cs.unc.edu
Mon Jun 7 14:28:42 EDT 2004


Hi Nick,

>How do I get rid of the command window without making my code platform
specific? 
I think by adding these lines:

IF(WIN32)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows") 
ENDIF(WIN32)

this should get rid of the command windows. At least it's working for me on
MSVC6 with Qt/Fltk.

Hope this helps,

Julien

-----Original Message-----
From: cmake-bounces at www.cmake.org [mailto:cmake-bounces at www.cmake.org] On
Behalf Of Nick Arini
Sent: Monday, June 07, 2004 10:41 AM
To: Andy Cedilnik
Cc: cmake at www.cmake.org
Subject: Re: [Cmake] WinMain



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>



More information about the Cmake mailing list