home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / enhframe.zip / enhframe.c < prev    next >
Text File  |  1995-08-07  |  5KB  |  115 lines

  1. /**************************************
  2.  
  3. Dan Akselrod (c) 1995.
  4.  
  5. Enhanced frame module. This file has the functionality to subclass
  6. any frame and add Opaqueness to it's move function.
  7.  
  8. **************************************/
  9. #define INCL_WIN
  10. #define INCL_DOS
  11. #include <os2.h>
  12.  
  13. #include "enhframe.h"
  14.  
  15. static MRESULT EXPENTRY EnhFrameProc(HWND, unsigned long, MPARAM, MPARAM);
  16. static MRESULT EXPENTRY (*OldFrameProc)(HWND, unsigned long, MPARAM, MPARAM);
  17. static MRESULT EXPENTRY EnhBarProc(HWND, unsigned long, MPARAM, MPARAM);
  18. static MRESULT EXPENTRY (*OldBarProc)(HWND, unsigned long, MPARAM, MPARAM);
  19.  
  20. int FrameMaximized=0;
  21. HWND hwndEnhFrame;
  22.  
  23.  
  24. int EnhanceFrame(HWND Frame) {
  25. HWND titlebar;
  26.  
  27.         hwndEnhFrame=Frame;/* save in global var */
  28.  
  29.         titlebar=WinWindowFromID(hwndEnhFrame,FID_TITLEBAR);
  30.         if (titlebar==NULLHANDLE)
  31.                 return ENHFRAMEERR_TITLEBAR_NOTEXIST;
  32.  
  33.         OldFrameProc=WinSubclassWindow(hwndEnhFrame,(PFNWP) EnhFrameProc);
  34.         if (OldFrameProc==0L)
  35.                 return ENHFRAMEERR_FRAME_SUBCLASS;
  36.  
  37.         OldBarProc=WinSubclassWindow(titlebar,(PFNWP) EnhBarProc);
  38.         if (OldBarProc==0L) {
  39.                 WinSubclassWindow(hwndEnhFrame,(PFNWP) OldFrameProc);/* restore old procedure */
  40.                 return ENHFRAMEERR_TITLEBAR_SUBCLASS;
  41.         }
  42.  
  43. return 0;
  44. }
  45.  
  46.  
  47.  
  48. MRESULT EXPENTRY EnhBarProc(HWND hwnd, unsigned long msg, MPARAM mp1, MPARAM mp2) {
  49. static POINTL ptDiff;
  50. /* difference bet. mouse PT and Frame's window lower-left corner.
  51.    When the window is moved, the mouse pointer is supposed to stay in the
  52.    same spot inside the window. This difference between the coords of
  53.    The mouse and coords of the frame window is used in calculating new coords
  54.    of the frame, when the mouse is moved.
  55.  */
  56. static BOOL IsMoving=0;/* true when button went down, but not up */
  57. static BOOL IsMoved=0;/* true on first move. When the button goes up/down
  58.                          w/o movement, a window ACTIVATE is preformed. */
  59.  
  60.         switch (msg) {
  61.         case WM_BUTTON1DOWN:
  62.         case WM_BUTTON2DOWN:
  63.         case WM_BUTTON3DOWN: /* start the drag process on any of the button clicks */
  64.            IsMoving=1;IsMoved=0; /* moving mode, but haven't moved yet */
  65.            ptDiff.x=SHORT1FROMMP(mp1);
  66.            ptDiff.y=SHORT2FROMMP(mp1);/* get the coords of the mouse inside the title wind. */
  67.            WinMapWindowPoints(hwnd, hwndEnhFrame, &ptDiff, 1);/* conver to frame coords */
  68.            WinSetCapture(HWND_DESKTOP, hwnd);/* now must receive all mouse input */
  69.            return (MRESULT)1;
  70.         case WM_MOUSEMOVE:
  71.            /* when the window is maximized, any movements are disallowed */
  72.            if (IsMoving && !FrameMaximized) { /* allowed to move */
  73.                 POINTL newPt;
  74.                 IsMoved=1;/* set flag that we've moved at least once */
  75.                 newPt.x=(SHORT)SHORT1FROMMP(mp1);
  76.                 newPt.y=(SHORT)SHORT2FROMMP(mp1);
  77.                 WinMapWindowPoints(hwnd, HWND_DESKTOP, &newPt, 1);/* absolute coords */
  78.                 WinSetWindowPos( hwndEnhFrame, NULLHANDLE, newPt.x-ptDiff.x,
  79.                                              newPt.y-ptDiff.y, 0, 0,
  80.                                                SWP_MOVE);/* subtract the difference bet
  81.                                                             pointer and frame, and move there */
  82.                 /* IMPORTANT */
  83.                 DosSleep(0);/* force a task switch, to allow other windows to update */
  84.            }
  85.            break;
  86.         case WM_BUTTON1UP:
  87.         case WM_BUTTON2UP:
  88.         case WM_BUTTON3UP:/* end of moving */
  89.            if (IsMoving==0)
  90.                 break;/* we're not even moving, life is easy. */
  91.            IsMoving=0;
  92.            WinSetCapture(HWND_DESKTOP, NULLHANDLE);/* unset mouse capture, nomal operation */
  93.            if (!IsMoved) {/* Not moved even once ... select the window */
  94.                 WinSetWindowPos( hwndEnhFrame, NULLHANDLE, 0, 0, 0, 0, SWP_ACTIVATE);
  95.            }
  96.            return (MRESULT)1;
  97.         }
  98.         return (OldBarProc)(hwnd, msg, mp1, mp2);
  99. }
  100.  
  101.  
  102.  
  103. MRESULT EXPENTRY EnhFrameProc(HWND hwnd, unsigned long msg, MPARAM mp1, MPARAM mp2) {
  104.         switch (msg) {
  105.         case WM_ADJUSTFRAMEPOS:
  106.                 /* must capture this msg, to know when we're getting max'ed/restored */
  107.                 if ( ((PSWP)mp1)->fl & SWP_MAXIMIZE)
  108.                         FrameMaximized=1;/* this flag prevents window from moving */
  109.                 else if ( (((PSWP)mp1)->fl & SWP_RESTORE) || (((PSWP)mp1)->fl & SWP_MINIMIZE) )
  110.                         FrameMaximized=0;/* this flag enables window to move */
  111.         break;
  112.         }
  113.         return (OldFrameProc)(hwnd, msg, mp1, mp2);
  114. }
  115.