home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / hooks / journal / app.c next >
Encoding:
C/C++ Source or Header  |  1988-01-12  |  3.4 KB  |  110 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.         /* ONLY ONE INSTANCE */
  37.         return FALSE;
  38.         }
  39.  
  40.     hWnd = CreateWindow((LPSTR)szAppName,
  41.                         (LPSTR)szMessage,
  42.                         WS_OVERLAPPEDWINDOW,
  43.                         400,               /*  x - ignored for tiled windows */
  44.                         0,                 /*  y - ignored for tiled windows */
  45.                         CW_USEDEFAULT,     /* cx - ignored for tiled windows */
  46.                         0,                 /* cy - ignored for tiled windows */
  47.                         (HWND)NULL,        /* no parent */
  48.                         (HMENU)NULL,       /* use class menu */
  49.                         (HANDLE)hInstance, /* handle to window instance */
  50.                         (LPSTR)NULL        /* no params to pass on */
  51.                         );
  52.  
  53.     /* Save instance handle for DialogBox */
  54.     hInst = hInstance;
  55.  
  56.     /* Insert "About..." into system menu */
  57.     hMenu = GetSystemMenu(hWnd, FALSE);
  58.     ChangeMenu(hMenu, 0, NULL, 999, MF_APPEND | MF_SEPARATOR);
  59.     ChangeMenu(hMenu, 0, (LPSTR)szAbout, IDSABOUT, MF_APPEND | MF_STRING);
  60.  
  61.     /* Make window visible according to the way the app is activated */
  62.     ShowWindow( hWnd, cmdShow );
  63.     UpdateWindow( hWnd );
  64.  
  65.     /* Polling messages from event queue */
  66.     while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  67.         TranslateMessage((LPMSG)&msg);
  68.         DispatchMessage((LPMSG)&msg);
  69.         }
  70.  
  71.     return (int)msg.wParam;
  72. }
  73. /*
  74. */
  75.  
  76.  
  77. /* Procedure called when the application is loaded for the first time */
  78. BOOL Init( hInstance )
  79. HANDLE hInstance;
  80. {
  81.     PWNDCLASS   pAPPClass;
  82.  
  83.     /* Load strings from resource */
  84.     LoadString( hInstance, IDSNAME, (LPSTR)szAppName, 10 );
  85.     LoadString( hInstance, IDSABOUT, (LPSTR)szAbout, 10 );
  86.     MessageLength = LoadString( hInstance, IDSTITLE, (LPSTR)szMessage, 15 );
  87.  
  88.     pAPPClass = (PWNDCLASS)LocalAlloc( LPTR, sizeof(WNDCLASS) );
  89.  
  90.     pAPPClass->hCursor        = LoadCursor( NULL, IDC_ARROW );
  91.     pAPPClass->hIcon          = LoadIcon( hInstance, MAKEINTRESOURCE(APPICON) );
  92.     pAPPClass->lpszMenuName   = (LPSTR)szAppName;
  93.     pAPPClass->lpszClassName  = (LPSTR)szAppName;
  94.     pAPPClass->hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  95.     pAPPClass->hInstance      = hInstance;
  96.     pAPPClass->style          = CS_HREDRAW | CS_VREDRAW;
  97.     pAPPClass->lpfnWndProc    = WndProc;
  98.  
  99.     if (!RegisterClass( (LPWNDCLASS)pAPPClass ) )
  100.         /* Initialization failed.
  101.          * Windows will automatically deallocate all allocated memory.
  102.          */
  103.         return FALSE;
  104.  
  105.     LocalFree( (HANDLE)pAPPClass );
  106.     return TRUE;        /* Initialization succeeded */
  107. }
  108. /*
  109. */
  110.