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

  1. /*
  2.  *  Function Name:   EnumTaskWindows
  3.  *  Program Name:    entawin.c
  4.  *
  5.  *  Special Notes:   The enumeration does not work.  The callback function
  6.  *                   EnumProc is never reached.
  7.  *
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  13.  
  14. HANDLE hInst;
  15.  
  16. /*************************************************************************/
  17.  
  18. BOOL FAR PASCAL EnumProc(hWnd, lParam)
  19. HWND      hWnd;
  20. LONG      lParam;
  21. {
  22.     MessageBox(hWnd,(LPSTR)"Made it to enumeration",(LPSTR)"",MB_ICONHAND);
  23.     return (1);
  24. }
  25.  
  26. /***********************************************************************/
  27.  
  28. void CALL_EnumTaskWindows(hWnd, hDC)
  29. HWND hWnd;
  30. HDC hDC;
  31. {
  32.   FARPROC lpprocEnumTaskWin;
  33.   HANDLE  hTask;
  34.  
  35.   hTask = GetCurrentTask();
  36.   if (hTask == NULL)
  37.     MessageBox(hWnd,(LPSTR)"task = null",(LPSTR)"",MB_ICONHAND);
  38.  
  39.   lpprocEnumTaskWin = MakeProcInstance ((FARPROC)EnumProc, hInst);
  40.   if (lpprocEnumTaskWin == NULL)
  41.     MessageBox(hWnd,(LPSTR)"lpEnumFunc = null",(LPSTR)"",MB_ICONHAND);
  42.  
  43.   EnumTaskWindows (hTask, lpprocEnumTaskWin, (LONG) NULL);
  44.  
  45.   FreeProcInstance (lpprocEnumTaskWin);
  46.   return;
  47. }
  48.  
  49. /**************************************************************************/
  50.  
  51. /* Procedure called when the application is loaded for the first time */
  52. BOOL WinInit( hInstance )
  53. HANDLE hInstance;
  54. {
  55.     WNDCLASS   wcClass;
  56.  
  57.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  58.     wcClass.lpfnWndProc    = WndProc;
  59.     wcClass.cbClsExtra     =0;
  60.     wcClass.cbWndExtra     =0;
  61.     wcClass.hInstance      = hInstance;
  62.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  63.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  64.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  65.     wcClass.lpszMenuName   = (LPSTR)NULL;
  66.     wcClass.lpszClassName  = (LPSTR)"EnumTaskWindows";
  67.  
  68.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  69.         /* Initialization failed.
  70.          * Windows will automatically deallocate all allocated memory.
  71.          */
  72.         return FALSE;
  73.  
  74.     return TRUE;        /* Initialization succeeded */
  75. }
  76.  
  77.  
  78. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  79. HANDLE hInstance, hPrevInstance;
  80. LPSTR lpszCmdLine;
  81. int cmdShow;
  82. {
  83.     MSG   msg;
  84.     HWND  hWnd;
  85.  
  86.     if (!hPrevInstance)
  87.         {
  88.         /* Call initialization procedure if this is the first instance */
  89.         if (!WinInit( hInstance ))
  90.             return FALSE;
  91.         }
  92.  
  93.     hWnd = CreateWindow((LPSTR)"EnumTaskWindows",
  94.                         (LPSTR)"EnumTaskWindows()",
  95.                         WS_OVERLAPPEDWINDOW,
  96.                         CW_USEDEFAULT,
  97.                         CW_USEDEFAULT,
  98.                         CW_USEDEFAULT,
  99.                         CW_USEDEFAULT,
  100.                         (HWND)NULL,        /* no parent */
  101.                         (HMENU)NULL,       /* use class menu */
  102.                         (HANDLE)hInstance, /* handle to window instance */
  103.                         (LPSTR)NULL        /* no params to pass on */
  104.                         );
  105.     hInst = hInstance;
  106.  
  107.     /* Make window visible according to the way the app is activated */
  108.     ShowWindow( hWnd, cmdShow );
  109.     UpdateWindow( hWnd );
  110.  
  111.     MessageBox(hWnd, "The enumeration does not work.  \
  112. The callback function is never reached.", "EnumTaskWindows", MB_OK);
  113.  
  114.     /* Polling messages from event queue */
  115.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  116.         {
  117.         TranslateMessage((LPMSG)&msg);
  118.         DispatchMessage((LPMSG)&msg);
  119.         }
  120.  
  121.     return (int)msg.wParam;
  122. }
  123.  
  124. /* Procedures which make up the window class. */
  125. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  126. HWND hWnd;
  127. unsigned message;
  128. WORD wParam;
  129. LONG lParam;
  130. {
  131.     PAINTSTRUCT ps;
  132.  
  133.     switch (message)
  134.     {
  135.  
  136.     case WM_PAINT:
  137.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  138.         CALL_EnumTaskWindows(hWnd, ps.hdc);
  139.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  140.         break;
  141.  
  142.     case WM_DESTROY:
  143.         PostQuitMessage( 0 );
  144.         break;
  145.  
  146.     default:
  147.         return DefWindowProc( hWnd, message, wParam, lParam );
  148.         break;
  149.     }
  150.     return(0L);
  151. }
  152.