home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / hooks / menuhelp / app.c next >
Encoding:
C/C++ Source or Header  |  1988-04-28  |  3.6 KB  |  113 lines

  1. /*  APP.c
  2.     Skeleton Application
  3.     Windows Toolkit Version 2.00
  4.     Copyright (c) Microsoft 1987
  5. */
  6.  
  7. #include "windows.h"
  8. #include "APP.h"
  9.  
  10. char szAppName[10];
  11. char szAbout[10];
  12. char szMessage[15];
  13. int MessageLength;
  14. HANDLE hInst;
  15. FARPROC lpprocAbout;
  16.  
  17. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  18. BOOL FAR PASCAL About( HWND, unsigned, WORD, LONG );
  19.  
  20.  
  21. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  22. HANDLE hInstance, hPrevInstance;
  23. LPSTR lpszCmdLine;
  24. int cmdShow;
  25. {
  26.     MSG   msg;
  27.     HWND  hWnd;
  28.     HMENU hMenu;
  29.  
  30.     if (!hPrevInstance) {
  31.         /* Call initialization procedure if this is the first instance */
  32.         if (!Init( hInstance ))
  33.             return FALSE;
  34.         }
  35.     else {
  36.         /* Copy data from previous instance */
  37.         GetInstanceData( hPrevInstance, (PSTR)szAppName, 10 );
  38.         GetInstanceData( hPrevInstance, (PSTR)szAbout, 10 );
  39.         GetInstanceData( hPrevInstance, (PSTR)szMessage, 15 );
  40.         GetInstanceData( hPrevInstance, (PSTR)&MessageLength, sizeof(int) );
  41.         }
  42.  
  43.     hWnd = CreateWindow((LPSTR)szAppName,
  44.                         (LPSTR)szMessage,
  45.                         WS_OVERLAPPEDWINDOW,
  46.                         400,               /*  x - ignored for tiled windows */
  47.                         0,                 /*  y - ignored for tiled windows */
  48.                         CW_USEDEFAULT,     /* cx - ignored for tiled windows */
  49.                         0,                 /* cy - ignored for tiled windows */
  50.                         (HWND)NULL,        /* no parent */
  51.                         (HMENU)NULL,       /* use class menu */
  52.                         (HANDLE)hInstance, /* handle to window instance */
  53.                         (LPSTR)NULL        /* no params to pass on */
  54.                         );
  55.  
  56.     /* Save instance handle for DialogBox */
  57.     hInst = hInstance;
  58.  
  59.     /* Insert "About..." into system menu */
  60.     hMenu = GetSystemMenu(hWnd, FALSE);
  61.     ChangeMenu(hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
  62.     ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT, MF_APPEND | MF_STRING);
  63.  
  64.     /* Make window visible according to the way the app is activated */
  65.     ShowWindow( hWnd, cmdShow );
  66.     UpdateWindow( hWnd );
  67.  
  68.     /* Polling messages from event queue */
  69.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  70.         TranslateMessage((LPMSG)&msg);
  71.         DispatchMessage((LPMSG)&msg);
  72.         }
  73.  
  74.     return (int)msg.wParam;
  75. }
  76. /*
  77. */
  78.  
  79.  
  80. /* Procedure called when the application is loaded for the first time */
  81. BOOL Init( hInstance )
  82. HANDLE hInstance;
  83. {
  84.     PWNDCLASS   pAPPClass;
  85.  
  86.     /* Load strings from resource */
  87.     LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
  88.     LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
  89.     MessageLength = LoadString( hInstance, IDSTITLE, (LPSTR)szMessage, 15 );
  90.  
  91.     pAPPClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  92.  
  93.     pAPPClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  94.     pAPPClass->hIcon          = LoadIcon( hInstance, (LPSTR)szAppName );
  95.     pAPPClass->lpszMenuName   = (LPSTR)szAppName;
  96.     pAPPClass->lpszClassName  = (LPSTR)szAppName;
  97.     pAPPClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  98.     pAPPClass->hInstance      = hInstance;
  99.     pAPPClass->style          = CS_HREDRAW | CS_VREDRAW;
  100.     pAPPClass->lpfnWndProc    = WndProc;
  101.  
  102.     if (!RegisterClass( (LPWNDCLASS)pAPPClass ) )
  103.         /* Initialization failed.
  104.          * Windows will automatically deallocate all allocated memory.
  105.          */
  106.         return FALSE;
  107.  
  108.     LocalFree( (HANDLE)pAPPClass );
  109.     return TRUE;        /* Initialization succeeded */
  110. }
  111. /*
  112. */
  113.