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

  1. /*
  2.  
  3. Function(s) demonstrated in this program: GetWindow
  4.  
  5. Windows version:  2.03
  6.  
  7. Windows SDK version:  2.00
  8.  
  9. Compiler version:  C 5.10
  10.  
  11. Description:  This function returns a handle to the next or previous Window
  12.    in the Window Manager list.  If no match is found a NULL handle is
  13.     returned.
  14.  
  15. Additional Comments:
  16.  
  17. */
  18.  
  19. #define NOMINMAX
  20. #include <windows.h>
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include "GetWind.h"
  24.  
  25.  
  26. HWND     hWndParent1;
  27. HANDLE   hInstMain;
  28.  
  29. char     szOutputBuffer1 [70];
  30. char     szOutputBuffer2 [500];
  31.  
  32.  
  33. /****************************************************************************/
  34. /************************    Message Structure      *************************/
  35. /****************************************************************************/
  36.  
  37. struct { char *szMessage; }
  38.        Messages [] = {
  39. "About\0",
  40. "     This is a sample application to demonstrate the\n\
  41. use of the GetWindow Windows function.",
  42.  
  43. "Help Message",
  44. "     This program uses the GetWindow Windows function\n\
  45. to get a handle to the next window in the Window\n\
  46. manager handle list.  This handle is then displayed\n\
  47. in a message box.  The window corresponding to that\n\
  48. handle is then iconized.  Use the menu to invoke\n\
  49. this function.",
  50.  
  51. };    
  52.  
  53. /****************************************************************************/
  54.  
  55. void ProcessMessage (HWND, int); 
  56.  
  57. void ProcessMessage (hWnd, MessageNumber) 
  58.      HWND     hWnd;
  59.      int      MessageNumber;
  60. {
  61.      sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  62.      sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  63.      MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  64. }       
  65.  
  66. /****************************************************************************/
  67.  
  68. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  69.      HANDLE      hInstance, hPrevInstance ;
  70.      LPSTR       lpszCmdLine ;
  71.      int         nCmdShow ;
  72.      {
  73.      static char szAppName [] = "GetWind" ;
  74.      HWND        hWnd ;
  75.      WNDCLASS    wndclass ;
  76.      MSG msg;
  77.      short       xScreen, yScreen ;
  78.  
  79.      if (!hPrevInstance) 
  80.           {
  81.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  82.           wndclass.lpfnWndProc   = WndProc ;
  83.           wndclass.cbClsExtra    = 0 ;
  84.           wndclass.cbWndExtra    = 0 ;
  85.           wndclass.hInstance     = hInstance ;
  86.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  87.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  88.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  89.           wndclass.lpszMenuName  = szAppName ;
  90.           wndclass.lpszClassName = szAppName ;
  91.  
  92.           if (!RegisterClass (&wndclass))
  93.                return FALSE ;
  94.           }
  95.  
  96.      xScreen = GetSystemMetrics (SM_CXSCREEN) ;
  97.      yScreen = GetSystemMetrics (SM_CYSCREEN) ;
  98.  
  99.      hWndParent1 = CreateWindow (szAppName,     /* window class name       */
  100.                     "GetWindow",               /* window caption          */
  101.                     WS_OVERLAPPEDWINDOW,        /* window style            */
  102.                     CW_USEDEFAULT,              /* initial x position      */
  103.                     0,                          /* initial y position      */
  104.                     CW_USEDEFAULT,              /* initial x size          */
  105.                     0,                          /* initial y size          */
  106.                     NULL,                       /* parent window handle    */
  107.                     NULL,                       /* window menu handle      */
  108.                     hInstance,                  /* program instance handle */
  109.                     NULL) ;                     /* create parameters       */
  110.  
  111.      ShowWindow (hWndParent1, nCmdShow) ;
  112.      UpdateWindow (hWndParent1) ;
  113.  
  114.      hInstMain = hInstance;
  115.  
  116.      while (GetMessage(&msg, NULL, 0, 0))
  117.      {
  118.       TranslateMessage(&msg);
  119.       DispatchMessage(&msg);
  120.      } 
  121.      return (msg.wParam) ;     
  122.      }
  123.  
  124. /****************************************************************************/
  125.  
  126. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  127. HWND     hWnd ;
  128. unsigned iMessage ;
  129. WORD     wParam ;
  130. LONG     lParam ;
  131. {
  132.  HMENU       hMenu;
  133.  HWND        hNextWindow;
  134.  PAINTSTRUCT ps;
  135.  static int  xClient, yClient;
  136.  switch(iMessage)
  137.  {
  138.   case WM_CREATE:
  139.        hMenu = GetSystemMenu (hWnd, FALSE);
  140.  
  141.        ChangeMenu (hMenu, NULL, "&About", IDM_ABOUT, 
  142.                    MF_APPEND | MF_STRING);
  143.        break;
  144.  
  145.   case WM_SYSCOMMAND:
  146.        switch (wParam) {
  147.           case IDM_ABOUT:
  148.                ProcessMessage (hWnd, 0);
  149.                break;
  150.           default:
  151.                return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  152.        }
  153.        break;
  154.  
  155.   case WM_COMMAND:
  156.        switch (wParam) {
  157.           case IDM_GETWINDOW:
  158.                hNextWindow = GetWindow (hWnd, GW_HWNDNEXT);
  159.                sprintf (szOutputBuffer1, 
  160.                       "The Handle to the Next Window is %x", hNextWindow);
  161.                MessageBox (hWnd, szOutputBuffer1, "GetWindow", MB_OK);
  162.                if (!IsIconic (hNextWindow))
  163.                   ShowWindow (hNextWindow, SW_SHOWMINIMIZED);
  164.                break;
  165.  
  166.           case IDM_HELP:
  167.                ProcessMessage (hWnd, 2);
  168.                break;
  169.        }
  170.        break;
  171.  
  172.   case WM_PAINT:
  173.        BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  174.        EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  175.        break;
  176.  
  177.   case WM_DESTROY:
  178.        PostQuitMessage(0);
  179.        break;
  180.  
  181.   default:
  182.   {
  183.    return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  184.   }
  185.  }
  186.  return (0L); 
  187. }
  188.  
  189.  
  190.  
  191.