| 1 | /***
 | 
|---|
| 2 |  This file belongs to the Gotcha! distribution.
 | 
|---|
| 3 |  Copyright (C) 1998-2002 Thorsten Thielen <thth@c2226.de>
 | 
|---|
| 4 | 
 | 
|---|
| 5 |  This program is free software; you can redistribute it and/or modify
 | 
|---|
| 6 |  it under the terms of the GNU General Public License as published by
 | 
|---|
| 7 |  the Free Software Foundation; either version 2 of the License, or
 | 
|---|
| 8 |  (at your option) any later version.
 | 
|---|
| 9 | 
 | 
|---|
| 10 |  This program is distributed in the hope that it will be useful,
 | 
|---|
| 11 |  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
|---|
| 12 |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
|---|
| 13 |  GNU General Public License for more details.
 | 
|---|
| 14 | 
 | 
|---|
| 15 |  You should have received a copy of the GNU General Public License
 | 
|---|
| 16 |  along with this program; if not, write to the Free Software
 | 
|---|
| 17 |  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 | 
|---|
| 18 |  ***/
 | 
|---|
| 19 | 
 | 
|---|
| 20 | // ** CreateMainWindow **************************************************** /*FOLD00*/
 | 
|---|
| 21 | 
 | 
|---|
| 22 | HWND CreateMainWindow (VOID)
 | 
|---|
| 23 | {
 | 
|---|
| 24 | #ifdef _QUIET_
 | 
|---|
| 25 |     hwndFrame = WinLoadDlg (HWND_OBJECT, NULLHANDLE, NULL, GETMODULE,
 | 
|---|
| 26 |                             ID_DLG_MAIN, NULL);
 | 
|---|
| 27 | #else
 | 
|---|
| 28 |     hwndFrame = WinLoadDlg (HWND_DESKTOP, NULLHANDLE, NULL, GETMODULE,
 | 
|---|
| 29 |                             ID_DLG_MAIN, NULL);
 | 
|---|
| 30 | #endif
 | 
|---|
| 31 |     OldFrameWP = WinSubclassWindow (hwndFrame, FrameProcedure);
 | 
|---|
| 32 | #ifndef _QUIET_
 | 
|---|
| 33 |     // attach the icon
 | 
|---|
| 34 |     if (HPOINTER hicon = WinLoadPointer (HWND_DESKTOP, GETMODULE, 1))
 | 
|---|
| 35 |         WinSendMsg (hwndFrame, WM_SETICON, MPFROMLONG (hicon), NULL);
 | 
|---|
| 36 | 
 | 
|---|
| 37 |     // attach the accelerator table
 | 
|---|
| 38 |     if (HACCEL haccel = WinLoadAccelTable (hab, GETMODULE, 1))
 | 
|---|
| 39 |         WinSetAccelTable (hab, haccel, hwndFrame);
 | 
|---|
| 40 | #endif
 | 
|---|
| 41 | 
 | 
|---|
| 42 |     // add extensions to system menu
 | 
|---|
| 43 | /*    static MENUITEM MenuAbout = { MIT_END, MIS_TEXT, 0, WID_PB_ABOUT, 0, 0 };
 | 
|---|
| 44 |     static MENUITEM MenuSettings = { MIT_END, MIS_TEXT, 0, WID_PB_SETTINGS, 0, 0 };
 | 
|---|
| 45 |     static MENUITEM MenuGeneralHelp = { MIT_END, MIS_TEXT, 0, HM_GENERAL_HELP, 0, 0 };
 | 
|---|
| 46 |     static MENUITEM MenuSeparator = { MIT_END, MIS_SEPARATOR, 0, 0, 0, 0 };
 | 
|---|
| 47 | 
 | 
|---|
| 48 |     AddSysMenuItem (hwndFrame, &MenuSeparator, NULL);
 | 
|---|
| 49 |     AddSysMenuItem (hwndFrame, &MenuSettings, RSTR(IDS_SETTINGS));
 | 
|---|
| 50 |     AddSysMenuItem (hwndFrame, &MenuGeneralHelp, RSTR(IDS_GENERALHELP));
 | 
|---|
| 51 |     AddSysMenuItem (hwndFrame, &MenuAbout, RSTR(IDS_PRODUCTINFORMATION));*/
 | 
|---|
| 52 | 
 | 
|---|
| 53 |     HWND   hwnd = WinWindowFromID (hwndFrame, FID_CLIENT);
 | 
|---|
| 54 | 
 | 
|---|
| 55 |     // select the radio button
 | 
|---|
| 56 |     switch (pset->QuerySaveStyle ())
 | 
|---|
| 57 |     {
 | 
|---|
| 58 |     case SAVESTYLE_CLIPBOARD:
 | 
|---|
| 59 |         WinSendDlgItemMsg (hwnd, WID_RB_CLIPBOARD, BM_CLICK,
 | 
|---|
| 60 |                            MPFROMSHORT (TRUE), 0);      break;
 | 
|---|
| 61 |     default:
 | 
|---|
| 62 |         WinSendDlgItemMsg (hwnd, WID_RB_FILE, BM_CLICK,
 | 
|---|
| 63 |                            MPFROMSHORT (TRUE), 0);      break;
 | 
|---|
| 64 |     }
 | 
|---|
| 65 |     AdjustSaveTypeButtons (BOOL (pset->QueryFileSaveStyle ()==FSS_FORCEFILE));
 | 
|---|
| 66 | 
 | 
|---|
| 67 |     if (pset->SerialCapture ())
 | 
|---|
| 68 |         WinEnableWindow (WinWindowFromID (hwnd, WID_CB_DELAYEDCAPTURE), FALSE);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |     // adjust the other buttons
 | 
|---|
| 71 |     WinSendDlgItemMsg (hwnd, WID_CB_HIDEWINDOW, BM_SETCHECK,
 | 
|---|
| 72 |                        MPFROMLONG (pset->HideWindow ()), MPFROMLONG (0));
 | 
|---|
| 73 |     WinSendDlgItemMsg (hwnd, WID_CB_DELAYEDCAPTURE, BM_SETCHECK,
 | 
|---|
| 74 |                        MPFROMLONG (pset->DelayedCapture ()), MPFROMLONG (0));
 | 
|---|
| 75 |     return hwndFrame;
 | 
|---|
| 76 | }
 | 
|---|
| 77 | 
 | 
|---|
| 78 | // ** Drag **************************************************************** /*FOLD00*/
 | 
|---|
| 79 | 
 | 
|---|
| 80 | VOID Drag (HWND hwnd)
 | 
|---|
| 81 | {
 | 
|---|
| 82 |     // determine the new window position
 | 
|---|
| 83 |     TRACKINFO   trackinfo ;
 | 
|---|
| 84 |     memset (&trackinfo, 0, sizeof (trackinfo));
 | 
|---|
| 85 | 
 | 
|---|
| 86 |     trackinfo.cxBorder = 1;
 | 
|---|
| 87 |     trackinfo.cyBorder = 1;
 | 
|---|
| 88 |     trackinfo.cxGrid = 1;
 | 
|---|
| 89 |     trackinfo.cyGrid = 1;
 | 
|---|
| 90 |     trackinfo.cxKeyboard = 8;
 | 
|---|
| 91 |     trackinfo.cyKeyboard = 8;
 | 
|---|
| 92 |  
 | 
|---|
| 93 |     SWP   swp;
 | 
|---|
| 94 |     WinQueryWindowPos (hwnd, &swp);
 | 
|---|
| 95 |     trackinfo.rclTrack.xLeft   = swp.x;
 | 
|---|
| 96 |     trackinfo.rclTrack.xRight  = swp.x + swp.cx;
 | 
|---|
| 97 |     trackinfo.rclTrack.yBottom = swp.y;
 | 
|---|
| 98 |     trackinfo.rclTrack.yTop    = swp.y + swp.cy;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |     WinQueryWindowPos (HWND_DESKTOP, &swp);
 | 
|---|
| 101 |     trackinfo.rclBoundary.xLeft   = swp.x;
 | 
|---|
| 102 |     trackinfo.rclBoundary.xRight  = swp.x + swp.cx;
 | 
|---|
| 103 |     trackinfo.rclBoundary.yBottom = swp.y;
 | 
|---|
| 104 |     trackinfo.rclBoundary.yTop    = swp.y + swp.cy;
 | 
|---|
| 105 | 
 | 
|---|
| 106 |     trackinfo.ptlMinTrackSize.x = 0;
 | 
|---|
| 107 |     trackinfo.ptlMinTrackSize.y = 0;
 | 
|---|
| 108 |     trackinfo.ptlMaxTrackSize.x = swp.cx;
 | 
|---|
| 109 |     trackinfo.ptlMaxTrackSize.y = swp.cy;
 | 
|---|
| 110 | 
 | 
|---|
| 111 |     trackinfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY;
 | 
|---|
| 112 | 
 | 
|---|
| 113 |     if (WinTrackRect (HWND_DESKTOP, 0, &trackinfo))
 | 
|---|
| 114 |         WinSetWindowPos (hwnd, 0, trackinfo.rclTrack.xLeft,
 | 
|---|
| 115 |                          trackinfo.rclTrack.yBottom, 0, 0, SWP_MOVE);
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | // ** FrameProcedure ****************************************************** /*FOLD00*/
 | 
|---|
| 119 | 
 | 
|---|
| 120 | MRESULT EXPENTRY FrameProcedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 121 | {
 | 
|---|
| 122 |     // ATTENTION: used by both main & snapshot window!
 | 
|---|
| 123 | 
 | 
|---|
| 124 |     switch (msg)
 | 
|---|
| 125 |     {
 | 
|---|
| 126 |     case WM_QUERYTRACKINFO:
 | 
|---|
| 127 |         {
 | 
|---|
| 128 |             OldFrameWP (hwnd, msg, mp1, mp2);
 | 
|---|
| 129 |             PTRACKINFO  pti = PTRACKINFO (mp2);
 | 
|---|
| 130 |             pti->ptlMinTrackSize.x = pti->ptlMinTrackSize.y = 16;
 | 
|---|
| 131 |         }
 | 
|---|
| 132 |         return MRESULT (TRUE);
 | 
|---|
| 133 | 
 | 
|---|
| 134 |     case WM_WINDOWPOSCHANGED:
 | 
|---|
| 135 |         if ((PSWP (mp1)->fl & SWP_HIDE))
 | 
|---|
| 136 |             WinPostMsg (WinWindowFromID (hwnd, FID_CLIENT),
 | 
|---|
| 137 |                         UM_WINDOWHIDDEN, 0,0);
 | 
|---|
| 138 |         break;
 | 
|---|
| 139 |     }
 | 
|---|
| 140 | 
 | 
|---|
| 141 |     return OldFrameWP (hwnd, msg, mp1, mp2);
 | 
|---|
| 142 | }
 | 
|---|
| 143 | 
 | 
|---|
| 144 | // ** WindowProcedure ***************************************************** /*FOLD00*/
 | 
|---|
| 145 | 
 | 
|---|
| 146 | MRESULT EXPENTRY WindowProcedure (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
 | 
|---|
| 147 | {
 | 
|---|
| 148 |     static BOOL     fInterior = FALSE;
 | 
|---|
| 149 |     static USHORT   usState = STATE_IDLE, usCap;
 | 
|---|
| 150 |     static ULONG    ulTimer, ulCountdown;
 | 
|---|
| 151 |     static HWND     hwndCap, hwndParent;
 | 
|---|
| 152 |     static RECTL    rcl;
 | 
|---|
| 153 | 
 | 
|---|
| 154 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 155 |     LogDebug( "MainWin:WindowProcedure:Message 0x%04x", msg );
 | 
|---|
| 156 | #endif
 | 
|---|
| 157 | 
 | 
|---|
| 158 |     switch (msg)
 | 
|---|
| 159 |     {
 | 
|---|
| 160 | #ifndef _QUIET_
 | 
|---|
| 161 |     case WM_CREATE:
 | 
|---|
| 162 | #else
 | 
|---|
| 163 |     case WM_INITDLG:
 | 
|---|
| 164 | #endif
 | 
|---|
| 165 |         {
 | 
|---|
| 166 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 167 |             LogDebug( "MainWin:WindowProcedure: WM_CREATE" );
 | 
|---|
| 168 | #endif
 | 
|---|
| 169 | #ifndef _QUIET_
 | 
|---|
| 170 |             USHORT   usResID = WinQueryWindowUShort (hwnd, QWS_ID);
 | 
|---|
| 171 | 
 | 
|---|
| 172 |             // attach the icon
 | 
|---|
| 173 |             if (HPOINTER hicon = WinLoadPointer (HWND_DESKTOP, GETMODULE, usResID))
 | 
|---|
| 174 |                 WinSendMsg (hwnd, WM_SETICON, MPFROMLONG (hicon), MPVOID);
 | 
|---|
| 175 | 
 | 
|---|
| 176 |             RECTL   rcl;
 | 
|---|
| 177 |             WinQueryWindowRect (hwndFrame, &rcl);
 | 
|---|
| 178 |             WinCalcFrameRect (hwndFrame, &rcl, TRUE);
 | 
|---|
| 179 |             WinSetWindowPos (WinWindowFromID (hwndFrame, FID_CLIENT), HWND_TOP,
 | 
|---|
| 180 |                              rcl.xLeft, rcl.yBottom, rcl.xRight - rcl.xLeft,
 | 
|---|
| 181 |                              rcl.yTop - rcl.yBottom,
 | 
|---|
| 182 |                              SWP_SHOW | SWP_MOVE | SWP_SIZE | SWP_ZORDER);
 | 
|---|
| 183 | #endif
 | 
|---|
| 184 |         }
 | 
|---|
| 185 | #ifdef _QUIET_
 | 
|---|
| 186 |         WinSendDlgItemMsg (hwnd, WID_CB_HIDEWINDOW, BM_SETCHECK,
 | 
|---|
| 187 |                            MPFROMLONG (TRUE), MPFROMLONG (0));
 | 
|---|
| 188 |         WinSendDlgItemMsg (hwnd, WID_CB_DELAYEDCAPTURE, BM_SETCHECK,
 | 
|---|
| 189 |                            MPFROMLONG (pset->DelayedCapture ()),
 | 
|---|
| 190 |                            MPFROMLONG (0));
 | 
|---|
| 191 |         WinSetFocus( WinWindowFromID (g_hwndPage0, WID_RB_FILE), FALSE );
 | 
|---|
| 192 |         return MRESULT (FALSE);
 | 
|---|
| 193 | #else
 | 
|---|
| 194 |         break;
 | 
|---|
| 195 | #endif
 | 
|---|
| 196 | 
 | 
|---|
| 197 |     case WM_QUIT:
 | 
|---|
| 198 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 199 |         LogDebug( "MainWin:WindowProcedure: WM_QUIT" );
 | 
|---|
| 200 | #endif
 | 
|---|
| 201 |     case WM_SAVEAPPLICATION:
 | 
|---|
| 202 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 203 |         LogDebug( "MainWin:WindowProcedure: WM_SAVEAPPLICATION" );
 | 
|---|
| 204 | #endif
 | 
|---|
| 205 |     case WM_CLOSE:
 | 
|---|
| 206 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 207 |         LogDebug( "MainWin:WindowProcedure: WM_CLOSE" );
 | 
|---|
| 208 | #endif
 | 
|---|
| 209 |         WinSendMsg (hwnd, UM_ADJUSTSETTINGS, 0,0);
 | 
|---|
| 210 |         break;
 | 
|---|
| 211 | 
 | 
|---|
| 212 |     case UM_ADJUSTSETTINGS:
 | 
|---|
| 213 |         {
 | 
|---|
| 214 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 215 |             LogDebug( "MainWin:WindowProcedure: UM_ADJUSTSETTINGS" );
 | 
|---|
| 216 | #endif
 | 
|---|
| 217 |             if (WinSendMsg (WinWindowFromID (hwnd, WID_RB_CLIPBOARD),
 | 
|---|
| 218 |                             BM_QUERYCHECK, 0,0))
 | 
|---|
| 219 |                 pset->SetSaveStyle (SAVESTYLE_CLIPBOARD);
 | 
|---|
| 220 |             else
 | 
|---|
| 221 |                 pset->SetSaveStyle (SAVESTYLE_FILE);
 | 
|---|
| 222 | 
 | 
|---|
| 223 |             BOOL   f = FALSE;
 | 
|---|
| 224 |             f = BOOL (WinSendDlgItemMsg (hwnd, WID_CB_HIDEWINDOW,
 | 
|---|
| 225 |                                          BM_QUERYCHECK, 0, 0));
 | 
|---|
| 226 |             pset->HideWindow (f);
 | 
|---|
| 227 | #ifndef _QUIET_
 | 
|---|
| 228 |             f = BOOL (WinSendDlgItemMsg (hwnd, WID_CB_DELAYEDCAPTURE,
 | 
|---|
| 229 |                                          BM_QUERYCHECK, 0, 0));
 | 
|---|
| 230 |             pset->DelayedCapture (f);
 | 
|---|
| 231 | #endif
 | 
|---|
| 232 |         }
 | 
|---|
| 233 |         return MRESULT (FALSE);
 | 
|---|
| 234 | 
 | 
|---|
| 235 |     case WM_MOUSEMOVE:
 | 
|---|
| 236 |         // we don't want the mouse pointer to be reset so capture this msg
 | 
|---|
| 237 |         return MRESULT (FALSE);
 | 
|---|
| 238 | 
 | 
|---|
| 239 | #ifndef _QUIET_
 | 
|---|
| 240 |     case WM_PAINT:
 | 
|---|
| 241 |         {
 | 
|---|
| 242 |             HPS   hps;
 | 
|---|
| 243 |             RECTL rcl;
 | 
|---|
| 244 |             COLOR color = SYSCLR_DIALOGBACKGROUND;
 | 
|---|
| 245 | 
 | 
|---|
| 246 |             HWND  hwnd2 = WinWindowFromID (hwnd, WID_RB_CLIPBOARD);
 | 
|---|
| 247 |             WinQueryPresParam (hwnd2, PP_BACKGROUNDCOLOR, 0, NULL,
 | 
|---|
| 248 |                                sizeof (color), &color, 0L);
 | 
|---|
| 249 | 
 | 
|---|
| 250 |             hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
 | 
|---|
| 251 |             WinQueryWindowRect (hwnd, &rcl);
 | 
|---|
| 252 |             WinFillRect (hps, &rcl, color);
 | 
|---|
| 253 |             WinEndPaint (hps);
 | 
|---|
| 254 |         }
 | 
|---|
| 255 |         break;
 | 
|---|
| 256 | #endif
 | 
|---|
| 257 | 
 | 
|---|
| 258 |     case WM_COMMAND:
 | 
|---|
| 259 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 260 |         LogDebug( "MainWin:WindowProcedure: WM_COMMAND" );
 | 
|---|
| 261 | #endif
 | 
|---|
| 262 |         if (usState != STATE_IDLE)
 | 
|---|
| 263 |         {
 | 
|---|
| 264 |             //Attempt to open settings probably a hang
 | 
|---|
| 265 |             if (SHORT1FROMMP (mp1) == WID_PB_SETTINGS) {
 | 
|---|
| 266 |                 WinSendMsg (hwnd, UM_ABORT, 0,0);
 | 
|---|
| 267 |                 pset->Dialog ();
 | 
|---|
| 268 |             }
 | 
|---|
| 269 |             // this means ESC was pressed
 | 
|---|
| 270 |             else if (SHORT1FROMMP (mp1) == DID_CANCEL)
 | 
|---|
| 271 |                 WinSendMsg (hwnd, UM_ABORT, MPFROMLONG(1),0);
 | 
|---|
| 272 |             return MRESULT (FALSE);
 | 
|---|
| 273 |         }
 | 
|---|
| 274 | #ifndef _QUIET_
 | 
|---|
| 275 |         else
 | 
|---|
| 276 |             // FIXME pretty yukki to do it this way I guess ...
 | 
|---|
| 277 |             WinSendMsg (hwnd, UM_ADJUSTSETTINGS, 0,0);
 | 
|---|
| 278 | #endif         
 | 
|---|
| 279 |         switch (SHORT1FROMMP (mp1))
 | 
|---|
| 280 |         {
 | 
|---|
| 281 |         case WID_RB_CLIPBOARD:
 | 
|---|
| 282 |             WinSendDlgItemMsg (hwnd, WID_RB_CLIPBOARD, BM_CLICK,
 | 
|---|
| 283 |                                MPFROMSHORT (TRUE), PVOID (0));
 | 
|---|
| 284 |             break;
 | 
|---|
| 285 |         case WID_RB_FILE:
 | 
|---|
| 286 |             WinSendDlgItemMsg (hwnd, WID_RB_FILE, BM_CLICK,
 | 
|---|
| 287 |                                MPFROMSHORT (TRUE), PVOID (0));
 | 
|---|
| 288 |             break;
 | 
|---|
| 289 |         case WID_CB_HIDEWINDOW:
 | 
|---|
| 290 |             WinSendDlgItemMsg (hwnd, WID_CB_HIDEWINDOW, BM_CLICK,
 | 
|---|
| 291 |                                MPFROMSHORT (TRUE), PVOID (0));
 | 
|---|
| 292 |             break;
 | 
|---|
| 293 |         case WID_CB_DELAYEDCAPTURE:
 | 
|---|
| 294 |             WinSendDlgItemMsg (hwnd, WID_CB_DELAYEDCAPTURE, BM_CLICK,
 | 
|---|
| 295 |                                MPFROMSHORT (TRUE), PVOID (0));
 | 
|---|
| 296 |             break;
 | 
|---|
| 297 | 
 | 
|---|
| 298 |         case WID_PB_ABOUT:
 | 
|---|
| 299 |             AboutBox (hwnd);
 | 
|---|
| 300 |             break;
 | 
|---|
| 301 | 
 | 
|---|
| 302 |         case WID_PB_SETTINGS:
 | 
|---|
| 303 |             pset->Dialog ();
 | 
|---|
| 304 |             break;
 | 
|---|
| 305 | 
 | 
|---|
| 306 |         case WID_PB_SETCAPTURETYPE:
 | 
|---|
| 307 |             //int capType;
 | 
|---|
| 308 |             if (LONGFROMMP(mp2) == 1) {
 | 
|---|
| 309 |                 pset->SetSaveStyle (SAVESTYLE_CLIPBOARD);
 | 
|---|
| 310 |             }
 | 
|---|
| 311 | 
 | 
|---|
| 312 |             switch (pset->QuerySSWCaptureType ())
 | 
|---|
| 313 |             {
 | 
|---|
| 314 |             case CAP_WINDOWINT:
 | 
|---|
| 315 |                 WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 316 |                             MPFROM2SHORT (WID_PB_WINDOWINTERIOR,0), 0);
 | 
|---|
| 317 |             case CAP_SCREENREGION:
 | 
|---|
| 318 |                 WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 319 |                             MPFROM2SHORT (WID_PB_SCREENREGION,0), 0);
 | 
|---|
| 320 |             case CAP_WINDOW:
 | 
|---|
| 321 |                 WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 322 |                             MPFROM2SHORT (WID_PB_WINDOW,0), 0);
 | 
|---|
| 323 |             default:
 | 
|---|
| 324 |                WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 325 |                             MPFROM2SHORT (WID_PB_SCREEN,0), 0);
 | 
|---|
| 326 |             }
 | 
|---|
| 327 |             break;
 | 
|---|
| 328 | 
 | 
|---|
| 329 |         case WID_PB_SCREEN:
 | 
|---|
| 330 |             usCap = CAP_SCREEN;
 | 
|---|
| 331 | #ifdef _QUIET_
 | 
|---|
| 332 |             WinShowWindow (g_hwndSettingsDialog, FALSE);
 | 
|---|
| 333 |             // WinSendMsg (g_hwndSettingsDialog, WM_CLOSE, 0,0); //Needs to go to the setting dialog
 | 
|---|
| 334 |             // Replace current global with pset->GetSettingDialogHwnd () or such
 | 
|---|
| 335 |             // Need for all 4 cases;
 | 
|---|
| 336 | #endif
 | 
|---|
| 337 |             WinSendMsg (hwnd, UM_PREPARECAPTURE, 0,0);
 | 
|---|
| 338 |             break;
 | 
|---|
| 339 | 
 | 
|---|
| 340 |         case WID_PB_SCREENREGION:
 | 
|---|
| 341 |             usCap = CAP_SCREENREGION;
 | 
|---|
| 342 | #ifdef _QUIET_
 | 
|---|
| 343 |             WinShowWindow (g_hwndSettingsDialog, FALSE);
 | 
|---|
| 344 | #endif
 | 
|---|
| 345 |             WinSendMsg (hwnd, UM_PREPARECAPTURE, 0,0);
 | 
|---|
| 346 |             break;
 | 
|---|
| 347 | 
 | 
|---|
| 348 |         case WID_PB_WINDOWINTERIOR:
 | 
|---|
| 349 |             usCap = CAP_WINDOWINT;
 | 
|---|
| 350 | #ifdef _QUIET_
 | 
|---|
| 351 |             WinShowWindow (g_hwndSettingsDialog, FALSE);
 | 
|---|
| 352 | #endif
 | 
|---|
| 353 |             WinSendMsg (hwnd, UM_PREPARECAPTURE, 0,0);
 | 
|---|
| 354 |             break;
 | 
|---|
| 355 | 
 | 
|---|
| 356 |         case WID_PB_WINDOW:
 | 
|---|
| 357 |             usCap = CAP_WINDOW;
 | 
|---|
| 358 | #ifdef _QUIET_
 | 
|---|
| 359 |             WinShowWindow (g_hwndSettingsDialog, FALSE);
 | 
|---|
| 360 | #endif
 | 
|---|
| 361 |             WinSendMsg (hwnd, UM_PREPARECAPTURE, 0,0);
 | 
|---|
| 362 |             break;
 | 
|---|
| 363 | 
 | 
|---|
| 364 |         case WID_PB_EXIT:
 | 
|---|
| 365 |             WinSendMsg (WinWindowFromID (hwndFrame, FID_CLIENT),
 | 
|---|
| 366 |                         WM_CLOSE, 0,0);
 | 
|---|
| 367 |             break;
 | 
|---|
| 368 | 
 | 
|---|
| 369 |         case HM_HELP_CONTENTS:    g_phelp->DisplayContents ();       break;
 | 
|---|
| 370 |         case HM_HELP_INDEX:       g_phelp->DisplayIndex ();          break;
 | 
|---|
| 371 |         case HM_KEYS_HELP:        g_phelp->DisplayKeysHelp ();       break;
 | 
|---|
| 372 | 
 | 
|---|
| 373 |         case HM_GENERAL_HELP:
 | 
|---|
| 374 |             g_phelp->DisplayGeneralHelp ();
 | 
|---|
| 375 |             break;
 | 
|---|
| 376 | 
 | 
|---|
| 377 |         default:
 | 
|---|
| 378 |             break;
 | 
|---|
| 379 |         }
 | 
|---|
| 380 |         return MRESULT (FALSE);
 | 
|---|
| 381 | 
 | 
|---|
| 382 |     case UM_PREPARECAPTURE:
 | 
|---|
| 383 |         WinSendMsg (hwndSnapshot, UM_STARTCAPTURE, 0,0);
 | 
|---|
| 384 |         usState = STATE_WAITFORHIDE;
 | 
|---|
| 385 | 
 | 
|---|
| 386 |         if (usCap == CAP_SCREENREGION || usCap == CAP_SCREEN) {
 | 
|---|
| 387 | #ifdef _QUIET_
 | 
|---|
| 388 |             hwndParent = WinQueryFocus(HWND_DESKTOP);
 | 
|---|
| 389 | #else
 | 
|---|
| 390 |             hwndParent = WinQueryWindow(hwndFrame, QW_NEXTTOP );
 | 
|---|
| 391 | #endif
 | 
|---|
| 392 |         }
 | 
|---|
| 393 |         /*else {
 | 
|---|
| 394 |             SWP     swp;
 | 
|---|
| 395 |             CHAR    ach[32] = {0};
 | 
|---|
| 396 | 
 | 
|---|
| 397 |             WinQueryClassName (WinQueryFocus(HWND_DESKTOP), sizeof (ach), ach);
 | 
|---|
| 398 |             if (stricmp (ach, "#4") == 0) {
 | 
|---|
| 399 |                 WinSendMsg (hwnd, UM_ABORT, 0,0);
 | 
|---|
| 400 |                 if (usCap == CAP_WINDOW)
 | 
|---|
| 401 |                     WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 402 |                                 MPFROM2SHORT (WID_PB_WINDOW,0), 0);
 | 
|---|
| 403 |                 else
 | 
|---|
| 404 |                     WinSendMsg (hwndFrame, WM_COMMAND,
 | 
|---|
| 405 |                                 MPFROM2SHORT (WID_PB_WINDOWINTERIOR,0), 0);
 | 
|---|
| 406 |                 return MRESULT (FALSE);
 | 
|---|
| 407 |             }
 | 
|---|
| 408 |         } */
 | 
|---|
| 409 | #ifndef _QUIET_
 | 
|---|
| 410 |         if (WinQueryButtonCheckstate (hwnd, WID_CB_HIDEWINDOW)) {
 | 
|---|
| 411 |             WinShowWindow (WinQueryWindow (hwnd, QW_PARENT), FALSE);
 | 
|---|
| 412 |         }
 | 
|---|
| 413 |         else
 | 
|---|
| 414 | #endif
 | 
|---|
| 415 |             WinPostMsg (hwnd, UM_WINDOWHIDDEN, 0,0);
 | 
|---|
| 416 |         return MRESULT (FALSE);
 | 
|---|
| 417 | 
 | 
|---|
| 418 |     case UM_WINDOWHIDDEN:
 | 
|---|
| 419 |         if (usState == STATE_WAITFORHIDE)
 | 
|---|
| 420 |         {
 | 
|---|
| 421 |             // FIXME
 | 
|---|
| 422 |             // I have no idea why this delay is necessary, but CAP_SCREEN with
 | 
|---|
| 423 |             // hiding our window does not work without it ...
 | 
|---|
| 424 |             DosSleep (100);
 | 
|---|
| 425 |             usState = STATE_SELECTWINDOW;
 | 
|---|
| 426 |             WinSendMsg (hwnd, UM_SELECTWINDOW, 0,0);
 | 
|---|
| 427 |         }
 | 
|---|
| 428 |         return MRESULT (FALSE);
 | 
|---|
| 429 | 
 | 
|---|
| 430 |     case UM_SELECTWINDOW:
 | 
|---|
| 431 |         switch (usCap)
 | 
|---|
| 432 |         {
 | 
|---|
| 433 |         case CAP_SCREEN:
 | 
|---|
| 434 |             usState = STATE_WINDOWSELECTED;
 | 
|---|
| 435 |             WinPostMsg (hwnd, UM_WINDOWSELECTED,
 | 
|---|
| 436 |                         MPFROMHWND (HWND_DESKTOP),
 | 
|---|
| 437 |                         MPFROMHWND (HWND_DESKTOP));
 | 
|---|
| 438 |             break;
 | 
|---|
| 439 | 
 | 
|---|
| 440 |         case CAP_SCREENREGION:
 | 
|---|
| 441 | #ifdef _QUIET_
 | 
|---|
| 442 |             WinSetFocus(HWND_DESKTOP, hwnd);
 | 
|---|
| 443 | #endif
 | 
|---|
| 444 |             if (DoTracking (&rcl))
 | 
|---|
| 445 |             {
 | 
|---|
| 446 |                 usState = STATE_WINDOWSELECTED;
 | 
|---|
| 447 |                 int rc = saymsg2(1, hwnd, RSTR(IDS_CAPTURE), RSTR(IDS_WISHCONTINUE));
 | 
|---|
| 448 |                 
 | 
|---|
| 449 |                 if (rc == 1)
 | 
|---|
| 450 |                     DosSleep(100); // Let the dialog close
 | 
|---|
| 451 |                     WinPostMsg (hwnd, UM_WINDOWSELECTED,
 | 
|---|
| 452 |                                 MPFROMHWND (HWND_DESKTOP),
 | 
|---|
| 453 |                                 MPFROMHWND (HWND_DESKTOP));
 | 
|---|
| 454 |                 if (rc == 2)
 | 
|---|
| 455 |                     WinSendMsg (hwnd, UM_ABORT, MPFROMLONG(1),0);
 | 
|---|
| 456 |                 if (rc == 3) {
 | 
|---|
| 457 |                     pset->Dialog ();
 | 
|---|
| 458 |                     DosSleep(100); // Let the dialogs close
 | 
|---|
| 459 |                     WinPostMsg (hwnd, UM_WINDOWSELECTED,
 | 
|---|
| 460 |                                 MPFROMHWND (HWND_DESKTOP),
 | 
|---|
| 461 |                                 MPFROMHWND (HWND_DESKTOP));
 | 
|---|
| 462 |                 }
 | 
|---|
| 463 |             }
 | 
|---|
| 464 |             else
 | 
|---|
| 465 |                 usState = STATE_IDLE;
 | 
|---|
| 466 |             break;
 | 
|---|
| 467 | 
 | 
|---|
| 468 |         case CAP_WINDOWINT:
 | 
|---|
| 469 |             fInterior = TRUE;
 | 
|---|
| 470 | #ifdef _QUIET_
 | 
|---|
| 471 |             WinSetFocus(HWND_DESKTOP, hwnd);
 | 
|---|
| 472 | #endif
 | 
|---|
| 473 |             StartSelection (hwnd);
 | 
|---|
| 474 |             break;
 | 
|---|
| 475 | 
 | 
|---|
| 476 |         case CAP_WINDOW:
 | 
|---|
| 477 |             fInterior = FALSE;
 | 
|---|
| 478 | #ifdef _QUIET_
 | 
|---|
| 479 |             WinSetFocus(HWND_DESKTOP, hwnd);
 | 
|---|
| 480 | #endif
 | 
|---|
| 481 |             StartSelection (hwnd);
 | 
|---|
| 482 |             break;
 | 
|---|
| 483 | 
 | 
|---|
| 484 |         default:
 | 
|---|
| 485 |             usState = STATE_IDLE;
 | 
|---|
| 486 |             break;
 | 
|---|
| 487 |         }
 | 
|---|
| 488 |         return MRESULT (FALSE);
 | 
|---|
| 489 | 
 | 
|---|
| 490 |     case WM_BUTTON1UP:
 | 
|---|
| 491 |         if (usState != STATE_SELECTWINDOW)
 | 
|---|
| 492 |             return MRESULT (FALSE);
 | 
|---|
| 493 |         else
 | 
|---|
| 494 |         {
 | 
|---|
| 495 |             POINTL   ptl;
 | 
|---|
| 496 |             WinQueryPointerPos (HWND_DESKTOP, &ptl);
 | 
|---|
| 497 |             HWND   hwndCapture =
 | 
|---|
| 498 |                 WinWindowFromPoint (HWND_DESKTOP, &ptl, FALSE);
 | 
|---|
| 499 | 
 | 
|---|
| 500 |             if (hwndCapture && (hwndCapture != HWND_DESKTOP))
 | 
|---|
| 501 |             {
 | 
|---|
| 502 |                 HWND   hwndOld = hwndCapture;
 | 
|---|
| 503 | 
 | 
|---|
| 504 |                 if (fInterior)
 | 
|---|
| 505 |                     if (! (hwndCapture = WinWindowFromID (hwndOld,
 | 
|---|
| 506 |                                                           FID_CLIENT)))
 | 
|---|
| 507 |                         hwndCapture = WinQueryWindow (hwndOld, QW_BOTTOM);
 | 
|---|
| 508 | 
 | 
|---|
| 509 |                 if (hwndCapture && (hwndCapture != HWND_DESKTOP))
 | 
|---|
| 510 |                 {
 | 
|---|
| 511 |                     usState = STATE_WINDOWSELECTED;
 | 
|---|
| 512 |                     WinPostMsg (hwnd, UM_WINDOWSELECTED,
 | 
|---|
| 513 |                                 MPFROMHWND (hwndCapture),
 | 
|---|
| 514 |                                 MPFROMHWND (hwndOld));
 | 
|---|
| 515 |                 }
 | 
|---|
| 516 |                 else
 | 
|---|
| 517 |                     usState = STATE_IDLE;
 | 
|---|
| 518 |             }
 | 
|---|
| 519 |             else
 | 
|---|
| 520 |                 usState = STATE_IDLE;
 | 
|---|
| 521 |         }
 | 
|---|
| 522 |         return MRESULT (FALSE);
 | 
|---|
| 523 | 
 | 
|---|
| 524 |     case UM_WINDOWSELECTED:
 | 
|---|
| 525 |         if (usState == STATE_WINDOWSELECTED)
 | 
|---|
| 526 |         {
 | 
|---|
| 527 |             // release the pointing device capture if it is active
 | 
|---|
| 528 |             if (WinQueryCapture (HWND_DESKTOP) == hwnd)
 | 
|---|
| 529 |                 WinSetCapture (HWND_DESKTOP, NULLHANDLE);
 | 
|---|
| 530 | 
 | 
|---|
| 531 |             // reset the pointer to normal shape
 | 
|---|
| 532 |             WinSetPointer (HWND_DESKTOP, WinQuerySysPointer (HWND_DESKTOP,
 | 
|---|
| 533 |                                                              SPTR_ARROW,
 | 
|---|
| 534 |                                                              FALSE));
 | 
|---|
| 535 |             hwndCap = HWND (mp1);
 | 
|---|
| 536 |             if (usCap != CAP_SCREENREGION && usCap != CAP_SCREEN)
 | 
|---|
| 537 |                 hwndParent = HWND (mp2);
 | 
|---|
| 538 |             if (pset->SerialCapture ())
 | 
|---|
| 539 |             {
 | 
|---|
| 540 |                 ulTimer = WinStartTimer (hab, hwnd, 1, 49);
 | 
|---|
| 541 |                 ulCountdown = pset->QuerySerialTime ();
 | 
|---|
| 542 |             }
 | 
|---|
| 543 |             else if (WinQueryButtonCheckstate (hwnd, WID_CB_DELAYEDCAPTURE))
 | 
|---|
| 544 |             {
 | 
|---|
| 545 |                 ulTimer = WinStartTimer (hab, hwnd, 1, 990);
 | 
|---|
| 546 |                 ulCountdown = pset->QueryDelayTime ();
 | 
|---|
| 547 |             }
 | 
|---|
| 548 |             else
 | 
|---|
| 549 |             {
 | 
|---|
| 550 |                 usState = STATE_CAPTURE;
 | 
|---|
| 551 |                 WinPostMsg (hwnd, UM_CAPTURE, 0,0);
 | 
|---|
| 552 |             }
 | 
|---|
| 553 |         }
 | 
|---|
| 554 |         return MRESULT (FALSE);
 | 
|---|
| 555 | 
 | 
|---|
| 556 |     case WM_TIMER:
 | 
|---|
| 557 |         ulCountdown --;
 | 
|---|
| 558 |        
 | 
|---|
| 559 |         if( ulCountdown % 20 == 0 )
 | 
|---|
| 560 |             WinSendMsg (hwndSnapshot, UM_COUNTDOWN,
 | 
|---|
| 561 |                         MPFROMLONG (ulCountdown), 0);
 | 
|---|
| 562 |         if (pset->DelayCountdown () && !pset->SerialCapture ())
 | 
|---|
| 563 |             DoCountdown (ulCountdown);
 | 
|---|
| 564 | 
 | 
|---|
| 565 |         if (ulCountdown == 0)
 | 
|---|
| 566 |         {
 | 
|---|
| 567 |             WinStopTimer (hab, hwnd, ulTimer);
 | 
|---|
| 568 |             usState = STATE_CAPTURE;
 | 
|---|
| 569 |             WinSendMsg (hwnd, UM_CAPTURE, 0,0);
 | 
|---|
| 570 |         }
 | 
|---|
| 571 |         return MRESULT (FALSE);
 | 
|---|
| 572 | 
 | 
|---|
| 573 |     case UM_CAPTURE:
 | 
|---|
| 574 |         usState = STATE_WAITFORHIDE2;
 | 
|---|
| 575 |         if (pset->SSWHide () && WinIsWindowVisible (hwndSnapshot))
 | 
|---|
| 576 |             WinShowWindow (hwndSnapshot, FALSE);
 | 
|---|
| 577 |         else
 | 
|---|
| 578 |             WinSendMsg (hwnd, UM_CAPTURE2, 0,0);
 | 
|---|
| 579 |         return MRESULT (FALSE);
 | 
|---|
| 580 | 
 | 
|---|
| 581 |     case UM_SSWHIDDEN:
 | 
|---|
| 582 |         // FIXME
 | 
|---|
| 583 |         // I have no idea why this delay is necessary, but CAP_SCREEN with
 | 
|---|
| 584 |         // hiding our window does not work without it ...
 | 
|---|
| 585 |         DosSleep (100);
 | 
|---|
| 586 |         WinSendMsg (hwnd, UM_CAPTURE2, 0,0);
 | 
|---|
| 587 |         return MRESULT (FALSE);
 | 
|---|
| 588 | 
 | 
|---|
| 589 |     case UM_CAPTURE2:
 | 
|---|
| 590 |         if (usState == STATE_WAITFORHIDE2)
 | 
|---|
| 591 |         {
 | 
|---|
| 592 |             HBITMAP  hbm;
 | 
|---|
| 593 | 
 | 
|---|
| 594 |             WinEnableWindow (hwnd, FALSE);
 | 
|---|
| 595 |             // capture the window to a bitmap and save this
 | 
|---|
| 596 |             if (usCap == CAP_SCREENREGION)
 | 
|---|
| 597 |                 hbm = CaptureWindow (hwndCap, hwndParent, &rcl, FALSE);
 | 
|---|
| 598 |             else if (usCap == CAP_SCREEN)
 | 
|---|
| 599 |                 hbm = CaptureWindow (hwndCap, hwndParent, NULL, FALSE);
 | 
|---|
| 600 |             else
 | 
|---|
| 601 |                 hbm = CaptureWindow (hwndCap, hwndParent, NULL, TRUE);
 | 
|---|
| 602 | 
 | 
|---|
| 603 |             if (pset->SerialCapture ())
 | 
|---|
| 604 |             {
 | 
|---|
| 605 |                 WinStopTimer (hab, hwnd, ulTimer);
 | 
|---|
| 606 |                 if (! WinIsWindowVisible (hwndSnapshot) && pset->SnapshotWindow ())
 | 
|---|
| 607 |                     WinShowWindow (hwndSnapshot, TRUE);
 | 
|---|
| 608 | 
 | 
|---|
| 609 |                 if (hbm)
 | 
|---|
| 610 |                 {
 | 
|---|
| 611 |                     usState = STATE_WINDOWSELECTED;
 | 
|---|
| 612 |                     WinPostMsg (hwnd, UM_WINDOWSELECTED,
 | 
|---|
| 613 |                                 MPFROMHWND (hwndCap),
 | 
|---|
| 614 |                                 MPFROMHWND (hwndParent));
 | 
|---|
| 615 |                 }
 | 
|---|
| 616 |                 else
 | 
|---|
| 617 |                     WinSendMsg (hwnd, UM_ABORT, 0,0);
 | 
|---|
| 618 |             }
 | 
|---|
| 619 |             else
 | 
|---|
| 620 |                 WinSendMsg (hwnd, UM_CLEANUP, 0,0);
 | 
|---|
| 621 |         }
 | 
|---|
| 622 |         return MRESULT (FALSE);
 | 
|---|
| 623 | 
 | 
|---|
| 624 |     case UM_ABORT:
 | 
|---|
| 625 |         if (LONGFROMMP(mp1) != 1)
 | 
|---|
| 626 |             DosBeep (75, 200);
 | 
|---|
| 627 |         WinSendMsg (hwnd, UM_CLEANUP, 0,0);
 | 
|---|
| 628 |         return MRESULT (FALSE);
 | 
|---|
| 629 | 
 | 
|---|
| 630 |     case UM_CLEANUP:
 | 
|---|
| 631 |         if (WinQueryCapture (HWND_DESKTOP) == hwnd)
 | 
|---|
| 632 |             WinSetCapture (HWND_DESKTOP, NULLHANDLE);
 | 
|---|
| 633 | 
 | 
|---|
| 634 |         pset->Load ();
 | 
|---|
| 635 | 
 | 
|---|
| 636 |         WinSendMsg (hwndSnapshot, UM_STOPCAPTURE, 0,0);
 | 
|---|
| 637 |         WinStopTimer (hab, hwnd, ulTimer);
 | 
|---|
| 638 | #ifdef _QUIET_
 | 
|---|
| 639 |         // ? FIXME to give option to reshow window.
 | 
|---|
| 640 |         if (WinQueryButtonCheckstate (hwnd, WID_CB_HIDEWINDOW))
 | 
|---|
| 641 |             WinSendMsg (g_hwndSettingsDialog, WM_CLOSE, 0,0);
 | 
|---|
| 642 |         else if (WinIsWindow ( hab, g_hwndSettingsDialog) &&
 | 
|---|
| 643 |             ! WinIsWindowVisible (g_hwndSettingsDialog))
 | 
|---|
| 644 |             WinShowWindow (g_hwndSettingsDialog, TRUE);
 | 
|---|
| 645 |         pset->HideWindow (TRUE);
 | 
|---|
| 646 | #else
 | 
|---|
| 647 |         // re-show the windows if they are hidden
 | 
|---|
| 648 |         // FIXME using global hwndFrame is pretty yukki
 | 
|---|
| 649 |         if (! WinIsWindowVisible (hwndFrame))
 | 
|---|
| 650 |             WinShowWindow (hwndFrame, TRUE);
 | 
|---|
| 651 |         if (! WinIsWindowVisible (hwndSnapshot) && pset->SnapshotWindow ())
 | 
|---|
| 652 |             WinShowWindow (hwndSnapshot, TRUE);
 | 
|---|
| 653 | #endif
 | 
|---|
| 654 |         WinEnableWindow (hwnd, TRUE);
 | 
|---|
| 655 |         WinSetActiveWindow (HWND_DESKTOP, hwnd);
 | 
|---|
| 656 |         usState = STATE_IDLE;
 | 
|---|
| 657 |         return MRESULT (FALSE);
 | 
|---|
| 658 |     }
 | 
|---|
| 659 | 
 | 
|---|
| 660 | #ifdef _DOLOGDEBUG_
 | 
|---|
| 661 |     LogDebug( "MainWin:WindowProcedure:WinDefWindowProc->0x%04x", msg );
 | 
|---|
| 662 | #endif
 | 
|---|
| 663 |     if (hwnd ==  g_hwndPage0)
 | 
|---|
| 664 |         return WinDefDlgProc (hwnd, msg, mp1, mp2);
 | 
|---|
| 665 |     else
 | 
|---|
| 666 |         return WinDefWindowProc (hwnd, msg, mp1, mp2);
 | 
|---|
| 667 | }
 | 
|---|
| 668 | 
 | 
|---|
| 669 | // ************************************************************************
 | 
|---|