home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / scmouse.arj / SCMOUSE.ZIP / source / SCMouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-14  |  4.1 KB  |  178 lines

  1. #define INCL_WIN
  2. #define INCL_DOSPROCESS
  3. #define INCL_DOSDEVICES
  4. #define INCL_DOSDEVIOCTL
  5. #include <os2.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #ifdef __EMX__
  10. #define INLINE inline
  11. #else
  12. #define INLINE
  13. #endif
  14.  
  15. HWND hwndWarpCenter=0;
  16. SWP  swpWCWindow;
  17.  
  18. char WarpCenterTitle[]="WarpCenter";
  19.  
  20. ULONG GetWarpCenterInfo() 
  21.     {
  22.     SWBLOCK *pSwBlock;
  23.     ULONG SwBlSize;
  24.     ULONG SwBlLen;
  25.     HWND hwnd;
  26.     static HSWITCH hswitchPrev=0;
  27.     int i;
  28.  
  29.     if(hwndWarpCenter && hswitchPrev==WinQuerySwitchHandle(hwndWarpCenter, 0))
  30.     {
  31.     WinQueryWindowPos(hwndWarpCenter, &swpWCWindow);
  32.     return 0;
  33.     }
  34. /* hwndWarpCenter is not changed since previous call */
  35.  
  36.     SwBlLen=WinQuerySwitchList(0L, NULL, 0);
  37. /* Get the number of entries in switch list */
  38.  
  39.     SwBlSize=sizeof(ULONG)+sizeof(SWENTRY)*SwBlLen;
  40.     if(DosAllocMem((PPVOID)&pSwBlock, SwBlSize, PAG_WRITE|PAG_COMMIT))
  41.     return 1;
  42.     WinQuerySwitchList(0L, pSwBlock, SwBlSize);
  43. /* Get the switch list */
  44.  
  45.     hwndWarpCenter=0;
  46.     for(i = SwBlLen-1; i>0; i--) 
  47.     if(strcmp(pSwBlock->aswentry[i].swctl.szSwtitle, WarpCenterTitle)==0)  
  48.         {
  49.         hwnd=pSwBlock->aswentry[i].swctl.hwnd;
  50.         WinQueryWindowPos(hwnd, &swpWCWindow);
  51.         if(swpWCWindow.x!=0) continue;
  52. /* Warp Center - Properties has the same title in list*/
  53.         hwndWarpCenter=hwnd;
  54.         hswitchPrev=pSwBlock->aswentry[i].hswitch;
  55.         break;
  56.         }
  57. /* First started processes are last in switch list */
  58.  
  59.     DosFreeMem(pSwBlock);
  60.     return (hwndWarpCenter==0);
  61.     }
  62.  
  63. INLINE
  64. ULONG ShowWarpCenter() 
  65.     {
  66.     if(GetWarpCenterInfo()) return 1;
  67. /* WarpCenter is not found */
  68.  
  69.     WinSetWindowPos(hwndWarpCenter, HWND_TOP, 0,0,0,0, SWP_ZORDER);
  70.  
  71.     return 0;
  72.     }
  73.  
  74. INLINE
  75. void HideWarpCenter() 
  76.     {
  77.     if(hwndWarpCenter)
  78.     WinSetWindowPos(hwndWarpCenter, HWND_BOTTOM, 0,0,0,0, SWP_ZORDER);
  79.     }
  80.  
  81. ULONG IsWarpCenterProperties(HWND hwnd)
  82.     {
  83.     HSWITCH hswitch;
  84.     SWCNTRL SwitchData;
  85.     static HWND hwndPrev=0;
  86.  
  87.     if(hwnd==hwndPrev) return 1;
  88.     hwndPrev=0; 
  89.     if(!(hswitch=WinQuerySwitchHandle(hwnd, 0))) return 0;
  90.  
  91.     WinQuerySwitchEntry(hswitch, &SwitchData);
  92.  
  93.     if(strcmp(SwitchData.szSwtitle, WarpCenterTitle)==0)
  94.     { hwndPrev=hwnd; return 1; }
  95.  
  96.     return 0;
  97.     }
  98.  
  99. #define DELAY_SHORT 200
  100. #define DELAY_LONG  3000
  101.  
  102. int main(int argc)
  103.     {
  104.     ULONG y;
  105.     BOOL WasShown=FALSE;
  106.     BOOL MouseOnWC=FALSE;
  107.     BOOL CheckWarpCenterPos=(argc!=1);
  108.     SWP  swpDesktop;
  109.     POINTL MousePos;
  110.     HWND hwndActive;
  111.  
  112.     int CheckingCoord, HideTop, HideBottom, WCTop, WCBottom, WCHeight;
  113.  
  114.     WinQueryWindowPos(HWND_DESKTOP, &swpDesktop); 
  115.  
  116.     for(;;)
  117.     {
  118.     while(GetWarpCenterInfo())
  119.         DosSleep(DELAY_LONG);
  120. /* Wait for starting of Warp Center */
  121.  
  122.     WCHeight=swpWCWindow.cy;
  123.     if(swpWCWindow.y!=0)        /* Top position */
  124.         {
  125.         CheckingCoord=swpDesktop.cy-1;
  126.         WCBottom=swpWCWindow.y;
  127.         HideBottom=swpDesktop.cy-(swpWCWindow.cy<<1);
  128.         WCTop=HideTop=swpDesktop.cy;
  129.         }
  130.     else                /* Bottom position */
  131.         {
  132.         CheckingCoord=0;
  133.         WCBottom=HideBottom=0;
  134.         WCTop=swpWCWindow.cy;
  135.         HideTop=(swpWCWindow.cy<<1);
  136.         }
  137.  
  138.     for(;;)
  139.         {
  140.         if(!WinQueryPointerPos(HWND_DESKTOP, &MousePos)) return 1;
  141. /* Mouse isn't work properly */
  142.  
  143.         y=MousePos.y;
  144.         if(y==CheckingCoord && !MouseOnWC && WinQueryActiveWindow(HWND_DESKTOP))
  145.         {  
  146.         if(ShowWarpCenter()) break;
  147. /* Warp Center was closed */
  148.  
  149.         WasShown=MouseOnWC=TRUE;
  150.  
  151.         if(swpWCWindow.cy!=WCHeight) break;
  152. /* Icons size was changed */
  153.         if((swpWCWindow.y!=0)^(CheckingCoord!=0)) break;
  154. /* Position was changed */
  155.         }
  156.  
  157.         if(MouseOnWC && (y<WCBottom||y>=WCTop)) 
  158.         MouseOnWC=FALSE;
  159.  
  160.         if(WasShown && (y<HideBottom||y>=HideTop))
  161.         { 
  162.         hwndActive=WinQueryActiveWindow(HWND_DESKTOP);
  163.         if(hwndActive && !IsWarpCenterProperties(hwndActive))
  164.             { HideWarpCenter(); WasShown=FALSE; }
  165.         }
  166. /* Hide if WarpCenter is not active */
  167.  
  168.         if(CheckWarpCenterPos)    /* Cheking Warp Center position each time */
  169.         {
  170.         if(GetWarpCenterInfo()) break;
  171.         if((swpWCWindow.y!=0)^(CheckingCoord==0)) break;
  172.         }
  173.  
  174.         DosSleep(DELAY_SHORT);
  175.         }
  176.     }
  177.     }
  178.