home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / utils / 6plus / abasica.c < prev    next >
C/C++ Source or Header  |  1995-05-18  |  11KB  |  106 lines

  1. //   AbasicA    1.00.00     9/12/93
  2.  
  3. #include "windows.h"                                                                    // All Windows programs must include this
  4. #include "AbasicA.h"                                                                     //  This is our private header file
  5.  
  6. HANDLE hKeyTranslatorTable;                                                     // This is the handle for what Windows calls ACCELERATORS
  7. HANDLE hInst;                                                                              // This handle is to make a copy of hInstance for our use
  8.  
  9. int PASCAL WinMain(hInstance,hPrevInstance,lpCmdLine,nCmdShow)      // Every program must have one of these
  10. HANDLE hInstance;                                                                     //  This is the handle of the CURRENT instance of the program
  11. HANDLE hPrevInstance;                                                             //  This is the handle of the LAST instance of the program
  12. LPSTR lpCmdLine;                                                                       //  This is a pointer to the command line string
  13. int nCmdShow;                                                                             //  This tells how the user wanted the program to start the window
  14.  
  15. {   MSG msg;                                                                                //  This is the variable that will hold the window's message
  16.     HWND hwnd;                                                                          //  This is the variable that will hold the window's handle
  17.  
  18.     if ( !hPrevInstance ) {                                                               //  If there is NOT a previous instance, register the window's class
  19.         WNDCLASS    wc;                                                              //  Variable to hold the window's class info
  20.         wc.style = 0;                                                                        //  Set initial window style
  21.         wc.lpfnWndProc = MainWndProc;                                      //  Set where WinMain's messages get dispatched to
  22.         wc.cbClsExtra = 0;                                                              //  Class extra storage if you need it
  23.         wc.cbWndExtra = 0;                                                           //  window extra if you need it
  24.         wc.hInstance = hInstance;                                                 //  Tells Windows what Instance is registering this window's class
  25.         wc.hIcon = LoadIcon ( hInstance,"MYICON" );                 //  Load an icon to use
  26.         wc.hCursor = LoadCursor ( NULL, IDC_ARROW );            //  Load a cursor to use
  27.         wc.hbrBackground = GetStockObject(WHITE_BRUSH);  //  Load a brush to paint the background
  28.         wc.lpszMenuName = "AbasicAMenu";                               //  Load a menu to use
  29.         wc.lpszClassName = "AbasicAWClass";                            //  What we will call our window's class
  30.         if(!RegisterClass(&wc))                                                        //  If the class doesn't register right for ant reason
  31.             return(FALSE);}                                                              //  Exit and tell Windows to blow it all away
  32.  
  33.     hInst = hInstance;                                                                          //  Make a copy of hInstance
  34.     hKeyTranslatorTable = LoadAccelerators(hInst,"AbasicAAcc");    //  Load our key translator table
  35.                                                                                                           //  Then create our main window
  36.     hwnd = CreateWindow("AbasicAWClass", "AbasicA", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300, NULL, NULL, hInstance, NULL);
  37.     if(!hwnd)                                                                                         //  If creating the window fails
  38.         return(FALSE);                                                                           //  Exit and tell Windows to blow it all away
  39.  
  40.     ShowWindow(hwnd,nCmdShow);                                                 //  Now show the window
  41.     UpdateWindow(hwnd);                                                                 //  Update it in case something changed
  42.  
  43.     while(GetMessage(&msg, NULL, 0, 0)){                                        //  Go get a message from Windows
  44.         if(!TranslateAccelerator(hwnd, hKeyTranslatorTable, &msg)){   //  If NOT a translated message
  45.             TranslateMessage(&msg);                                                     //  Do local translation if any
  46.             DispatchMessage(&msg);}}                                                   //  Then dispatch it to WinMainProc
  47.     return(msg.wParam);}                                                                    //  And send the wParam back to Windows
  48.  
  49.  
  50. long FAR PASCAL MainWndProc ( hWnd, message, wParam, lParam )    //  This is where your program does it's work
  51.                                                                                                                    //  By acting on Windows events
  52. HWND hWnd;                                                                                   //  Variable to hold the window's handle (can be one or many)
  53. UINT message;                                                                                  //  Variable to hold the message
  54. WPARAM wParam;                                                                           //  Variable to hold the word paramerter (32 bits in NT)
  55. LPARAM lParam;                                                                               //  Variable to hold the long paramerter
  56.  
  57. {   FARPROC lpProcAbout;                                                               //  Variable to hold the pointer to the about routine
  58.     switch ( message ) {                                                                      //  Switch the message to check it against our choices
  59.         case WM_COMMAND :                                                           //  If it is a COMMAND message
  60.             switch (LOWORD(wParam)){                                                //  Switch it to check it against our commands
  61.  
  62.                 case IDM_ABOUT :                                                         //  If the user clicked ABOUT
  63.                     lpProcAbout = MakeProcInstance (About, hInst);        //  Have Windows load code and give us a pointer
  64.                     DialogBox (hInst, "AboutBox", hWnd, lpProcAbout);   //  Have Windows display the dialog box
  65.                     FreeProcInstance (lpProcAbout);                                 //  When done have Windows discard it
  66.                     break;                                                                          //  break stop code execution here
  67.  
  68.                 case IDM_EXIT :                                                             //  If the user clicked EXIT
  69.                     DestroyWindow ( hWnd ) ;                                          //  Tell Windows to destroy the window
  70.                     break ;                                                                        //   break ...
  71.  
  72.                 default :                                                                          //  If what the user did a command we don't handle
  73.                     return ( DefWindowProc ( hWnd, message, wParam, lParam ) ) ; }     //  Send it back to Windows
  74.             return (0);                                                                            //  If the program gets here something bad happened
  75.                                                                                          
  76.         case WM_CLOSE :                                                                //  User clicked on the CLOSE in the COMMAND MENU
  77.             DestroyWindow ( hWnd ) ;                                                 //  Tell Windows to destroy the window
  78.             break ;
  79.  
  80.         case WM_DESTROY :                                                          //  After destroting the window Windows send this
  81.             PostQuitMessage ( 0 ) ;                                                      //  before it destroys our code here
  82.             break ;                                                                                //  If that is what we want, we return a 0
  83.  
  84.         default :                                                                                               //  If the user did something we don't handle
  85.             return ( DefWindowProc ( hWnd, message, wParam, lParam ) ) ; } //  Send the message back to Windows
  86.     return ( 0 ) ;}                                                                                            //  If it gets here we destroy the thing
  87.  
  88.  
  89. BOOL FAR PASCAL About ( hDlg, message, wParam, lParam )     //  The about box code
  90. HWND hDlg ;                                                                                  //  This doesn't do much
  91. unsigned message ;                                                                         //  A message box would do just as well
  92. WORD wParam ;                                                                             //  But the about box is always added to samples
  93. LONG lParam ;                                                                                 //  As an example of how your program should
  94. {   switch ( message ) {                                                                     //  Handle dialog boxes in general
  95.  
  96.         case WM_INITDIALOG :                                                         //  When Windows fires up a dialog box
  97.             return ( TRUE ) ;                                                                   //  It sends a INIT message so you do special setup
  98.                                                                                                          
  99.         case WM_COMMAND :                                                           //  This works the same as commands
  100.             if ( wParam == IDOK || wParam == IDCANCEL ) {                 //  In your main window
  101.                 EndDialog( hDlg, TRUE ) ;                                               //  You handle the responses 
  102.                 return ( TRUE ) ; }                                                            //  That you want to here
  103.             return ( TRUE ) ; }                                                                //  OK and CANCEL are it for this one
  104.     return ( FALSE ) ;}
  105.  
  106.