home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pmvnc100.zip / window.c < prev   
C/C++ Source or Header  |  1999-07-22  |  19KB  |  682 lines

  1. /*
  2.  * window.c - PM VNC Viewer, Window Manipulations
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. #define INCL_PM
  10. #include <os2.h>
  11.  
  12. #include "pmvncdef.h"
  13. #include "pmvncres.h"
  14.  
  15. /*
  16.  * window handles and their size & position
  17.  */
  18.  
  19. HWND    hwndFrame  = NULLHANDLE ;
  20. HWND    hwndClient = NULLHANDLE ;
  21. HWND    hwndHorz   = NULLHANDLE ;
  22. HWND    hwndVert   = NULLHANDLE ;
  23.  
  24. static  SWP     swpFrame  = { 0 } ; /* size/pos of frame  window    */
  25. static  SWP     swpClient = { 0 } ; /* size/pos of client window    */
  26. static  SIZEL   sizMax    = { 0 } ; /* max size of frame            */
  27. static  SIZEL   sizRfb    = { 0 } ; /* size of remote screen        */
  28. static  POINTL  mapRfb    = { 0 } ; /* mapping position             */
  29.  
  30. static  ULONG   sv_cxScreen     ;   /* width  of screen             */
  31. static  ULONG   sv_cyScreen     ;   /* height of screen             */
  32. static  ULONG   sv_cyTitleBar   ;   /* height of title bar          */
  33. static  ULONG   sv_cxSizeBorder ;   /* width  of sizing border      */
  34. static  ULONG   sv_cySizeBorder ;   /* height of sizing border      */
  35.  
  36. /*
  37.  * winIconized - TRUE if window was iconized
  38.  */
  39.  
  40. static  BOOL    isIconized = FALSE ;
  41.  
  42. BOOL    winIconized(void)
  43. {
  44.     return isIconized ;
  45. }
  46.  
  47. /*
  48.  * procFrame - subclassed frame window
  49.  */
  50.  
  51. static  PFNWP   pfnFrame ;
  52.  
  53. static MRESULT EXPENTRY procFrame(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  54. {
  55.     PSWP    pswp ;
  56.     
  57.     switch (msg) {
  58.  
  59.     case WM_PAINT :
  60.         kstAdjust(hwndFrame) ;
  61.         break ;
  62.         
  63.     case WM_WINDOWPOSCHANGED :
  64.         pswp = (PSWP) PVOIDFROMMP(mp1) ;
  65.     swpFrame = *pswp ;
  66.     if (! isIconized && swpFrame.cx > 0 && swpFrame.cy > 0) {
  67.             SessSavedPos.x  = swpFrame.x  ;
  68.             SessSavedPos.y  = swpFrame.y  ;
  69.         SessSavedSiz.cx = swpFrame.cx ;
  70.         SessSavedSiz.cy = swpFrame.cy ;
  71.     }
  72.     break ;
  73.  
  74.     case WM_ADJUSTWINDOWPOS :
  75.         pswp = (PSWP) PVOIDFROMMP(mp1) ;
  76.     if ((pswp->fl & SWP_MAXIMIZE) && (pswp->fl & SWP_RESTORE) == 0) {
  77.         pswp->fl &= ~SWP_MAXIMIZE ;
  78.         pswp->fl |=  (SWP_SIZE | SWP_MOVE) ;
  79.         pswp->cx = sizMax.cx ;
  80.         pswp->cy = sizMax.cy ;
  81.         pswp->y -= (sizMax.cy - swpFrame.cy) ;
  82.  
  83.             if (pswp->cx > sv_cxScreen) {
  84.             pswp->x = -(sv_cxSizeBorder) ;
  85.         } else if (pswp->x < 0) {
  86.             pswp->x = 0 ;
  87.         } else if ((pswp->x + pswp->cx) > sv_cxScreen) {
  88.             pswp->x -= (pswp->x + pswp->cx - sv_cxScreen) ;
  89.         }
  90.         if (pswp->cy > sv_cyScreen) {
  91.             pswp->y = -(pswp->cy - sv_cyScreen - sv_cyTitleBar - sv_cySizeBorder) ;
  92.             } else if (pswp->y < 0) {
  93.             pswp->y = 0 ;
  94.         } else if ((pswp->y + pswp->cy) > sv_cyScreen) {
  95.             pswp->y -= (pswp->y + pswp->cy - sv_cyScreen) ;
  96.         }
  97.     }
  98.     if (pswp->fl & SWP_MINIMIZE) {
  99.         isIconized = TRUE ;
  100.     }
  101.     if (pswp->fl & SWP_RESTORE) {
  102.         isIconized = FALSE ;
  103.         protoSendRequest(TRUE, NULL) ;
  104.     }
  105.  
  106.     /*
  107.      * limit window sizing
  108.      */
  109.  
  110.     if ((pswp->fl & SWP_SIZE) && (pswp->cx > sizMax.cx)) {
  111.             if (pswp->x == swpFrame.x) {    /* Enlarged to Right */
  112.             pswp->x += (pswp->cx - sizMax.cx) ;
  113.         pswp->fl |= SWP_MOVE ;
  114.         }
  115.         pswp->cx = sizMax.cx ;
  116.     }
  117.     if ((pswp->fl & SWP_SIZE) && (pswp->cy > sizMax.cy)) {
  118.         if (pswp->y == swpFrame.y) {    /* Enlaged to Upper */
  119.             pswp->y += (pswp->cy - sizMax.cy) ;
  120.         pswp->fl |= SWP_MOVE ;
  121.         }
  122.         pswp->cy = sizMax.cy ;
  123.     }
  124.  
  125.     /*
  126.      * control scroll bars
  127.      */
  128.     
  129.     if (hwndHorz != NULLHANDLE && (pswp->fl & SWP_SIZE)) {
  130.             if (pswp->cx >= sizMax.cx) {
  131.             WinSetParent(hwndHorz, HWND_OBJECT, FALSE) ;
  132.         } else {
  133.             WinSetParent(hwndHorz, hwnd, FALSE) ;
  134.         }
  135.     }
  136.     if (hwndVert != NULLHANDLE && (pswp->fl & SWP_SIZE)) {
  137.             if (pswp->cy >= sizMax.cy) {
  138.             WinSetParent(hwndVert, HWND_OBJECT, FALSE) ;
  139.         } else {
  140.             WinSetParent(hwndVert, hwnd, FALSE) ;
  141.         }
  142.     }
  143.     break ;
  144.  
  145.     case WM_INITMENU :
  146.         menuHook(hwnd, SHORT1FROMMP(mp1)) ;
  147.         return (MRESULT) 0 ;
  148.     }
  149.     return (*pfnFrame) (hwnd, msg, mp1, mp2) ;
  150. }
  151.  
  152. /*
  153.  * winSetup - adjust window with Remote Frame Buffer
  154.  */
  155.  
  156. static  BOOL    dontAdjustY = FALSE ;
  157.  
  158. static  BOOL    winSetup(SHORT cx, SHORT cy, PUCHAR str)
  159. {
  160.     UCHAR   title[256] ;
  161.     
  162.     if (hwndFrame == NULLHANDLE || hwndClient == NULLHANDLE) {
  163.         errMessage("winSetup - no windows") ;
  164.     return FALSE ;
  165.     }
  166.     
  167.     if (str == NULL) {
  168.         strcpy(title, ProgramVers) ;
  169.     } else if (strlen(str) < 8) {
  170.         sprintf(title, "%s [%s]", ProgramVers, str) ;
  171.     } else if (strlen(str) < 128) {
  172.         strcpy(title, str) ;
  173.     } else {
  174.         str[128] = '\0' ;
  175.     strcpy(title, str) ;
  176.     }
  177.  
  178.     /*
  179.      * Save & Initialize RFB size and position
  180.      */
  181.  
  182.     sizRfb.cx = cx ;
  183.     sizRfb.cy = cy ;
  184.     mapRfb.x  = 0  ;
  185.     mapRfb.y  = sizRfb.cy ;
  186.     
  187.     sizMax.cx = sizRfb.cx + (sv_cxSizeBorder * 2) - 1 ;
  188.     sizMax.cy = sizRfb.cy + (sv_cySizeBorder * 2) + sv_cyTitleBar - 1 ;
  189.  
  190.     if (SessSavedRfb.cx == sizRfb.cx && SessSavedRfb.cy == sizRfb.cy) {
  191.         /*
  192.      * RFB size is save as last session, then use last positions
  193.      */
  194.     swpFrame.x  = SessSavedPos.x  ;
  195.     swpFrame.y  = SessSavedPos.y  ;
  196.     swpFrame.cx = SessSavedSiz.cx ;
  197.     swpFrame.cy = SessSavedSiz.cy ;
  198.     mapRfb.x    = SessSavedOff.x  ;
  199.     mapRfb.y    = SessSavedOff.y  ;
  200.         dontAdjustY = TRUE ;
  201.     TRACE("winSetup - use last positions (off %d,%d)\n",
  202.                                         mapRfb.x, mapRfb.y) ;
  203.     } else {
  204.  
  205.         /*
  206.      * otherwize, center window and place RFB at top-left
  207.      */
  208.         if (sizMax.cx <= sv_cxScreen) {
  209.             swpFrame.cx = sizMax.cx ;
  210.             swpFrame.x = (sv_cxScreen - sizMax.cx) / 2 ;
  211.         } else {
  212.             swpFrame.cx = sv_cxScreen ;
  213.             swpFrame.x  = 0 ;
  214.         }
  215.         if (sizMax.cy <= sv_cyScreen) {
  216.             swpFrame.cy = sizMax.cy ;
  217.             swpFrame.y = (sv_cyScreen - sizMax.cy) / 2 ;
  218.         } else {
  219.             swpFrame.cy = sv_cyScreen ;
  220.             swpFrame.y = 0 ;
  221.         }
  222.     TRACE("winSetup - use new  positions (off %d,%d)\n",
  223.                                         mapRfb.x, mapRfb.y) ;
  224.     }
  225.     
  226.     /*
  227.      * show window
  228.      */
  229.      
  230.     WinSetWindowText(hwndFrame, title) ;
  231.     WinSetWindowPos(hwndFrame, NULLHANDLE,
  232.         swpFrame.x, swpFrame.y, swpFrame.cx, swpFrame.cy,
  233.     (SWP_MOVE | SWP_SIZE | SWP_SHOW)) ;
  234.  
  235.     SessSavedRfb = sizRfb ;
  236.  
  237.     return TRUE ;
  238. }
  239.  
  240. /*
  241.  * mapSize - adjust RFB position to client window size
  242.  */
  243.  
  244. static  void    mapSize(SHORT cx, SHORT cy)
  245. {
  246.     SHORT   diff, vpos ;
  247.     
  248.     if (dontAdjustY) {
  249.         dontAdjustY = FALSE ;
  250.     } else if ((mapRfb.y += (swpClient.cy - cy)) < 0) {
  251.         mapRfb.y = 0 ;
  252.     }
  253.  
  254.     swpClient.cx = cx ;
  255.     swpClient.cy = cy ;
  256.     
  257.     if ((mapRfb.x + swpClient.cx) >= sizRfb.cx) {
  258.         mapRfb.x = sizRfb.cx - swpClient.cx ;
  259.     }
  260.     if ((mapRfb.y + swpClient.cy) >= sizRfb.cy) {
  261.         mapRfb.y = sizRfb.cy - swpClient.cy ;
  262.     }
  263.     
  264.     if (swpClient.cx >= sizRfb.cx) {
  265.         WinEnableWindow(hwndHorz, FALSE) ;
  266.     } else {
  267.         diff = sizRfb.cx - swpClient.cx ;
  268.     WinSendMsg(hwndHorz, SBM_SETTHUMBSIZE,
  269.                 MPFROM2SHORT(swpClient.cx, sizRfb.cx), NULL) ;
  270.         WinSendMsg(hwndHorz, SBM_SETSCROLLBAR,
  271.             MPFROM2SHORT(mapRfb.x, 0), MPFROM2SHORT(0, diff)) ;
  272.         WinEnableWindow(hwndHorz, TRUE) ;
  273.     }
  274.     
  275.     if (swpClient.cy >= sizRfb.cy) {
  276.         WinEnableWindow(hwndVert, FALSE) ;
  277.     } else {
  278.         diff = sizRfb.cy - swpClient.cy ;
  279.     vpos = diff - mapRfb.y ;
  280.     WinSendMsg(hwndVert, SBM_SETTHUMBSIZE,
  281.                 MPFROM2SHORT(swpClient.cy, sizRfb.cy), NULL) ;
  282.         WinSendMsg(hwndVert, SBM_SETSCROLLBAR,
  283.             MPFROM2SHORT(vpos, 0), MPFROM2SHORT(0, diff)) ;
  284.         WinEnableWindow(hwndVert, TRUE) ;
  285.     }
  286.     
  287.     if (! isIconized) {
  288.         SessSavedPos.x  = swpFrame.x  ;
  289.     SessSavedPos.y  = swpFrame.y  ;
  290.     SessSavedSiz.cx = swpFrame.cx ;
  291.     SessSavedSiz.cy = swpFrame.cy ;
  292.     SessSavedOff.x  = mapRfb.x    ;
  293.     SessSavedOff.y  = mapRfb.y    ;
  294.     }
  295.     TRACE("mapSize off %d %d\n", mapRfb.x, mapRfb.y) ;
  296. }
  297.  
  298. /*
  299.  * mapHorz - adjust horizontal mapping
  300.  */
  301.  
  302. #define PAGEDIV     8
  303. #define LINEUNIT    8
  304.  
  305. static  void    mapHorz(USHORT cmd, SHORT x)
  306. {
  307.     SHORT       new, lim ;
  308.     BOOL        set ;
  309.     
  310.     lim = sizRfb.cx - swpClient.cx ;
  311.     
  312.     switch (cmd) {
  313.     case SB_SLIDERTRACK    :
  314.     case SB_SLIDERPOSITION :
  315.         new = x     ;
  316.     set = FALSE ;
  317.     break ;
  318.     case SB_LINELEFT :
  319.         new = mapRfb.x - LINEUNIT ;
  320.     set = TRUE ;
  321.     break ;
  322.     case SB_LINERIGHT :
  323.         new = mapRfb.x + LINEUNIT ;
  324.     set = TRUE ;
  325.     break ;
  326.     case SB_PAGELEFT :
  327.         new = mapRfb.x - (sizRfb.cx / PAGEDIV) ;
  328.     set = TRUE ;
  329.     break ;
  330.     case SB_PAGERIGHT :
  331.         new = mapRfb.x + (sizRfb.cx / PAGEDIV) ;
  332.     set = TRUE ;
  333.     break ;
  334.     default :
  335.         return ;
  336.     }
  337.     
  338.     if (new < 0)   new = 0   ;
  339.     if (new > lim) new = lim ;
  340.     
  341.     if (set) {
  342.         WinSendMsg(hwndHorz, SBM_SETSCROLLBAR,
  343.             MPFROM2SHORT(new, 0), MPFROM2SHORT(0, lim)) ;
  344.     }
  345.     if (new != mapRfb.x) {
  346.         mapRfb.x = new ;
  347.         WinInvalidateRect(hwndClient, NULL, FALSE) ;
  348.     }
  349.     if (! isIconized) {
  350.     SessSavedOff.x  = mapRfb.x ;
  351.     SessSavedOff.y  = mapRfb.y ;
  352.     }
  353.     TRACE("mapHorz off %d %d\n", mapRfb.x, mapRfb.y) ;
  354. }
  355.  
  356. /*
  357.  * mapVert - adjust vertical mapping
  358.  */
  359.  
  360. static  void    mapVert(USHORT cmd, SHORT y)
  361. {
  362.     SHORT       new, lim ;
  363.     BOOL        set ;
  364.     
  365.     lim = sizRfb.cy - swpClient.cy ;
  366.     
  367.     switch (cmd) {
  368.     case SB_SLIDERTRACK    :
  369.     case SB_SLIDERPOSITION :
  370.         new = lim - y ;
  371.     set = FALSE ;
  372.     break ;
  373.     case SB_LINEUP :
  374.         new = mapRfb.y + LINEUNIT ;
  375.     set = TRUE ;
  376.     break ;
  377.     case SB_LINEDOWN :
  378.         new = mapRfb.y - LINEUNIT ;
  379.     set = TRUE ;
  380.     break ;
  381.     case SB_PAGEUP :
  382.         new = mapRfb.y + (sizRfb.cy / PAGEDIV) ;
  383.     set = TRUE ;
  384.     break ;
  385.     case SB_PAGEDOWN :
  386.         new = mapRfb.y - (sizRfb.cy / PAGEDIV) ;
  387.     set = TRUE ;
  388.     break ;
  389.     default :
  390.         return ;
  391.     }
  392.  
  393.     if (new < 0)   new = 0   ;
  394.     if (new > lim) new = lim ;
  395.     
  396.     if (set) {
  397.         WinSendMsg(hwndVert, SBM_SETSCROLLBAR,
  398.             MPFROM2SHORT((lim - new), 0), MPFROM2SHORT(0, lim)) ;
  399.     }
  400.     if (new != mapRfb.y) {
  401.         mapRfb.y = new ;
  402.     WinInvalidateRect(hwndClient, NULL, FALSE) ;
  403.     }
  404.     if (! isIconized) {
  405.     SessSavedOff.x  = mapRfb.x ;
  406.     SessSavedOff.y  = mapRfb.y ;
  407.     }
  408.     TRACE("mapVert off %d %d\n", mapRfb.x, mapRfb.y) ;
  409. }
  410.  
  411. /*
  412.  * mapPoint - map window point to RFB point
  413.  */
  414.  
  415. static  void    mapPoint(SHORT x, SHORT y, PPOINTL pt)
  416. {
  417.     /*
  418.      * don't exceed current window
  419.      */
  420.     if (x < 0) x = 0 ;
  421.     if (x > swpClient.cx) x = swpClient.cx ;
  422.     if (y < 0) y = 0 ;
  423.     if (y > swpClient.cy) y = swpClient.cy ;
  424.     
  425.     /*
  426.      * convert to Remote Frame Buffer position
  427.      */
  428.     x += mapRfb.x ;
  429.     y += mapRfb.y ;
  430.     pt->x = x             ;
  431.     pt->y = sizRfb.cy - y ;
  432. }
  433.  
  434. /*
  435.  * procClient - client window procedure
  436.  */
  437.  
  438. static  BOOL    mouseCaptured = FALSE ;
  439.  
  440. static MRESULT EXPENTRY procClient(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  441. {
  442.     HPS     hps ;
  443.     RECTL   rct ;
  444.     POINTL  pt  ;
  445.     POINTL  apt[4] ;
  446.     SHORT   x, y, w, h ;
  447.  
  448.     switch (msg) {
  449.  
  450.     case WM_CREATE :
  451.         mouseInit(hwnd) ;
  452.     return (MRESULT) 0 ;
  453.     case WM_DESTROY :
  454.         mouseDone(hwnd) ;
  455.     return (MRESULT) 0 ;    
  456.     
  457.     case WM_SIZE  :
  458.         mapSize(SHORT1FROMMP(mp2), SHORT2FROMMP(mp2)) ;
  459.     return (MRESULT) 0 ;
  460.     
  461.     case WM_HSCROLL :
  462.         mapHorz(SHORT2FROMMP(mp2), SHORT1FROMMP(mp2)) ;
  463.     return (MRESULT) 0 ;
  464.     case WM_VSCROLL :
  465.         mapVert(SHORT2FROMMP(mp2), SHORT1FROMMP(mp2)) ;
  466.         return (MRESULT) 0 ;
  467.     
  468.     case WM_MOUSEMOVE     :
  469.         mapPoint(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), &pt) ;
  470.         mouseMove(hwnd, &pt) ;
  471.     return (MRESULT) 0 ;
  472.  
  473.     case WM_BUTTON1DOWN   :
  474.     case WM_BUTTON2DOWN   :
  475.     case WM_BUTTON3DOWN   :
  476.         if (mouseCaptured == FALSE) {
  477.         WinSetCapture(HWND_DESKTOP, hwnd) ;
  478.         mouseCaptured = TRUE ;
  479.     }
  480.         mapPoint(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), &pt) ;
  481.         mouseEvent(hwnd, msg, &pt) ;
  482.         return WinDefWindowProc(hwnd, msg, mp1, mp2) ;
  483.  
  484.     case WM_BUTTON1UP     :
  485.     case WM_BUTTON2UP     :
  486.     case WM_BUTTON3UP     :
  487.         if (mouseCaptured == TRUE) {
  488.             WinSetCapture(HWND_DESKTOP, NULLHANDLE) ;
  489.         mouseCaptured = FALSE ;
  490.         }
  491.         mapPoint(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), &pt) ;
  492.         mouseEvent(hwnd, msg, &pt) ;
  493.         return WinDefWindowProc(hwnd, msg, mp1, mp2) ;
  494.  
  495.     case WM_BUTTON1CLICK  :
  496.     case WM_BUTTON2CLICK  :
  497.     case WM_BUTTON3CLICK  :
  498.         if (mouseCaptured == TRUE) {
  499.             WinSetCapture(HWND_DESKTOP, NULLHANDLE) ;
  500.         mouseCaptured = FALSE ;
  501.         }
  502.         mapPoint(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), &pt) ;
  503.         mouseEvent(hwnd, msg, &pt) ;
  504.         return WinDefWindowProc(hwnd, msg, mp1, mp2) ;
  505.  
  506.     case WM_BUTTON1DBLCLK :
  507.     case WM_BUTTON2DBLCLK :
  508.     case WM_BUTTON3DBLCLK :
  509.         if (mouseCaptured == FALSE) {
  510.         WinSetCapture(HWND_DESKTOP, hwnd) ;
  511.         mouseCaptured = TRUE ;
  512.     }
  513.         mapPoint(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), &pt) ;
  514.         mouseEvent(hwnd, msg, &pt) ;
  515.         return WinDefWindowProc(hwnd, msg, mp1, mp2) ;
  516.  
  517.     case WM_CHAR :
  518.         keyEvent(hwnd, 
  519.         SHORT1FROMMP(mp1), SHORT1FROMMP(mp2), 
  520.         SHORT2FROMMP(mp2), (USHORT) CHAR4FROMMP(mp1)) ;
  521.         return (MRESULT) 0 ;
  522.  
  523.     case WM_SETFOCUS :
  524.         keyFocusChange(hwnd) ;
  525.         return (MRESULT) 0 ;
  526.         
  527.     case WM_TIMER :
  528.         mouseTimer(hwnd) ;
  529.     return (MRESULT) 0 ;
  530.     
  531.     /*
  532.      * local messages
  533.      */
  534.  
  535.     case WM_VNC_FAIL :
  536.         errMessage((PUCHAR) mp2) ;
  537.     WinPostMsg(hwnd, WM_CLOSE, NULL, NULL) ;
  538.     return (MRESULT) 0 ;
  539.     
  540.     case WM_VNC_AUTH :
  541.         authCypher(hwnd, (PUCHAR) mp2) ;
  542.         protoSendAuth() ;
  543.         return (MRESULT) 0 ;
  544.     
  545.     case WM_VNC_INIT :
  546.         if (winSetup(SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), 
  547.                                                 (PUCHAR) mp2) != TRUE) {
  548.             WinPostMsg(hwnd, WM_CLOSE, NULL, NULL) ;
  549.         return (MRESULT) 0 ;
  550.         }
  551.         return (MRESULT) 0 ;
  552.  
  553.     case WM_VNC_BELL :
  554.     if (SessOptDeiconify) {
  555.             WinSetWindowPos(hwndFrame,
  556.                 HWND_TOP, 0, 0, 0, 0, (SWP_RESTORE | SWP_ZORDER)) ;
  557.     }
  558.         WinAlarm(HWND_DESKTOP, WA_NOTE) ;
  559.     return (MRESULT) 0 ;
  560.     
  561.     case WM_VNC_CLIP :
  562.         clipHold(hwnd, (PUCHAR) mp2) ;
  563.         return (MRESULT) 0 ;
  564.     
  565.     case WM_VNC_UPDATE :
  566.         x = SHORT1FROMMP(mp1) ;
  567.     y = SHORT2FROMMP(mp1) ;
  568.     w = SHORT1FROMMP(mp2) ;
  569.     h = SHORT2FROMMP(mp2) ;
  570.         rct.xLeft   = x     - mapRfb.x - 1 ;
  571.         rct.xRight  = x + w - mapRfb.x + 1 ;
  572.         rct.yBottom = y     - mapRfb.y - 1 ;
  573.         rct.yTop    = y + h - mapRfb.y + 1 ;
  574.         WinInvalidateRect(hwndClient, &rct, FALSE) ;
  575.         return (MRESULT) 0 ;
  576.  
  577.     case WM_PAINT :
  578.         hps = WinBeginPaint(hwnd, NULLHANDLE, &rct) ;
  579.         apt[0].x = rct.xLeft   ;
  580.         apt[0].y = rct.yBottom ;
  581.         apt[1].x = rct.xRight  ;
  582.         apt[1].y = rct.yTop    ;
  583.         apt[2].x = mapRfb.x + rct.xLeft   ;
  584.         apt[2].y = mapRfb.y + rct.yBottom ;
  585.         apt[3].x = mapRfb.x + rct.xRight  ;
  586.         apt[3].y = mapRfb.y + rct.yTop    ;
  587.         (*VncCtx->rectDraw) (hps, apt) ;
  588.     WinEndPaint(hps) ;
  589.     return (MRESULT) 0 ;
  590.     
  591.     case WM_COMMAND :
  592.         menuProc(hwnd, SHORT1FROMMP(mp1)) ; 
  593.         return (MRESULT) 0 ;
  594.     }
  595.     return WinDefWindowProc(hwnd, msg, mp1, mp2) ;
  596. }
  597.  
  598. /*
  599.  * winCreate - create windows
  600.  *      windows are first invisible and 0 sized.  They are sized to
  601.  *      RFB on received ServerInit message from VNC server.
  602.  */
  603.  
  604. #define VNCPROC "vncViewer"
  605.  
  606. BOOL    winCreate(HAB hab)
  607. {
  608.     ULONG   flFrameStyle ;
  609.     ULONG   flFrameFlags ;
  610.     
  611.     if (hwndFrame != NULLHANDLE || hwndClient != NULLHANDLE) {
  612.         return FALSE ;
  613.     }
  614.     
  615.     /*
  616.      * create standard window (set)
  617.      */
  618.  
  619.     flFrameStyle = 0 ;
  620.     flFrameFlags = FCF_TASKLIST | FCF_TITLEBAR | FCF_ICON | FCF_SYSMENU |
  621.                    FCF_SIZEBORDER | FCF_MINBUTTON | FCF_MAXBUTTON |
  622.                    FCF_HORZSCROLL | FCF_VERTSCROLL | FCF_ACCELTABLE ;
  623.  
  624.     WinRegisterClass(hab, VNCPROC, procClient, CS_SIZEREDRAW, 0) ;
  625.     
  626.     hwndFrame = WinCreateStdWindow(
  627.             HWND_DESKTOP,           /* parent window handle     */
  628.         flFrameStyle,           /* frame window styles      */
  629.         &flFrameFlags,          /* create flags             */
  630.         VNCPROC,                /* client window class      */
  631.         ProgramName,            /* as title                 */
  632.         0,                      /* client window styles     */
  633.         NULLHANDLE,             /* resource (internal)      */
  634.         ID_PMVNC,               /* window ID                */
  635.         &hwndClient) ;          /* client window            */
  636.  
  637.     if (hwndFrame == NULLHANDLE || hwndClient == NULLHANDLE) {
  638.         return FALSE ;
  639.     }
  640.  
  641.     pfnFrame = WinSubclassWindow(hwndFrame, procFrame) ;
  642.  
  643.     WinStartTimer(hab, hwndClient, 1, 50) ;
  644.     
  645.     WinQueryWindowPos(hwndFrame,  &swpFrame)  ;
  646.     WinQueryWindowPos(hwndClient, &swpClient) ;
  647.     
  648.     hwndHorz = WinWindowFromID(hwndFrame, FID_HORZSCROLL) ;
  649.     hwndVert = WinWindowFromID(hwndFrame, FID_VERTSCROLL) ;
  650.  
  651.     menuInit(hwndFrame)  ;      /* expand system menu   */
  652.     kstCreate(hwndFrame) ;      /* add modal key state  */
  653.     
  654.     sv_cxScreen     = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN)     ;
  655.     sv_cyScreen     = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN)     ;
  656.     sv_cyTitleBar   = WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR)   ;
  657.     sv_cxSizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER) ;
  658.     sv_cySizeBorder = WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER) ;
  659.  
  660.     return TRUE ;
  661. }
  662.  
  663. /*
  664.  * winDispose - dispose windows
  665.  */
  666.  
  667. void    winDispose(HAB hab)
  668. {
  669.     WinStopTimer(hab, hwndClient, 1) ;
  670.     
  671.     kstDestroy() ;
  672.     
  673.     if (hwndClient != NULLHANDLE) {
  674.         WinDestroyWindow(hwndClient) ;
  675.     hwndClient = NULLHANDLE ;
  676.     }
  677.     if (hwndFrame != NULLHANDLE) {
  678.         WinDestroyWindow(hwndFrame) ;
  679.     hwndFrame = NULLHANDLE ;
  680.     }
  681. }
  682.