home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR9 / WDOS0793.ZIP / PALMER.ZIP / PALMER1.C next >
C/C++ Source or Header  |  1993-05-25  |  5KB  |  167 lines

  1. #include <windows.h>
  2. #include "spopup.h"
  3.  
  4. LRESULT _export CALLBACK SPopupWndFn( HWND, UINT,
  5.         WPARAM, LPARAM );
  6.  
  7. #define    SPOPUP_MAXWIDTH          400
  8.  
  9. static int aPattern[] = { 0xAA, 0x55, 0xAA, 0x55,
  10.                                    0xAA, 0x55, 0xAA, 0x55 };
  11.  
  12. BOOL FAR PASCAL RegisterSPopupClass( HANDLE hInst )
  13. {
  14.     WNDCLASS wc;
  15.  
  16.     wc.hCursor          = LoadCursor( NULL, IDC_ARROW );
  17.     wc.hIcon            = NULL;
  18.     wc.lpszMenuName     = NULL;
  19.     wc.lpszClassName    = "spopup";
  20.     wc.hbrBackground    = (HBRUSH)( COLOR_WINDOW + 1 );
  21.     wc.hInstance        = hInst;
  22.     wc.style            = CS_HREDRAW | CS_VREDRAW;
  23.     wc.lpfnWndProc      = SPopupWndFn;
  24.     wc.cbClsExtra       = 0;
  25.     wc.cbWndExtra       = 0;
  26.     if( !RegisterClass( &wc ) )
  27.         return( FALSE );
  28.     return( TRUE );
  29. }
  30.  
  31. HWND FAR PASCAL CreateSPopup( int x, int y, int cx, int cy,
  32.    HWND hwnd, HANDLE hInst, void FAR * lParam )
  33. {
  34.    HWND hwndPopup;
  35.    DWORD dwStyle = 0L;
  36.  
  37.    if( hwnd )
  38.       dwStyle = WS_CHILD;
  39.    else
  40.       dwStyle = WS_POPUP;
  41.    hwndPopup = CreateWindow( "spopup", NULL,
  42.             dwStyle, x, y, cx, cy, hwnd, NULL,
  43.             hInst, lParam );
  44.    ShowWindow( hwndPopup, SW_SHOWNOACTIVATE );
  45.    UpdateWindow( hwndPopup );
  46.    return( hwndPopup );
  47. }
  48.  
  49. void FAR PASCAL PopupText( HWND hwnd, int x, int y,
  50.                                             LPSTR lpszText )
  51. {
  52.     HWND hwndPopup;
  53.     HANDLE hInst;
  54.     RECT rc;
  55.     BOOL fDone;
  56.     MSG msg;
  57.     HDC hdc;
  58.  
  59.     hdc = CreateDC( "DISPLAY", NULL, NULL, NULL );
  60.     SelectObject( hdc, GetStockObject( SYSTEM_FONT ) );
  61.     SetRect( &rc, 0, 0, SPOPUP_MAXWIDTH, 0 );
  62.     DrawText( hdc, lpszText, -1, &rc,
  63.         DT_NOPREFIX|DT_WORDBREAK|DT_CALCRECT );
  64.     rc.right += 10;
  65.     DeleteDC( hdc );
  66.  
  67.     hInst = GetWindowWord( hwnd, GWW_HINSTANCE );
  68.     hwndPopup = CreateSPopup( x, y,
  69.         rc.right + SPOPUP_SHADOWWIDTH * 3,
  70.         rc.bottom + SPOPUP_SHADOWHEIGHT * 3,
  71.         hwnd, hInst, NULL );
  72.     hdc = GetDC( hwndPopup );
  73.     OffsetRect( &rc, SPOPUP_SHADOWWIDTH,
  74.                     SPOPUP_SHADOWHEIGHT );
  75.     DrawText( hdc, lpszText, -1, &rc,
  76.         DT_WORDBREAK|DT_NOPREFIX );
  77.     ReleaseDC( hwndPopup, hdc );
  78.  
  79.     SetCapture( hwndPopup );
  80.     for( fDone = FALSE; !fDone; )
  81.         if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  82.             if( msg.message == WM_KEYDOWN ||
  83.                  msg.message == WM_SYSKEYDOWN ||
  84.                  msg.message == WM_LBUTTONDOWN ||
  85.                  msg.message == WM_MBUTTONDOWN ||
  86.                  msg.message == WM_RBUTTONDOWN )
  87.                 fDone = TRUE;
  88.             else {
  89.                 TranslateMessage( &msg );
  90.                 DispatchMessage( &msg );
  91.                 }
  92.     ReleaseCapture();
  93.     DestroyWindow( hwndPopup );
  94. }
  95.  
  96. LRESULT __export CALLBACK SPopupWndFn( HWND hwnd,
  97.     UINT message, WPARAM wParam, LPARAM lParam )
  98. {
  99.     static HBITMAP hbm = NULL;
  100.     static HBRUSH hbr = NULL;
  101.     static int nUsage = 0;
  102.  
  103.     switch( message )
  104.         {
  105.         case WM_NCCREATE:
  106.             if( nUsage++ == 0 ) {
  107.                 hbm = CreateBitmap( 8, 8, 1, 1, aPattern );
  108.                 hbr = CreatePatternBrush( hbm );
  109.                 }
  110.             break;
  111.  
  112.         case WM_NCDESTROY:
  113.             if( --nUsage == 0 ) {
  114.                 DeleteObject( hbm );
  115.                 DeleteObject( hbr );
  116.                 }
  117.             break;
  118.  
  119.         case WM_NCCALCSIZE: {
  120.             LPRECT lpClRc = (LPRECT)lParam;
  121.  
  122.             lpClRc->left += 1;
  123.             lpClRc->top += 1;
  124.             lpClRc->right -= SPOPUP_SHADOWWIDTH + 1;
  125.             lpClRc->bottom -= SPOPUP_SHADOWHEIGHT + 1;
  126.             break;
  127.             }
  128.  
  129.         case WM_NCPAINT: {
  130.             RECT rc;
  131.             HDC hdc;
  132.             HBRUSH hbrFrame;
  133.             HBRUSH hbrOld;
  134.  
  135.             hdc = GetWindowDC( hwnd );
  136.             GetWindowRect( hwnd, &rc );
  137.             rc.right -= rc.left;
  138.             rc.bottom -= rc.top;
  139.             rc.top = 0;
  140.             rc.left = 0;
  141.  
  142.             UnrealizeObject( hbr );
  143.             hbrOld = SelectObject( hdc, hbr );
  144.             PatBlt( hdc, rc.left + SPOPUP_SHADOWWIDTH,
  145.                       rc.bottom - SPOPUP_SHADOWHEIGHT,
  146.                       rc.right - SPOPUP_SHADOWWIDTH,
  147.                       SPOPUP_SHADOWHEIGHT, 0xA000C9 );
  148.             PatBlt( hdc, rc.right - SPOPUP_SHADOWWIDTH,
  149.                       rc.top + SPOPUP_SHADOWHEIGHT,
  150.                       SPOPUP_SHADOWWIDTH,
  151.                       rc.bottom, 0xA000C9);
  152.             SelectObject( hdc, hbrOld );
  153.  
  154.             hbrFrame = CreateSolidBrush(
  155.                     GetSysColor( COLOR_WINDOWFRAME ) );
  156.             rc.right -= SPOPUP_SHADOWWIDTH;
  157.             rc.bottom -= SPOPUP_SHADOWHEIGHT;
  158.             FrameRect( hdc, &rc, hbrFrame );
  159.             DeleteObject( hbrFrame );
  160.  
  161.             ReleaseDC( hwnd, hdc );
  162.          break;
  163.             }
  164.         }
  165.     return( DefWindowProc( hwnd,message, wParam, lParam ) );
  166. }
  167.