Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

WinMain.cxx

Go to the documentation of this file.
00001 #ifdef WIN32 // only used for the windows app
00002 // $Header: /nfs/slac/g/glast/ground/cvs/gui/src/WinMain.cxx,v 1.1 2001/01/07 21:34:44 burnett Exp $
00003 
00004 #include "WinGui.h"
00005 #include "WinScene.h"
00006 #include "WinGUIostream.h"
00007 #include "gui/Menu.h"
00008 #include "gui/SubMenu.h"
00009 #include "resource.h"
00010 
00011 extern "C" { int main(int argn, char *argc[] );} 
00012 
00013 static char *szAppName = "WinGUI";
00014 
00015 
00016 //========================================================================
00017 //               Windows routines
00018 //========================================================================
00019 
00020 LRESULT CALLBACK   WndProc (HWND hWnd, unsigned Message,
00021                           WPARAM wParam, LONG lParam)
00022 {
00023     // decide which window this is, set appropriate scene to message
00024     WinScene* display = ( hWnd==WinGUI::s_hwnd  || WinGUI::s_hwnd==0)?
00025         WinGUI::s_graphics_window :
00026         WinGUI::s_2d_window;
00027     switch(Message)
00028     {
00029         
00030     case WM_COMMAND:
00031         WinGUI::s_gui->execute(wParam);
00032         break;
00033         
00034     case WM_PAINT:
00035         {
00036             PAINTSTRUCT ps;
00037             HDC hdc=  BeginPaint( hWnd, &ps);
00038             if(display)
00039                 display->redisplay(hdc);
00040             EndPaint(hWnd, &ps);
00041         }
00042         break;
00043     case WM_CHAR:
00044         {       // single non-special key
00045             char c = static_cast<char>(wParam);
00046             
00047             // check if is is registered with the Menu
00048             if( Menu::instance()->strike(c)) break;
00049             
00050             // no, just pass it to the display
00051             char cmd[2] = {c,0};
00052             if( display->do_command(cmd)>0 )
00053                 display->redisplay();
00054         }
00055         break;
00056     case WM_KEYDOWN:
00057         { char cmd[2] = {0,0};
00058         switch (wParam){
00059         case VK_LEFT: cmd[1]=75; break;
00060         case VK_RIGHT:cmd[1]=77; break;
00061         case VK_HOME: cmd[1]=71; break;
00062         case VK_UP:   cmd[1]=72; break;
00063         case VK_DOWN: cmd[1]=80; break;
00064         case VK_PRIOR:cmd[1]=73; break;
00065         case VK_NEXT: cmd[1]=81; break;
00066         }
00067         if (!cmd[1] )break;
00068         if( display->do_command(cmd)>0 )
00069             display->redisplay();
00070         
00071         }
00072         break;
00073     case WM_LBUTTONDOWN:
00074         {
00075             int xPos = LOWORD(lParam);  // horizontal position of cursor
00076             int yPos = HIWORD(lParam);  // vertical position of cursor
00077             display->mouseDown(xPos,yPos);
00078         }
00079         break;
00080     case WM_LBUTTONUP:
00081         {
00082             int xPos = LOWORD(lParam);  // horizontal position of cursor
00083             int yPos = HIWORD(lParam);  // vertical position of cursor
00084             display->mouseUp(xPos,yPos);
00085         }
00086         break;
00087     case WM_RBUTTONUP :
00088         {
00089 
00090             RECT winpos;
00091             ::GetWindowRect(hWnd, &winpos);
00092             ::TrackPopupMenu(
00093                 (HMENU)(display->menu()->tag()),  // handle to shortcut menu
00094                 TPM_LEFTALIGN | TPM_TOPALIGN,   // screen-position and mouse-button flags
00095                 winpos.left+LOWORD(lParam),       // horizontal position, in screen coordinates
00096                 winpos.top+HIWORD(lParam),        // vertical position, in screen coordinates
00097                 0,              // reserved, must be zero
00098                 hWnd,           // handle to owner window
00099                 0);
00100         }
00101         break;
00102     case WM_ACTIVATEAPP:
00103         {
00104             int fActive = LOWORD(wParam);           // activation flag 
00105             if( fActive)
00106                 ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
00107             break;
00108         }
00109     case WM_DESTROY:
00110         ::PostQuitMessage(0);
00111         WinGUI::s_quitting=true;
00112         GUI::running=false;
00113         break;
00114     case WM_SETCURSOR:  // mouse comes over window--make it the normal arrow
00115         {
00116             ::SetCursor(::LoadCursor(NULL, IDC_ARROW));
00117             break;
00118         }
00119     default:
00120         return ::DefWindowProc(hWnd, Message, wParam, lParam);
00121     }
00122     return 0;
00123 }  
00124 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00125 int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance,
00126                    LPSTR lpszCmdLine, int nCmdShow)
00127 {
00128     WinGUI::s_instance =  hThisInstance;  //need the instance
00129 
00130     // declare, and create a windows class for the main window
00131     WNDCLASS    wndClass;
00132 
00133     if (!hPrevInstance)    {
00134         wndClass.style          = CS_HREDRAW | CS_VREDRAW ;
00135         wndClass.lpfnWndProc    = WndProc;
00136         wndClass.cbClsExtra     = 0;
00137         wndClass.cbWndExtra     = 0;
00138         wndClass.hInstance      = hThisInstance;
00139         wndClass.hIcon          = wndClass.hIcon= LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON1));;
00140         wndClass.hCursor        = NULL;
00141         wndClass.hbrBackground  = (HBRUSH)GetStockObject (LTGRAY_BRUSH);
00142         wndClass.lpszMenuName   = NULL;
00143         wndClass.lpszClassName  = szAppName;
00144         
00145         if( !RegisterClass(&wndClass) ) return FALSE;
00146     }
00147     
00148     // create the main window to be used later
00149     WinGUI::s_hwnd = CreateWindow(szAppName, 
00150         "",
00151         (WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX |
00152         WS_MAXIMIZEBOX | WS_THICKFRAME | WS_SYSMENU),//WS_OVERLAPPEDWINDOW,
00153         20,  20, //CW_USEDEFAULT, 0,
00154         500, 500, //CW_USEDEFAULT, 0,
00155         NULL, NULL, 
00156         WinGUI::s_instance, 
00157         NULL);
00158 
00159     // setup the console window here
00160     WinGUI::s_text_window = new WinGUIostream( "wingui", WinGUI::s_hwnd, WinGUI::s_instance);
00161     
00162     //  parse command line by hand
00163     const unsigned MAX_TOKENS=20;
00164     char * _argv[MAX_TOKENS];
00165     _argv[0] = szAppName;
00166     int argc = 1;
00167     
00168     char seps[]   = " \t\n";
00169     
00170     /* Establish string and get the first token: */
00171     char * token = strtok( lpszCmdLine, seps );
00172     while(token != NULL && argc < MAX_TOKENS)
00173     {
00174         /* While there are tokens in "string" */
00175         _argv[argc++] = token;
00176         /* Get next token: */
00177         token = strtok( NULL, seps );
00178     }
00179 //    ::UserMain(argc, _argv);
00180     ::main(argc, _argv);
00181     return 0;
00182 }
00183 #endif

Generated at Wed Nov 21 12:20:55 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000