home *** CD-ROM | disk | FTP | other *** search
/ Desktop Works 1995 - 1996 / desktopworks1995-1996.iso / animator / showtask.c < prev    next >
C/C++ Source or Header  |  1996-01-01  |  2KB  |  97 lines

  1. #include "animator.h"
  2.  
  3. static char szTitle [MAX_FILE_SIZE];
  4.  
  5. //////////////////////////////////////////////////////////////////////////
  6. // ShowTaskDlg - Dialog box procedure for the Set Window Task menu command
  7. // by enumerating all of the windows on the display, and adding their
  8. // titles to a listbox.  Uses FindWindow on the title to get the 
  9. // window handle and returns it to the calling DialogBox function.
  10. //////////////////////////////////////////////////////////////////////////
  11.  
  12. HANDLE _export CALLBACK ShowTaskDlg(DLGPROC_PARAMS)
  13. {
  14.     HWND    hwndList = GetDlgItem (hDlg, IDD_LISTBOX);
  15.     FARPROC lpfn;
  16.     HANDLE  hwnd;
  17.  
  18.     switch (uMsg) 
  19.     {
  20.         case WM_INITDIALOG:
  21.         {
  22.             CenterWindow (hDlg);
  23.  
  24.             lpfn = MakeProcInstance ((FARPROC)EnumCallback, _hInst);
  25.  
  26.             if (!EnumWindows (lpfn, MAKELONG (hwndList, 0)))
  27.             {
  28.                 MESSAGE (IDS_TaskListErr);
  29.                 EndDialog (hDlg, NULL);
  30.                 break ;
  31.             }
  32.  
  33.             FreeProcInstance (lpfn);
  34.             return (TRUE);
  35.         }
  36.  
  37.         case WM_COMMAND:
  38.         {
  39.             switch (wParam)
  40.             {
  41.                 case IDD_LISTBOX:
  42.                 {
  43.                     if (HIWORD(lParam)==LBN_DBLCLK)
  44.                     {
  45.                         PostMessage (hDlg,WM_COMMAND,IDOK,0L);
  46.                     }
  47.                     break ;
  48.                 }
  49.                 case IDOK:
  50.                 {
  51.                     ListBox_GetText (hwndList, ListBox_GetCurSel(hwndList),
  52.                         (LPSTR)szTitle);
  53.  
  54.                     hwnd = FindWindow (NULL, (LPSTR)szTitle);
  55.  
  56.                     EndDialog (hDlg, hwnd);
  57.  
  58.                     break ;
  59.                 }
  60.                 case IDCANCEL:
  61.                 {
  62.                     EndDialog (hDlg, NULL);
  63.                     break ;
  64.                 }
  65.                 default:
  66.                     break ;
  67.             }
  68.             return TRUE;
  69.         }
  70.     }
  71.  
  72.     return (FALSE);
  73. }
  74.  
  75. //////////////////////////////////////////////////////////////////////////
  76. // EnumCallback - This is the function used by ShowTaskDlg that adds the 
  77. // task window titles to the listbox.  The global all-purpose variable
  78. // szTitle is used to fetch the task titles.  If the task is 
  79. // visible and has a title, then add it to the list.
  80. //////////////////////////////////////////////////////////////////////////
  81.  
  82. BOOL _export CALLBACK EnumCallback (HWND hWnd, LONG lParam)
  83. {
  84.     if (GetParent (hWnd) == NULL)
  85.     {
  86.         GetWindowText (hWnd, (LPSTR)szTitle, MAX_FILE_SIZE);
  87.         if (lstrlen (szTitle) && IsWindowVisible(hWnd))
  88.         {
  89.             if (LB_ERR == ListBox_AddString (LOWORD(lParam), (LPSTR)szTitle))
  90.             {
  91.                 return FALSE;
  92.             }
  93.         }
  94.     }
  95.     return TRUE;
  96. }
  97.