home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / string / addatom.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.9 KB  |  102 lines

  1. /*
  2.  * Function (s) demonstrated in this program: AddAtom
  3.  * Compiler version: MSC v5.10
  4.  * Description: Program adds a character string to the atom table and creates
  5.  *              a new atom that uniquely identifies the string.
  6.  */
  7.  
  8. #include <windows.h>
  9. #include "addatom.h"
  10.  
  11. int     sprintf (LPSTR, LPSTR, int);
  12. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  13.  
  14. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  15. HANDLE      hInstance, hPrevInstance;
  16. LPSTR       lpszCmdLine;
  17. int         nCmdShow;
  18.   {
  19.   static char   szAppName [] = "AddAtom";
  20.   HWND        hWnd;
  21.   WNDCLASS    wndclass;
  22.   MSG msg;
  23.   HMENU hMenu;
  24.  
  25.   if (!hPrevInstance)
  26.     {
  27.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  28.     wndclass.lpfnWndProc   = WndProc;
  29.     wndclass.cbClsExtra    = 0;
  30.     wndclass.cbWndExtra    = 0;
  31.     wndclass.hInstance     = hInstance;
  32.     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  33.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  34.     wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  35.     wndclass.lpszMenuName  = NULL;
  36.     wndclass.lpszClassName = szAppName;
  37.  
  38.     if (!RegisterClass (&wndclass))
  39.       return FALSE;
  40.     }
  41.  
  42.   hMenu = LoadMenu (hInstance, "OurMenu");
  43.   hWnd = CreateWindow (szAppName, "AddAtom Demonstration",
  44.                       WS_OVERLAPPEDWINDOW,
  45.                       CW_USEDEFAULT, 0,
  46.                       CW_USEDEFAULT,  0,
  47.                       NULL, hMenu, hInstance, NULL);
  48.  
  49.   ShowWindow (hWnd, nCmdShow);
  50.   UpdateWindow (hWnd);
  51.  
  52.   while (GetMessage (&msg, NULL, 0, 0))
  53.     {
  54.     TranslateMessage (&msg);
  55.     DispatchMessage (&msg);
  56.     }
  57.   return (msg.wParam);
  58.   }
  59.  
  60. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  61. HWND     hWnd;
  62. unsigned iMessage;
  63. WORD     wParam;
  64. LONG     lParam;
  65.   {
  66.   int    AtomMaxSize = 20;
  67.   ATOM    lpIDForAtom;
  68.   WORD ActualAtomSize;
  69.   int    hToAtom;
  70.   BOOL    bTableAdded;
  71.   char  szBuff[20];
  72.  
  73.   switch (iMessage)
  74.     {
  75.     case WM_COMMAND:
  76.       if (wParam == IDM_EXECUTE)
  77.         {
  78.         SetFocus (hWnd);
  79.         lpIDForAtom = AddAtom ( (LPSTR)"Hello World");
  80.         ActualAtomSize = GetAtomName (lpIDForAtom, (LPSTR)szBuff, AtomMaxSize);
  81.         MessageBox (GetFocus (), (LPSTR)szBuff, (LPSTR)"Atom added was...", MB_OK);
  82.         hToAtom = GetAtomHandle (lpIDForAtom);
  83.         lpIDForAtom = DeleteAtom (lpIDForAtom);
  84.         if (lpIDForAtom == NULL)
  85.           MessageBox (GetFocus (), (LPSTR)"Success", (LPSTR)"Atom Deleted", MB_OK);
  86.         else
  87.           MessageBox (GetFocus (), (LPSTR)"Failure", (LPSTR)"Atom not deleted", MB_OK);
  88.         }
  89.       else
  90.         return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  91.       break;
  92.  
  93.     case WM_DESTROY:
  94.       PostQuitMessage (0);
  95.       break;
  96.  
  97.     default:
  98.       return DefWindowProc (hWnd, iMessage, wParam, lParam);
  99.     }
  100.   return (0L);
  101.   }
  102.