home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / window / getwnlng.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.0 KB  |  99 lines

  1. /*
  2.  * GetWindowLong
  3.  *
  4.  * This program registers a window and creates it on the screen.  The
  5.  *  program then creates the window, shows the window, and then updates
  6.  *  the window.  The WinMain proceeds to execute the GetWindowLong function.
  7.  *  If the function call is successful, two message boxes are created which
  8.  *  show if the window is tiled and the pointer to the window procedure.
  9.  *
  10.  *  Windows Version 2.0 function demonstration application
  11.  *
  12.  */
  13.  
  14. #include "windows.h"
  15.  
  16. /* Global Variables */
  17. static HANDLE hInst;
  18. static HWND hWnd;
  19.  
  20. /* FORWARD REFERENCES */
  21. long FAR PASCAL WindowProc (HWND, unsigned, WORD, LONG);
  22.  
  23. /* WINMAIN */
  24. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  25. HANDLE hInstance, hPrevInstance;
  26. LPSTR lpszCmdLine;
  27. int cmdShow;
  28. {
  29.   MSG msg;
  30.   HDC hDC;           /* Handle to the Display Context.         */
  31.   LONG lLong;        /* LONG returned by GetWindowLong.         */
  32.   char szbuf[80];  /* String buffer used in Message Boxes. */
  33.  
  34.   if (!hPrevInstance)  {
  35.  
  36.      WNDCLASS rClass;
  37.  
  38.      rClass.lpszClassName = (LPSTR)"getwnlng";
  39.      rClass.hInstance      = hInstance;
  40.      rClass.lpfnWndProc   = DefWindowProc;
  41.      rClass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  42.      rClass.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);
  43.      rClass.lpszMenuName  = (LPSTR)NULL;
  44.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  45.      rClass.style          = CS_HREDRAW | CS_VREDRAW;
  46.      rClass.cbClsExtra      = 0;
  47.      rClass.cbWndExtra      = 0;
  48.  
  49.      RegisterClass((LPWNDCLASS)&rClass);
  50.  
  51.      }
  52.    else
  53.       ;
  54.  
  55.    hInst = hInstance;
  56.  
  57.    hWnd = CreateWindow((LPSTR) "getwnlng",
  58.                (LPSTR) "GetWindowLong",
  59.                WS_OVERLAPPEDWINDOW,            /* Use overlapped window.   */
  60.                CW_USEDEFAULT,                  /* Use default coordinates. */
  61.                CW_USEDEFAULT,                  /* Use default coordinates. */
  62.                CW_USEDEFAULT,                  /* Use default coordinates. */
  63.                CW_USEDEFAULT,                  /* Use default coordinates. */
  64.                (HWND)NULL,
  65.                (HMENU)NULL,
  66.                (HANDLE)hInstance,
  67.                (LPSTR)NULL
  68.              );
  69.  
  70.    ShowWindow(hWnd, cmdShow);
  71.  
  72.    UpdateWindow(hWnd);
  73.  
  74.    /* Get the style of the Window */
  75.  
  76.    lLong = GetWindowLong(hWnd, GWL_STYLE);
  77.  
  78.    /*  If the Window is tiled, say so; otherwise, report that it is not */
  79.  
  80.    if ((lLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW)
  81.    {  sprintf(szbuf,"%s","The Window has the Overlapped Style!");
  82.       MessageBox(NULL, (LPSTR)szbuf, (LPSTR)"GWL_STYLE", MB_OK);
  83.    }
  84.    else
  85.    {  sprintf(szbuf, "%s", "The Window is not Overlapped!!!");
  86.       MessageBox(NULL, (LPSTR)szbuf, (LPSTR)"GWL_STYLE", MB_OK);
  87.    }
  88.  
  89.    /*  Now, get the pointer to the function's window procedure.         */
  90.  
  91.    lLong = GetWindowLong(hWnd, GWL_WNDPROC);
  92.  
  93.    /*  Print out the address of the window procedure in a message box.    */
  94.  
  95.    sprintf(szbuf,"%s%lx","The Pointer to the Window Procedure is ",lLong);
  96.    MessageBox(NULL, (LPSTR)szbuf, (LPSTR)"GWL_WNDPROC", MB_OK);
  97.  
  98. } /* WinMain */
  99.