home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_01 / 3n01009b < prev    next >
Text File  |  1991-11-26  |  3KB  |  89 lines

  1. /*****************************************************/
  2. /* menu.c                                            */
  3. /* -- Popup menu routines.                           */
  4. /* -- Don't forget to export FEnumWnd() in your .def */
  5. /*    file!                                          */
  6. /*****************************************************/
  7.  
  8. /*****************************************************/
  9. /* Header files.                                     */
  10. /*****************************************************/
  11. #include <windows.h>
  12. #include "menu.h"
  13.  
  14. /*****************************************************/
  15. /* Private prototypes.                               */
  16. /*****************************************************/
  17. BOOL FAR  PASCAL  FEnumWnd(HWND, DWORD);
  18.  
  19. /*****************************************************/
  20. /* Routines.                                         */
  21. /*****************************************************/
  22.  
  23. VOID
  24. DrawMenu(HDC hdc, POINT pt, HANDLE hins)
  25. /*****************************************************/
  26. /* -- Capture the popup menu if it ie visible.       */
  27. /* -- hdc     : DC to receive menu image.            */
  28. /* -- pt      : Where to paint image in hdc.         */
  29. /* -- hins    : Application's instance handle.       */
  30. /*****************************************************/
  31.     {
  32.     HWND    hwndMenu    = HwndGetPopupMenu(hins);
  33.     HDC     hdcMenu;
  34.     RECT    rectMenu;
  35.     int     dx, dy;
  36.  
  37.     /* Make sure popup menu is visible. */
  38.     if (!IsWindow(hwndMenu) ||
  39.       !IsWindowVisible(hwndMenu))
  40.         return;
  41.  
  42.     /* Get a DC for the menu, and copy its image. */
  43.     hdcMenu = GetDC(hwndMenu);
  44.     GetWindowRect(hwndMenu, &rectMenu);
  45.     dx = rectMenu.right - rectMenu.left;
  46.     dy = rectMenu.bottom - rectMenu.top;
  47.     BitBlt(hdc, pt.x, pt.y, dx, dy, hdcMenu, 0, 0,
  48.       SRCCOPY);
  49.     ReleaseDC(hwndMenu, hdcMenu);
  50.     }
  51.  
  52. HWND
  53. HwndGetPopupMenu(HANDLE hins)
  54. /*****************************************************/
  55. /* -- Find the window handle of the shared popup    */
  56. /*    menu.                                          */
  57. /* -- hins    : Application's instance handle.       */
  58. /*****************************************************/
  59.     {
  60.     FARPROC lpfn;
  61.     HWND    hwndMenu    = NULL;
  62.  
  63.     lpfn = MakeProcInstance(FEnumWnd, hins);
  64.     EnumWindows(lpfn, (LONG)(WORD)&hwndMenu);
  65.     FreeProcInstance(lpfn);
  66.     return hwndMenu;
  67.     }
  68.  
  69.  
  70.  
  71. BOOL FAR PASCAL
  72. FEnumWnd(HWND hwnd, DWORD lParam)
  73. /*****************************************************/
  74. /* -- EnumWindows() callback to get popup menu       */
  75. /*    window handle.                                 */
  76. /*****************************************************/
  77.     {
  78.     char    szBuf[40];
  79.  
  80.     GetClassName(hwnd, szBuf, sizeof szBuf);
  81.     if (!lstrcmp(szBuf, "#32768"))
  82.         {
  83.     *(HWND *)lParam = hwnd;
  84.         return FALSE;
  85.         }
  86.  
  87.     return TRUE;
  88.     }
  89.