home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / biff / biff.c next >
C/C++ Source or Header  |  1989-03-16  |  5KB  |  184 lines

  1. /*  biff.c
  2.     biff Application
  3.     Windows Toolkit Version 2.10
  4.     Copyright (c) Microsoft 1989 */
  5.  
  6. /*  This IS the old HELLO application with
  7.     just one piece of code added to bring 
  8.     up a dialog box when a key is pressed.
  9.     See bigg.c for more information.
  10.  */
  11.  
  12. #include "windows.h"
  13. #include "biff.h"
  14.  
  15. char szAppName[10];
  16. char szAbout[10];
  17. char szMessage[20];
  18. int MessageLength;
  19.  
  20. HWND    hWnd;
  21. HANDLE  hInst;
  22. FARPROC lpprocAbout;
  23.  
  24. extern  void FAR GetBiff(HWND, HANDLE);
  25.  
  26. long FAR PASCAL BiffWndProc(HWND, WORD, WORD, LONG);
  27. BOOL FAR PASCAL BiffDlgProc(HWND, WORD, WORD, LONG);
  28.  
  29. BOOL FAR PASCAL About( HWND hDlg, WORD wMessage, WORD wParam, LONG lParam )
  30. {
  31.     switch (wMessage) {
  32.         case WM_INITDIALOG:
  33.             break;
  34.         case WM_COMMAND:
  35.             EndDialog(hDlg, TRUE);
  36.             break;
  37.         default:
  38.             return FALSE;
  39.             break;
  40.         }
  41.     return(TRUE);
  42. }
  43.  
  44.  
  45. void BiffPaint( hDC )
  46. HDC hDC;
  47. {
  48.     TextOut( hDC, 10, 10, 
  49.              (LPSTR)"Press any key to bring up dialog.", 33 );
  50. }
  51.  
  52.  
  53. /* Procedure called when the application is loaded for the first time */
  54. BOOL BiffInit( hInstance )
  55. HANDLE hInstance;
  56. {
  57.     PWNDCLASS   pbiffClass;
  58.  
  59.     /* Load strings from resource */
  60.     LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
  61.     LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
  62.     MessageLength = LoadString( hInstance, IDSTITLE, (LPSTR)szMessage, 15 );
  63.  
  64.     pbiffClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  65.  
  66.     pbiffClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  67.     pbiffClass->hIcon          = LoadIcon( hInstance, MAKEINTRESOURCE(BIFFICON) );
  68.     pbiffClass->lpszMenuName   = (LPSTR)NULL;
  69.     pbiffClass->lpszClassName  = (LPSTR)szAppName;
  70.     pbiffClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  71.     pbiffClass->hInstance      = hInstance;
  72.     pbiffClass->style          = CS_HREDRAW | CS_VREDRAW;
  73.     pbiffClass->lpfnWndProc    = BiffWndProc;
  74.  
  75.     if (!RegisterClass( (LPWNDCLASS)pbiffClass ) )
  76.         /* Initialization failed.
  77.          * Windows will automatically deallocate all allocated memory.
  78.          */
  79.         return FALSE;
  80.  
  81.     LocalFree( (HANDLE)pbiffClass );
  82.     return TRUE;        /* Initialization succeeded */
  83. }
  84.  
  85.  
  86. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  87. HANDLE hInstance, hPrevInstance;
  88. LPSTR lpszCmdLine;
  89. int cmdShow;
  90. {
  91.     MSG   msg;
  92.     HMENU hMenu;
  93.  
  94.     if (!hPrevInstance) {
  95.         /* Call initialization procedure if this is the first instance */
  96.         if (!BiffInit( hInstance ))
  97.             return FALSE;
  98.         }
  99.     else {
  100.         /* Copy data from previous instance */
  101.         GetInstanceData( hPrevInstance, (PSTR)szAppName, 10 );
  102.         GetInstanceData( hPrevInstance, (PSTR)szAbout, 10 );
  103.         GetInstanceData( hPrevInstance, (PSTR)szMessage, 15 );
  104.         GetInstanceData( hPrevInstance, (PSTR)&MessageLength, sizeof(int) );
  105.         }
  106.  
  107.     hWnd = CreateWindow((LPSTR)szAppName,
  108.                         (LPSTR)szMessage,
  109.                          WS_OVERLAPPEDWINDOW,
  110.                          CW_USEDEFAULT,
  111.                          CW_USEDEFAULT,
  112.                          CW_USEDEFAULT,
  113.                          CW_USEDEFAULT,
  114.                         (HWND)NULL,        /* no parent */
  115.                         (HMENU)NULL,       /* use class menu */
  116.                         (HANDLE)hInstance, /* handle to window instance */
  117.                         (LPSTR)NULL        /* no params to pass on */
  118.                         );
  119.  
  120.     /* Save instance handle for DialogBox */
  121.     hInst = hInstance;
  122.  
  123.     /* Insert "About..." into system menu */
  124.     hMenu = GetSystemMenu(hWnd, FALSE);
  125.     ChangeMenu(hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
  126.     ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT, MF_APPEND | MF_STRING);
  127.  
  128.     /* Make window visible according to the way the app is activated */
  129.     ShowWindow( hWnd, cmdShow );
  130.     UpdateWindow( hWnd );
  131.  
  132.     /* Polling messages from event queue */
  133.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  134.         TranslateMessage((LPMSG)&msg);
  135.         DispatchMessage((LPMSG)&msg);
  136.         }
  137.  
  138.     return (int)msg.wParam;
  139. }
  140.  
  141.  
  142. /* Procedures which make up the window class. */
  143. long FAR PASCAL BiffWndProc( HWND hWnd, WORD wMessage, WORD wParam, LONG lParam )
  144. {
  145.     PAINTSTRUCT ps;
  146.  
  147.     switch (wMessage)
  148.     {
  149.     case WM_SYSCOMMAND:
  150.         switch (wParam)
  151.         {
  152.         case IDSABOUT:
  153.             lpprocAbout = MakeProcInstance( (FARPROC)About, hInst );
  154.             DialogBox( hInst, MAKEINTRESOURCE(ABOUTBOX), hWnd, lpprocAbout );
  155.             FreeProcInstance(lpprocAbout);
  156.             break;
  157.         default:
  158.             return DefWindowProc( hWnd, wMessage, wParam, lParam );
  159.         }
  160.         break;
  161.  
  162.     case WM_DESTROY:
  163.         PostQuitMessage( 0 );
  164.         break;
  165.  
  166.     case WM_RBUTTONDOWN:
  167.     case WM_CHAR:
  168.  
  169.         GetBiff(hWnd, hInst);
  170.         break;
  171.  
  172.     case WM_PAINT:
  173.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  174.         BiffPaint( ps.hdc );
  175.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  176.         break;
  177.  
  178.     default:
  179.         return DefWindowProc( hWnd, wMessage, wParam, lParam );
  180.         break;
  181.     }
  182.     return(0L);
  183. }
  184.