home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / lower.zip / source.zip / lower.c next >
C/C++ Source or Header  |  1993-11-08  |  2KB  |  64 lines

  1. /* LOWER, written by Matthew Austern (matt@physics.berkeley.edu), 1993.
  2.    This program is public domain.
  3. */
  4.  
  5. /* Very simple program that lowers whatever object the user clicks on.
  6.  
  7.    It grabs the mouse and changes the cursor to something recognizably
  8.    different.  It doesn't let go until the user clicks the mouse somewhere;
  9.    if the user clicks button 1, it uses WinSetWindowPos to lower that window,
  10.    and if the user clicks any other button, the program quits without doing
  11.    anything.  Either way, the program exits as soon as a mouse button is
  12.    clicked.
  13. */
  14.  
  15. #define INCL_PM
  16. #include <os2.h>
  17.  
  18. int main(void)
  19. {
  20.   HAB hab = WinInitialize(0);
  21.   HMQ Queue = WinCreateMsgQueue (hab, 0);
  22.   HPOINTER XPtr = WinLoadPointer(HWND_DESKTOP, 0, 2);
  23.   
  24.   if (!WinQuerySysValue(HWND_DESKTOP, SV_MOUSEPRESENT) ||
  25.       !WinSetCapture(HWND_DESKTOP, HWND_THREADCAPTURE)) 
  26.       WinMessageBox(HWND_DESKTOP, HWND_DESKTOP,    /* Notify the user. */
  27.             "Error: can't access the mouse.",
  28.             "Lower", 0, MB_ERROR | MB_OK | MB_MOVEABLE);
  29.   else {
  30.     QMSG Msg;
  31.     WinSetPointer(HWND_DESKTOP, XPtr);
  32.     while(WinGetMsg(hab, &Msg, 0, 0, 0)) {
  33.       switch(Msg.msg) {
  34.       case WM_BUTTON1DOWN: {
  35.     POINTL thePosition;
  36.     HWND theWin = HWND_DESKTOP;
  37.  
  38.     thePosition.x = SHORT1FROMMP(Msg.mp1);
  39.     thePosition.y = SHORT2FROMMP(Msg.mp1);
  40.     theWin = WinWindowFromPoint(HWND_DESKTOP, &thePosition, 0);
  41.     if (theWin && theWin != HWND_DESKTOP)
  42.       WinSetWindowPos(theWin,
  43.               HWND_BOTTOM,
  44.               0, 0, 0, 0,
  45.               SWP_ZORDER | SWP_DEACTIVATE);
  46.     goto EndLoop;
  47.       }
  48.       case WM_BUTTON2DOWN:
  49.       case WM_BUTTON3DOWN:
  50.     goto EndLoop;
  51.       default:
  52.     WinDispatchMsg(hab, &Msg);
  53.       }
  54.     }
  55.   EndLoop:
  56.     WinSetCapture(HWND_DESKTOP, 0);
  57.   }
  58.  
  59.   WinDestroyMsgQueue(Queue);
  60.   WinTerminate(hab);
  61.   return 0;
  62. }
  63.            
  64.