| 1 |  | 
|---|
| 2 | /* | 
|---|
| 3 | *@@sourcefile winh.c: | 
|---|
| 4 | *      contains Presentation Manager helper functions that are | 
|---|
| 5 | *      independent of a single application, i.e. these can be | 
|---|
| 6 | *      used w/out the rest of the XWorkplace source in any PM | 
|---|
| 7 | *      program. | 
|---|
| 8 | * | 
|---|
| 9 | *      Usage: All PM programs. | 
|---|
| 10 | * | 
|---|
| 11 | *      Function prefixes (new with V0.81): | 
|---|
| 12 | *      --  winh*   Win (Presentation Manager) helper functions | 
|---|
| 13 | * | 
|---|
| 14 | *      Note: Version numbering in this file relates to XWorkplace version | 
|---|
| 15 | *            numbering. | 
|---|
| 16 | * | 
|---|
| 17 | *@@header "helpers\winh.h" | 
|---|
| 18 | */ | 
|---|
| 19 |  | 
|---|
| 20 | /* | 
|---|
| 21 | *      Copyright (C) 1997-2002 Ulrich Mller. | 
|---|
| 22 | *      This file is part of the "XWorkplace helpers" source package. | 
|---|
| 23 | *      This is free software; you can redistribute it and/or modify | 
|---|
| 24 | *      it under the terms of the GNU General Public License as published | 
|---|
| 25 | *      by the Free Software Foundation, in version 2 as it comes in the | 
|---|
| 26 | *      "COPYING" file of the XWorkplace main distribution. | 
|---|
| 27 | *      This program is distributed in the hope that it will be useful, | 
|---|
| 28 | *      but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 29 | *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 30 | *      GNU General Public License for more details. | 
|---|
| 31 | */ | 
|---|
| 32 |  | 
|---|
| 33 | #define OS2EMX_PLAIN_CHAR | 
|---|
| 34 | // this is needed for "os2emx.h"; if this is defined, | 
|---|
| 35 | // emx will define PSZ as _signed_ char, otherwise | 
|---|
| 36 | // as unsigned char | 
|---|
| 37 |  | 
|---|
| 38 | #define INCL_DOSPROCESS | 
|---|
| 39 | #define INCL_DOSMODULEMGR | 
|---|
| 40 | #define INCL_DOSSEMAPHORES | 
|---|
| 41 | #define INCL_DOSDEVICES | 
|---|
| 42 | #define INCL_DOSDEVIOCTL | 
|---|
| 43 | #define INCL_DOSSESMGR | 
|---|
| 44 | #define INCL_DOSERRORS | 
|---|
| 45 |  | 
|---|
| 46 | #define INCL_WINWINDOWMGR | 
|---|
| 47 | #define INCL_WINMESSAGEMGR | 
|---|
| 48 | #define INCL_WINFRAMEMGR | 
|---|
| 49 | #define INCL_WININPUT | 
|---|
| 50 | #define INCL_WINDIALOGS | 
|---|
| 51 | #define INCL_WINPOINTERS | 
|---|
| 52 | #define INCL_WINRECTANGLES | 
|---|
| 53 | #define INCL_WINSHELLDATA | 
|---|
| 54 | #define INCL_WINTIMER | 
|---|
| 55 | #define INCL_WINSYS | 
|---|
| 56 | #define INCL_WINHELP | 
|---|
| 57 | #define INCL_WINPROGRAMLIST | 
|---|
| 58 | #define INCL_WINSWITCHLIST | 
|---|
| 59 | #define INCL_WINBUTTONS | 
|---|
| 60 | #define INCL_WINSTATICS | 
|---|
| 61 | #define INCL_WINMENUS | 
|---|
| 62 | #define INCL_WINENTRYFIELDS | 
|---|
| 63 | #define INCL_WINSCROLLBARS | 
|---|
| 64 | #define INCL_WINLISTBOXES | 
|---|
| 65 | #define INCL_WINSTDSPIN | 
|---|
| 66 | #define INCL_WINSTDSLIDER | 
|---|
| 67 | #define INCL_WINCIRCULARSLIDER | 
|---|
| 68 | #define INCL_WINSTDFILE | 
|---|
| 69 | #define INCL_WINCLIPBOARD | 
|---|
| 70 |  | 
|---|
| 71 | #define INCL_SPL | 
|---|
| 72 | #define INCL_SPLDOSPRINT | 
|---|
| 73 | #define INCL_SPLERRORS | 
|---|
| 74 |  | 
|---|
| 75 | #define INCL_GPIBITMAPS | 
|---|
| 76 | #define INCL_GPIPRIMITIVES | 
|---|
| 77 | #include <os2.h> | 
|---|
| 78 |  | 
|---|
| 79 | #include <stdlib.h> | 
|---|
| 80 | #include <string.h> | 
|---|
| 81 | #include <stdio.h> | 
|---|
| 82 | #include <stdarg.h> | 
|---|
| 83 |  | 
|---|
| 84 | #include "setup.h"                      // code generation and debugging options | 
|---|
| 85 |  | 
|---|
| 86 | #include "helpers\dosh.h" | 
|---|
| 87 | #include "helpers\winh.h" | 
|---|
| 88 | #include "helpers\prfh.h" | 
|---|
| 89 | #include "helpers\gpih.h" | 
|---|
| 90 | #include "helpers\nls.h" | 
|---|
| 91 | #include "helpers\standards.h" | 
|---|
| 92 | #include "helpers\stringh.h" | 
|---|
| 93 | #include "helpers\xstring.h"            // extended string helpers | 
|---|
| 94 |  | 
|---|
| 95 | /* | 
|---|
| 96 | *@@category: Helpers\PM helpers\Wrappers | 
|---|
| 97 | */ | 
|---|
| 98 |  | 
|---|
| 99 | /* ****************************************************************** | 
|---|
| 100 | * | 
|---|
| 101 | *   Wrappers | 
|---|
| 102 | * | 
|---|
| 103 | ********************************************************************/ | 
|---|
| 104 |  | 
|---|
| 105 | #ifdef WINH_STANDARDWRAPPERS | 
|---|
| 106 |  | 
|---|
| 107 | /* | 
|---|
| 108 | *@@ winhSendMsg: | 
|---|
| 109 | *      wrapper for WinSendMsg. | 
|---|
| 110 | * | 
|---|
| 111 | *      If WINH_STANDARDWRAPPERS is #defined before | 
|---|
| 112 | *      including win.h, all WinSendMsg calls are | 
|---|
| 113 | *      redefined to use this wrapper instead. This | 
|---|
| 114 | *      reduces the amount of external fixups required | 
|---|
| 115 | *      for loading the module. | 
|---|
| 116 | * | 
|---|
| 117 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 118 | */ | 
|---|
| 119 |  | 
|---|
| 120 | MRESULT winhSendMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 121 | { | 
|---|
| 122 | // put the call in brackets so the macro won't apply here | 
|---|
| 123 | return ((WinSendMsg)(hwnd, msg, mp1, mp2)); | 
|---|
| 124 | } | 
|---|
| 125 |  | 
|---|
| 126 | /* | 
|---|
| 127 | *@@ winhSendDlgItemMsg: | 
|---|
| 128 | *      wrapper for WinSendDlgItemMsg. | 
|---|
| 129 | * | 
|---|
| 130 | *      If WINH_STANDARDWRAPPERS is #defined before | 
|---|
| 131 | *      including win.h, all WinSendMsg calls are | 
|---|
| 132 | *      redefined to use this wrapper instead. This | 
|---|
| 133 | *      reduces the amount of external fixups required | 
|---|
| 134 | *      for loading the module. | 
|---|
| 135 | * | 
|---|
| 136 | *@@added V0.9.13 (2001-06-27) [umoeller] | 
|---|
| 137 | */ | 
|---|
| 138 |  | 
|---|
| 139 | MRESULT winhSendDlgItemMsg(HWND hwnd, ULONG id, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 140 | { | 
|---|
| 141 | return ((WinSendDlgItemMsg)(hwnd, id, msg, mp1, mp2)); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | /* | 
|---|
| 145 | *@@ winhPostMsg: | 
|---|
| 146 | *      wrapper for WinPostMsg. | 
|---|
| 147 | * | 
|---|
| 148 | *      If WINH_STANDARDWRAPPERS is #defined before | 
|---|
| 149 | *      including win.h, all WinSendMsg calls are | 
|---|
| 150 | *      redefined to use this wrapper instead. This | 
|---|
| 151 | *      reduces the amount of external fixups required | 
|---|
| 152 | *      for loading the module. | 
|---|
| 153 | * | 
|---|
| 154 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 155 | */ | 
|---|
| 156 |  | 
|---|
| 157 | BOOL winhPostMsg(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 158 | { | 
|---|
| 159 | // put the call in brackets so the macro won't apply here | 
|---|
| 160 | return ((WinPostMsg)(hwnd, msg, mp1, mp2)); | 
|---|
| 161 | } | 
|---|
| 162 |  | 
|---|
| 163 | /* | 
|---|
| 164 | *@@ winhWindowFromID: | 
|---|
| 165 | * | 
|---|
| 166 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 167 | */ | 
|---|
| 168 |  | 
|---|
| 169 | HWND winhWindowFromID(HWND hwnd, ULONG id) | 
|---|
| 170 | { | 
|---|
| 171 | // put the call in brackets so the macro won't apply here | 
|---|
| 172 | return ((WinWindowFromID)(hwnd, id)); | 
|---|
| 173 | } | 
|---|
| 174 |  | 
|---|
| 175 | /* | 
|---|
| 176 | *@@ winhQueryWindow: | 
|---|
| 177 | * | 
|---|
| 178 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 179 | */ | 
|---|
| 180 |  | 
|---|
| 181 | HWND winhQueryWindow(HWND hwnd, LONG lCode) | 
|---|
| 182 | { | 
|---|
| 183 | // put the call in brackets so the macro won't apply here | 
|---|
| 184 | return ((WinQueryWindow)(hwnd, lCode)); | 
|---|
| 185 | } | 
|---|
| 186 |  | 
|---|
| 187 | /* | 
|---|
| 188 | *@@ winhQueryWindowPtr: | 
|---|
| 189 | * | 
|---|
| 190 | *@@added V0.9.13 (2001-06-21) [umoeller] | 
|---|
| 191 | */ | 
|---|
| 192 |  | 
|---|
| 193 | PVOID winhQueryWindowPtr(HWND hwnd, LONG index) | 
|---|
| 194 | { | 
|---|
| 195 | // put the call in brackets so the macro won't apply here | 
|---|
| 196 | return ((WinQueryWindowPtr)(hwnd, index)); | 
|---|
| 197 | } | 
|---|
| 198 |  | 
|---|
| 199 | /* | 
|---|
| 200 | *@@ winhSetWindowText2: | 
|---|
| 201 | * | 
|---|
| 202 | *@@added V0.9.13 (2001-06-21) [umoeller] | 
|---|
| 203 | */ | 
|---|
| 204 |  | 
|---|
| 205 | BOOL winhSetWindowText2(HWND hwnd, const char *pcsz) | 
|---|
| 206 | { | 
|---|
| 207 | // put the call in brackets so the macro won't apply here | 
|---|
| 208 | return (WinSetWindowText)(hwnd, (PSZ)pcsz); | 
|---|
| 209 | } | 
|---|
| 210 |  | 
|---|
| 211 | /* | 
|---|
| 212 | *@@ winhSetDlgItemText: | 
|---|
| 213 | * | 
|---|
| 214 | *@@added V0.9.13 (2001-06-21) [umoeller] | 
|---|
| 215 | */ | 
|---|
| 216 |  | 
|---|
| 217 | BOOL winhSetDlgItemText(HWND hwnd, ULONG id, const char *pcsz) | 
|---|
| 218 | { | 
|---|
| 219 | // put the call in brackets so the macro won't apply here | 
|---|
| 220 | return (WinSetDlgItemText)(hwnd, id, (PSZ)pcsz); | 
|---|
| 221 | } | 
|---|
| 222 |  | 
|---|
| 223 | /* | 
|---|
| 224 | *@@ winhRequestMutexSem: | 
|---|
| 225 | * | 
|---|
| 226 | *@@added V0.9.16 (2002-01-26) [umoeller] | 
|---|
| 227 | */ | 
|---|
| 228 |  | 
|---|
| 229 | APIRET winhRequestMutexSem(HMTX hmtx, ULONG ulTimeout) | 
|---|
| 230 | { | 
|---|
| 231 | // put the call in brackets so the macro won't apply here | 
|---|
| 232 | return (WinRequestMutexSem)(hmtx, ulTimeout); | 
|---|
| 233 | } | 
|---|
| 234 |  | 
|---|
| 235 | #endif // WINH_STANDARDWRAPPERS | 
|---|
| 236 |  | 
|---|
| 237 | /* | 
|---|
| 238 | *@@category: Helpers\PM helpers\Rectangle helpers | 
|---|
| 239 | */ | 
|---|
| 240 |  | 
|---|
| 241 | /* ****************************************************************** | 
|---|
| 242 | * | 
|---|
| 243 | *   Rectangle helpers | 
|---|
| 244 | * | 
|---|
| 245 | ********************************************************************/ | 
|---|
| 246 |  | 
|---|
| 247 | /* | 
|---|
| 248 | *@@ winhOffsetRect: | 
|---|
| 249 | *      like WinOffsetRect, but doesn't require | 
|---|
| 250 | *      an anchor block to be passed in. Why | 
|---|
| 251 | *      the original would need an anchor block | 
|---|
| 252 | *      for this awfully complicated task is | 
|---|
| 253 | *      a mystery to me anyway. | 
|---|
| 254 | * | 
|---|
| 255 | *@@added V0.9.9 (2001-03-13) [umoeller] | 
|---|
| 256 | */ | 
|---|
| 257 |  | 
|---|
| 258 | VOID winhOffsetRect(PRECTL prcl, | 
|---|
| 259 | LONG lx, | 
|---|
| 260 | LONG ly) | 
|---|
| 261 | { | 
|---|
| 262 | prcl->xLeft += lx; | 
|---|
| 263 | prcl->xRight += lx; | 
|---|
| 264 | prcl->yBottom += ly; | 
|---|
| 265 | prcl->yTop += ly; | 
|---|
| 266 | } | 
|---|
| 267 |  | 
|---|
| 268 | /* | 
|---|
| 269 | *@@category: Helpers\PM helpers\Generics | 
|---|
| 270 | */ | 
|---|
| 271 |  | 
|---|
| 272 | /* ****************************************************************** | 
|---|
| 273 | * | 
|---|
| 274 | *   Generics | 
|---|
| 275 | * | 
|---|
| 276 | ********************************************************************/ | 
|---|
| 277 |  | 
|---|
| 278 | /* | 
|---|
| 279 | *@@ winhQueryWindowStyle: | 
|---|
| 280 | * | 
|---|
| 281 | *@@added V0.9.13 (2001-07-02) [umoeller] | 
|---|
| 282 | */ | 
|---|
| 283 |  | 
|---|
| 284 | ULONG winhQueryWindowStyle(HWND hwnd) | 
|---|
| 285 | { | 
|---|
| 286 | return WinQueryWindowULong(hwnd, QWL_STYLE); | 
|---|
| 287 | } | 
|---|
| 288 |  | 
|---|
| 289 | /* | 
|---|
| 290 | *@@ winhEnableDlgItem: | 
|---|
| 291 | * | 
|---|
| 292 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 293 | */ | 
|---|
| 294 |  | 
|---|
| 295 | BOOL winhEnableDlgItem(HWND hwndDlg, | 
|---|
| 296 | SHORT id, | 
|---|
| 297 | BOOL fEnable) | 
|---|
| 298 | { | 
|---|
| 299 | return WinEnableWindow(WinWindowFromID(hwndDlg, id), fEnable); | 
|---|
| 300 | } | 
|---|
| 301 |  | 
|---|
| 302 | /* | 
|---|
| 303 | *@@ winhIsDlgItemEnabled: | 
|---|
| 304 | * | 
|---|
| 305 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 306 | */ | 
|---|
| 307 |  | 
|---|
| 308 | BOOL winhIsDlgItemEnabled(HWND hwndDlg, | 
|---|
| 309 | SHORT id) | 
|---|
| 310 | { | 
|---|
| 311 | return WinIsWindowEnabled(WinWindowFromID(hwndDlg, id)); | 
|---|
| 312 | } | 
|---|
| 313 |  | 
|---|
| 314 |  | 
|---|
| 315 | /* | 
|---|
| 316 | *@@category: Helpers\PM helpers\Menu helpers | 
|---|
| 317 | */ | 
|---|
| 318 |  | 
|---|
| 319 | /* ****************************************************************** | 
|---|
| 320 | * | 
|---|
| 321 | *   Menu helpers | 
|---|
| 322 | * | 
|---|
| 323 | ********************************************************************/ | 
|---|
| 324 |  | 
|---|
| 325 | /* | 
|---|
| 326 | *@@ winhQueryMenuItem: | 
|---|
| 327 | *      wrapper around MM_QUERYITEM. | 
|---|
| 328 | * | 
|---|
| 329 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 330 | */ | 
|---|
| 331 |  | 
|---|
| 332 | BOOL winhQueryMenuItem(HWND hwndMenu, | 
|---|
| 333 | USHORT usItemID, | 
|---|
| 334 | BOOL fSearchSubmenus, | 
|---|
| 335 | PMENUITEM pmi)           // out: MENUITEM data | 
|---|
| 336 | { | 
|---|
| 337 | return (BOOL)WinSendMsg(hwndMenu, | 
|---|
| 338 | MM_QUERYITEM, | 
|---|
| 339 | MPFROM2SHORT(usItemID, fSearchSubmenus), | 
|---|
| 340 | (MPARAM)pmi); | 
|---|
| 341 | } | 
|---|
| 342 |  | 
|---|
| 343 | /* | 
|---|
| 344 | *@@ winhQuerySubmenu: | 
|---|
| 345 | *      tests whether sID specifies a submenu in | 
|---|
| 346 | *      hMenu and returns the submenu window handle | 
|---|
| 347 | *      if so. | 
|---|
| 348 | * | 
|---|
| 349 | *@@added V0.9.20 (2002-08-10) [umoeller] | 
|---|
| 350 | */ | 
|---|
| 351 |  | 
|---|
| 352 | HWND winhQuerySubmenu(HWND hMenu, | 
|---|
| 353 | SHORT sID) | 
|---|
| 354 | { | 
|---|
| 355 | MENUITEM mi = {0}; | 
|---|
| 356 | if (    (WinSendMsg(hMenu, | 
|---|
| 357 | MM_QUERYITEM, | 
|---|
| 358 | MPFROM2SHORT(sID, | 
|---|
| 359 | FALSE), | 
|---|
| 360 | (MPARAM)&mi)) | 
|---|
| 361 | && (mi.afStyle & MIS_SUBMENU) | 
|---|
| 362 | ) | 
|---|
| 363 | return mi.hwndSubMenu; | 
|---|
| 364 |  | 
|---|
| 365 | return NULLHANDLE; | 
|---|
| 366 | } | 
|---|
| 367 |  | 
|---|
| 368 | /* | 
|---|
| 369 | *@@ winhInsertMenuItem: | 
|---|
| 370 | *      this inserts one one menu item into a given menu. | 
|---|
| 371 | * | 
|---|
| 372 | *      Returns the return value of the MM_INSERTITEM msg: | 
|---|
| 373 | *      --  MIT_MEMERROR:    space allocation for menu item failed | 
|---|
| 374 | *      --  MIT_ERROR:       other error | 
|---|
| 375 | *      --  other:           zero-based index of new item in menu. | 
|---|
| 376 | */ | 
|---|
| 377 |  | 
|---|
| 378 | SHORT winhInsertMenuItem(HWND hwndMenu,     // in:  menu to insert item into | 
|---|
| 379 | SHORT iPosition,   // in:  zero-based index of where to | 
|---|
| 380 | //      insert or MIT_END | 
|---|
| 381 | SHORT sItemId,     // in:  ID of new menu item | 
|---|
| 382 | const char *pcszItemTitle,  // in:  title of new menu item | 
|---|
| 383 | SHORT afStyle, | 
|---|
| 384 | // in:  MIS_* style flags. | 
|---|
| 385 | // Valid menu item styles are: | 
|---|
| 386 | // --  MIS_SUBMENU | 
|---|
| 387 | // --  MIS_SEPARATOR | 
|---|
| 388 | // --  MIS_BITMAP: the display object is a bit map. | 
|---|
| 389 | // --  MIS_TEXT: the display object is a text string. | 
|---|
| 390 | // --  MIS_BUTTONSEPARATOR: | 
|---|
| 391 | //          The item is a menu button. Any menu can have zero, | 
|---|
| 392 | //          one, or two items of this type.  These are the last | 
|---|
| 393 | //          items in a menu and are automatically displayed after | 
|---|
| 394 | //          a separator bar. The user cannot move the cursor to | 
|---|
| 395 | //          these items, but can select them with the pointing | 
|---|
| 396 | //          device or with the appropriate key. | 
|---|
| 397 | // --  MIS_BREAK: the item begins a new row or column. | 
|---|
| 398 | // --  MIS_BREAKSEPARATOR: | 
|---|
| 399 | //          Same as MIS_BREAK, except that it draws a separator | 
|---|
| 400 | //          between rows or columns of a pull-down menu. | 
|---|
| 401 | //          This style can only be used within a submenu. | 
|---|
| 402 | // --  MIS_SYSCOMMAND: | 
|---|
| 403 | //          menu posts a WM_SYSCOMMAND message rather than a | 
|---|
| 404 | //          WM_COMMAND message. | 
|---|
| 405 | // --  MIS_OWNERDRAW: | 
|---|
| 406 | //          WM_DRAWITEM and WM_MEASUREITEM notification messages | 
|---|
| 407 | //          are sent to the owner to draw the item or determine its size. | 
|---|
| 408 | // --  MIS_HELP: | 
|---|
| 409 | //          menu posts a WM_HELP message rather than a | 
|---|
| 410 | //          WM_COMMAND message. | 
|---|
| 411 | // --  MIS_STATIC | 
|---|
| 412 | //          This type of item exists for information purposes only. | 
|---|
| 413 | //          It cannot be selected with the pointing device or | 
|---|
| 414 | //          keyboard. | 
|---|
| 415 | SHORT afAttr) | 
|---|
| 416 | // in:  MIA_* attribute flags | 
|---|
| 417 | // Valid menu item attributes (afAttr) are: | 
|---|
| 418 | // --  MIA_HILITED: if and only if, the item is selected. | 
|---|
| 419 | // --  MIA_CHECKED: a check mark appears next to the item (submenu only). | 
|---|
| 420 | // --  MIA_DISABLED: item is disabled and cannot be selected. | 
|---|
| 421 | //         The item is drawn in a disabled state (gray). | 
|---|
| 422 | // --  MIA_FRAMED: a frame is drawn around the item (top-level menu only). | 
|---|
| 423 | // --  MIA_NODISMISS: | 
|---|
| 424 | //          if the item is selected, the submenu remains down. A menu | 
|---|
| 425 | //          with this attribute is not hidden until the  application | 
|---|
| 426 | //          or user explicitly does so, for example by selecting either | 
|---|
| 427 | //          another menu on the action bar or by pressing the escape key. | 
|---|
| 428 | { | 
|---|
| 429 | MENUITEM mi; | 
|---|
| 430 |  | 
|---|
| 431 | mi.iPosition = iPosition; | 
|---|
| 432 | mi.afStyle = afStyle; | 
|---|
| 433 | mi.afAttribute = afAttr; | 
|---|
| 434 | mi.id = sItemId; | 
|---|
| 435 | mi.hwndSubMenu = 0; | 
|---|
| 436 | mi.hItem = 0; | 
|---|
| 437 |  | 
|---|
| 438 | return SHORT1FROMMR(WinSendMsg(hwndMenu, | 
|---|
| 439 | MM_INSERTITEM, | 
|---|
| 440 | (MPARAM)&mi, | 
|---|
| 441 | (MPARAM)pcszItemTitle)); | 
|---|
| 442 | } | 
|---|
| 443 |  | 
|---|
| 444 | /* | 
|---|
| 445 | *@@ winhInsertSubmenu: | 
|---|
| 446 | *      this inserts a submenu into a given menu and, if | 
|---|
| 447 | *      sItemId != 0, inserts one item into this new submenu also. | 
|---|
| 448 | * | 
|---|
| 449 | *      See winhInsertMenuItem for valid menu item styles and | 
|---|
| 450 | *      attributes. | 
|---|
| 451 | * | 
|---|
| 452 | *      Returns the HWND of the new submenu. | 
|---|
| 453 | */ | 
|---|
| 454 |  | 
|---|
| 455 | HWND winhInsertSubmenu(HWND hwndMenu,       // in: menu to add submenu to | 
|---|
| 456 | ULONG iPosition,     // in: index where to add submenu or MIT_END | 
|---|
| 457 | SHORT sMenuId,       // in: menu ID of new submenu | 
|---|
| 458 | const char *pcszSubmenuTitle, // in: title of new submenu | 
|---|
| 459 | USHORT afMenuStyle,  // in: MIS* style flags for submenu; | 
|---|
| 460 | // MIS_SUBMENU will always be added | 
|---|
| 461 | SHORT sItemId,       // in: ID of first item to add to submenu; | 
|---|
| 462 | // if 0, no first item is inserted | 
|---|
| 463 | const char *pcszItemTitle,    // in: title of this item | 
|---|
| 464 | // (if sItemID != 0) | 
|---|
| 465 | USHORT afItemStyle,  // in: style flags for this item, e.g. MIS_TEXT | 
|---|
| 466 | // (this is ignored if sItemID == 0) | 
|---|
| 467 | USHORT afAttribute)  // in: attributes for this item, e.g. MIA_DISABLED | 
|---|
| 468 | // (this is ignored if sItemID == 0) | 
|---|
| 469 | { | 
|---|
| 470 | MENUITEM mi; | 
|---|
| 471 | SHORT    src = MIT_ERROR; | 
|---|
| 472 | HWND     hwndNewMenu; | 
|---|
| 473 |  | 
|---|
| 474 | // create new, empty menu | 
|---|
| 475 | hwndNewMenu = WinCreateMenu(hwndMenu, | 
|---|
| 476 | NULL); // no menu template | 
|---|
| 477 | if (hwndNewMenu) | 
|---|
| 478 | { | 
|---|
| 479 | // add "submenu item" to this empty menu; | 
|---|
| 480 | // for some reason, PM always needs submenus | 
|---|
| 481 | // to be a menu item | 
|---|
| 482 | mi.iPosition = iPosition; | 
|---|
| 483 | mi.afStyle = afMenuStyle | MIS_SUBMENU; | 
|---|
| 484 | mi.afAttribute = 0; | 
|---|
| 485 | mi.id = sMenuId; | 
|---|
| 486 | mi.hwndSubMenu = hwndNewMenu; | 
|---|
| 487 | mi.hItem = 0; | 
|---|
| 488 | src = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, (MPARAM)pcszSubmenuTitle)); | 
|---|
| 489 | if (    (src != MIT_MEMERROR) | 
|---|
| 490 | &&  (src != MIT_ERROR) | 
|---|
| 491 | ) | 
|---|
| 492 | { | 
|---|
| 493 | // set the new menu's ID to the same as the | 
|---|
| 494 | // submenu item | 
|---|
| 495 | WinSetWindowUShort(hwndNewMenu, QWS_ID, sMenuId); | 
|---|
| 496 |  | 
|---|
| 497 | if (sItemId) | 
|---|
| 498 | { | 
|---|
| 499 | // item id given: insert first menu item also | 
|---|
| 500 | mi.iPosition = 0; | 
|---|
| 501 | mi.afStyle = afItemStyle; | 
|---|
| 502 | mi.afAttribute = afAttribute; | 
|---|
| 503 | mi.id = sItemId; | 
|---|
| 504 | mi.hwndSubMenu = 0; | 
|---|
| 505 | mi.hItem = 0; | 
|---|
| 506 | WinSendMsg(hwndNewMenu, | 
|---|
| 507 | MM_INSERTITEM, | 
|---|
| 508 | (MPARAM)&mi, | 
|---|
| 509 | (MPARAM)pcszItemTitle); | 
|---|
| 510 | } | 
|---|
| 511 | } | 
|---|
| 512 | } | 
|---|
| 513 | return hwndNewMenu; | 
|---|
| 514 | } | 
|---|
| 515 |  | 
|---|
| 516 | /* | 
|---|
| 517 | *@@ winhSetMenuCondCascade: | 
|---|
| 518 | *      sets the "conditional cascade" style | 
|---|
| 519 | *      on the specified submenu. | 
|---|
| 520 | * | 
|---|
| 521 | *      This style must always be enabled manually | 
|---|
| 522 | *      because the resource compiler won't handle it. | 
|---|
| 523 | * | 
|---|
| 524 | *      Note: Pass in the _submenu_ window handle, | 
|---|
| 525 | *      not the one of the parent. With lDefaultItem, | 
|---|
| 526 | *      specify the item ID in the submenu which is | 
|---|
| 527 | *      to be checked as the default item. | 
|---|
| 528 | * | 
|---|
| 529 | *@@added V0.9.12 (2001-05-22) [umoeller] | 
|---|
| 530 | *@@changed V0.9.20 (2002-08-10) [umoeller]: now supporting calling this more than once | 
|---|
| 531 | */ | 
|---|
| 532 |  | 
|---|
| 533 | BOOL winhSetMenuCondCascade(HWND hwndMenu,          // in: submenu handle | 
|---|
| 534 | LONG lDefaultItem)      // in: item ID of new default item | 
|---|
| 535 | { | 
|---|
| 536 | BOOL    brc; | 
|---|
| 537 | ULONG   ulStyle = WinQueryWindowULong(hwndMenu, QWL_STYLE); | 
|---|
| 538 | LONG    lOldDefault = -1; | 
|---|
| 539 |  | 
|---|
| 540 | if (ulStyle & MS_CONDITIONALCASCADE) | 
|---|
| 541 | { | 
|---|
| 542 | // menu is already conditional cascade: | 
|---|
| 543 | lOldDefault = (LONG)WinSendMsg(hwndMenu, | 
|---|
| 544 | MM_QUERYDEFAULTITEMID, | 
|---|
| 545 | 0, | 
|---|
| 546 | 0); | 
|---|
| 547 | } | 
|---|
| 548 | else | 
|---|
| 549 | { | 
|---|
| 550 | ulStyle |= MS_CONDITIONALCASCADE; | 
|---|
| 551 | WinSetWindowULong(hwndMenu, QWL_STYLE, ulStyle); | 
|---|
| 552 | } | 
|---|
| 553 |  | 
|---|
| 554 | // make the first item in the subfolder | 
|---|
| 555 | // the default of cascading submenu | 
|---|
| 556 | brc = (BOOL)WinSendMsg(hwndMenu, | 
|---|
| 557 | MM_SETDEFAULTITEMID, | 
|---|
| 558 | (MPARAM)lDefaultItem, | 
|---|
| 559 | 0); | 
|---|
| 560 |  | 
|---|
| 561 | if (    (lOldDefault != -1) | 
|---|
| 562 | && (lOldDefault != lDefaultItem) | 
|---|
| 563 | ) | 
|---|
| 564 | { | 
|---|
| 565 | // unset the "checked" attribute of the old one | 
|---|
| 566 | // or we'll have two in the menu | 
|---|
| 567 | WinSendMsg(hwndMenu, | 
|---|
| 568 | MM_SETITEMATTR, | 
|---|
| 569 | MPFROM2SHORT(lOldDefault, | 
|---|
| 570 | FALSE), | 
|---|
| 571 | MPFROM2SHORT(MIA_CHECKED, 0)); | 
|---|
| 572 | } | 
|---|
| 573 |  | 
|---|
| 574 | return brc; | 
|---|
| 575 | } | 
|---|
| 576 |  | 
|---|
| 577 | /* | 
|---|
| 578 | *@@ winhRemoveMenuItems: | 
|---|
| 579 | *      removes multiple menu items at once, as | 
|---|
| 580 | *      specified in the given array of menu item | 
|---|
| 581 | *      IDs. | 
|---|
| 582 | * | 
|---|
| 583 | *@@added V1.0.0 (2002-08-12) [umoeller] | 
|---|
| 584 | */ | 
|---|
| 585 |  | 
|---|
| 586 | BOOL XWPENTRY winhRemoveMenuItems(HWND hwndMenu,            // in: menu to remove from | 
|---|
| 587 | const SHORT *asItemIDs,   // in: array of menu item IDs | 
|---|
| 588 | ULONG cItemIDs)           // in: array item count | 
|---|
| 589 | { | 
|---|
| 590 | ULONG ul; | 
|---|
| 591 | for (ul = 0; | 
|---|
| 592 | ul < cItemIDs; | 
|---|
| 593 | ++ul) | 
|---|
| 594 | { | 
|---|
| 595 | SHORT s = asItemIDs[ul]; | 
|---|
| 596 | winhRemoveMenuItem(hwndMenu, | 
|---|
| 597 | s); | 
|---|
| 598 | } | 
|---|
| 599 |  | 
|---|
| 600 | return TRUE; | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | /* | 
|---|
| 604 | *@@ winhInsertMenuSeparator: | 
|---|
| 605 | *      this inserts a separator into a given menu at | 
|---|
| 606 | *      the given position (which may be MIT_END); | 
|---|
| 607 | *      returns the position at which the item was | 
|---|
| 608 | *      inserted. | 
|---|
| 609 | */ | 
|---|
| 610 |  | 
|---|
| 611 | SHORT winhInsertMenuSeparator(HWND hMenu,       // in: menu to add separator to | 
|---|
| 612 | SHORT iPosition,  // in: index where to add separator or MIT_END | 
|---|
| 613 | SHORT sId)        // in: separator menu ID (doesn't really matter) | 
|---|
| 614 | { | 
|---|
| 615 | MENUITEM mi; | 
|---|
| 616 | mi.iPosition = iPosition; | 
|---|
| 617 | mi.afStyle = MIS_SEPARATOR;             // append separator | 
|---|
| 618 | mi.afAttribute = 0; | 
|---|
| 619 | mi.id = sId; | 
|---|
| 620 | mi.hwndSubMenu = 0; | 
|---|
| 621 | mi.hItem = 0; | 
|---|
| 622 |  | 
|---|
| 623 | return SHORT1FROMMR(WinSendMsg(hMenu, | 
|---|
| 624 | MM_INSERTITEM, | 
|---|
| 625 | (MPARAM)&mi, | 
|---|
| 626 | (MPARAM)"")); | 
|---|
| 627 | } | 
|---|
| 628 |  | 
|---|
| 629 | /* | 
|---|
| 630 | *@@ winhCopyMenuItem2: | 
|---|
| 631 | *      copies a menu item from hmenuSource to hmenuTarget. | 
|---|
| 632 | * | 
|---|
| 633 | *      This creates a full duplicate. If usID specifies | 
|---|
| 634 | *      a submenu, the entire submenu is copied as well | 
|---|
| 635 | *      (this will then recurse). | 
|---|
| 636 | * | 
|---|
| 637 | *      fl can be any combination of: | 
|---|
| 638 | * | 
|---|
| 639 | *      --  COPYFL_STRIPTABS: strip off \t and everything | 
|---|
| 640 | *          that follows, if present. | 
|---|
| 641 | * | 
|---|
| 642 | *      NOTE: Copying submenus will work only if each item | 
|---|
| 643 | *      in the submenu has a unique menu ID. This is due | 
|---|
| 644 | *      to the dumb implementation of menus in PM where | 
|---|
| 645 | *      it is impossible to query menu items without | 
|---|
| 646 | *      knowing their ID. | 
|---|
| 647 | * | 
|---|
| 648 | *@@added V0.9.9 (2001-03-09) [umoeller] | 
|---|
| 649 | *@@changed V0.9.20 (2002-08-10) [umoeller]: renamed, added fl | 
|---|
| 650 | */ | 
|---|
| 651 |  | 
|---|
| 652 | BOOL winhCopyMenuItem2(HWND hmenuTarget, | 
|---|
| 653 | HWND hmenuSource, | 
|---|
| 654 | USHORT usID, | 
|---|
| 655 | SHORT sTargetPosition,    // in: position to insert at or MIT_END | 
|---|
| 656 | ULONG fl)                 // in: COPYFL_* flags | 
|---|
| 657 | { | 
|---|
| 658 | BOOL brc = FALSE; | 
|---|
| 659 | MENUITEM mi = {0}; | 
|---|
| 660 | if (WinSendMsg(hmenuSource, | 
|---|
| 661 | MM_QUERYITEM, | 
|---|
| 662 | MPFROM2SHORT(usID, | 
|---|
| 663 | FALSE), | 
|---|
| 664 | (MPARAM)&mi)) | 
|---|
| 665 | { | 
|---|
| 666 | // found in source: | 
|---|
| 667 | // is it a separator? | 
|---|
| 668 | if (mi.afStyle & MIS_SEPARATOR) | 
|---|
| 669 | winhInsertMenuSeparator(hmenuTarget, | 
|---|
| 670 | sTargetPosition, | 
|---|
| 671 | usID); | 
|---|
| 672 | else | 
|---|
| 673 | { | 
|---|
| 674 | // no separator: | 
|---|
| 675 | // get item text | 
|---|
| 676 | PSZ pszSource; | 
|---|
| 677 | if (pszSource = winhQueryMenuItemText(hmenuSource, | 
|---|
| 678 | usID)) | 
|---|
| 679 | { | 
|---|
| 680 | PSZ p; | 
|---|
| 681 | // remove the hotkey description | 
|---|
| 682 | // V0.9.20 (2002-08-10) [umoeller] | 
|---|
| 683 | if (    (fl & COPYFL_STRIPTABS) | 
|---|
| 684 | && (p = strchr(pszSource, '\t')) | 
|---|
| 685 | ) | 
|---|
| 686 | *p = '\0'; | 
|---|
| 687 |  | 
|---|
| 688 | if (    (mi.afStyle & MIS_SUBMENU) | 
|---|
| 689 | && (mi.hwndSubMenu) | 
|---|
| 690 | ) | 
|---|
| 691 | { | 
|---|
| 692 | // this is the top of a submenu: | 
|---|
| 693 | HWND hwndSubMenu; | 
|---|
| 694 | if (hwndSubMenu = winhInsertSubmenu(hmenuTarget, | 
|---|
| 695 | sTargetPosition, | 
|---|
| 696 | mi.id, | 
|---|
| 697 | pszSource, | 
|---|
| 698 | mi.afStyle, | 
|---|
| 699 | 0, | 
|---|
| 700 | NULL, | 
|---|
| 701 | 0, | 
|---|
| 702 | 0)) | 
|---|
| 703 | { | 
|---|
| 704 | // now copy all the items in the submenu | 
|---|
| 705 | SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, | 
|---|
| 706 | MM_QUERYITEMCOUNT, | 
|---|
| 707 | 0, | 
|---|
| 708 | 0)); | 
|---|
| 709 | // loop through all entries in the original submenu | 
|---|
| 710 | ULONG i; | 
|---|
| 711 | for (i = 0; | 
|---|
| 712 | i < cMenuItems; | 
|---|
| 713 | i++) | 
|---|
| 714 | { | 
|---|
| 715 | SHORT id = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, | 
|---|
| 716 | MM_ITEMIDFROMPOSITION, | 
|---|
| 717 | MPFROMSHORT(i), | 
|---|
| 718 | 0)); | 
|---|
| 719 | // recurse | 
|---|
| 720 | winhCopyMenuItem2(hwndSubMenu, | 
|---|
| 721 | mi.hwndSubMenu, | 
|---|
| 722 | id, | 
|---|
| 723 | MIT_END, | 
|---|
| 724 | fl); | 
|---|
| 725 | } | 
|---|
| 726 |  | 
|---|
| 727 | // now check... was the original submenu | 
|---|
| 728 | // "conditional cascade"? | 
|---|
| 729 | if (WinQueryWindowULong(mi.hwndSubMenu, | 
|---|
| 730 | QWL_STYLE) | 
|---|
| 731 | & MS_CONDITIONALCASCADE) | 
|---|
| 732 | // yes: | 
|---|
| 733 | { | 
|---|
| 734 | // get the original default item | 
|---|
| 735 | SHORT sDefID = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, | 
|---|
| 736 | MM_QUERYDEFAULTITEMID, | 
|---|
| 737 | 0, | 
|---|
| 738 | 0)); | 
|---|
| 739 | // set "conditional cascade style" on target too | 
|---|
| 740 | winhSetMenuCondCascade(hwndSubMenu, sDefID); | 
|---|
| 741 | } | 
|---|
| 742 | } // end if (hwndSubmenu) | 
|---|
| 743 | } // end if (    (mi.afStyle & MIS_SUBMENU) | 
|---|
| 744 | else | 
|---|
| 745 | { | 
|---|
| 746 | // no submenu: | 
|---|
| 747 | // just copy that item | 
|---|
| 748 | SHORT s; | 
|---|
| 749 | mi.iPosition = sTargetPosition; | 
|---|
| 750 | s = SHORT1FROMMR(WinSendMsg(hmenuTarget, | 
|---|
| 751 | MM_INSERTITEM, | 
|---|
| 752 | MPFROMP(&mi), | 
|---|
| 753 | MPFROMP(pszSource))); | 
|---|
| 754 | if (    (s != MIT_MEMERROR) | 
|---|
| 755 | && (s != MIT_ERROR) | 
|---|
| 756 | ) | 
|---|
| 757 | brc = TRUE; | 
|---|
| 758 | } | 
|---|
| 759 |  | 
|---|
| 760 | free(pszSource); | 
|---|
| 761 |  | 
|---|
| 762 | } // end if (pszSource) | 
|---|
| 763 | } // end else if (mi.afStyle & MIS_SEPARATOR) | 
|---|
| 764 | } // end if (WinSendMsg(hmenuSource, MM_QUERYITEM,... | 
|---|
| 765 |  | 
|---|
| 766 | return brc; | 
|---|
| 767 | } | 
|---|
| 768 |  | 
|---|
| 769 | /* | 
|---|
| 770 | *@@ winhCopyMenuItem: | 
|---|
| 771 | *      wrapper for winhCopyMenuItem2 because it was | 
|---|
| 772 | *      exported. | 
|---|
| 773 | * | 
|---|
| 774 | *@@added V0.9.20 (2002-08-10) [umoeller] | 
|---|
| 775 | */ | 
|---|
| 776 |  | 
|---|
| 777 | BOOL winhCopyMenuItem(HWND hmenuTarget, | 
|---|
| 778 | HWND hmenuSource, | 
|---|
| 779 | USHORT usID, | 
|---|
| 780 | SHORT sTargetPosition)    // in: position to insert at or MIT_END | 
|---|
| 781 | { | 
|---|
| 782 | return winhCopyMenuItem2(hmenuTarget, hmenuSource, usID, sTargetPosition, 0); | 
|---|
| 783 | } | 
|---|
| 784 |  | 
|---|
| 785 | /* | 
|---|
| 786 | *@@ winhMergeIntoSubMenu: | 
|---|
| 787 | *      creates a new submenu in hmenuTarget with the | 
|---|
| 788 | *      specified title at the specified position | 
|---|
| 789 | *      and copies the entire contents of hmenuSource | 
|---|
| 790 | *      into that. | 
|---|
| 791 | * | 
|---|
| 792 | *      Returns the window handle of the new submenu | 
|---|
| 793 | *      or NULLHANDLE on errors. | 
|---|
| 794 | * | 
|---|
| 795 | *      NOTE: Copying submenus will work only if each item | 
|---|
| 796 | *      in the submenu has a unique menu ID. This is due | 
|---|
| 797 | *      to the dumb implementation of menus in PM where | 
|---|
| 798 | *      it is impossible to query menu items without | 
|---|
| 799 | *      knowing their ID. | 
|---|
| 800 | * | 
|---|
| 801 | *@@added V0.9.9 (2001-03-09) [umoeller] | 
|---|
| 802 | */ | 
|---|
| 803 |  | 
|---|
| 804 | HWND winhMergeIntoSubMenu(HWND hmenuTarget,         // in: menu where to create submenu | 
|---|
| 805 | SHORT sTargetPosition,    // in: position to insert at or MIT_END | 
|---|
| 806 | const char *pcszTitle,    // in: title of new submenu or NULL | 
|---|
| 807 | SHORT sID,                // in: ID of new submenu | 
|---|
| 808 | HWND hmenuSource)         // in: menu to merge | 
|---|
| 809 | { | 
|---|
| 810 | HWND    hwndNewSubmenu; | 
|---|
| 811 | if (hwndNewSubmenu = WinCreateMenu(hmenuTarget, NULL)) | 
|---|
| 812 | { | 
|---|
| 813 | MENUITEM    mi = {0}; | 
|---|
| 814 | SHORT       src = 0; | 
|---|
| 815 | // SHORT s = 0; | 
|---|
| 816 | mi.iPosition = MIT_END; | 
|---|
| 817 | mi.afStyle = MIS_TEXT | MIS_SUBMENU; | 
|---|
| 818 | mi.id = 2000; | 
|---|
| 819 | mi.hwndSubMenu = hwndNewSubmenu; | 
|---|
| 820 |  | 
|---|
| 821 | WinSetWindowUShort(hwndNewSubmenu, QWS_ID, sID); | 
|---|
| 822 |  | 
|---|
| 823 | // insert new submenu into hmenuTarget | 
|---|
| 824 | src = SHORT1FROMMR(WinSendMsg(hmenuTarget, | 
|---|
| 825 | MM_INSERTITEM, | 
|---|
| 826 | (MPARAM)&mi, | 
|---|
| 827 | (MPARAM)pcszTitle)); | 
|---|
| 828 | if (    (src != MIT_MEMERROR) | 
|---|
| 829 | &&  (src != MIT_ERROR) | 
|---|
| 830 | ) | 
|---|
| 831 | { | 
|---|
| 832 | int i; | 
|---|
| 833 | SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource, | 
|---|
| 834 | MM_QUERYITEMCOUNT, | 
|---|
| 835 | 0, 0)); | 
|---|
| 836 |  | 
|---|
| 837 | // loop through all entries in the original menu | 
|---|
| 838 | for (i = 0; i < cMenuItems; i++) | 
|---|
| 839 | { | 
|---|
| 840 | SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource, | 
|---|
| 841 | MM_ITEMIDFROMPOSITION, | 
|---|
| 842 | MPFROMSHORT(i), | 
|---|
| 843 | 0)); | 
|---|
| 844 | winhCopyMenuItem(hwndNewSubmenu, | 
|---|
| 845 | hmenuSource, | 
|---|
| 846 | id, | 
|---|
| 847 | MIT_END); | 
|---|
| 848 | } | 
|---|
| 849 | } | 
|---|
| 850 | else | 
|---|
| 851 | { | 
|---|
| 852 | // error: | 
|---|
| 853 | WinDestroyWindow(hwndNewSubmenu); | 
|---|
| 854 | hwndNewSubmenu = NULLHANDLE; | 
|---|
| 855 | } | 
|---|
| 856 | } | 
|---|
| 857 |  | 
|---|
| 858 | return hwndNewSubmenu; | 
|---|
| 859 | } | 
|---|
| 860 |  | 
|---|
| 861 | /* | 
|---|
| 862 | *@@ winhMergeIntoSubMenu: | 
|---|
| 863 | *      copies all items from hmenuSource into hmenuTarget, | 
|---|
| 864 | *      starting at the given position. | 
|---|
| 865 | * | 
|---|
| 866 | *      Returns the no. of items that were copied. | 
|---|
| 867 | * | 
|---|
| 868 | *      NOTE: Copying submenus will work only if each item | 
|---|
| 869 | *      in the submenu has a unique menu ID. This is due | 
|---|
| 870 | *      to the dumb implementation of menus in PM where | 
|---|
| 871 | *      it is impossible to query menu items without | 
|---|
| 872 | *      knowing their ID. | 
|---|
| 873 | * | 
|---|
| 874 | *@@added V0.9.20 (2002-08-10) [umoeller] | 
|---|
| 875 | */ | 
|---|
| 876 |  | 
|---|
| 877 | ULONG winhMergeMenus(HWND hmenuTarget,         // in: menu to copy items to | 
|---|
| 878 | SHORT sTargetPosition,    // in: position to insert at or MIT_END | 
|---|
| 879 | HWND hmenuSource,         // in: menu to merge | 
|---|
| 880 | ULONG fl)                 // in: COPYFL_* flags for winhCopyMenuItem2 | 
|---|
| 881 | { | 
|---|
| 882 | SHORT   sTarget = MIT_END; | 
|---|
| 883 |  | 
|---|
| 884 | int i; | 
|---|
| 885 | SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource, | 
|---|
| 886 | MM_QUERYITEMCOUNT, | 
|---|
| 887 | 0, 0)); | 
|---|
| 888 |  | 
|---|
| 889 | // loop through all entries in the original menu | 
|---|
| 890 | for (i = 0; i < cMenuItems; i++) | 
|---|
| 891 | { | 
|---|
| 892 | SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource, | 
|---|
| 893 | MM_ITEMIDFROMPOSITION, | 
|---|
| 894 | MPFROM2SHORT(i, 0), | 
|---|
| 895 | 0)); | 
|---|
| 896 | winhCopyMenuItem2(hmenuTarget, | 
|---|
| 897 | hmenuSource, | 
|---|
| 898 | id, | 
|---|
| 899 | MIT_END, | 
|---|
| 900 | fl); | 
|---|
| 901 | } | 
|---|
| 902 |  | 
|---|
| 903 | return i; | 
|---|
| 904 | } | 
|---|
| 905 |  | 
|---|
| 906 | /* | 
|---|
| 907 | *@@ winhClearMenu: | 
|---|
| 908 | *      removes all menu items from the given (sub)menu. | 
|---|
| 909 | *      The menu itself is not destroyed, but is empty | 
|---|
| 910 | *      after calling this function. | 
|---|
| 911 | * | 
|---|
| 912 | *@@added V1.0.0 (2002-08-31) [umoeller] | 
|---|
| 913 | */ | 
|---|
| 914 |  | 
|---|
| 915 | ULONG winhClearMenu(HWND hwndMenu) | 
|---|
| 916 | { | 
|---|
| 917 | ULONG   cDeleted = 0; | 
|---|
| 918 | SHORT   sID; | 
|---|
| 919 |  | 
|---|
| 920 | // what we do is getting the menu item count | 
|---|
| 921 | // and then delete the first item in the menu | 
|---|
| 922 | // x times because there is no "delete menu item | 
|---|
| 923 | // from position" message, and there might be | 
|---|
| 924 | // duplicate IDs in the menu... this should | 
|---|
| 925 | // work always | 
|---|
| 926 |  | 
|---|
| 927 | SHORT   cMenuItems = SHORT1FROMMR(WinSendMsg(hwndMenu, | 
|---|
| 928 | MM_QUERYITEMCOUNT, | 
|---|
| 929 | 0, | 
|---|
| 930 | 0)); | 
|---|
| 931 | while (cMenuItems-- > 0) | 
|---|
| 932 | { | 
|---|
| 933 | sID = SHORT1FROMMR(WinSendMsg(hwndMenu, | 
|---|
| 934 | MM_ITEMIDFROMPOSITION, | 
|---|
| 935 | MPFROMSHORT(0), | 
|---|
| 936 | MPNULL)); | 
|---|
| 937 |  | 
|---|
| 938 | WinSendMsg(hwndMenu, | 
|---|
| 939 | MM_DELETEITEM, | 
|---|
| 940 | MPFROM2SHORT(sID, FALSE), | 
|---|
| 941 | 0); | 
|---|
| 942 |  | 
|---|
| 943 | ++cDeleted; | 
|---|
| 944 | } | 
|---|
| 945 |  | 
|---|
| 946 | return cDeleted; | 
|---|
| 947 | } | 
|---|
| 948 |  | 
|---|
| 949 | /* | 
|---|
| 950 | *@@ winhQueryMenuItemText: | 
|---|
| 951 | *      this returns a menu item text as a PSZ | 
|---|
| 952 | *      to a newly allocated buffer or NULL if | 
|---|
| 953 | *      not found. | 
|---|
| 954 | * | 
|---|
| 955 | *      Returns NULL on error. Use free() | 
|---|
| 956 | *      to free the return value. | 
|---|
| 957 | * | 
|---|
| 958 | *      This uses MM_QUERYITEMTEXT internally. | 
|---|
| 959 | *      PMREF doesn't say anything about this, | 
|---|
| 960 | *      but from my testing this always recurses | 
|---|
| 961 | *      into submenus. | 
|---|
| 962 | * | 
|---|
| 963 | *      Use the WinSetMenuItemText macro to | 
|---|
| 964 | *      set the menu item text. | 
|---|
| 965 | */ | 
|---|
| 966 |  | 
|---|
| 967 | PSZ winhQueryMenuItemText(HWND hwndMenu, | 
|---|
| 968 | USHORT usItemID)  // in: menu item ID (not index) | 
|---|
| 969 | { | 
|---|
| 970 | PSZ     prc = NULL; | 
|---|
| 971 |  | 
|---|
| 972 | SHORT   sLength; | 
|---|
| 973 | if (sLength = SHORT1FROMMR(WinSendMsg(hwndMenu, | 
|---|
| 974 | MM_QUERYITEMTEXTLENGTH, | 
|---|
| 975 | (MPARAM)(ULONG)usItemID, | 
|---|
| 976 | (MPARAM)NULL))) | 
|---|
| 977 | { | 
|---|
| 978 | prc = (PSZ)malloc(sLength + 1); | 
|---|
| 979 | WinSendMsg(hwndMenu, | 
|---|
| 980 | MM_QUERYITEMTEXT, | 
|---|
| 981 | MPFROM2SHORT(usItemID, sLength + 1), | 
|---|
| 982 | (MPARAM)prc); | 
|---|
| 983 | } | 
|---|
| 984 |  | 
|---|
| 985 | return prc; | 
|---|
| 986 | } | 
|---|
| 987 |  | 
|---|
| 988 | /* | 
|---|
| 989 | *@@ winhAppend2MenuItemText: | 
|---|
| 990 | * | 
|---|
| 991 | *@@added V0.9.2 (2000-03-08) [umoeller] | 
|---|
| 992 | */ | 
|---|
| 993 |  | 
|---|
| 994 | BOOL winhAppend2MenuItemText(HWND hwndMenu, | 
|---|
| 995 | USHORT usItemID,  // in: menu item ID (not index) | 
|---|
| 996 | const char *pcszAppend, // in: text to append | 
|---|
| 997 | BOOL fTab)    // in: if TRUE, add \t before pcszAppend | 
|---|
| 998 | { | 
|---|
| 999 | BOOL brc = FALSE; | 
|---|
| 1000 | CHAR szItemText[400]; | 
|---|
| 1001 | if (WinSendMsg(hwndMenu, | 
|---|
| 1002 | MM_QUERYITEMTEXT, | 
|---|
| 1003 | MPFROM2SHORT(usItemID, | 
|---|
| 1004 | sizeof(szItemText)), | 
|---|
| 1005 | (MPARAM)szItemText)) | 
|---|
| 1006 | { | 
|---|
| 1007 | // text copied: | 
|---|
| 1008 | if (fTab) | 
|---|
| 1009 | { | 
|---|
| 1010 | if (strchr(szItemText, '\t')) | 
|---|
| 1011 | // we already have a tab: | 
|---|
| 1012 | strcat(szItemText, " "); | 
|---|
| 1013 | else | 
|---|
| 1014 | strcat(szItemText, "\t"); | 
|---|
| 1015 | } | 
|---|
| 1016 | strcat(szItemText, pcszAppend); | 
|---|
| 1017 |  | 
|---|
| 1018 | brc = (BOOL)WinSendMsg(hwndMenu, | 
|---|
| 1019 | MM_SETITEMTEXT, | 
|---|
| 1020 | MPFROMSHORT(usItemID), | 
|---|
| 1021 | (MPARAM)szItemText); | 
|---|
| 1022 | } | 
|---|
| 1023 |  | 
|---|
| 1024 | return brc; | 
|---|
| 1025 | } | 
|---|
| 1026 |  | 
|---|
| 1027 | /* | 
|---|
| 1028 | *@@ winhMenuRemoveEllipse: | 
|---|
| 1029 | *      removes a "..." substring from a menu item | 
|---|
| 1030 | *      title, if found. This is useful if confirmations | 
|---|
| 1031 | *      have been turned off for a certain menu item, which | 
|---|
| 1032 | *      should be reflected in the menu. | 
|---|
| 1033 | */ | 
|---|
| 1034 |  | 
|---|
| 1035 | VOID winhMenuRemoveEllipse(HWND hwndMenu, | 
|---|
| 1036 | USHORT usItemId)    // in:  item to remove "..." from | 
|---|
| 1037 | { | 
|---|
| 1038 | CHAR szBuf[255]; | 
|---|
| 1039 | CHAR *p; | 
|---|
| 1040 | WinSendMsg(hwndMenu, | 
|---|
| 1041 | MM_QUERYITEMTEXT, | 
|---|
| 1042 | MPFROM2SHORT(usItemId, sizeof(szBuf)-1), | 
|---|
| 1043 | (MPARAM)&szBuf); | 
|---|
| 1044 | if ((p = strstr(szBuf, "..."))) | 
|---|
| 1045 | strcpy(p, p+3); | 
|---|
| 1046 | WinSendMsg(hwndMenu, | 
|---|
| 1047 | MM_SETITEMTEXT, | 
|---|
| 1048 | MPFROMSHORT(usItemId), | 
|---|
| 1049 | (MPARAM)&szBuf); | 
|---|
| 1050 | } | 
|---|
| 1051 |  | 
|---|
| 1052 | /* | 
|---|
| 1053 | *@@ winhQueryItemUnderMouse: | 
|---|
| 1054 | *      this queries the menu item which corresponds | 
|---|
| 1055 | *      to the given mouse coordinates. | 
|---|
| 1056 | *      Returns the ID of the menu item and stores its | 
|---|
| 1057 | *      rectangle in *prtlItem; returns (-1) upon errors. | 
|---|
| 1058 | */ | 
|---|
| 1059 |  | 
|---|
| 1060 | SHORT winhQueryItemUnderMouse(HWND hwndMenu,      // in: menu handle | 
|---|
| 1061 | POINTL *pptlMouse,  // in: mouse coordinates | 
|---|
| 1062 | RECTL *prtlItem)    // out: rectangle of menu item | 
|---|
| 1063 | { | 
|---|
| 1064 | SHORT   s, sItemId, sItemCount; | 
|---|
| 1065 | HAB     habDesktop = WinQueryAnchorBlock(HWND_DESKTOP); | 
|---|
| 1066 |  | 
|---|
| 1067 | sItemCount = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_QUERYITEMCOUNT, MPNULL, MPNULL)); | 
|---|
| 1068 |  | 
|---|
| 1069 | for (s = 0; | 
|---|
| 1070 | s <= sItemCount; | 
|---|
| 1071 | s++) | 
|---|
| 1072 | { | 
|---|
| 1073 | sItemId = SHORT1FROMMR(WinSendMsg(hwndMenu, | 
|---|
| 1074 | MM_ITEMIDFROMPOSITION, | 
|---|
| 1075 | (MPARAM)(ULONG)s, MPNULL)); | 
|---|
| 1076 | WinSendMsg(hwndMenu, | 
|---|
| 1077 | MM_QUERYITEMRECT, | 
|---|
| 1078 | MPFROM2SHORT(sItemId, FALSE), | 
|---|
| 1079 | (MPARAM)prtlItem); | 
|---|
| 1080 | if (WinPtInRect(habDesktop, prtlItem, pptlMouse)) | 
|---|
| 1081 | return sItemId; | 
|---|
| 1082 | } | 
|---|
| 1083 | /* sItemId = (SHORT)WinSendMsg(hwndMenu, MM_ITEMIDFROMPOSITION, (MPARAM)(sItemCount-1), MPNULL); | 
|---|
| 1084 | return (sItemId); */ | 
|---|
| 1085 |  | 
|---|
| 1086 | return -1; // error: no valid menu item | 
|---|
| 1087 | } | 
|---|
| 1088 |  | 
|---|
| 1089 | /* | 
|---|
| 1090 | *@@category: Helpers\PM helpers\Slider helpers | 
|---|
| 1091 | */ | 
|---|
| 1092 |  | 
|---|
| 1093 | /* ****************************************************************** | 
|---|
| 1094 | * | 
|---|
| 1095 | *   Slider helpers | 
|---|
| 1096 | * | 
|---|
| 1097 | ********************************************************************/ | 
|---|
| 1098 |  | 
|---|
| 1099 | /* | 
|---|
| 1100 | *@@ winhReplaceWithLinearSlider: | 
|---|
| 1101 | *      this destroys the control with the ID ulID in hwndDlg | 
|---|
| 1102 | *      and creates a linear slider at the same position with the | 
|---|
| 1103 | *      same ID (effectively replacing it). | 
|---|
| 1104 | * | 
|---|
| 1105 | *      This is needed because the IBM dialog editor (DLGEDIT.EXE) | 
|---|
| 1106 | *      keeps crashing when creating sliders. So the way to do | 
|---|
| 1107 | *      this easily is to create some other control with DLGEDIT | 
|---|
| 1108 | *      where the slider should be later and call this function | 
|---|
| 1109 | *      on that control when the dialog is initialized. | 
|---|
| 1110 | * | 
|---|
| 1111 | *      You need to specify _one_ of the following with ulSliderStyle: | 
|---|
| 1112 | *      -- SLS_HORIZONTAL: horizontal slider (default) | 
|---|
| 1113 | *      -- SLS_VERTICAL: vertical slider | 
|---|
| 1114 | * | 
|---|
| 1115 | *      plus _one_ additional common slider style for positioning: | 
|---|
| 1116 | *      -- for horizontal sliders: SLS_BOTTOM, SLS_CENTER, or SLS_TOP | 
|---|
| 1117 | *      -- for vertical sliders: SLS_LEFT, SLS_CENTER, or SLS_RIGHT | 
|---|
| 1118 | * | 
|---|
| 1119 | *      Additional common slider styles are: | 
|---|
| 1120 | *      -- SLS_PRIMARYSCALE1: determines the location of the scale | 
|---|
| 1121 | *                  on the slider shaft by using increment | 
|---|
| 1122 | *                  and spacing specified for scale 1 as | 
|---|
| 1123 | *                  the incremental value for positioning | 
|---|
| 1124 | *                  the slider arm. Scale 1 is displayed | 
|---|
| 1125 | *                  above the slider shaft of a horizontal | 
|---|
| 1126 | *                  slider and to the right of the slider | 
|---|
| 1127 | *                  shaft of a vertical slider. This is | 
|---|
| 1128 | *                  the default for a slider. | 
|---|
| 1129 | *      -- SLS_PRIMARYSCALE2: not supported by this function | 
|---|
| 1130 | *      -- SLS_READONLY: creates a read-only slider, which | 
|---|
| 1131 | *                  presents information to the user but | 
|---|
| 1132 | *                  allows no interaction with the user. | 
|---|
| 1133 | *      -- SLS_RIBBONSTRIP: fills, as the slider arm moves, the | 
|---|
| 1134 | *                  slider shaft between the home position | 
|---|
| 1135 | *                  and the slider arm with a color value | 
|---|
| 1136 | *                  different from slider shaft color, | 
|---|
| 1137 | *                  similar to mercury in a thermometer. | 
|---|
| 1138 | *      -- SLS_OWNERDRAW: notifies the application whenever the | 
|---|
| 1139 | *                  slider shaft, the ribbon strip, the | 
|---|
| 1140 | *                  slider arm, and the slider background | 
|---|
| 1141 | *                  are to be drawn. | 
|---|
| 1142 | *      -- SLS_SNAPTOINCREMENT: causes the slider arm, when positioned | 
|---|
| 1143 | *                  between two values, to be positioned | 
|---|
| 1144 | *                  to the nearest value and redrawn at | 
|---|
| 1145 | *                  that position. | 
|---|
| 1146 | * | 
|---|
| 1147 | *      Additionally, for horizontal sliders: | 
|---|
| 1148 | *      -- SLS_BUTTONSLEFT: specifies that the optional slider | 
|---|
| 1149 | *                  buttons are to be used and places them | 
|---|
| 1150 | *                  to the left of the slider shaft. The | 
|---|
| 1151 | *                  buttons move the slider arm by one | 
|---|
| 1152 | *                  position, left or right, in the | 
|---|
| 1153 | *                  direction selected. | 
|---|
| 1154 | *      -- SLS_BUTTONSRIGHT: specifies that the optional slider | 
|---|
| 1155 | *                  buttons are to be used and places them | 
|---|
| 1156 | *                  to the right of the slider shaft. The | 
|---|
| 1157 | *                  buttons move the slider arm by one | 
|---|
| 1158 | *                  position, left or right, in the | 
|---|
| 1159 | *                  direction selected. | 
|---|
| 1160 | *      -- SLS_HOMELEFT: specifies the slider arm's home | 
|---|
| 1161 | *                  position. The left edge is used as the | 
|---|
| 1162 | *                  base value for incrementing (default). | 
|---|
| 1163 | *      -- SLS_HOMERIGHT: specifies the slider arm's home | 
|---|
| 1164 | *                  position. The right edge is used as | 
|---|
| 1165 | *                  the base value for incrementing. | 
|---|
| 1166 | * | 
|---|
| 1167 | *      Instead, for vertical sliders: | 
|---|
| 1168 | *      -- SLS_BUTTONSBOTTOM: specifies that the optional slider | 
|---|
| 1169 | *                  buttons are to be used and places them | 
|---|
| 1170 | *                  at the bottom of the slider shaft. The | 
|---|
| 1171 | *                  buttons move the slider arm by one | 
|---|
| 1172 | *                  position, up or down, in the direction | 
|---|
| 1173 | *                  selected. | 
|---|
| 1174 | *      -- SLS_BUTTONSTOP: specifies that the optional slider | 
|---|
| 1175 | *                  buttons are to be used and places them | 
|---|
| 1176 | *                  at the top of the slider shaft. The | 
|---|
| 1177 | *                  buttons move the slider arm by one | 
|---|
| 1178 | *                  position, up or down, in the direction | 
|---|
| 1179 | *                  selected. | 
|---|
| 1180 | *      -- SLS_HOMEBOTTOM: specifies the slider arm's home | 
|---|
| 1181 | *                  position. The bottom of the slider is | 
|---|
| 1182 | *                  used as the base value for | 
|---|
| 1183 | *                  incrementing. | 
|---|
| 1184 | *      -- SLS_HOMETOP: specifies the slider arm's home | 
|---|
| 1185 | *                  position. The top of the slider is | 
|---|
| 1186 | *                  used as the base value for | 
|---|
| 1187 | *                  incrementing. | 
|---|
| 1188 | * | 
|---|
| 1189 | *      Notes: This function automatically adds WS_PARENTCLIP, | 
|---|
| 1190 | *      WS_TABSTOP, and WS_SYNCPAINT to the specified styles. | 
|---|
| 1191 | *      For the WS_TABSTOP style, hwndInsertAfter is important. | 
|---|
| 1192 | *      If you specify HWND_TOP, your window will be the first | 
|---|
| 1193 | *      in the tab stop list. | 
|---|
| 1194 | * | 
|---|
| 1195 | *      It also shows the slider after having done all the | 
|---|
| 1196 | *      processing in here by calling WinShowWindow. | 
|---|
| 1197 | * | 
|---|
| 1198 | *      Also, we only provide support for scale 1 here, so | 
|---|
| 1199 | *      do not specify SLS_PRIMARYSCALE2 with ulSliderStyle, | 
|---|
| 1200 | *      and we have the slider calculate all the spacings. | 
|---|
| 1201 | * | 
|---|
| 1202 | *      This returns the HWND of the slider or NULLHANDLE upon | 
|---|
| 1203 | *      errors. | 
|---|
| 1204 | * | 
|---|
| 1205 | *@@added V0.9.0 [umoeller] | 
|---|
| 1206 | */ | 
|---|
| 1207 |  | 
|---|
| 1208 | HWND winhReplaceWithLinearSlider(HWND hwndParent,   // in: parent of old control and slider | 
|---|
| 1209 | HWND hwndOwner,          // in: owner of old control and slider | 
|---|
| 1210 | HWND hwndInsertAfter,    // in: the control after which the slider should | 
|---|
| 1211 | // come up, or HWND_TOP, or HWND_BOTTOM | 
|---|
| 1212 | ULONG ulID,              // in: ID of old control and slider | 
|---|
| 1213 | ULONG ulSliderStyle,     // in: SLS_* styles | 
|---|
| 1214 | ULONG ulTickCount)       // in: number of ticks (scale 1) | 
|---|
| 1215 | { | 
|---|
| 1216 | HWND    hwndSlider = NULLHANDLE; | 
|---|
| 1217 | HWND    hwndKill = WinWindowFromID(hwndParent, ulID); | 
|---|
| 1218 | if (hwndKill) | 
|---|
| 1219 | { | 
|---|
| 1220 | SWP swpControl; | 
|---|
| 1221 | if (WinQueryWindowPos(hwndKill, &swpControl)) | 
|---|
| 1222 | { | 
|---|
| 1223 | SLDCDATA slcd; | 
|---|
| 1224 |  | 
|---|
| 1225 | // destroy the old control | 
|---|
| 1226 | WinDestroyWindow(hwndKill); | 
|---|
| 1227 |  | 
|---|
| 1228 | // initialize slider control data | 
|---|
| 1229 | slcd.cbSize = sizeof(SLDCDATA); | 
|---|
| 1230 | slcd.usScale1Increments = ulTickCount; | 
|---|
| 1231 | slcd.usScale1Spacing = 0;           // have slider calculate it | 
|---|
| 1232 | slcd.usScale2Increments = 0; | 
|---|
| 1233 | slcd.usScale2Spacing = 0; | 
|---|
| 1234 |  | 
|---|
| 1235 | // create a slider with the same ID at the same | 
|---|
| 1236 | // position | 
|---|
| 1237 | hwndSlider = WinCreateWindow(hwndParent, | 
|---|
| 1238 | WC_SLIDER, | 
|---|
| 1239 | NULL,           // no window text | 
|---|
| 1240 | ulSliderStyle | 
|---|
| 1241 | | WS_PARENTCLIP | 
|---|
| 1242 | | WS_SYNCPAINT | 
|---|
| 1243 | | WS_TABSTOP, | 
|---|
| 1244 | swpControl.x, | 
|---|
| 1245 | swpControl.y, | 
|---|
| 1246 | swpControl.cx, | 
|---|
| 1247 | swpControl.cy, | 
|---|
| 1248 | hwndOwner, | 
|---|
| 1249 | hwndInsertAfter, | 
|---|
| 1250 | ulID,           // same ID as destroyed control | 
|---|
| 1251 | &slcd,          // slider control data | 
|---|
| 1252 | NULL);          // presparams | 
|---|
| 1253 |  | 
|---|
| 1254 | WinSendMsg(hwndSlider, | 
|---|
| 1255 | SLM_SETTICKSIZE, | 
|---|
| 1256 | MPFROM2SHORT(SMA_SETALLTICKS, | 
|---|
| 1257 | 6),     // 15 pixels high | 
|---|
| 1258 | NULL); | 
|---|
| 1259 |  | 
|---|
| 1260 | WinShowWindow(hwndSlider, TRUE); | 
|---|
| 1261 | } | 
|---|
| 1262 | } | 
|---|
| 1263 |  | 
|---|
| 1264 | return hwndSlider; | 
|---|
| 1265 | } | 
|---|
| 1266 |  | 
|---|
| 1267 | /* | 
|---|
| 1268 | *@@ winhSetSliderTicks: | 
|---|
| 1269 | *      this adds ticks to the given linear slider, | 
|---|
| 1270 | *      which are ulPixels pixels high. A useful | 
|---|
| 1271 | *      value for this is 4. | 
|---|
| 1272 | * | 
|---|
| 1273 | *      This queries the slider for the primary | 
|---|
| 1274 | *      scale values. Only the primary scale is | 
|---|
| 1275 | *      supported. | 
|---|
| 1276 | * | 
|---|
| 1277 | *      This function goes sets the ticks twice, | 
|---|
| 1278 | *      once with mpEveryOther1 and ulPixels1, | 
|---|
| 1279 | *      and then a second time with mpEveryOther2 | 
|---|
| 1280 | *      and ulPixels2. This allows you to quickly | 
|---|
| 1281 | *      give, say, every tenth item a taller tick. | 
|---|
| 1282 | * | 
|---|
| 1283 | *      For every set, if mpEveryOther is 0, this sets | 
|---|
| 1284 | *      all ticks on the primary slider scale. | 
|---|
| 1285 | * | 
|---|
| 1286 | *      If mpEveryOther is != 0, SHORT1FROMMP | 
|---|
| 1287 | *      specifies the first tick to set, and | 
|---|
| 1288 | *      SHORT2FROMMP specifies every other tick | 
|---|
| 1289 | *      to set from there. For example: | 
|---|
| 1290 | * | 
|---|
| 1291 | +          MPFROM2SHORT(9, 10) | 
|---|
| 1292 | * | 
|---|
| 1293 | *      would set tick 9, 19, 29, and so forth. | 
|---|
| 1294 | * | 
|---|
| 1295 | *      If both mpEveryOther and ulPixels are -1, | 
|---|
| 1296 | *      that set is skipped. | 
|---|
| 1297 | * | 
|---|
| 1298 | *      Example: Considering a slider with a | 
|---|
| 1299 | *      primary scale from 0 to 30, using | 
|---|
| 1300 | * | 
|---|
| 1301 | +          winhSetSliderTicks(hwndSlider, | 
|---|
| 1302 | +                             0,                       // every tick | 
|---|
| 1303 | +                             3,                       //      to three pixels | 
|---|
| 1304 | +                             MPFROM2SHORT(9, 10)      // then every tenth | 
|---|
| 1305 | +                             6);                      //      to six pixels. | 
|---|
| 1306 | * | 
|---|
| 1307 | *      Returns FALSE upon errors. | 
|---|
| 1308 | * | 
|---|
| 1309 | *@@added V0.9.1 (99-12-04) [umoeller] | 
|---|
| 1310 | *@@changed V0.9.7 (2001-01-18) [umoeller]: added second set | 
|---|
| 1311 | */ | 
|---|
| 1312 |  | 
|---|
| 1313 | BOOL winhSetSliderTicks(HWND hwndSlider,            // in: linear slider | 
|---|
| 1314 | MPARAM mpEveryOther1,       // in: set 1 | 
|---|
| 1315 | ULONG ulPixels1, | 
|---|
| 1316 | MPARAM mpEveryOther2,       // in: set 2 | 
|---|
| 1317 | ULONG ulPixels2) | 
|---|
| 1318 | { | 
|---|
| 1319 | BOOL brc = FALSE; | 
|---|
| 1320 |  | 
|---|
| 1321 | ULONG ulSet; | 
|---|
| 1322 | MPARAM mpEveryOther = mpEveryOther1; | 
|---|
| 1323 | ULONG ulPixels = ulPixels1; | 
|---|
| 1324 |  | 
|---|
| 1325 | // do this twice | 
|---|
| 1326 | for (ulSet = 0; | 
|---|
| 1327 | ulSet < 2; | 
|---|
| 1328 | ulSet++) | 
|---|
| 1329 | { | 
|---|
| 1330 | if (mpEveryOther == 0) | 
|---|
| 1331 | { | 
|---|
| 1332 | // set all ticks: | 
|---|
| 1333 | brc = (BOOL)WinSendMsg(hwndSlider, | 
|---|
| 1334 | SLM_SETTICKSIZE, | 
|---|
| 1335 | MPFROM2SHORT(SMA_SETALLTICKS, | 
|---|
| 1336 | ulPixels), | 
|---|
| 1337 | NULL); | 
|---|
| 1338 | } | 
|---|
| 1339 | else if ( (mpEveryOther != (MPARAM)-1) && (ulPixels != -1) ) | 
|---|
| 1340 | { | 
|---|
| 1341 | SLDCDATA  slcd; | 
|---|
| 1342 | WNDPARAMS   wp; | 
|---|
| 1343 | memset(&wp, 0, sizeof(WNDPARAMS)); | 
|---|
| 1344 | wp.fsStatus = WPM_CTLDATA; | 
|---|
| 1345 | wp.cbCtlData = sizeof(slcd); | 
|---|
| 1346 | wp.pCtlData = &slcd; | 
|---|
| 1347 | // get primary scale data from the slider | 
|---|
| 1348 | if (WinSendMsg(hwndSlider, | 
|---|
| 1349 | WM_QUERYWINDOWPARAMS, | 
|---|
| 1350 | (MPARAM)&wp, | 
|---|
| 1351 | 0)) | 
|---|
| 1352 | { | 
|---|
| 1353 | USHORT usStart = SHORT1FROMMP(mpEveryOther), | 
|---|
| 1354 | usEveryOther = SHORT2FROMMP(mpEveryOther); | 
|---|
| 1355 |  | 
|---|
| 1356 | USHORT usScale1Max = slcd.usScale1Increments, | 
|---|
| 1357 | us; | 
|---|
| 1358 |  | 
|---|
| 1359 | brc = TRUE; | 
|---|
| 1360 |  | 
|---|
| 1361 | for (us = usStart; us < usScale1Max; us += usEveryOther) | 
|---|
| 1362 | { | 
|---|
| 1363 | if (!(BOOL)WinSendMsg(hwndSlider, | 
|---|
| 1364 | SLM_SETTICKSIZE, | 
|---|
| 1365 | MPFROM2SHORT(us, | 
|---|
| 1366 | ulPixels), | 
|---|
| 1367 | NULL)) | 
|---|
| 1368 | { | 
|---|
| 1369 | brc = FALSE; | 
|---|
| 1370 | break; | 
|---|
| 1371 | } | 
|---|
| 1372 | } | 
|---|
| 1373 | } | 
|---|
| 1374 | } | 
|---|
| 1375 |  | 
|---|
| 1376 | // for the second loop, use second value set | 
|---|
| 1377 | mpEveryOther = mpEveryOther2; | 
|---|
| 1378 | ulPixels = ulPixels2; | 
|---|
| 1379 | // we only loop twice | 
|---|
| 1380 | } // end for (ulSet = 0; ulSet < 2; | 
|---|
| 1381 |  | 
|---|
| 1382 | return brc; | 
|---|
| 1383 | } | 
|---|
| 1384 |  | 
|---|
| 1385 | /* | 
|---|
| 1386 | *@@ winhReplaceWithCircularSlider: | 
|---|
| 1387 | *      this destroys the control with the ID ulID in hwndDlg | 
|---|
| 1388 | *      and creates a linear slider at the same position with the | 
|---|
| 1389 | *      same ID (effectively replacing it). | 
|---|
| 1390 | * | 
|---|
| 1391 | *      This is needed because the IBM dialog editor (DLGEDIT.EXE) | 
|---|
| 1392 | *      cannot create circular sliders. So the way to do this | 
|---|
| 1393 | *      easily is to create some other control with DLGEDIT | 
|---|
| 1394 | *      where the slider should be later and call this function | 
|---|
| 1395 | *      on that control when the dialog is initialized. | 
|---|
| 1396 | * | 
|---|
| 1397 | *      You need to specify the following with ulSliderStyle: | 
|---|
| 1398 | *      --  CSS_CIRCULARVALUE: draws a circular thumb, rather than a line, | 
|---|
| 1399 | *                  for the value indicator. | 
|---|
| 1400 | *      --  CSS_MIDPOINT: makes the mid-point tick mark larger. | 
|---|
| 1401 | *      --  CSS_NOBUTTON: does not display value buttons. Per default, the | 
|---|
| 1402 | *                  slider displays "-" and "+" buttons to the bottom left | 
|---|
| 1403 | *                  and bottom right of the knob. (BTW, these bitmaps can be | 
|---|
| 1404 | *                  changed using CSM_SETBITMAPDATA.) | 
|---|
| 1405 | *      --  CSS_NONUMBER: does not display the value on the dial. | 
|---|
| 1406 | *      --  CSS_NOTEXT: does not display title text under the dial. | 
|---|
| 1407 | *                  Otherwise, the text in the pszTitle parameter | 
|---|
| 1408 | *                  will be used. | 
|---|
| 1409 | *      --  CSS_NOTICKS (only listed in pmstddlg.h, not in PMREF): | 
|---|
| 1410 | *                  obviously, this prevents tick marks from being drawn. | 
|---|
| 1411 | *      --  CSS_POINTSELECT: permits the values on the circular slider | 
|---|
| 1412 | *                  to change immediately when dragged. | 
|---|
| 1413 | *                  Direct manipulation is performed by using a mouse to | 
|---|
| 1414 | *                  click on and drag the circular slider. There are two | 
|---|
| 1415 | *                  modes of direct manipulation for the circular slider: | 
|---|
| 1416 | *                  <BR><B>1)</B> The default direct manipulation mode is to scroll to | 
|---|
| 1417 | *                  the value indicated by the position of the mouse. | 
|---|
| 1418 | *                  This could be important if you used a circular slider | 
|---|
| 1419 | *                  for a volume control, for example. Increasing the volume | 
|---|
| 1420 | *                  from 0% to 100% too quickly could result in damage to | 
|---|
| 1421 | *                  both the user's ears and the equipment. | 
|---|
| 1422 | *                  <BR><B>2)</B>The other mode of direct manipulation permits | 
|---|
| 1423 | *                  the value on the circular slider to change immediately when dragged. | 
|---|
| 1424 | *                  This mode is enabled using the CSS_POINTSELECT style bit. When this | 
|---|
| 1425 | *                  style is used, the value of the dial can be changed by tracking | 
|---|
| 1426 | *                  the value with the mouse, which changes values quickly. | 
|---|
| 1427 | *      --  CSS_PROPORTIONALTICKS: allow the length of the tick marks to be calculated | 
|---|
| 1428 | *                  as a percentage of the radius (for small sliders). | 
|---|
| 1429 | *      --  CSS_360: permits the scroll range to extend 360 degrees. | 
|---|
| 1430 | *                  CSS_360 forces the CSS_NONUMBER style on. This is necessary | 
|---|
| 1431 | *                  to keep the value indicator from corrupting the number value. | 
|---|
| 1432 | * | 
|---|
| 1433 | *      FYI: The most commonly known circular slider in OS/2, the one in the | 
|---|
| 1434 | *      default "Sound" object, has a style of 0x9002018a, meaning | 
|---|
| 1435 | *      CSS_NOTEXT | CSS_POINTSELECT | CSS_NOTICKS. | 
|---|
| 1436 | * | 
|---|
| 1437 | *      Notes: This function automatically adds WS_PARENTCLIP, | 
|---|
| 1438 | *      WS_TABSTOP, and WS_SYNCPAINT to the specified styles. | 
|---|
| 1439 | *      For the WS_TABSTOP style, hwndInsertAfter is important. | 
|---|
| 1440 | *      If you specify HWND_TOP, your window will be the first | 
|---|
| 1441 | *      in the tab stop list. | 
|---|
| 1442 | * | 
|---|
| 1443 | *      It also shows the slider after having done all the | 
|---|
| 1444 | *      processing in here by calling WinShowWindow. | 
|---|
| 1445 | * | 
|---|
| 1446 | *      This returns the HWND of the slider or NULLHANDLE upon | 
|---|
| 1447 | *      errors. | 
|---|
| 1448 | * | 
|---|
| 1449 | *@@added V0.9.0 [umoeller] | 
|---|
| 1450 | */ | 
|---|
| 1451 |  | 
|---|
| 1452 | HWND winhReplaceWithCircularSlider(HWND hwndParent,   // in: parent of old control and slider | 
|---|
| 1453 | HWND hwndOwner,          // in: owner of old control and slider | 
|---|
| 1454 | HWND hwndInsertAfter,    // in: the control after which the slider should | 
|---|
| 1455 | // come up, or HWND_TOP, or HWND_BOTTOM | 
|---|
| 1456 | ULONG ulID,              // in: ID of old control and slider | 
|---|
| 1457 | ULONG ulSliderStyle,     // in: SLS_* styles | 
|---|
| 1458 | SHORT sMin,              // in: minimum value (e.g. 0) | 
|---|
| 1459 | SHORT sMax,              // in: maximum value (e.g. 100) | 
|---|
| 1460 | USHORT usIncrement,      // in: minimum increment (e.g. 1) | 
|---|
| 1461 | USHORT usTicksEvery)     // in: ticks ever x values (e.g. 20) | 
|---|
| 1462 | { | 
|---|
| 1463 | HWND    hwndSlider = NULLHANDLE; | 
|---|
| 1464 | HWND    hwndKill = WinWindowFromID(hwndParent, ulID); | 
|---|
| 1465 | if (hwndKill) | 
|---|
| 1466 | { | 
|---|
| 1467 | SWP swpControl; | 
|---|
| 1468 | if (WinQueryWindowPos(hwndKill, &swpControl)) | 
|---|
| 1469 | { | 
|---|
| 1470 | // destroy the old control | 
|---|
| 1471 | WinDestroyWindow(hwndKill); | 
|---|
| 1472 |  | 
|---|
| 1473 | // WinRegisterCircularSlider(); | 
|---|
| 1474 |  | 
|---|
| 1475 | // create a slider with the same ID at the same | 
|---|
| 1476 | // position | 
|---|
| 1477 | hwndSlider = WinCreateWindow(hwndParent, | 
|---|
| 1478 | WC_CIRCULARSLIDER, | 
|---|
| 1479 | "dummy",        // no window text | 
|---|
| 1480 | ulSliderStyle | 
|---|
| 1481 | // | WS_PARENTCLIP | 
|---|
| 1482 | // | WS_SYNCPAINT | 
|---|
| 1483 | | WS_TABSTOP, | 
|---|
| 1484 | swpControl.x, | 
|---|
| 1485 | swpControl.y, | 
|---|
| 1486 | swpControl.cx, | 
|---|
| 1487 | swpControl.cy, | 
|---|
| 1488 | hwndOwner, | 
|---|
| 1489 | hwndInsertAfter, | 
|---|
| 1490 | ulID,           // same ID as destroyed control | 
|---|
| 1491 | NULL,           // control data | 
|---|
| 1492 | NULL);          // presparams | 
|---|
| 1493 |  | 
|---|
| 1494 | if (hwndSlider) | 
|---|
| 1495 | { | 
|---|
| 1496 | // set slider range | 
|---|
| 1497 | WinSendMsg(hwndSlider, | 
|---|
| 1498 | CSM_SETRANGE, | 
|---|
| 1499 | (MPARAM)(ULONG)sMin, | 
|---|
| 1500 | (MPARAM)(ULONG)sMax); | 
|---|
| 1501 |  | 
|---|
| 1502 | // set slider increments | 
|---|
| 1503 | WinSendMsg(hwndSlider, | 
|---|
| 1504 | CSM_SETINCREMENT, | 
|---|
| 1505 | (MPARAM)(ULONG)usIncrement, | 
|---|
| 1506 | (MPARAM)(ULONG)usTicksEvery); | 
|---|
| 1507 |  | 
|---|
| 1508 | // set slider value | 
|---|
| 1509 | WinSendMsg(hwndSlider, | 
|---|
| 1510 | CSM_SETVALUE, | 
|---|
| 1511 | (MPARAM)0, | 
|---|
| 1512 | (MPARAM)0); | 
|---|
| 1513 |  | 
|---|
| 1514 | // for some reason, the slider always has | 
|---|
| 1515 | // WS_CLIPSIBLINGS set, even though we don't | 
|---|
| 1516 | // set this; we must unset this now, or | 
|---|
| 1517 | // the slider won't draw itself (%&$&%"$&%!!!) | 
|---|
| 1518 | WinSetWindowBits(hwndSlider, | 
|---|
| 1519 | QWL_STYLE, | 
|---|
| 1520 | 0,         // unset bit | 
|---|
| 1521 | WS_CLIPSIBLINGS); | 
|---|
| 1522 |  | 
|---|
| 1523 | WinShowWindow(hwndSlider, TRUE); | 
|---|
| 1524 | } | 
|---|
| 1525 | } | 
|---|
| 1526 | } | 
|---|
| 1527 |  | 
|---|
| 1528 | return hwndSlider; | 
|---|
| 1529 | } | 
|---|
| 1530 |  | 
|---|
| 1531 | /* | 
|---|
| 1532 | *@@category: Helpers\PM helpers\Spin button helpers | 
|---|
| 1533 | */ | 
|---|
| 1534 |  | 
|---|
| 1535 | /* ****************************************************************** | 
|---|
| 1536 | * | 
|---|
| 1537 | *   Spin button helpers | 
|---|
| 1538 | * | 
|---|
| 1539 | ********************************************************************/ | 
|---|
| 1540 |  | 
|---|
| 1541 | /* | 
|---|
| 1542 | *@@ winhSetDlgItemSpinData: | 
|---|
| 1543 | *      sets a spin button's limits and data within a dialog window. | 
|---|
| 1544 | *      This only works for decimal spin buttons. | 
|---|
| 1545 | */ | 
|---|
| 1546 |  | 
|---|
| 1547 | VOID winhSetDlgItemSpinData(HWND hwndDlg,       // in: dlg window | 
|---|
| 1548 | ULONG idSpinButton,  // in: item ID of spin button | 
|---|
| 1549 | ULONG min,           // in: minimum allowed value | 
|---|
| 1550 | ULONG max,           // in: maximum allowed value | 
|---|
| 1551 | ULONG current)       // in: new current value | 
|---|
| 1552 | { | 
|---|
| 1553 | HWND hwndSpinButton = WinWindowFromID(hwndDlg, idSpinButton); | 
|---|
| 1554 | if (hwndSpinButton) | 
|---|
| 1555 | { | 
|---|
| 1556 | WinSendMsg(hwndSpinButton, | 
|---|
| 1557 | SPBM_SETLIMITS,          // Set limits message | 
|---|
| 1558 | (MPARAM)max,             // Spin Button maximum setting | 
|---|
| 1559 | (MPARAM)min);             // Spin Button minimum setting | 
|---|
| 1560 |  | 
|---|
| 1561 | WinSendMsg(hwndSpinButton, | 
|---|
| 1562 | SPBM_SETCURRENTVALUE,    // Set current value message | 
|---|
| 1563 | (MPARAM)current, | 
|---|
| 1564 | (MPARAM)NULL); | 
|---|
| 1565 | } | 
|---|
| 1566 | } | 
|---|
| 1567 |  | 
|---|
| 1568 | /* | 
|---|
| 1569 | *@@ winhAdjustDlgItemSpinData: | 
|---|
| 1570 | *      this can be called on a spin button control to | 
|---|
| 1571 | *      have its current data snap to a grid. This only | 
|---|
| 1572 | *      works for LONG integer values. | 
|---|
| 1573 | * | 
|---|
| 1574 | *      For example, if you specify 100 for the grid and call | 
|---|
| 1575 | *      this func after you have received SPBN_UP/DOWNARROW, | 
|---|
| 1576 | *      the spin button's value will always in/decrease | 
|---|
| 1577 | *      so that the spin button's value is a multiple of 100. | 
|---|
| 1578 | * | 
|---|
| 1579 | *      By contrast, if (lGrid < 0), this will not really | 
|---|
| 1580 | *      snap the value to a multiple of -lGrid, but instead | 
|---|
| 1581 | *      in/decrease the value by -lGrid. The value will not | 
|---|
| 1582 | *      necessarily be a multiple of the grid. (0.9.14) | 
|---|
| 1583 | * | 
|---|
| 1584 | *      This returns the "snapped" value to which the spin | 
|---|
| 1585 | *      button was set. | 
|---|
| 1586 | * | 
|---|
| 1587 | *      If you specify lGrid == 0, this returns the spin | 
|---|
| 1588 | *      button's value only without snapping (V0.9.0). | 
|---|
| 1589 | * | 
|---|
| 1590 | *@@changed V0.9.0 [umoeller]: added check for lGrid == 0 (caused division by zero previously) | 
|---|
| 1591 | *@@changed V0.9.14 (2001-08-03) [umoeller]: added fixes for age-old problems with wrap around | 
|---|
| 1592 | *@@changed V0.9.14 (2001-08-03) [umoeller]: added lGrid < 0 mode | 
|---|
| 1593 | */ | 
|---|
| 1594 |  | 
|---|
| 1595 | LONG winhAdjustDlgItemSpinData(HWND hwndDlg,     // in: dlg window | 
|---|
| 1596 | USHORT usItemID,  // in: item ID of spin button | 
|---|
| 1597 | LONG lGrid,       // in: grid | 
|---|
| 1598 | USHORT usNotifyCode) // in: SPBN_UP* or *DOWNARROW of WM_CONTROL message | 
|---|
| 1599 | { | 
|---|
| 1600 | HWND hwndSpin = WinWindowFromID(hwndDlg, usItemID); | 
|---|
| 1601 | LONG lBottom, lTop, lValue; | 
|---|
| 1602 |  | 
|---|
| 1603 | // get value, which has already increased / | 
|---|
| 1604 | // decreased by 1 | 
|---|
| 1605 | WinSendMsg(hwndSpin, | 
|---|
| 1606 | SPBM_QUERYVALUE, | 
|---|
| 1607 | (MPARAM)&lValue, | 
|---|
| 1608 | MPFROM2SHORT(0, SPBQ_ALWAYSUPDATE)); | 
|---|
| 1609 |  | 
|---|
| 1610 | if ((lGrid) | 
|---|
| 1611 | && (    (usNotifyCode == SPBN_UPARROW) | 
|---|
| 1612 | || (usNotifyCode == SPBN_DOWNARROW) | 
|---|
| 1613 | ) | 
|---|
| 1614 | ) | 
|---|
| 1615 | { | 
|---|
| 1616 | // only if the up/down buttons were pressed, | 
|---|
| 1617 | // snap to the nearest grid; if the user | 
|---|
| 1618 | // manually enters something (SPBN_CHANGE), | 
|---|
| 1619 | // we'll accept that value | 
|---|
| 1620 | LONG lChanged = (usNotifyCode == SPBN_UPARROW) | 
|---|
| 1621 | // if the spin button went up, subtract 1 | 
|---|
| 1622 | ? -1 | 
|---|
| 1623 | : +1; | 
|---|
| 1624 | LONG lPrev  = lValue + lChanged; | 
|---|
| 1625 |  | 
|---|
| 1626 | // if grid is negative, it is assumed to | 
|---|
| 1627 | // not be a "real" grid but jump in those | 
|---|
| 1628 | // steps only | 
|---|
| 1629 | if (lGrid < 0) | 
|---|
| 1630 | { | 
|---|
| 1631 | // add /subtract grid | 
|---|
| 1632 | if (usNotifyCode == SPBN_UPARROW) | 
|---|
| 1633 | lValue = lPrev - lGrid; | 
|---|
| 1634 | else | 
|---|
| 1635 | lValue = lPrev + lGrid; | 
|---|
| 1636 |  | 
|---|
| 1637 | // lValue = (lValue / lGrid) * lGrid; | 
|---|
| 1638 | } | 
|---|
| 1639 | else | 
|---|
| 1640 | { | 
|---|
| 1641 | // add /subtract grid | 
|---|
| 1642 | if (usNotifyCode == SPBN_UPARROW) | 
|---|
| 1643 | lValue = lPrev + lGrid; | 
|---|
| 1644 | else | 
|---|
| 1645 | lValue = lPrev - lGrid; | 
|---|
| 1646 |  | 
|---|
| 1647 | lValue = (lValue / lGrid) * lGrid; | 
|---|
| 1648 | } | 
|---|
| 1649 |  | 
|---|
| 1650 | // balance with spin button limits | 
|---|
| 1651 | WinSendMsg(hwndSpin, | 
|---|
| 1652 | SPBM_QUERYLIMITS, | 
|---|
| 1653 | (MPARAM)&lTop, | 
|---|
| 1654 | (MPARAM)&lBottom); | 
|---|
| 1655 | if (lValue < lBottom) | 
|---|
| 1656 | lValue = lTop; | 
|---|
| 1657 | else if (lValue > lTop) | 
|---|
| 1658 | lValue = lBottom; | 
|---|
| 1659 |  | 
|---|
| 1660 | WinSendMsg(hwndSpin, | 
|---|
| 1661 | SPBM_SETCURRENTVALUE, | 
|---|
| 1662 | (MPARAM)(lValue), | 
|---|
| 1663 | MPNULL); | 
|---|
| 1664 | } | 
|---|
| 1665 | return lValue; | 
|---|
| 1666 | } | 
|---|
| 1667 |  | 
|---|
| 1668 | /* | 
|---|
| 1669 | *@@category: Helpers\PM helpers\List box helpers | 
|---|
| 1670 | */ | 
|---|
| 1671 |  | 
|---|
| 1672 | /* ****************************************************************** | 
|---|
| 1673 | * | 
|---|
| 1674 | *   List box helpers | 
|---|
| 1675 | * | 
|---|
| 1676 | ********************************************************************/ | 
|---|
| 1677 |  | 
|---|
| 1678 | /* | 
|---|
| 1679 | *@@ winhQueryLboxItemText: | 
|---|
| 1680 | *      returns the text of the specified | 
|---|
| 1681 | *      list box item in a newly allocated | 
|---|
| 1682 | *      buffer. | 
|---|
| 1683 | * | 
|---|
| 1684 | *      Returns NULL on error. Use fre() | 
|---|
| 1685 | *      to free the return value. | 
|---|
| 1686 | * | 
|---|
| 1687 | *@@added V0.9.1 (99-12-14) [umoeller] | 
|---|
| 1688 | */ | 
|---|
| 1689 |  | 
|---|
| 1690 | PSZ winhQueryLboxItemText(HWND hwndListbox, | 
|---|
| 1691 | SHORT sIndex) | 
|---|
| 1692 | { | 
|---|
| 1693 | PSZ   pszReturn = 0; | 
|---|
| 1694 | SHORT cbText = SHORT1FROMMR(WinSendMsg(hwndListbox, | 
|---|
| 1695 | LM_QUERYITEMTEXTLENGTH, | 
|---|
| 1696 | (MPARAM)(ULONG)sIndex, | 
|---|
| 1697 | 0)); | 
|---|
| 1698 | if ((cbText) && (cbText != LIT_ERROR)) | 
|---|
| 1699 | { | 
|---|
| 1700 | pszReturn = (PSZ)malloc(cbText + 1);        // add zero terminator | 
|---|
| 1701 | WinSendMsg(hwndListbox, | 
|---|
| 1702 | LM_QUERYITEMTEXT, | 
|---|
| 1703 | MPFROM2SHORT(sIndex, | 
|---|
| 1704 | cbText + 1), | 
|---|
| 1705 | (MPARAM)pszReturn); | 
|---|
| 1706 | } | 
|---|
| 1707 |  | 
|---|
| 1708 | return pszReturn; | 
|---|
| 1709 | } | 
|---|
| 1710 |  | 
|---|
| 1711 | /* | 
|---|
| 1712 | *@@ winhMoveLboxItem: | 
|---|
| 1713 | *      this moves one list box item from one | 
|---|
| 1714 | *      list box to another, including the | 
|---|
| 1715 | *      item text and the item "handle" | 
|---|
| 1716 | *      (see LM_QUERYITEMHANDLE). | 
|---|
| 1717 | * | 
|---|
| 1718 | *      sTargetIndex can either be a regular | 
|---|
| 1719 | *      item index or one of the following | 
|---|
| 1720 | *      (as in LM_INSERTITEM): | 
|---|
| 1721 | *      -- LIT_END | 
|---|
| 1722 | *      -- LIT_SORTASCENDING | 
|---|
| 1723 | *      -- LIT_SORTDESCENDING | 
|---|
| 1724 | * | 
|---|
| 1725 | *      If (fSelectTarget == TRUE), the new | 
|---|
| 1726 | *      item is also selected in the target | 
|---|
| 1727 | *      list box. | 
|---|
| 1728 | * | 
|---|
| 1729 | *      Returns FALSE if moving failed. In | 
|---|
| 1730 | *      that case, the list boxes are unchanged. | 
|---|
| 1731 | * | 
|---|
| 1732 | *@@added V0.9.1 (99-12-14) [umoeller] | 
|---|
| 1733 | */ | 
|---|
| 1734 |  | 
|---|
| 1735 | BOOL winhMoveLboxItem(HWND hwndSource, | 
|---|
| 1736 | SHORT sSourceIndex, | 
|---|
| 1737 | HWND hwndTarget, | 
|---|
| 1738 | SHORT sTargetIndex, | 
|---|
| 1739 | BOOL fSelectTarget) | 
|---|
| 1740 | { | 
|---|
| 1741 | BOOL brc = FALSE; | 
|---|
| 1742 |  | 
|---|
| 1743 | PSZ pszItemText = winhQueryLboxItemText(hwndSource, sSourceIndex); | 
|---|
| 1744 | if (pszItemText) | 
|---|
| 1745 | { | 
|---|
| 1746 | ULONG   ulItemHandle = winhQueryLboxItemHandle(hwndSource, | 
|---|
| 1747 | sSourceIndex); | 
|---|
| 1748 | // probably 0, if not used | 
|---|
| 1749 | LONG lTargetIndex = WinInsertLboxItem(hwndTarget, | 
|---|
| 1750 | sTargetIndex, | 
|---|
| 1751 | pszItemText); | 
|---|
| 1752 | if (    (lTargetIndex != LIT_ERROR) | 
|---|
| 1753 | && (lTargetIndex != LIT_MEMERROR) | 
|---|
| 1754 | ) | 
|---|
| 1755 | { | 
|---|
| 1756 | // successfully inserted: | 
|---|
| 1757 | winhSetLboxItemHandle(hwndTarget, lTargetIndex, ulItemHandle); | 
|---|
| 1758 | if (fSelectTarget) | 
|---|
| 1759 | winhSetLboxSelectedItem(hwndTarget, lTargetIndex, TRUE); | 
|---|
| 1760 |  | 
|---|
| 1761 | // remove source | 
|---|
| 1762 | WinDeleteLboxItem(hwndSource, | 
|---|
| 1763 | sSourceIndex); | 
|---|
| 1764 |  | 
|---|
| 1765 | brc = TRUE; | 
|---|
| 1766 | } | 
|---|
| 1767 |  | 
|---|
| 1768 | free(pszItemText); | 
|---|
| 1769 | } | 
|---|
| 1770 |  | 
|---|
| 1771 | return brc; | 
|---|
| 1772 | } | 
|---|
| 1773 |  | 
|---|
| 1774 | /* | 
|---|
| 1775 | *@@ winhLboxSelectAll: | 
|---|
| 1776 | *      this selects or deselects all items in the | 
|---|
| 1777 | *      given list box, depending on fSelect. | 
|---|
| 1778 | * | 
|---|
| 1779 | *      Returns the number of items in the list box. | 
|---|
| 1780 | */ | 
|---|
| 1781 |  | 
|---|
| 1782 | ULONG winhLboxSelectAll(HWND hwndListBox,   // in: list box | 
|---|
| 1783 | BOOL fSelect)       // in: TRUE = select, FALSE = deselect | 
|---|
| 1784 | { | 
|---|
| 1785 | LONG lItemCount = WinQueryLboxCount(hwndListBox); | 
|---|
| 1786 | ULONG ul; | 
|---|
| 1787 |  | 
|---|
| 1788 | for (ul = 0; ul < lItemCount; ul++) | 
|---|
| 1789 | { | 
|---|
| 1790 | WinSendMsg(hwndListBox, | 
|---|
| 1791 | LM_SELECTITEM, | 
|---|
| 1792 | (MPARAM)ul,      // index | 
|---|
| 1793 | (MPARAM)fSelect); | 
|---|
| 1794 | } | 
|---|
| 1795 |  | 
|---|
| 1796 | return lItemCount; | 
|---|
| 1797 | } | 
|---|
| 1798 |  | 
|---|
| 1799 | /* | 
|---|
| 1800 | *@@ winhLboxFindItemFromHandle: | 
|---|
| 1801 | *      finds the list box item with the specified | 
|---|
| 1802 | *      handle. | 
|---|
| 1803 | * | 
|---|
| 1804 | *      Of course this only makes sense if each item | 
|---|
| 1805 | *      has a unique handle indeed. | 
|---|
| 1806 | * | 
|---|
| 1807 | *      Returns the index of the item found or -1. | 
|---|
| 1808 | * | 
|---|
| 1809 | *@@added V0.9.12 (2001-05-18) [umoeller] | 
|---|
| 1810 | */ | 
|---|
| 1811 |  | 
|---|
| 1812 | ULONG winhLboxFindItemFromHandle(HWND hwndListBox, | 
|---|
| 1813 | ULONG ulHandle) | 
|---|
| 1814 | { | 
|---|
| 1815 | LONG cItems; | 
|---|
| 1816 | if (cItems = WinQueryLboxCount(hwndListBox)) | 
|---|
| 1817 | { | 
|---|
| 1818 | ULONG ul; | 
|---|
| 1819 | for (ul = 0; | 
|---|
| 1820 | ul < cItems; | 
|---|
| 1821 | ul++) | 
|---|
| 1822 | { | 
|---|
| 1823 | if (ulHandle == winhQueryLboxItemHandle(hwndListBox, | 
|---|
| 1824 | ul)) | 
|---|
| 1825 | return ul; | 
|---|
| 1826 | } | 
|---|
| 1827 | } | 
|---|
| 1828 |  | 
|---|
| 1829 | return -1; | 
|---|
| 1830 | } | 
|---|
| 1831 |  | 
|---|
| 1832 | /* | 
|---|
| 1833 | *@@category: Helpers\PM helpers\Scroll bar helpers | 
|---|
| 1834 | */ | 
|---|
| 1835 |  | 
|---|
| 1836 | /* ****************************************************************** | 
|---|
| 1837 | * | 
|---|
| 1838 | *   Scroll bar helpers | 
|---|
| 1839 | * | 
|---|
| 1840 | ********************************************************************/ | 
|---|
| 1841 |  | 
|---|
| 1842 | /* | 
|---|
| 1843 | *@@ winhUpdateScrollBar: | 
|---|
| 1844 | *      updates the given scroll bar according to the given | 
|---|
| 1845 | *      values. This updates the scroll bar's thumb size, | 
|---|
| 1846 | *      extension, and position, all in one shot. | 
|---|
| 1847 | * | 
|---|
| 1848 | *      This function usually gets called when the window is | 
|---|
| 1849 | *      created and later when the window is resized. | 
|---|
| 1850 | * | 
|---|
| 1851 | *      This simplifies the typical functionality of a scroll | 
|---|
| 1852 | *      bar in a client window which is to be scrolled. I am | 
|---|
| 1853 | *      wondering why IBM never included such a function, since | 
|---|
| 1854 | *      it is so damn basic and still writing it cost me a whole | 
|---|
| 1855 | *      day. | 
|---|
| 1856 | * | 
|---|
| 1857 | *      Terminology: | 
|---|
| 1858 | * | 
|---|
| 1859 | *      -- "window": the actual window with scroll bars which displays | 
|---|
| 1860 | *         a subrectangle of the available data. With a typical PM | 
|---|
| 1861 | *         application, this will be your client window. | 
|---|
| 1862 | * | 
|---|
| 1863 | *         The width or height of this must be passed in ulWinPels. | 
|---|
| 1864 | * | 
|---|
| 1865 | *      -- "viewport": the entire data to be displayed, of which the | 
|---|
| 1866 | *         "window" can only display a subrectangle, if the viewport | 
|---|
| 1867 | *         is larger than the window. | 
|---|
| 1868 | * | 
|---|
| 1869 | *         The width or height of this must be passed in ulViewportPels. | 
|---|
| 1870 | *         This can be smaller than ulWinPels (if the window is larger | 
|---|
| 1871 | *         than the data) or the same or larger than ulWinPels | 
|---|
| 1872 | *         (if the window is too small to show all the data). | 
|---|
| 1873 | * | 
|---|
| 1874 | *      -- "window offset": the offset of the current window within | 
|---|
| 1875 | *         the viewport. | 
|---|
| 1876 | * | 
|---|
| 1877 | *         For horizontal scroll bars, this is the X coordinate, | 
|---|
| 1878 | *         counting from the left of the window (0 means leftmost). | 
|---|
| 1879 | * | 
|---|
| 1880 | *         For vertical scroll bars, this is counted from the _top_ | 
|---|
| 1881 | *         of the viewport (0 means topmost, as opposed to OS/2 | 
|---|
| 1882 | *         window coordinates!). This is because for vertical scroll | 
|---|
| 1883 | *         bars controls, higher values move the thumb _down_. Yes | 
|---|
| 1884 | *         indeed, this conflicts with PM's coordinate system. | 
|---|
| 1885 | * | 
|---|
| 1886 | *         The window offset is therefore always positive. | 
|---|
| 1887 | * | 
|---|
| 1888 | *      The scroll bar gets disabled if the entire viewport is visible, | 
|---|
| 1889 | *      that is, if ulViewportPels <= ulWinPels. In that case | 
|---|
| 1890 | *      FALSE is returned. If (fAutoHide == TRUE), the scroll | 
|---|
| 1891 | *      bar is not only disabled, but also hidden from the display. | 
|---|
| 1892 | *      In that case, you will need to reformat your output because | 
|---|
| 1893 | *      your viewport becomes larger without the scroll bar. | 
|---|
| 1894 | * | 
|---|
| 1895 | *      This function will set the range of the scroll bar to 0 up | 
|---|
| 1896 | *      to a value depending on the viewport size. For vertical scroll | 
|---|
| 1897 | *      bars, 0 means topmost (which is kinda sick with the OS/2 | 
|---|
| 1898 | *      coordinate system), for horizontal scroll bars, 0 means leftmost. | 
|---|
| 1899 | * | 
|---|
| 1900 | *      The maximum value of the scroll bar will be | 
|---|
| 1901 | * | 
|---|
| 1902 | +          (ulViewportPels - ulWinPels) / usScrollUnitPels | 
|---|
| 1903 | * | 
|---|
| 1904 | *      The thumb size of the scroll bar will also be adjusted | 
|---|
| 1905 | *      based on the viewport and window size, as it should be. | 
|---|
| 1906 | * | 
|---|
| 1907 | *@@added V0.9.1 (2000-02-14) [umoeller] | 
|---|
| 1908 | *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion | 
|---|
| 1909 | *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically | 
|---|
| 1910 | */ | 
|---|
| 1911 |  | 
|---|
| 1912 | BOOL winhUpdateScrollBar(HWND hwndScrollBar,    // in: scroll bar (vertical or horizontal) | 
|---|
| 1913 | ULONG ulWinPels,       // in: vertical or horizontal dimension of | 
|---|
| 1914 | // visible window part (in pixels), | 
|---|
| 1915 | // excluding the scroll bar! | 
|---|
| 1916 | ULONG ulViewportPels,  // in: dimension of total data part, of | 
|---|
| 1917 | // which ulWinPels is a sub-dimension | 
|---|
| 1918 | // (in pixels); | 
|---|
| 1919 | // if <= ulWinPels, the scrollbar will be | 
|---|
| 1920 | // disabled | 
|---|
| 1921 | ULONG ulCurPelsOfs,    // in: current offset of visible part | 
|---|
| 1922 | // (in pixels) | 
|---|
| 1923 | BOOL fAutoHide)        // in: hide scroll bar if disabled | 
|---|
| 1924 | { | 
|---|
| 1925 | BOOL brc = FALSE; | 
|---|
| 1926 |  | 
|---|
| 1927 | // _Pmpf(("Entering winhUpdateScrollBar")); | 
|---|
| 1928 |  | 
|---|
| 1929 | // for large viewports, adjust scroll bar units | 
|---|
| 1930 | USHORT  usScrollUnitPels = 1; | 
|---|
| 1931 | if (ulViewportPels > 10000) | 
|---|
| 1932 | usScrollUnitPels = 100; | 
|---|
| 1933 |  | 
|---|
| 1934 | if (ulViewportPels > ulWinPels) | 
|---|
| 1935 | { | 
|---|
| 1936 | // scrollbar needed: | 
|---|
| 1937 | USHORT  usThumbDivisorUnits = usScrollUnitPels; | 
|---|
| 1938 | USHORT  lMaxAllowedUnitOfs; | 
|---|
| 1939 | // _Pmpf(("winhUpdateScrollBar: ulViewportPels > ulWinPels, enabling scroller")); | 
|---|
| 1940 | // divisor for thumb size (below) | 
|---|
| 1941 | if (ulViewportPels > 10000) | 
|---|
| 1942 | // for very large viewports, we need to | 
|---|
| 1943 | // raise the divisor, because we only | 
|---|
| 1944 | // have a USHORT | 
|---|
| 1945 | usThumbDivisorUnits = usScrollUnitPels * 100; | 
|---|
| 1946 |  | 
|---|
| 1947 | // viewport is larger than window: | 
|---|
| 1948 | WinEnableWindow(hwndScrollBar, TRUE); | 
|---|
| 1949 | if (fAutoHide) | 
|---|
| 1950 | WinShowWindow(hwndScrollBar, TRUE); | 
|---|
| 1951 |  | 
|---|
| 1952 | // calculate limit | 
|---|
| 1953 | lMaxAllowedUnitOfs = ((ulViewportPels - ulWinPels + usScrollUnitPels) | 
|---|
| 1954 | // scroll unit is 10 | 
|---|
| 1955 | / usScrollUnitPels); | 
|---|
| 1956 |  | 
|---|
| 1957 | // _Pmpf(("    usCurUnitOfs: %d", ulCurUnitOfs)); | 
|---|
| 1958 | // _Pmpf(("    usMaxUnits: %d", lMaxAllowedUnitOfs)); | 
|---|
| 1959 |  | 
|---|
| 1960 | // set thumb position and limit | 
|---|
| 1961 | WinSendMsg(hwndScrollBar, | 
|---|
| 1962 | SBM_SETSCROLLBAR, | 
|---|
| 1963 | (MPARAM)(ulCurPelsOfs), //  / usThumbDivisorUnits),   // position: 0 means top | 
|---|
| 1964 | MPFROM2SHORT(0,  // minimum | 
|---|
| 1965 | lMaxAllowedUnitOfs));    // maximum | 
|---|
| 1966 |  | 
|---|
| 1967 | // set thumb size based on ulWinPels and | 
|---|
| 1968 | // ulViewportPels | 
|---|
| 1969 | WinSendMsg(hwndScrollBar, | 
|---|
| 1970 | SBM_SETTHUMBSIZE, | 
|---|
| 1971 | MPFROM2SHORT(    ulWinPels / usThumbDivisorUnits,       // visible | 
|---|
| 1972 | ulViewportPels / usThumbDivisorUnits), // total | 
|---|
| 1973 | 0); | 
|---|
| 1974 | brc = TRUE; | 
|---|
| 1975 | } | 
|---|
| 1976 | else | 
|---|
| 1977 | { | 
|---|
| 1978 | // _Pmpf(("winhUpdateScrollBar: ulViewportPels <= ulWinPels")); | 
|---|
| 1979 | // entire viewport is visible: | 
|---|
| 1980 | WinEnableWindow(hwndScrollBar, FALSE); | 
|---|
| 1981 | if (fAutoHide) | 
|---|
| 1982 | WinShowWindow(hwndScrollBar, FALSE); | 
|---|
| 1983 | } | 
|---|
| 1984 |  | 
|---|
| 1985 | // _Pmpf(("End of winhUpdateScrollBar")); | 
|---|
| 1986 |  | 
|---|
| 1987 | return brc; | 
|---|
| 1988 | } | 
|---|
| 1989 |  | 
|---|
| 1990 | /* | 
|---|
| 1991 | *@@ winhHandleScrollMsg: | 
|---|
| 1992 | *      this helper handles a WM_VSCROLL or WM_HSCROLL | 
|---|
| 1993 | *      message posted to a client window when the user | 
|---|
| 1994 | *      has worked on a client scroll bar. Calling this | 
|---|
| 1995 | *      function is ALL you need to do to handle those | 
|---|
| 1996 | *      two messages. | 
|---|
| 1997 | * | 
|---|
| 1998 | *      This is most useful in conjunction with winhUpdateScrollBar. | 
|---|
| 1999 | *      See that function for the terminology also. | 
|---|
| 2000 | * | 
|---|
| 2001 | *      This function calculates the new scrollbar position | 
|---|
| 2002 | *      (from the mp2 value, which can be line up/down, | 
|---|
| 2003 | *      page up/down, or slider track) and calls WinScrollWindow | 
|---|
| 2004 | *      accordingly. The window part which became invalid | 
|---|
| 2005 | *      because of the scrolling is automatically invalidated | 
|---|
| 2006 | *      (using WinInvalidateRect), so expect a WM_PAINT after | 
|---|
| 2007 | *      calling this function. | 
|---|
| 2008 | * | 
|---|
| 2009 | *      This function assumes that the scrollbar operates | 
|---|
| 2010 | *      on values starting from zero. The maximum value | 
|---|
| 2011 | *      of the scroll bar is: | 
|---|
| 2012 | * | 
|---|
| 2013 | +          ulViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom) | 
|---|
| 2014 | * | 
|---|
| 2015 | *      This function also automatically changes the scroll bar | 
|---|
| 2016 | *      units, should you have a viewport size which doesn't fit | 
|---|
| 2017 | *      into the SHORT's that the scroll bar uses internally. As | 
|---|
| 2018 | *      a result, this function handles a the complete range of | 
|---|
| 2019 | *      a ULONG for the viewport. | 
|---|
| 2020 | * | 
|---|
| 2021 | *      Replace "bottom" and "top" with "right" and "left" for | 
|---|
| 2022 | *      horizontal scrollbars in the above formula. | 
|---|
| 2023 | * | 
|---|
| 2024 | *@@added V0.9.1 (2000-02-13) [umoeller] | 
|---|
| 2025 | *@@changed V0.9.3 (2000-04-30) [umoeller]: changed prototype, fixed pels/unit confusion | 
|---|
| 2026 | *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically | 
|---|
| 2027 | *@@changed V0.9.7 (2001-01-17) [umoeller]: changed PLONG to PULONG | 
|---|
| 2028 | */ | 
|---|
| 2029 |  | 
|---|
| 2030 | BOOL winhHandleScrollMsg(HWND hwnd2Scroll,          // in: client window to scroll | 
|---|
| 2031 | HWND hwndScrollBar,        // in: vertical or horizontal scroll bar window | 
|---|
| 2032 | PULONG pulCurPelsOfs,      // in/out: current viewport offset; | 
|---|
| 2033 | // this is updated with the proper scroll units | 
|---|
| 2034 | PRECTL prcl2Scroll,        // in: hwnd2Scroll rectangle to scroll | 
|---|
| 2035 | // (in window coordinates); | 
|---|
| 2036 | // this is passed to WinScrollWindow, | 
|---|
| 2037 | // which considers this inclusive! | 
|---|
| 2038 | LONG ulViewportPels,       // in: total viewport dimension, | 
|---|
| 2039 | // into which *pulCurPelsOfs is an offset | 
|---|
| 2040 | USHORT usLineStepPels,     // in: pixels to scroll line-wise | 
|---|
| 2041 | // (scroll bar buttons pressed) | 
|---|
| 2042 | ULONG msg,                 // in: either WM_VSCROLL or WM_HSCROLL | 
|---|
| 2043 | MPARAM mp2)                // in: complete mp2 of WM_VSCROLL/WM_HSCROLL; | 
|---|
| 2044 | // this has two SHORT's (usPos and usCmd), | 
|---|
| 2045 | // see PMREF for details | 
|---|
| 2046 | { | 
|---|
| 2047 | ULONG   ulOldPelsOfs = *pulCurPelsOfs; | 
|---|
| 2048 | USHORT  usPosUnits = SHORT1FROMMP(mp2), // in scroll units | 
|---|
| 2049 | usCmd = SHORT2FROMMP(mp2); | 
|---|
| 2050 | LONG    lMaxAllowedUnitOfs; | 
|---|
| 2051 | ULONG   ulWinPels; | 
|---|
| 2052 |  | 
|---|
| 2053 | // for large viewports, adjust scroll bar units | 
|---|
| 2054 | USHORT  usScrollUnitPels = 1; | 
|---|
| 2055 | if (ulViewportPels > 10000) | 
|---|
| 2056 | usScrollUnitPels = 100; | 
|---|
| 2057 |  | 
|---|
| 2058 | // calculate window size (vertical or horizontal) | 
|---|
| 2059 | if (msg == WM_VSCROLL) | 
|---|
| 2060 | ulWinPels = (prcl2Scroll->yTop - prcl2Scroll->yBottom); | 
|---|
| 2061 | else | 
|---|
| 2062 | ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft); | 
|---|
| 2063 |  | 
|---|
| 2064 | lMaxAllowedUnitOfs = ((LONG)ulViewportPels - ulWinPels) / usScrollUnitPels; | 
|---|
| 2065 |  | 
|---|
| 2066 | // _Pmpf(("Entering winhHandleScrollMsg")); | 
|---|
| 2067 |  | 
|---|
| 2068 | switch (usCmd) | 
|---|
| 2069 | { | 
|---|
| 2070 | case SB_LINEUP: | 
|---|
| 2071 | if (*pulCurPelsOfs > usLineStepPels) | 
|---|
| 2072 | *pulCurPelsOfs -= usLineStepPels;  //  * usScrollUnitPels); | 
|---|
| 2073 | else | 
|---|
| 2074 | *pulCurPelsOfs = 0; | 
|---|
| 2075 | break; | 
|---|
| 2076 |  | 
|---|
| 2077 | case SB_LINEDOWN: | 
|---|
| 2078 | *pulCurPelsOfs += usLineStepPels;  //  * usScrollUnitPels); | 
|---|
| 2079 | break; | 
|---|
| 2080 |  | 
|---|
| 2081 | case SB_PAGEUP: | 
|---|
| 2082 | if (*pulCurPelsOfs > ulWinPels) | 
|---|
| 2083 | *pulCurPelsOfs -= ulWinPels; // convert to units | 
|---|
| 2084 | else | 
|---|
| 2085 | *pulCurPelsOfs = 0; | 
|---|
| 2086 | break; | 
|---|
| 2087 |  | 
|---|
| 2088 | case SB_PAGEDOWN: | 
|---|
| 2089 | *pulCurPelsOfs += ulWinPels; // convert to units | 
|---|
| 2090 | break; | 
|---|
| 2091 |  | 
|---|
| 2092 | case SB_SLIDERTRACK: | 
|---|
| 2093 | *pulCurPelsOfs = (usPosUnits * usScrollUnitPels); | 
|---|
| 2094 | // _Pmpf(("    SB_SLIDERTRACK: usUnits = %d", usPosUnits)); | 
|---|
| 2095 | break; | 
|---|
| 2096 |  | 
|---|
| 2097 | case SB_SLIDERPOSITION: | 
|---|
| 2098 | *pulCurPelsOfs = (usPosUnits * usScrollUnitPels); | 
|---|
| 2099 | break; | 
|---|
| 2100 | } | 
|---|
| 2101 |  | 
|---|
| 2102 | // are we close to the lower limit? | 
|---|
| 2103 | /* if (*plCurUnitOfs < usLineStepUnits) // usScrollUnit) | 
|---|
| 2104 | *plCurUnitOfs = 0; | 
|---|
| 2105 | // are we close to the upper limit? | 
|---|
| 2106 | else if (*plCurUnitOfs + usLineStepUnits > lMaxUnitOfs) | 
|---|
| 2107 | { | 
|---|
| 2108 | _Pmpf(("        !!! limiting: %d to %d", *plCurUnitOfs, lMaxUnitOfs)); | 
|---|
| 2109 | *plCurUnitOfs = lMaxUnitOfs; | 
|---|
| 2110 | } */ | 
|---|
| 2111 |  | 
|---|
| 2112 | /* if (*plCurPelsOfs < 0) | 
|---|
| 2113 | *plCurPelsOfs = 0; */       // checked above | 
|---|
| 2114 | if (*pulCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels)) | 
|---|
| 2115 | { | 
|---|
| 2116 | *pulCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels); | 
|---|
| 2117 | } | 
|---|
| 2118 | if (    (*pulCurPelsOfs != ulOldPelsOfs) | 
|---|
| 2119 | || (*pulCurPelsOfs == 0) | 
|---|
| 2120 | || (*pulCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels)) | 
|---|
| 2121 | ) | 
|---|
| 2122 | { | 
|---|
| 2123 | RECTL   rcl2Scroll, | 
|---|
| 2124 | rcl2Update; | 
|---|
| 2125 |  | 
|---|
| 2126 | // changed: | 
|---|
| 2127 | WinSendMsg(hwndScrollBar, | 
|---|
| 2128 | SBM_SETPOS, | 
|---|
| 2129 | (MPARAM)(*pulCurPelsOfs / usScrollUnitPels), //  / usScrollUnit), | 
|---|
| 2130 | 0); | 
|---|
| 2131 | // scroll window rectangle: | 
|---|
| 2132 | rcl2Scroll.xLeft =  prcl2Scroll->xLeft; | 
|---|
| 2133 | rcl2Scroll.xRight =  prcl2Scroll->xRight; | 
|---|
| 2134 | rcl2Scroll.yBottom =  prcl2Scroll->yBottom; | 
|---|
| 2135 | rcl2Scroll.yTop =  prcl2Scroll->yTop; | 
|---|
| 2136 |  | 
|---|
| 2137 | if (msg == WM_VSCROLL) | 
|---|
| 2138 | WinScrollWindow(hwnd2Scroll, | 
|---|
| 2139 | 0, | 
|---|
| 2140 | (*pulCurPelsOfs - ulOldPelsOfs)  // scroll units changed | 
|---|
| 2141 | ,    // * usScrollUnitPels,     // convert to pels | 
|---|
| 2142 | &rcl2Scroll,  // rcl to scroll | 
|---|
| 2143 | prcl2Scroll, // clipping rect | 
|---|
| 2144 | NULLHANDLE, // no region | 
|---|
| 2145 | &rcl2Update, | 
|---|
| 2146 | 0); | 
|---|
| 2147 | else | 
|---|
| 2148 | WinScrollWindow(hwnd2Scroll, | 
|---|
| 2149 | -(LONG)(*pulCurPelsOfs - ulOldPelsOfs) // scroll units changed | 
|---|
| 2150 | ,    // * usScrollUnitPels, | 
|---|
| 2151 | 0, | 
|---|
| 2152 | &rcl2Scroll,  // rcl to scroll | 
|---|
| 2153 | prcl2Scroll, // clipping rect | 
|---|
| 2154 | NULLHANDLE, // no region | 
|---|
| 2155 | &rcl2Update, | 
|---|
| 2156 | 0); | 
|---|
| 2157 |  | 
|---|
| 2158 | // WinScrollWindow has stored the invalid window | 
|---|
| 2159 | // rectangle which needs to be repainted in rcl2Update: | 
|---|
| 2160 | WinInvalidateRect(hwnd2Scroll, &rcl2Update, FALSE); | 
|---|
| 2161 | } | 
|---|
| 2162 |  | 
|---|
| 2163 | // _Pmpf(("End of winhHandleScrollMsg")); | 
|---|
| 2164 |  | 
|---|
| 2165 | return TRUE; | 
|---|
| 2166 | } | 
|---|
| 2167 |  | 
|---|
| 2168 | /* | 
|---|
| 2169 | *@@ winhProcessScrollChars: | 
|---|
| 2170 | *      helper for processing WM_CHAR messages for | 
|---|
| 2171 | *      client windows with scroll bars. | 
|---|
| 2172 | * | 
|---|
| 2173 | *      If your window has scroll bars, you normally | 
|---|
| 2174 | *      need to process a number of keystrokes to be | 
|---|
| 2175 | *      able to scroll the window contents. This is | 
|---|
| 2176 | *      tiresome to code, so here is a helper. | 
|---|
| 2177 | * | 
|---|
| 2178 | *      When receiving WM_CHAR, call this function. | 
|---|
| 2179 | *      If this returns TRUE, the keystroke has been | 
|---|
| 2180 | *      a scroll keystroke, and the window has been | 
|---|
| 2181 | *      updated (by sending WM_VSCROLL or WM_HSCROLL | 
|---|
| 2182 | *      to hwndClient). Otherwise, you should process | 
|---|
| 2183 | *      the keystroke as usual because it's not a | 
|---|
| 2184 | *      scroll keystroke. | 
|---|
| 2185 | * | 
|---|
| 2186 | *      The following keystrokes are processed here: | 
|---|
| 2187 | * | 
|---|
| 2188 | *      -- "cursor up, down, right, left": scroll one | 
|---|
| 2189 | *         line in the proper direction. | 
|---|
| 2190 | *      -- "page up, down": scroll one page up or down. | 
|---|
| 2191 | *      -- "Home": scroll leftmost. | 
|---|
| 2192 | *      -- "Ctrl+ Home": scroll topmost. | 
|---|
| 2193 | *      -- "End": scroll rightmost. | 
|---|
| 2194 | *      -- "Ctrl+ End": scroll bottommost. | 
|---|
| 2195 | *      -- "Ctrl + page up, down": scroll one screen left or right. | 
|---|
| 2196 | * | 
|---|
| 2197 | *      This is CUA behavior. | 
|---|
| 2198 | * | 
|---|
| 2199 | *      Returns TRUE if the message has been | 
|---|
| 2200 | *      processed. | 
|---|
| 2201 | * | 
|---|
| 2202 | *@@added V0.9.3 (2000-04-29) [umoeller] | 
|---|
| 2203 | *@@changed V0.9.9 (2001-02-01) [lafaix]: Ctrl+PgUp/Dn now do one screen left/right | 
|---|
| 2204 | */ | 
|---|
| 2205 |  | 
|---|
| 2206 | BOOL winhProcessScrollChars(HWND hwndClient,    // in: client window | 
|---|
| 2207 | HWND hwndVScroll,   // in: vertical scroll bar | 
|---|
| 2208 | HWND hwndHScroll,   // in: horizontal scroll bar | 
|---|
| 2209 | MPARAM mp1,         // in: WM_CHAR mp1 | 
|---|
| 2210 | MPARAM mp2,         // in: WM_CHAR mp2 | 
|---|
| 2211 | ULONG ulVertMax,    // in: maximum viewport cy | 
|---|
| 2212 | ULONG ulHorzMax)    // in: maximum viewport cx | 
|---|
| 2213 | { | 
|---|
| 2214 | BOOL    fProcessed = FALSE; | 
|---|
| 2215 | USHORT usFlags    = SHORT1FROMMP(mp1); | 
|---|
| 2216 | // USHORT usch       = SHORT1FROMMP(mp2); | 
|---|
| 2217 | USHORT usvk       = SHORT2FROMMP(mp2); | 
|---|
| 2218 |  | 
|---|
| 2219 | // _Pmpf(("Entering winhProcessScrollChars")); | 
|---|
| 2220 |  | 
|---|
| 2221 | if (usFlags & KC_VIRTUALKEY) | 
|---|
| 2222 | { | 
|---|
| 2223 | ULONG   ulMsg = 0; | 
|---|
| 2224 | SHORT   sPos = 0; | 
|---|
| 2225 | SHORT   usCmd = 0; | 
|---|
| 2226 | fProcessed = TRUE; | 
|---|
| 2227 |  | 
|---|
| 2228 | switch (usvk) | 
|---|
| 2229 | { | 
|---|
| 2230 | case VK_UP: | 
|---|
| 2231 | ulMsg = WM_VSCROLL; | 
|---|
| 2232 | usCmd = SB_LINEUP; | 
|---|
| 2233 | break; | 
|---|
| 2234 |  | 
|---|
| 2235 | case VK_DOWN: | 
|---|
| 2236 | ulMsg = WM_VSCROLL; | 
|---|
| 2237 | usCmd = SB_LINEDOWN; | 
|---|
| 2238 | break; | 
|---|
| 2239 |  | 
|---|
| 2240 | case VK_RIGHT: | 
|---|
| 2241 | ulMsg = WM_HSCROLL; | 
|---|
| 2242 | usCmd = SB_LINERIGHT; | 
|---|
| 2243 | break; | 
|---|
| 2244 |  | 
|---|
| 2245 | case VK_LEFT: | 
|---|
| 2246 | ulMsg = WM_HSCROLL; | 
|---|
| 2247 | usCmd = SB_LINELEFT; | 
|---|
| 2248 | break; | 
|---|
| 2249 |  | 
|---|
| 2250 | case VK_PAGEUP: | 
|---|
| 2251 | if (usFlags & KC_CTRL) | 
|---|
| 2252 | ulMsg = WM_HSCROLL; | 
|---|
| 2253 | else | 
|---|
| 2254 | ulMsg = WM_VSCROLL; | 
|---|
| 2255 | usCmd = SB_PAGEUP; | 
|---|
| 2256 | break; | 
|---|
| 2257 |  | 
|---|
| 2258 | case VK_PAGEDOWN: | 
|---|
| 2259 | if (usFlags & KC_CTRL) | 
|---|
| 2260 | ulMsg = WM_HSCROLL; | 
|---|
| 2261 | else | 
|---|
| 2262 | ulMsg = WM_VSCROLL; | 
|---|
| 2263 | usCmd = SB_PAGEDOWN; | 
|---|
| 2264 | break; | 
|---|
| 2265 |  | 
|---|
| 2266 | case VK_HOME: | 
|---|
| 2267 | if (usFlags & KC_CTRL) | 
|---|
| 2268 | // vertical: | 
|---|
| 2269 | ulMsg = WM_VSCROLL; | 
|---|
| 2270 | else | 
|---|
| 2271 | ulMsg = WM_HSCROLL; | 
|---|
| 2272 |  | 
|---|
| 2273 | sPos = 0; | 
|---|
| 2274 | usCmd = SB_SLIDERPOSITION; | 
|---|
| 2275 | break; | 
|---|
| 2276 |  | 
|---|
| 2277 | case VK_END: | 
|---|
| 2278 | if (usFlags & KC_CTRL) | 
|---|
| 2279 | { | 
|---|
| 2280 | // vertical: | 
|---|
| 2281 | ulMsg = WM_VSCROLL; | 
|---|
| 2282 | sPos = ulVertMax; | 
|---|
| 2283 | } | 
|---|
| 2284 | else | 
|---|
| 2285 | { | 
|---|
| 2286 | ulMsg = WM_HSCROLL; | 
|---|
| 2287 | sPos = ulHorzMax; | 
|---|
| 2288 | } | 
|---|
| 2289 |  | 
|---|
| 2290 | usCmd = SB_SLIDERPOSITION; | 
|---|
| 2291 | break; | 
|---|
| 2292 |  | 
|---|
| 2293 | default: | 
|---|
| 2294 | // other: | 
|---|
| 2295 | fProcessed = FALSE; | 
|---|
| 2296 | } | 
|---|
| 2297 |  | 
|---|
| 2298 | if (    ((usFlags & KC_KEYUP) == 0) | 
|---|
| 2299 | && (ulMsg) | 
|---|
| 2300 | ) | 
|---|
| 2301 | { | 
|---|
| 2302 | HWND   hwndScrollBar = ((ulMsg == WM_VSCROLL) | 
|---|
| 2303 | ? hwndVScroll | 
|---|
| 2304 | : hwndHScroll); | 
|---|
| 2305 | if (WinIsWindowEnabled(hwndScrollBar)) | 
|---|
| 2306 | { | 
|---|
| 2307 | USHORT usID = WinQueryWindowUShort(hwndScrollBar, | 
|---|
| 2308 | QWS_ID); | 
|---|
| 2309 | WinSendMsg(hwndClient, | 
|---|
| 2310 | ulMsg, | 
|---|
| 2311 | MPFROMSHORT(usID), | 
|---|
| 2312 | MPFROM2SHORT(sPos, | 
|---|
| 2313 | usCmd)); | 
|---|
| 2314 | } | 
|---|
| 2315 | } | 
|---|
| 2316 | } | 
|---|
| 2317 |  | 
|---|
| 2318 | // _Pmpf(("End of  winhProcessScrollChars")); | 
|---|
| 2319 |  | 
|---|
| 2320 | return fProcessed; | 
|---|
| 2321 | } | 
|---|
| 2322 |  | 
|---|
| 2323 | /* | 
|---|
| 2324 | *@@category: Helpers\PM helpers\Window positioning | 
|---|
| 2325 | */ | 
|---|
| 2326 |  | 
|---|
| 2327 | /* ****************************************************************** | 
|---|
| 2328 | * | 
|---|
| 2329 | *   Window positioning helpers | 
|---|
| 2330 | * | 
|---|
| 2331 | ********************************************************************/ | 
|---|
| 2332 |  | 
|---|
| 2333 | /* | 
|---|
| 2334 | *@@ winhSaveWindowPos: | 
|---|
| 2335 | *      saves the position of a certain window. As opposed | 
|---|
| 2336 | *      to the barely documented WinStoreWindowPos API, this | 
|---|
| 2337 | *      one only saves one regular SWP structure for the given | 
|---|
| 2338 | *      window, as returned by WinQueryWindowPos for hwnd. | 
|---|
| 2339 | * | 
|---|
| 2340 | *      If the window is currently maximized or minimized, | 
|---|
| 2341 | *      we won't store the current window size and position | 
|---|
| 2342 | *      (which wouldn't make much sense), but retrieve the | 
|---|
| 2343 | *      "restored" window position from the window words | 
|---|
| 2344 | *      instead. | 
|---|
| 2345 | * | 
|---|
| 2346 | *      The window should still be visible on the screen | 
|---|
| 2347 | *      when calling this function. Do not call it in WM_DESTROY, | 
|---|
| 2348 | *      because then the SWP data is no longer valid. | 
|---|
| 2349 | * | 
|---|
| 2350 | *      This returns TRUE if saving was successful. | 
|---|
| 2351 | * | 
|---|
| 2352 | *@@changed V0.9.1 (99-12-19) [umoeller]: added minimize/maximize support | 
|---|
| 2353 | */ | 
|---|
| 2354 |  | 
|---|
| 2355 | BOOL winhSaveWindowPos(HWND hwnd,   // in: window to save | 
|---|
| 2356 | HINI hIni,   // in: INI file (or HINI_USER/SYSTEM) | 
|---|
| 2357 | const char *pcszApp,  // in: INI application name | 
|---|
| 2358 | const char *pcszKey)  // in: INI key name | 
|---|
| 2359 | { | 
|---|
| 2360 | BOOL brc = FALSE; | 
|---|
| 2361 | SWP swp; | 
|---|
| 2362 | if (WinQueryWindowPos(hwnd, &swp)) | 
|---|
| 2363 | { | 
|---|
| 2364 | if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE)) | 
|---|
| 2365 | { | 
|---|
| 2366 | // window currently maximized or minimized: | 
|---|
| 2367 | // retrieve "restore" position from window words | 
|---|
| 2368 | swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE); | 
|---|
| 2369 | swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE); | 
|---|
| 2370 | swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE); | 
|---|
| 2371 | swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE); | 
|---|
| 2372 | } | 
|---|
| 2373 |  | 
|---|
| 2374 | brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, sizeof(swp)); | 
|---|
| 2375 | } | 
|---|
| 2376 | return brc; | 
|---|
| 2377 | } | 
|---|
| 2378 |  | 
|---|
| 2379 | /* | 
|---|
| 2380 | *@@ winhRestoreWindowPos: | 
|---|
| 2381 | *      this will retrieve a window position which was | 
|---|
| 2382 | *      previously stored using winhSaveWindowPos. | 
|---|
| 2383 | * | 
|---|
| 2384 | *      The window should not be visible to avoid flickering. | 
|---|
| 2385 | *      "fl" must contain the SWP_flags as in WinSetWindowPos. | 
|---|
| 2386 | * | 
|---|
| 2387 | *      Note that only the following may be used: | 
|---|
| 2388 | *      --  SWP_MOVE        reposition the window | 
|---|
| 2389 | *      --  SWP_SIZE        also resize the window to | 
|---|
| 2390 | *                          the stored position; this might | 
|---|
| 2391 | *                          lead to problems with different | 
|---|
| 2392 | *                          video resolutions, so be careful. | 
|---|
| 2393 | *      --  SWP_SHOW        make window visible too | 
|---|
| 2394 | *      --  SWP_NOREDRAW    changes are not redrawn | 
|---|
| 2395 | *      --  SWP_NOADJUST    do not send a WM_ADJUSTWINDOWPOS message | 
|---|
| 2396 | *                          before moving or sizing | 
|---|
| 2397 | *      --  SWP_ACTIVATE    activate window (make topmost) | 
|---|
| 2398 | *      --  SWP_DEACTIVATE  deactivate window (make bottommost) | 
|---|
| 2399 | * | 
|---|
| 2400 | *      Do not specify any other SWP_* flags. | 
|---|
| 2401 | * | 
|---|
| 2402 | *      If SWP_SIZE is not set, the window will be moved only. | 
|---|
| 2403 | * | 
|---|
| 2404 | *      This returns TRUE if INI data was found. | 
|---|
| 2405 | * | 
|---|
| 2406 | *      This function automatically checks for whether the | 
|---|
| 2407 | *      window would be positioned outside the visible screen | 
|---|
| 2408 | *      area and will adjust coordinates accordingly. This can | 
|---|
| 2409 | *      happen when changing video resolutions. | 
|---|
| 2410 | * | 
|---|
| 2411 | *@@changed V0.9.7 (2000-12-20) [umoeller]: fixed invalid params if INI key not found | 
|---|
| 2412 | */ | 
|---|
| 2413 |  | 
|---|
| 2414 | BOOL winhRestoreWindowPos(HWND hwnd,   // in: window to restore | 
|---|
| 2415 | HINI hIni,   // in: INI file (or HINI_USER/SYSTEM) | 
|---|
| 2416 | const char *pcszApp,  // in: INI application name | 
|---|
| 2417 | const char *pcszKey,  // in: INI key name | 
|---|
| 2418 | ULONG fl)    // in: "fl" parameter for WinSetWindowPos | 
|---|
| 2419 | { | 
|---|
| 2420 | BOOL    brc = FALSE; | 
|---|
| 2421 | SWP     swp; | 
|---|
| 2422 | ULONG   cbswp = sizeof(swp); | 
|---|
| 2423 | ULONG   fl2 = (fl & ~SWP_ZORDER); | 
|---|
| 2424 |  | 
|---|
| 2425 | if (PrfQueryProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, &swp, &cbswp)) | 
|---|
| 2426 | { | 
|---|
| 2427 | ULONG ulScreenCX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN); | 
|---|
| 2428 | ULONG ulScreenCY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN); | 
|---|
| 2429 |  | 
|---|
| 2430 | brc = TRUE; | 
|---|
| 2431 |  | 
|---|
| 2432 | if ((fl & SWP_SIZE) == 0) | 
|---|
| 2433 | { | 
|---|
| 2434 | // if no resize, we need to get the current position | 
|---|
| 2435 | SWP swpNow; | 
|---|
| 2436 | brc = WinQueryWindowPos(hwnd, &swpNow); | 
|---|
| 2437 | swp.cx = swpNow.cx; | 
|---|
| 2438 | swp.cy = swpNow.cy; | 
|---|
| 2439 | } | 
|---|
| 2440 |  | 
|---|
| 2441 | if (brc) | 
|---|
| 2442 | { | 
|---|
| 2443 | // check for full visibility | 
|---|
| 2444 | if ( (swp.x + swp.cx) > ulScreenCX) | 
|---|
| 2445 | swp.x = ulScreenCX - swp.cx; | 
|---|
| 2446 | if ( (swp.y + swp.cy) > ulScreenCY) | 
|---|
| 2447 | swp.y = ulScreenCY - swp.cy; | 
|---|
| 2448 | } | 
|---|
| 2449 |  | 
|---|
| 2450 | brc = TRUE; | 
|---|
| 2451 |  | 
|---|
| 2452 | } | 
|---|
| 2453 | else | 
|---|
| 2454 | { | 
|---|
| 2455 | // window pos not found in INI: unset SWP_MOVE etc. | 
|---|
| 2456 | WinQueryWindowPos(hwnd, &swp); | 
|---|
| 2457 | fl2 &= ~(SWP_MOVE | SWP_SIZE); | 
|---|
| 2458 | } | 
|---|
| 2459 |  | 
|---|
| 2460 | WinSetWindowPos(hwnd, | 
|---|
| 2461 | NULLHANDLE,       // insert-behind window | 
|---|
| 2462 | swp.x, | 
|---|
| 2463 | swp.y, | 
|---|
| 2464 | swp.cx, | 
|---|
| 2465 | swp.cy, | 
|---|
| 2466 | fl2);        // SWP_* flags | 
|---|
| 2467 |  | 
|---|
| 2468 | return brc; | 
|---|
| 2469 | } | 
|---|
| 2470 |  | 
|---|
| 2471 | /* | 
|---|
| 2472 | *@@ winhAdjustControls: | 
|---|
| 2473 | *      helper function for dynamically adjusting a window's | 
|---|
| 2474 | *      controls when the window is resized. | 
|---|
| 2475 | * | 
|---|
| 2476 | *      This is most useful with dialogs loaded from resources | 
|---|
| 2477 | *      which should be sizeable. Normally, when the dialog | 
|---|
| 2478 | *      frame is resized, the controls stick to their positions, | 
|---|
| 2479 | *      and for dialogs with many controls, programming the | 
|---|
| 2480 | *      changes can be tiresome. | 
|---|
| 2481 | * | 
|---|
| 2482 | *      Enter this function. ;-) Basically, this takes a | 
|---|
| 2483 | *      static array of MPARAM's as input (plus one dynamic | 
|---|
| 2484 | *      storage area for the window positions). | 
|---|
| 2485 | * | 
|---|
| 2486 | *      This function must get called in three contexts: | 
|---|
| 2487 | *      during WM_INITDLG, during WM_WINDOWPOSCHANGED, and | 
|---|
| 2488 | *      during WM_DESTROY, with varying parameters. | 
|---|
| 2489 | * | 
|---|
| 2490 | *      In detail, there are four things you need to do to make | 
|---|
| 2491 | *      this work: | 
|---|
| 2492 | * | 
|---|
| 2493 | *      1)  Set up a static array (as a global variable) of | 
|---|
| 2494 | *          MPARAM's, one for each control in your array. | 
|---|
| 2495 | *          Each MPARAM will have the control's ID and the | 
|---|
| 2496 | *          XAC_* flags (winh.h) how the control shall be moved. | 
|---|
| 2497 | *          Use MPFROM2SHORT to easily create this. Example: | 
|---|
| 2498 | * | 
|---|
| 2499 | +          MPARAM ampControlFlags[] = | 
|---|
| 2500 | +              {  MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX), | 
|---|
| 2501 | +                 MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY), | 
|---|
| 2502 | +                  ... | 
|---|
| 2503 | +              } | 
|---|
| 2504 | * | 
|---|
| 2505 | *          This can safely be declared as a global variable | 
|---|
| 2506 | *          because this data will only be read and never | 
|---|
| 2507 | *          changed by this function. | 
|---|
| 2508 | * | 
|---|
| 2509 | *      2)  In WM_INITDLG of your dialog function, set up | 
|---|
| 2510 | *          an XADJUSTCTRLS structure, preferrably in your | 
|---|
| 2511 | *          window words (QWL_USER). | 
|---|
| 2512 | * | 
|---|
| 2513 | *          ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS), | 
|---|
| 2514 | *          or this func will not work (because it will intialize | 
|---|
| 2515 | *          things on the first WM_WINDOWPOSCHANGED). | 
|---|
| 2516 | * | 
|---|
| 2517 | *      3)  Intercept WM_WINDOWPOSCHANGED: | 
|---|
| 2518 | * | 
|---|
| 2519 | +          case WM_WINDOWPOSCHANGED: | 
|---|
| 2520 | +          { | 
|---|
| 2521 | +              // this msg is passed two SWP structs: | 
|---|
| 2522 | +              // one for the old, one for the new data | 
|---|
| 2523 | +              // (from PM docs) | 
|---|
| 2524 | +              PSWP pswpNew = PVOIDFROMMP(mp1); | 
|---|
| 2525 | +              PSWP pswpOld = pswpNew + 1; | 
|---|
| 2526 | + | 
|---|
| 2527 | +              // resizing? | 
|---|
| 2528 | +              if (pswpNew->fl & SWP_SIZE) | 
|---|
| 2529 | +              { | 
|---|
| 2530 | +                  PXADJUSTCTRLS pxac = ... // get it from your window words | 
|---|
| 2531 | + | 
|---|
| 2532 | +                  winhAdjustControls(hwndDlg,             // dialog | 
|---|
| 2533 | +                                     ampControlFlags,     // MPARAMs array | 
|---|
| 2534 | +                                     sizeof(ampControlFlags) / sizeof(MPARAM), | 
|---|
| 2535 | +                                                          // items count | 
|---|
| 2536 | +                                     pswpNew,             // mp1 | 
|---|
| 2537 | +                                     pxac);               // storage area | 
|---|
| 2538 | +              } | 
|---|
| 2539 | +              mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ... | 
|---|
| 2540 | * | 
|---|
| 2541 | *      4)  In WM_DESTROY, call this function again with pmpFlags, | 
|---|
| 2542 | *          pswpNew, and pswpNew set to NULL. This will clean up the | 
|---|
| 2543 | *          data which has been allocated internally (pointed to from | 
|---|
| 2544 | *          the XADJUSTCTRLS structure). | 
|---|
| 2545 | *          Don't forget to free your storage for XADJUSTCTLRS | 
|---|
| 2546 | *          _itself_, that's the job of the caller. | 
|---|
| 2547 | * | 
|---|
| 2548 | *      This might sound complicated, but it's a lot easier than | 
|---|
| 2549 | *      having to write dozens of WinSetWindowPos calls oneself. | 
|---|
| 2550 | * | 
|---|
| 2551 | *@@added V0.9.0 [umoeller] | 
|---|
| 2552 | *@@changed V0.9.19 (2002-04-13) [umoeller]: added correlation for entry field repositioning, this was always off | 
|---|
| 2553 | */ | 
|---|
| 2554 |  | 
|---|
| 2555 | BOOL winhAdjustControls(HWND hwndDlg,           // in: dialog (req.) | 
|---|
| 2556 | const MPARAM *pmpFlags, // in: init flags or NULL for cleanup | 
|---|
| 2557 | ULONG ulCount,          // in: item count (req.) | 
|---|
| 2558 | PSWP pswpNew,           // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup | 
|---|
| 2559 | PXADJUSTCTRLS pxac)     // in: adjust-controls storage area (req.) | 
|---|
| 2560 | { | 
|---|
| 2561 | BOOL    brc = FALSE; | 
|---|
| 2562 | ULONG   ul = 0; | 
|---|
| 2563 |  | 
|---|
| 2564 | /* if (!WinIsWindowVisible(hwndDlg)) | 
|---|
| 2565 | return (FALSE); */ | 
|---|
| 2566 |  | 
|---|
| 2567 | if ((pmpFlags) && (pxac)) | 
|---|
| 2568 | { | 
|---|
| 2569 | PSWP    pswpThis; | 
|---|
| 2570 | const MPARAM  *pmpThis; | 
|---|
| 2571 | LONG    ldcx, ldcy; | 
|---|
| 2572 | ULONG   cWindows = 0; | 
|---|
| 2573 |  | 
|---|
| 2574 | // V0.9.19 (2002-04-13) [umoeller] | 
|---|
| 2575 | LONG cxMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER); | 
|---|
| 2576 | LONG cyMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER); | 
|---|
| 2577 |  | 
|---|
| 2578 | // setup mode: | 
|---|
| 2579 | if (pxac->fInitialized == FALSE) | 
|---|
| 2580 | { | 
|---|
| 2581 | // first call: get all the SWP's | 
|---|
| 2582 | WinQueryWindowPos(hwndDlg, &pxac->swpMain); | 
|---|
| 2583 | // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d", | 
|---|
| 2584 | //      pxac->swpMain.cx, pxac->swpMain.cy)); | 
|---|
| 2585 |  | 
|---|
| 2586 | pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount); | 
|---|
| 2587 |  | 
|---|
| 2588 | pswpThis = pxac->paswp; | 
|---|
| 2589 | pmpThis = pmpFlags; | 
|---|
| 2590 |  | 
|---|
| 2591 | for (ul = 0; | 
|---|
| 2592 | ul < ulCount; | 
|---|
| 2593 | ul++) | 
|---|
| 2594 | { | 
|---|
| 2595 | HWND hwndThis; | 
|---|
| 2596 | CHAR szClass[10]; | 
|---|
| 2597 | if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis))) | 
|---|
| 2598 | { | 
|---|
| 2599 | WinQueryWindowPos(hwndThis, pswpThis); | 
|---|
| 2600 |  | 
|---|
| 2601 | // correlate the stupid repositioning of entry fields | 
|---|
| 2602 | // V0.9.19 (2002-04-13) [umoeller] | 
|---|
| 2603 | if (    (WinQueryClassName(hwndThis, sizeof(szClass), szClass) | 
|---|
| 2604 | && (!strcmp(szClass, "#6")) | 
|---|
| 2605 | && (WinQueryWindowULong(hwndThis, QWL_STYLE) & ES_MARGIN)) | 
|---|
| 2606 | ) | 
|---|
| 2607 | { | 
|---|
| 2608 | pswpThis->x += cxMarginEF; | 
|---|
| 2609 | pswpThis->y += cyMarginEF; | 
|---|
| 2610 | pswpThis->cx -= 2 * cxMarginEF; | 
|---|
| 2611 | pswpThis->cy -= 2 * cyMarginEF; | 
|---|
| 2612 | } | 
|---|
| 2613 |  | 
|---|
| 2614 | cWindows++; | 
|---|
| 2615 | } | 
|---|
| 2616 |  | 
|---|
| 2617 | pswpThis++; | 
|---|
| 2618 | pmpThis++; | 
|---|
| 2619 | } | 
|---|
| 2620 |  | 
|---|
| 2621 | pxac->fInitialized = TRUE; | 
|---|
| 2622 | // _Pmpf(("winhAdjustControls: queried %d controls", cWindows)); | 
|---|
| 2623 | } | 
|---|
| 2624 |  | 
|---|
| 2625 | if (pswpNew) | 
|---|
| 2626 | { | 
|---|
| 2627 | // compute width and height delta | 
|---|
| 2628 | ldcx = (pswpNew->cx - pxac->swpMain.cx); | 
|---|
| 2629 | ldcy = (pswpNew->cy - pxac->swpMain.cy); | 
|---|
| 2630 |  | 
|---|
| 2631 | // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d", | 
|---|
| 2632 | //       pswpNew->cx, pswpNew->cy)); | 
|---|
| 2633 |  | 
|---|
| 2634 | // now adjust the controls | 
|---|
| 2635 | cWindows = 0; | 
|---|
| 2636 | pswpThis = pxac->paswp; | 
|---|
| 2637 | pmpThis = pmpFlags; | 
|---|
| 2638 | for (ul = 0; | 
|---|
| 2639 | ul < ulCount; | 
|---|
| 2640 | ul++) | 
|---|
| 2641 | { | 
|---|
| 2642 | HWND hwndThis; | 
|---|
| 2643 | if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis))) | 
|---|
| 2644 | { | 
|---|
| 2645 | LONG    x = pswpThis->x, | 
|---|
| 2646 | y = pswpThis->y, | 
|---|
| 2647 | cx = pswpThis->cx, | 
|---|
| 2648 | cy = pswpThis->cy; | 
|---|
| 2649 |  | 
|---|
| 2650 | ULONG   ulSwpFlags = 0; | 
|---|
| 2651 | // get flags for this control | 
|---|
| 2652 | USHORT  usFlags = SHORT2FROMMP(*pmpThis); | 
|---|
| 2653 |  | 
|---|
| 2654 | if (usFlags & XAC_MOVEX) | 
|---|
| 2655 | { | 
|---|
| 2656 | x += ldcx; | 
|---|
| 2657 | ulSwpFlags |= SWP_MOVE; | 
|---|
| 2658 | } | 
|---|
| 2659 | if (usFlags & XAC_MOVEY) | 
|---|
| 2660 | { | 
|---|
| 2661 | y += ldcy; | 
|---|
| 2662 | ulSwpFlags |= SWP_MOVE; | 
|---|
| 2663 | } | 
|---|
| 2664 | if (usFlags & XAC_SIZEX) | 
|---|
| 2665 | { | 
|---|
| 2666 | cx += ldcx; | 
|---|
| 2667 | ulSwpFlags |= SWP_SIZE; | 
|---|
| 2668 | } | 
|---|
| 2669 | if (usFlags & XAC_SIZEY) | 
|---|
| 2670 | { | 
|---|
| 2671 | cy += ldcy; | 
|---|
| 2672 | ulSwpFlags |= SWP_SIZE; | 
|---|
| 2673 | } | 
|---|
| 2674 |  | 
|---|
| 2675 | if (ulSwpFlags) | 
|---|
| 2676 | { | 
|---|
| 2677 | WinSetWindowPos(hwndThis, | 
|---|
| 2678 | NULLHANDLE, // hwndInsertBehind | 
|---|
| 2679 | x, y, cx, cy, | 
|---|
| 2680 | ulSwpFlags); | 
|---|
| 2681 | cWindows++; | 
|---|
| 2682 | brc = TRUE; | 
|---|
| 2683 | } | 
|---|
| 2684 | } | 
|---|
| 2685 |  | 
|---|
| 2686 | pswpThis++; | 
|---|
| 2687 | pmpThis++; | 
|---|
| 2688 | } | 
|---|
| 2689 |  | 
|---|
| 2690 | // _Pmpf(("winhAdjustControls: set %d windows", cWindows)); | 
|---|
| 2691 | } | 
|---|
| 2692 | } | 
|---|
| 2693 | else | 
|---|
| 2694 | { | 
|---|
| 2695 | // pxac == NULL: | 
|---|
| 2696 | // cleanup mode | 
|---|
| 2697 | if (pxac->paswp) | 
|---|
| 2698 | free(pxac->paswp); | 
|---|
| 2699 | } | 
|---|
| 2700 |  | 
|---|
| 2701 | return brc; | 
|---|
| 2702 | } | 
|---|
| 2703 |  | 
|---|
| 2704 | /* | 
|---|
| 2705 | *@@ winhCenterWindow: | 
|---|
| 2706 | *      centers a window within its parent window. If that's | 
|---|
| 2707 | *      the PM desktop, it will be centered according to the | 
|---|
| 2708 | *      whole screen. | 
|---|
| 2709 | *      For dialog boxes, use WinCenteredDlgBox as a one-shot | 
|---|
| 2710 | *      function. | 
|---|
| 2711 | * | 
|---|
| 2712 | *      Note: When calling this function, the window should | 
|---|
| 2713 | *      not be visible to avoid flickering. | 
|---|
| 2714 | *      This func does not show the window either, so call | 
|---|
| 2715 | *      WinShowWindow afterwards. | 
|---|
| 2716 | */ | 
|---|
| 2717 |  | 
|---|
| 2718 | void winhCenterWindow(HWND hwnd) | 
|---|
| 2719 | { | 
|---|
| 2720 | RECTL rclParent; | 
|---|
| 2721 | RECTL rclWindow; | 
|---|
| 2722 |  | 
|---|
| 2723 | WinQueryWindowRect(hwnd, &rclWindow); | 
|---|
| 2724 | WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent); | 
|---|
| 2725 |  | 
|---|
| 2726 | rclWindow.xLeft   = (rclParent.xRight - rclWindow.xRight) / 2; | 
|---|
| 2727 | rclWindow.yBottom = (rclParent.yTop   - rclWindow.yTop  ) / 2; | 
|---|
| 2728 |  | 
|---|
| 2729 | WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom, | 
|---|
| 2730 | 0, 0, SWP_MOVE); | 
|---|
| 2731 | } | 
|---|
| 2732 |  | 
|---|
| 2733 | /* | 
|---|
| 2734 | *@@ winhCenteredDlgBox: | 
|---|
| 2735 | *      just like WinDlgBox, but the dlg box is centered on the screen; | 
|---|
| 2736 | *      you should mark the dlg template as not visible in the dlg | 
|---|
| 2737 | *      editor, or display will flicker. | 
|---|
| 2738 | *      As opposed to winhCenterWindow, this _does_ show the window. | 
|---|
| 2739 | */ | 
|---|
| 2740 |  | 
|---|
| 2741 | ULONG winhCenteredDlgBox(HWND hwndParent, | 
|---|
| 2742 | HWND hwndOwner, | 
|---|
| 2743 | PFNWP pfnDlgProc, | 
|---|
| 2744 | HMODULE hmod, | 
|---|
| 2745 | ULONG idDlg, | 
|---|
| 2746 | PVOID pCreateParams) | 
|---|
| 2747 | { | 
|---|
| 2748 | ULONG   ulReply; | 
|---|
| 2749 | HWND    hwndDlg = WinLoadDlg(hwndParent, | 
|---|
| 2750 | hwndOwner, | 
|---|
| 2751 | pfnDlgProc, | 
|---|
| 2752 | hmod, | 
|---|
| 2753 | idDlg, | 
|---|
| 2754 | pCreateParams); | 
|---|
| 2755 | winhCenterWindow(hwndDlg); | 
|---|
| 2756 | ulReply = WinProcessDlg(hwndDlg); | 
|---|
| 2757 | WinDestroyWindow(hwndDlg); | 
|---|
| 2758 | return ulReply; | 
|---|
| 2759 | } | 
|---|
| 2760 |  | 
|---|
| 2761 | /* | 
|---|
| 2762 | *@@ winhPlaceBesides: | 
|---|
| 2763 | *      attempts to place hwnd somewhere besides | 
|---|
| 2764 | *      hwndRelative. | 
|---|
| 2765 | * | 
|---|
| 2766 | *      fl is presently ignored, but should be | 
|---|
| 2767 | *      PLF_SMART for future extensions. | 
|---|
| 2768 | * | 
|---|
| 2769 | *      Works only if hwnd is a desktop child. | 
|---|
| 2770 | * | 
|---|
| 2771 | *@@added V0.9.19 (2002-04-17) [umoeller] | 
|---|
| 2772 | *@@changed V1.0.0 (2002-08-26) [umoeller]: fixed cx and cy confusion | 
|---|
| 2773 | */ | 
|---|
| 2774 |  | 
|---|
| 2775 | BOOL winhPlaceBesides(HWND hwnd, | 
|---|
| 2776 | HWND hwndRelative, | 
|---|
| 2777 | ULONG fl) | 
|---|
| 2778 | { | 
|---|
| 2779 | SWP     swpRel, | 
|---|
| 2780 | swpThis; | 
|---|
| 2781 | LONG    xNew, yNew; | 
|---|
| 2782 |  | 
|---|
| 2783 | if (    (WinQueryWindowPos(hwndRelative, &swpRel)) | 
|---|
| 2784 | && (WinQueryWindowPos(hwnd, &swpThis)) | 
|---|
| 2785 | ) | 
|---|
| 2786 | { | 
|---|
| 2787 | HWND    hwndRelParent, | 
|---|
| 2788 | hwndThisParent; | 
|---|
| 2789 | POINTL  ptlRel = {swpRel.x, swpRel.y}; | 
|---|
| 2790 | if (    (hwndRelParent = WinQueryWindow(hwndRelative, QW_PARENT)) | 
|---|
| 2791 | && (hwndThisParent = WinQueryWindow(hwnd, QW_PARENT)) | 
|---|
| 2792 | && (hwndRelParent != hwndThisParent) | 
|---|
| 2793 | ) | 
|---|
| 2794 | { | 
|---|
| 2795 | WinMapWindowPoints(hwndRelParent, | 
|---|
| 2796 | hwndThisParent, | 
|---|
| 2797 | &ptlRel, | 
|---|
| 2798 | 1); | 
|---|
| 2799 | } | 
|---|
| 2800 |  | 
|---|
| 2801 | // place right first | 
|---|
| 2802 | xNew = ptlRel.x + swpRel.cx; | 
|---|
| 2803 | // center vertically | 
|---|
| 2804 | yNew = ptlRel.y  + ((swpRel.cy - swpThis.cy) / 2); | 
|---|
| 2805 |  | 
|---|
| 2806 | // if (xNew + swpThis.cy > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN)) | 
|---|
| 2807 | // not cy, but cx V1.0.0 (2002-08-26) [umoeller] | 
|---|
| 2808 | if (xNew + swpThis.cx > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN)) | 
|---|
| 2809 | { | 
|---|
| 2810 | // place left then | 
|---|
| 2811 | xNew = ptlRel.x - swpThis.cx; | 
|---|
| 2812 |  | 
|---|
| 2813 | if (xNew < 0) | 
|---|
| 2814 | { | 
|---|
| 2815 | // center then | 
|---|
| 2816 | winhCenterWindow(hwnd); | 
|---|
| 2817 | return TRUE; | 
|---|
| 2818 | } | 
|---|
| 2819 | } | 
|---|
| 2820 |  | 
|---|
| 2821 | return WinSetWindowPos(hwnd, | 
|---|
| 2822 | 0, | 
|---|
| 2823 | xNew, | 
|---|
| 2824 | yNew, | 
|---|
| 2825 | 0, | 
|---|
| 2826 | 0, | 
|---|
| 2827 | SWP_MOVE); | 
|---|
| 2828 | } | 
|---|
| 2829 |  | 
|---|
| 2830 | return FALSE; | 
|---|
| 2831 | } | 
|---|
| 2832 |  | 
|---|
| 2833 | /* | 
|---|
| 2834 | *@@ winhFindWindowBelow: | 
|---|
| 2835 | *      finds the window with the same parent | 
|---|
| 2836 | *      which sits right below hwndFind in the | 
|---|
| 2837 | *      window Z-order. | 
|---|
| 2838 | * | 
|---|
| 2839 | *@@added V0.9.7 (2000-12-04) [umoeller] | 
|---|
| 2840 | */ | 
|---|
| 2841 |  | 
|---|
| 2842 | HWND winhFindWindowBelow(HWND hwndFind) | 
|---|
| 2843 | { | 
|---|
| 2844 | HWND hwnd = NULLHANDLE, | 
|---|
| 2845 | hwndParent = WinQueryWindow(hwndFind, QW_PARENT); | 
|---|
| 2846 |  | 
|---|
| 2847 | if (hwndParent) | 
|---|
| 2848 | { | 
|---|
| 2849 | HENUM   henum = WinBeginEnumWindows(hwndParent); | 
|---|
| 2850 | HWND    hwndThis; | 
|---|
| 2851 | while (hwndThis = WinGetNextWindow(henum)) | 
|---|
| 2852 | { | 
|---|
| 2853 | SWP swp; | 
|---|
| 2854 | WinQueryWindowPos(hwndThis, &swp); | 
|---|
| 2855 | if (swp.hwndInsertBehind == hwndFind) | 
|---|
| 2856 | { | 
|---|
| 2857 | hwnd = hwndThis; | 
|---|
| 2858 | break; | 
|---|
| 2859 | } | 
|---|
| 2860 | } | 
|---|
| 2861 | WinEndEnumWindows(henum); | 
|---|
| 2862 | } | 
|---|
| 2863 |  | 
|---|
| 2864 | return hwnd; | 
|---|
| 2865 | } | 
|---|
| 2866 |  | 
|---|
| 2867 | /* | 
|---|
| 2868 | *@@category: Helpers\PM helpers\Presentation parameters | 
|---|
| 2869 | */ | 
|---|
| 2870 |  | 
|---|
| 2871 | /* ****************************************************************** | 
|---|
| 2872 | * | 
|---|
| 2873 | *   Presparams helpers | 
|---|
| 2874 | * | 
|---|
| 2875 | ********************************************************************/ | 
|---|
| 2876 |  | 
|---|
| 2877 | /* | 
|---|
| 2878 | *@@ winhQueryWindowFont: | 
|---|
| 2879 | *      returns the window font presentation parameter | 
|---|
| 2880 | *      in a newly allocated buffer. | 
|---|
| 2881 | * | 
|---|
| 2882 | *      Returns NULL on error. Use free() | 
|---|
| 2883 | *      to free the return value. | 
|---|
| 2884 | * | 
|---|
| 2885 | *@@added V0.9.1 (2000-02-14) [umoeller] | 
|---|
| 2886 | */ | 
|---|
| 2887 |  | 
|---|
| 2888 | PSZ winhQueryWindowFont(HWND hwnd) | 
|---|
| 2889 | { | 
|---|
| 2890 | CHAR  szNewFont[100] = ""; | 
|---|
| 2891 | WinQueryPresParam(hwnd, | 
|---|
| 2892 | PP_FONTNAMESIZE, | 
|---|
| 2893 | 0, | 
|---|
| 2894 | NULL, | 
|---|
| 2895 | (ULONG)sizeof(szNewFont), | 
|---|
| 2896 | (PVOID)&szNewFont, | 
|---|
| 2897 | QPF_NOINHERIT); | 
|---|
| 2898 | if (szNewFont[0] != 0) | 
|---|
| 2899 | return strdup(szNewFont); | 
|---|
| 2900 |  | 
|---|
| 2901 | return NULL; | 
|---|
| 2902 | } | 
|---|
| 2903 |  | 
|---|
| 2904 | /* | 
|---|
| 2905 | *@@ winhSetWindowFont: | 
|---|
| 2906 | *      this sets a window's font by invoking | 
|---|
| 2907 | *      WinSetPresParam on it. | 
|---|
| 2908 | * | 
|---|
| 2909 | *      If (pszFont == NULL), a default font will be set | 
|---|
| 2910 | *      (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv"). | 
|---|
| 2911 | * | 
|---|
| 2912 | *      winh.h also defines the winhSetDlgItemFont macro. | 
|---|
| 2913 | * | 
|---|
| 2914 | *      Returns TRUE if successful or FALSE otherwise. | 
|---|
| 2915 | * | 
|---|
| 2916 | *@@added V0.9.0 [umoeller] | 
|---|
| 2917 | *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655 | 
|---|
| 2918 | */ | 
|---|
| 2919 |  | 
|---|
| 2920 | BOOL winhSetWindowFont(HWND hwnd, | 
|---|
| 2921 | const char *pcszFont) | 
|---|
| 2922 | { | 
|---|
| 2923 | CHAR    szFont[256]; | 
|---|
| 2924 |  | 
|---|
| 2925 | if (pcszFont == NULL) | 
|---|
| 2926 | { | 
|---|
| 2927 | if (doshIsWarp4()) | 
|---|
| 2928 | if(nlsDBCS()) | 
|---|
| 2929 | strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont)); | 
|---|
| 2930 | else | 
|---|
| 2931 | strhncpy0(szFont, "9.WarpSans", sizeof(szFont)); | 
|---|
| 2932 | else | 
|---|
| 2933 | if(nlsDBCS()) | 
|---|
| 2934 | strhncpy0(szFont, "8.Helv Combined", sizeof(szFont)); | 
|---|
| 2935 | else | 
|---|
| 2936 | strhncpy0(szFont, "8.Helv", sizeof(szFont)); | 
|---|
| 2937 | } | 
|---|
| 2938 | else | 
|---|
| 2939 | strhncpy0(szFont, pcszFont, sizeof(szFont)); | 
|---|
| 2940 |  | 
|---|
| 2941 | return WinSetPresParam(hwnd, | 
|---|
| 2942 | PP_FONTNAMESIZE, | 
|---|
| 2943 | strlen(szFont)+1, | 
|---|
| 2944 | szFont); | 
|---|
| 2945 | } | 
|---|
| 2946 |  | 
|---|
| 2947 | /* | 
|---|
| 2948 | *@@ winhSetControlsFont: | 
|---|
| 2949 | *      this sets the font for all the controls of hwndDlg | 
|---|
| 2950 | *      which have a control ID in the range of usIDMin to | 
|---|
| 2951 | *      usIDMax. "Unused" IDs (i.e. -1) will also be set. | 
|---|
| 2952 | * | 
|---|
| 2953 | *      If (pszFont == NULL), a default font will be set | 
|---|
| 2954 | *      (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv"). | 
|---|
| 2955 | * | 
|---|
| 2956 | *      Returns the no. of controls set. | 
|---|
| 2957 | * | 
|---|
| 2958 | *@@added V0.9.0 [umoeller] | 
|---|
| 2959 | *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655 | 
|---|
| 2960 | */ | 
|---|
| 2961 |  | 
|---|
| 2962 | ULONG winhSetControlsFont(HWND hwndDlg,      // in: dlg to set | 
|---|
| 2963 | SHORT usIDMin,     // in: minimum control ID to be set (inclusive) | 
|---|
| 2964 | SHORT usIDMax,     // in: maximum control ID to be set (inclusive) | 
|---|
| 2965 | const char *pcszFont)  // in: font to use (e.g. "9.WarpSans") or NULL | 
|---|
| 2966 | { | 
|---|
| 2967 | ULONG   ulrc = 0; | 
|---|
| 2968 | HENUM   henum; | 
|---|
| 2969 | HWND    hwndItem; | 
|---|
| 2970 | CHAR    szFont[256]; | 
|---|
| 2971 | ULONG   cbFont; | 
|---|
| 2972 |  | 
|---|
| 2973 | if (pcszFont == NULL) | 
|---|
| 2974 | { | 
|---|
| 2975 | if (doshIsWarp4()) | 
|---|
| 2976 | if(nlsDBCS()) | 
|---|
| 2977 | strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont)); | 
|---|
| 2978 | else | 
|---|
| 2979 | strhncpy0(szFont, "9.WarpSans", sizeof(szFont)); | 
|---|
| 2980 | else | 
|---|
| 2981 | if(nlsDBCS()) | 
|---|
| 2982 | strhncpy0(szFont, "8.Helv Combined", sizeof(szFont)); | 
|---|
| 2983 | else | 
|---|
| 2984 | strhncpy0(szFont, "8.Helv", sizeof(szFont)); | 
|---|
| 2985 | } | 
|---|
| 2986 | else | 
|---|
| 2987 | strhncpy0(szFont, pcszFont, sizeof(szFont)); | 
|---|
| 2988 |  | 
|---|
| 2989 | cbFont = strlen(szFont) + 1; | 
|---|
| 2990 |  | 
|---|
| 2991 | // set font for all the dialog controls | 
|---|
| 2992 | henum = WinBeginEnumWindows(hwndDlg); | 
|---|
| 2993 | while ((hwndItem = WinGetNextWindow(henum))) | 
|---|
| 2994 | { | 
|---|
| 2995 | SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID); | 
|---|
| 2996 | if (    (sID == -1) | 
|---|
| 2997 | || ((sID >= usIDMin) && (sID <= usIDMax)) | 
|---|
| 2998 | ) | 
|---|
| 2999 | if (WinSetPresParam(hwndItem, | 
|---|
| 3000 | PP_FONTNAMESIZE, | 
|---|
| 3001 | cbFont, | 
|---|
| 3002 | szFont)) | 
|---|
| 3003 | // successful: | 
|---|
| 3004 | ulrc++; | 
|---|
| 3005 | } | 
|---|
| 3006 | WinEndEnumWindows(henum); | 
|---|
| 3007 |  | 
|---|
| 3008 | return ulrc; | 
|---|
| 3009 | } | 
|---|
| 3010 |  | 
|---|
| 3011 | /* | 
|---|
| 3012 | *@@ winhStorePresParam: | 
|---|
| 3013 | *      this appends a new presentation parameter to an | 
|---|
| 3014 | *      array of presentation parameters which can be | 
|---|
| 3015 | *      passed to WinCreateWindow. This is preferred | 
|---|
| 3016 | *      over setting the presparams using WinSetPresParams, | 
|---|
| 3017 | *      because that call will cause a lot of messages. | 
|---|
| 3018 | * | 
|---|
| 3019 | *      On the first call, pppp _must_ be NULL. This | 
|---|
| 3020 | *      will allocate memory for storing the given | 
|---|
| 3021 | *      data as necessary and modify *pppp to point | 
|---|
| 3022 | *      to the new array. | 
|---|
| 3023 | * | 
|---|
| 3024 | *      On subsequent calls with the same pppp, memory | 
|---|
| 3025 | *      will be reallocated, the old data will be copied, | 
|---|
| 3026 | *      and the new given data will be appended. | 
|---|
| 3027 | * | 
|---|
| 3028 | *      Use free() on your PPRESPARAMS pointer (whose | 
|---|
| 3029 | *      address was passed) after WinCreateWindow. | 
|---|
| 3030 | * | 
|---|
| 3031 | *      See winhQueryPresColor for typical presparams | 
|---|
| 3032 | *      used in OS/2. | 
|---|
| 3033 | * | 
|---|
| 3034 | *      Example: | 
|---|
| 3035 | * | 
|---|
| 3036 | +          PPRESPARAMS ppp = NULL; | 
|---|
| 3037 | +          CHAR szFont[] = "9.WarpSans"; | 
|---|
| 3038 | +          LONG lColor = CLR_WHITE; | 
|---|
| 3039 | +          winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont); | 
|---|
| 3040 | +          winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor); | 
|---|
| 3041 | +          WinCreateWindow(...., ppp); | 
|---|
| 3042 | +          free(ppp); | 
|---|
| 3043 | * | 
|---|
| 3044 | *@@added V0.9.0 [umoeller] | 
|---|
| 3045 | */ | 
|---|
| 3046 |  | 
|---|
| 3047 | BOOL winhStorePresParam(PPRESPARAMS *pppp,      // in: data pointer (modified) | 
|---|
| 3048 | ULONG ulAttrType,       // in: PP_* index | 
|---|
| 3049 | ULONG cbData,           // in: sizeof(*pData), e.g. sizeof(LONG) | 
|---|
| 3050 | PVOID pData)            // in: presparam data (e.g. a PLONG to a color) | 
|---|
| 3051 | { | 
|---|
| 3052 | BOOL        brc = FALSE; | 
|---|
| 3053 | if (pppp) | 
|---|
| 3054 | { | 
|---|
| 3055 | ULONG       cbOld = 0, | 
|---|
| 3056 | cbNew; | 
|---|
| 3057 | PBYTE       pbTemp = 0; | 
|---|
| 3058 | PPRESPARAMS pppTemp = 0; | 
|---|
| 3059 | PPARAM      pppCopyTo = 0; | 
|---|
| 3060 |  | 
|---|
| 3061 | if (*pppp != NULL) | 
|---|
| 3062 | // subsequent calls: | 
|---|
| 3063 | cbOld = (**pppp).cb; | 
|---|
| 3064 |  | 
|---|
| 3065 | cbNew = sizeof(ULONG)       // PRESPARAMS.cb | 
|---|
| 3066 | + cbOld             // old count, which does not include PRESPARAMS.cb | 
|---|
| 3067 | + sizeof(ULONG)     // PRESPARAMS.aparam[0].id | 
|---|
| 3068 | + sizeof(ULONG)     // PRESPARAMS.aparam[0].cb | 
|---|
| 3069 | + cbData;           // PRESPARAMS.aparam[0].ab[] | 
|---|
| 3070 |  | 
|---|
| 3071 | pbTemp = (PBYTE)malloc(cbNew); | 
|---|
| 3072 | if (pbTemp) | 
|---|
| 3073 | { | 
|---|
| 3074 | pppTemp = (PPRESPARAMS)pbTemp; | 
|---|
| 3075 |  | 
|---|
| 3076 | if (*pppp != NULL) | 
|---|
| 3077 | { | 
|---|
| 3078 | // copy old data | 
|---|
| 3079 | memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb | 
|---|
| 3080 | pppCopyTo = (PPARAM)(pbTemp             // new buffer | 
|---|
| 3081 | + sizeof(ULONG)    // skipping PRESPARAMS.cb | 
|---|
| 3082 | + cbOld);          // old PARAM array | 
|---|
| 3083 | } | 
|---|
| 3084 | else | 
|---|
| 3085 | // first call: | 
|---|
| 3086 | pppCopyTo = pppTemp->aparam; | 
|---|
| 3087 |  | 
|---|
| 3088 | pppTemp->cb = cbNew - sizeof(ULONG);     // excluding PRESPARAMS.cb | 
|---|
| 3089 | pppCopyTo->id = ulAttrType; | 
|---|
| 3090 | pppCopyTo->cb = cbData;       // byte count of PARAM.ab[] | 
|---|
| 3091 | memcpy(pppCopyTo->ab, pData, cbData); | 
|---|
| 3092 |  | 
|---|
| 3093 | free(*pppp); | 
|---|
| 3094 | *pppp = pppTemp; | 
|---|
| 3095 |  | 
|---|
| 3096 | brc = TRUE; | 
|---|
| 3097 | } | 
|---|
| 3098 | } | 
|---|
| 3099 | return brc; | 
|---|
| 3100 | } | 
|---|
| 3101 |  | 
|---|
| 3102 | /* | 
|---|
| 3103 | *@@ winhQueryPresColor2: | 
|---|
| 3104 | *      returns the specified color. This is queried in the | 
|---|
| 3105 | *      following order: | 
|---|
| 3106 | * | 
|---|
| 3107 | *      1)  hwnd's pres params are searched for ulPP | 
|---|
| 3108 | *          (which should be a PP_* index); | 
|---|
| 3109 | *      2)  if (fInherit == TRUE), the parent windows | 
|---|
| 3110 | *          are searched also; | 
|---|
| 3111 | *      3)  if this fails or (fInherit == FALSE), WinQuerySysColor | 
|---|
| 3112 | *          is called to get lSysColor (which should be a SYSCLR_* | 
|---|
| 3113 | *          index), if lSysColor != -1; | 
|---|
| 3114 | *      4)  if (lSysColor == -1), -1 is returned. | 
|---|
| 3115 | * | 
|---|
| 3116 | *      The return value is always an RGB LONG, _not_ a color index. | 
|---|
| 3117 | *      This is even true for the returned system colors, which are | 
|---|
| 3118 | *      converted to RGB. | 
|---|
| 3119 | * | 
|---|
| 3120 | *      If you do any painting with this value, you should switch | 
|---|
| 3121 | *      the HPS you're using to RGB mode (use gpihSwitchToRGB for that). | 
|---|
| 3122 | * | 
|---|
| 3123 | *      Some useful ulPP / lSysColor pairs | 
|---|
| 3124 | *      (default values as in PMREF): | 
|---|
| 3125 | * | 
|---|
| 3126 | +          --  PP_FOREGROUNDCOLOR          SYSCLR_WINDOWTEXT (for most controls also) | 
|---|
| 3127 | +                                          SYSCLR_WINDOWSTATICTEXT (for static controls) | 
|---|
| 3128 | +                 Foreground color (default: black) | 
|---|
| 3129 | +          --  PP_BACKGROUNDCOLOR          SYSCLR_BACKGROUND | 
|---|
| 3130 | +                                          SYSCLR_DIALOGBACKGROUND | 
|---|
| 3131 | +                                          SYSCLR_FIELDBACKGROUND (for disabled scrollbars) | 
|---|
| 3132 | +                                          SYSCLR_WINDOW (application surface -- empty clients) | 
|---|
| 3133 | +                 Background color (default: light gray) | 
|---|
| 3134 | +          --  PP_ACTIVETEXTFGNDCOLOR | 
|---|
| 3135 | +          --  PP_HILITEFOREGROUNDCOLOR    SYSCLR_HILITEFOREGROUND | 
|---|
| 3136 | +                 Highlighted foreground color, for example for selected menu | 
|---|
| 3137 | +                 (def.: white) | 
|---|
| 3138 | +          --  PP_ACTIVETEXTBGNDCOLOR | 
|---|
| 3139 | +          --  PP_HILITEBACKGROUNDCOLOR    SYSCLR_HILITEBACKGROUND | 
|---|
| 3140 | +                 Highlighted background color (def.: dark gray) | 
|---|
| 3141 | +          --  PP_INACTIVETEXTFGNDCOLOR | 
|---|
| 3142 | +          --  PP_DISABLEDFOREGROUNDCOLOR  SYSCLR_MENUDISABLEDTEXT | 
|---|
| 3143 | +                 Disabled foreground color (dark gray) | 
|---|
| 3144 | +          --  PP_INACTIVETEXTBGNDCOLOR | 
|---|
| 3145 | +          --  PP_DISABLEDBACKGROUNDCOLOR | 
|---|
| 3146 | +                 Disabled background color | 
|---|
| 3147 | +          --  PP_BORDERCOLOR              SYSCLR_WINDOWFRAME | 
|---|
| 3148 | +                                          SYSCLR_INACTIVEBORDER | 
|---|
| 3149 | +                 Border color (around pushbuttons, in addition to | 
|---|
| 3150 | +                 the 3D colors) | 
|---|
| 3151 | +          --  PP_ACTIVECOLOR              SYSCLR_ACTIVETITLE | 
|---|
| 3152 | +                 Active color | 
|---|
| 3153 | +          --  PP_INACTIVECOLOR            SYSCLR_INACTIVETITLE | 
|---|
| 3154 | +                 Inactive color | 
|---|
| 3155 | * | 
|---|
| 3156 | *      For menus: | 
|---|
| 3157 | +          --  PP_MENUBACKGROUNDCOLOR      SYSCLR_MENU | 
|---|
| 3158 | +          --  PP_MENUFOREGROUNDCOLOR      SYSCLR_MENUTEXT | 
|---|
| 3159 | +          --  PP_MENUHILITEBGNDCOLOR      SYSCLR_MENUHILITEBGND | 
|---|
| 3160 | +          --  PP_MENUHILITEFGNDCOLOR      SYSCLR_MENUHILITE | 
|---|
| 3161 | +          --  ??                          SYSCLR_MENUDISABLEDTEXT | 
|---|
| 3162 | + | 
|---|
| 3163 | *      For containers (according to the API ref. at EDM/2): | 
|---|
| 3164 | +          --  PP_FOREGROUNDCOLOR          SYSCLR_WINDOWTEXT | 
|---|
| 3165 | +          --  PP_BACKGROUNDCOLOR          SYSCLR_WINDOW | 
|---|
| 3166 | +          --  PP_HILITEFOREGROUNDCOLOR    SYSCLR_HILITEFOREGROUND | 
|---|
| 3167 | +          --  PP_HILITEBACKGROUNDCOLOR    SYSCLR_HILITEBACKGROUND | 
|---|
| 3168 | +          --  PP_BORDERCOLOR | 
|---|
| 3169 | +                  (used for separator lines, eg. in Details view) | 
|---|
| 3170 | +          --  PP_ICONTEXTBACKGROUNDCOLOR | 
|---|
| 3171 | +                  (column titles in Details view?!?) | 
|---|
| 3172 | + | 
|---|
| 3173 | *      For listboxes / entryfields / MLE's: | 
|---|
| 3174 | +          --  PP_BACKGROUNDCOLOR          SYSCLR_ENTRYFIELD | 
|---|
| 3175 | * | 
|---|
| 3176 | *  PMREF has more of these. | 
|---|
| 3177 | * | 
|---|
| 3178 | *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed | 
|---|
| 3179 | *@@changed V0.9.0 [umoeller]: added fInherit parameter | 
|---|
| 3180 | *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support | 
|---|
| 3181 | *@@changed V0.9.20 (2002-08-04) [umoeller]: added ulPPIndex, renamed func | 
|---|
| 3182 | */ | 
|---|
| 3183 |  | 
|---|
| 3184 | LONG winhQueryPresColor2(HWND hwnd,          // in: window to query | 
|---|
| 3185 | ULONG ulppRGB,      // in: PP_* index for RGB color | 
|---|
| 3186 | ULONG ulppIndex,    // in: PP_* index for color _index_ (can be null) | 
|---|
| 3187 | BOOL fInherit,      // in: search parent windows too? | 
|---|
| 3188 | LONG lSysColor)     // in: SYSCLR_* index or -1 | 
|---|
| 3189 | { | 
|---|
| 3190 | ULONG   ul, | 
|---|
| 3191 | attrFound; | 
|---|
| 3192 | LONG    lColorFound; | 
|---|
| 3193 |  | 
|---|
| 3194 | if (ulppRGB != (ULONG)-1) | 
|---|
| 3195 | { | 
|---|
| 3196 | ULONG fl = 0; | 
|---|
| 3197 | if (!fInherit) | 
|---|
| 3198 | fl = QPF_NOINHERIT; | 
|---|
| 3199 | if (ulppIndex) | 
|---|
| 3200 | fl |= QPF_ID2COLORINDEX;            // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller] | 
|---|
| 3201 |  | 
|---|
| 3202 | if ((ul = WinQueryPresParam(hwnd, | 
|---|
| 3203 | ulppRGB, | 
|---|
| 3204 | ulppIndex, | 
|---|
| 3205 | &attrFound, | 
|---|
| 3206 | sizeof(lColorFound), | 
|---|
| 3207 | &lColorFound, | 
|---|
| 3208 | fl))) | 
|---|
| 3209 | return lColorFound; | 
|---|
| 3210 | } | 
|---|
| 3211 |  | 
|---|
| 3212 | // not found: get system color | 
|---|
| 3213 | if (lSysColor != -1) | 
|---|
| 3214 | return WinQuerySysColor(HWND_DESKTOP, lSysColor, 0); | 
|---|
| 3215 |  | 
|---|
| 3216 | return -1; | 
|---|
| 3217 | } | 
|---|
| 3218 |  | 
|---|
| 3219 | /* | 
|---|
| 3220 | *@@ winhQueryPresColor: | 
|---|
| 3221 | *      compatibility function because this one was | 
|---|
| 3222 | *      exported. | 
|---|
| 3223 | * | 
|---|
| 3224 | *@@added V0.9.20 (2002-08-04) [umoeller] | 
|---|
| 3225 | */ | 
|---|
| 3226 |  | 
|---|
| 3227 | LONG XWPENTRY winhQueryPresColor(HWND hwnd, | 
|---|
| 3228 | ULONG ulPP, | 
|---|
| 3229 | BOOL fInherit, | 
|---|
| 3230 | LONG lSysColor) | 
|---|
| 3231 | { | 
|---|
| 3232 | return winhQueryPresColor2(hwnd, | 
|---|
| 3233 | ulPP, | 
|---|
| 3234 | 0, | 
|---|
| 3235 | fInherit, | 
|---|
| 3236 | lSysColor); | 
|---|
| 3237 | } | 
|---|
| 3238 |  | 
|---|
| 3239 | /* | 
|---|
| 3240 | *@@ winhSetPresColor: | 
|---|
| 3241 | *      sets a color presparam. ulIndex specifies | 
|---|
| 3242 | *      the presparam to be set and would normally | 
|---|
| 3243 | *      be either PP_BACKGROUNDCOLOR or PP_FOREGROUNDCOLOR. | 
|---|
| 3244 | * | 
|---|
| 3245 | *@@added V0.9.16 (2001-10-15) [umoeller] | 
|---|
| 3246 | */ | 
|---|
| 3247 |  | 
|---|
| 3248 | BOOL winhSetPresColor(HWND hwnd, | 
|---|
| 3249 | ULONG ulIndex, | 
|---|
| 3250 | LONG lColor) | 
|---|
| 3251 | { | 
|---|
| 3252 | return WinSetPresParam(hwnd, | 
|---|
| 3253 | ulIndex, | 
|---|
| 3254 | sizeof(LONG), | 
|---|
| 3255 | &lColor); | 
|---|
| 3256 | } | 
|---|
| 3257 |  | 
|---|
| 3258 | /* | 
|---|
| 3259 | *@@category: Helpers\PM helpers\Help (IPF) | 
|---|
| 3260 | */ | 
|---|
| 3261 |  | 
|---|
| 3262 | /* ****************************************************************** | 
|---|
| 3263 | * | 
|---|
| 3264 | *   Help instance helpers | 
|---|
| 3265 | * | 
|---|
| 3266 | ********************************************************************/ | 
|---|
| 3267 |  | 
|---|
| 3268 | /* | 
|---|
| 3269 | *@@ winhCreateHelp: | 
|---|
| 3270 | *      creates a help instance and connects it with the | 
|---|
| 3271 | *      given frame window. | 
|---|
| 3272 | * | 
|---|
| 3273 | *      If (pszFileName == NULL), we'll retrieve the | 
|---|
| 3274 | *      executable's fully qualified file name and | 
|---|
| 3275 | *      replace the extension with .HLP simply. This | 
|---|
| 3276 | *      avoids the typical "Help not found" errors if | 
|---|
| 3277 | *      the program isn't started in its own directory. | 
|---|
| 3278 | * | 
|---|
| 3279 | *      If you have created a help table in memory, specify it | 
|---|
| 3280 | *      with pHelpTable. To load a help table from the resources, | 
|---|
| 3281 | *      specify hmod (or NULLHANDLE) and set pHelpTable to the | 
|---|
| 3282 | *      following: | 
|---|
| 3283 | + | 
|---|
| 3284 | +          (PHELPTABLE)MAKELONG(usTableID, 0xffff) | 
|---|
| 3285 | * | 
|---|
| 3286 | *      Returns the help window handle or NULLHANDLE on errors. | 
|---|
| 3287 | * | 
|---|
| 3288 | *      Based on an EDM/2 code snippet. | 
|---|
| 3289 | * | 
|---|
| 3290 | *@@added V0.9.4 (2000-07-03) [umoeller] | 
|---|
| 3291 | */ | 
|---|
| 3292 |  | 
|---|
| 3293 | HWND winhCreateHelp(HWND hwndFrame,      // in: app's frame window handle; can be NULLHANDLE | 
|---|
| 3294 | const char *pcszFileName,    // in: help file name or NULL | 
|---|
| 3295 | HMODULE hmod,           // in: module with help table or NULLHANDLE (current) | 
|---|
| 3296 | PHELPTABLE pHelpTable,  // in: help table or resource ID | 
|---|
| 3297 | const char *pcszWindowTitle) // in: help window title or NULL | 
|---|
| 3298 | { | 
|---|
| 3299 | HELPINIT hi; | 
|---|
| 3300 | PSZ      pszExt; | 
|---|
| 3301 | CHAR     szName[CCHMAXPATH]; | 
|---|
| 3302 | HWND     hwndHelp; | 
|---|
| 3303 |  | 
|---|
| 3304 | if (pcszFileName == NULL) | 
|---|
| 3305 | { | 
|---|
| 3306 | PPIB     ppib; | 
|---|
| 3307 | PTIB     ptib; | 
|---|
| 3308 | DosGetInfoBlocks(&ptib, &ppib); | 
|---|
| 3309 | DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName); | 
|---|
| 3310 |  | 
|---|
| 3311 | pszExt = strrchr(szName, '.'); | 
|---|
| 3312 | if (pszExt) | 
|---|
| 3313 | strcpy(pszExt, ".hlp"); | 
|---|
| 3314 | else | 
|---|
| 3315 | strcat(szName, ".hlp"); | 
|---|
| 3316 |  | 
|---|
| 3317 | pcszFileName = szName; | 
|---|
| 3318 | } | 
|---|
| 3319 |  | 
|---|
| 3320 | hi.cb                       = sizeof(HELPINIT); | 
|---|
| 3321 | hi.ulReturnCode             = 0; | 
|---|
| 3322 | hi.pszTutorialName          = NULL; | 
|---|
| 3323 | hi.phtHelpTable             = pHelpTable; | 
|---|
| 3324 | hi.hmodHelpTableModule      = hmod; | 
|---|
| 3325 | hi.hmodAccelActionBarModule = NULLHANDLE; | 
|---|
| 3326 | hi.idAccelTable             = 0; | 
|---|
| 3327 | hi.idActionBar              = 0; | 
|---|
| 3328 | hi.pszHelpWindowTitle       = (PSZ)pcszWindowTitle; | 
|---|
| 3329 | hi.fShowPanelId             = CMIC_HIDE_PANEL_ID; | 
|---|
| 3330 | hi.pszHelpLibraryName       = (PSZ)pcszFileName; | 
|---|
| 3331 |  | 
|---|
| 3332 | hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame), | 
|---|
| 3333 | &hi); | 
|---|
| 3334 | if ((hwndFrame) && (hwndHelp)) | 
|---|
| 3335 | { | 
|---|
| 3336 | WinAssociateHelpInstance(hwndHelp, hwndFrame); | 
|---|
| 3337 | } | 
|---|
| 3338 |  | 
|---|
| 3339 | return hwndHelp; | 
|---|
| 3340 | } | 
|---|
| 3341 |  | 
|---|
| 3342 | /* | 
|---|
| 3343 | *@@ winhDisplayHelpPanel: | 
|---|
| 3344 | *      displays the specified help panel ID. | 
|---|
| 3345 | * | 
|---|
| 3346 | *      If (ulHelpPanel == 0), this displays the | 
|---|
| 3347 | *      standard OS/2 "Using help" panel. | 
|---|
| 3348 | * | 
|---|
| 3349 | *      Returns zero on success or one of the | 
|---|
| 3350 | *      help manager error codes on failure. | 
|---|
| 3351 | *      See HM_ERROR for those. | 
|---|
| 3352 | * | 
|---|
| 3353 | *@@added V0.9.7 (2001-01-21) [umoeller] | 
|---|
| 3354 | */ | 
|---|
| 3355 |  | 
|---|
| 3356 | ULONG winhDisplayHelpPanel(HWND hwndHelpInstance,   // in: from winhCreateHelp | 
|---|
| 3357 | ULONG ulHelpPanel)       // in: help panel ID | 
|---|
| 3358 | { | 
|---|
| 3359 | return (ULONG)WinSendMsg(hwndHelpInstance, | 
|---|
| 3360 | HM_DISPLAY_HELP, | 
|---|
| 3361 | (MPARAM)ulHelpPanel, | 
|---|
| 3362 | (MPARAM)(    (ulHelpPanel != 0) | 
|---|
| 3363 | ? HM_RESOURCEID | 
|---|
| 3364 | : 0)); | 
|---|
| 3365 | } | 
|---|
| 3366 |  | 
|---|
| 3367 | /* | 
|---|
| 3368 | *@@ winhDestroyHelp: | 
|---|
| 3369 | *      destroys the help instance created by winhCreateHelp. | 
|---|
| 3370 | * | 
|---|
| 3371 | *      Based on an EDM/2 code snippet. | 
|---|
| 3372 | * | 
|---|
| 3373 | *@@added V0.9.4 (2000-07-03) [umoeller] | 
|---|
| 3374 | */ | 
|---|
| 3375 |  | 
|---|
| 3376 | void winhDestroyHelp(HWND hwndHelp, | 
|---|
| 3377 | HWND hwndFrame)    // can be NULLHANDLE if not used with winhCreateHelp | 
|---|
| 3378 | { | 
|---|
| 3379 | if (hwndHelp) | 
|---|
| 3380 | { | 
|---|
| 3381 | if (hwndFrame) | 
|---|
| 3382 | WinAssociateHelpInstance(NULLHANDLE, hwndFrame); | 
|---|
| 3383 | WinDestroyHelpInstance(hwndHelp); | 
|---|
| 3384 | } | 
|---|
| 3385 | } | 
|---|
| 3386 |  | 
|---|
| 3387 | /* | 
|---|
| 3388 | *@@category: Helpers\PM helpers\Application control | 
|---|
| 3389 | */ | 
|---|
| 3390 |  | 
|---|
| 3391 | /* ****************************************************************** | 
|---|
| 3392 | * | 
|---|
| 3393 | *   Application control | 
|---|
| 3394 | * | 
|---|
| 3395 | ********************************************************************/ | 
|---|
| 3396 |  | 
|---|
| 3397 | /* | 
|---|
| 3398 | *@@ winhAnotherInstance: | 
|---|
| 3399 | *      this tests whether another instance of the same | 
|---|
| 3400 | *      application is already running. | 
|---|
| 3401 | * | 
|---|
| 3402 | *      To identify instances of the same application, the | 
|---|
| 3403 | *      application must call this function during startup | 
|---|
| 3404 | *      with the unique name of an OS/2 semaphore. As with | 
|---|
| 3405 | *      all OS/2 semaphores, the semaphore name must begin | 
|---|
| 3406 | *      with "\\SEM32\\". The semaphore isn't really used | 
|---|
| 3407 | *      except for testing for its existence, since that | 
|---|
| 3408 | *      name is unique among all processes. | 
|---|
| 3409 | * | 
|---|
| 3410 | *      If another instance is found, TRUE is returned. If | 
|---|
| 3411 | *      (fSwitch == TRUE), that instance is switched to, | 
|---|
| 3412 | *      using the tasklist. | 
|---|
| 3413 | * | 
|---|
| 3414 | *      If no other instance is found, FALSE is returned only. | 
|---|
| 3415 | * | 
|---|
| 3416 | *      Based on an EDM/2 code snippet. | 
|---|
| 3417 | * | 
|---|
| 3418 | *@@added V0.9.0 (99-10-22) [umoeller] | 
|---|
| 3419 | */ | 
|---|
| 3420 |  | 
|---|
| 3421 | BOOL winhAnotherInstance(const char *pcszSemName,    // in: semaphore ID | 
|---|
| 3422 | BOOL fSwitch)      // in: if TRUE, switch to first instance if running | 
|---|
| 3423 | { | 
|---|
| 3424 | HMTX hmtx; | 
|---|
| 3425 |  | 
|---|
| 3426 | if (DosCreateMutexSem((PSZ)pcszSemName, | 
|---|
| 3427 | &hmtx, | 
|---|
| 3428 | DC_SEM_SHARED, | 
|---|
| 3429 | TRUE) | 
|---|
| 3430 | == NO_ERROR) | 
|---|
| 3431 | // semapore created: this doesn't happen if the semaphore | 
|---|
| 3432 | // exists already, so no other instance is running | 
|---|
| 3433 | return FALSE; | 
|---|
| 3434 |  | 
|---|
| 3435 | // else: instance running | 
|---|
| 3436 | hmtx = NULLHANDLE; | 
|---|
| 3437 |  | 
|---|
| 3438 | // switch to other instance? | 
|---|
| 3439 | if (fSwitch) | 
|---|
| 3440 | { | 
|---|
| 3441 | // yes: query mutex creator | 
|---|
| 3442 | if (DosOpenMutexSem((PSZ)pcszSemName, | 
|---|
| 3443 | &hmtx) | 
|---|
| 3444 | == NO_ERROR) | 
|---|
| 3445 | { | 
|---|
| 3446 | PID     pid = 0; | 
|---|
| 3447 | TID     tid = 0;        // unused | 
|---|
| 3448 | ULONG   ulCount;        // unused | 
|---|
| 3449 |  | 
|---|
| 3450 | if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR) | 
|---|
| 3451 | { | 
|---|
| 3452 | HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid); | 
|---|
| 3453 | if (hswitch != NULLHANDLE) | 
|---|
| 3454 | WinSwitchToProgram(hswitch); | 
|---|
| 3455 | } | 
|---|
| 3456 |  | 
|---|
| 3457 | DosCloseMutexSem(hmtx); | 
|---|
| 3458 | } | 
|---|
| 3459 | } | 
|---|
| 3460 |  | 
|---|
| 3461 | return TRUE;      // another instance exists | 
|---|
| 3462 | } | 
|---|
| 3463 |  | 
|---|
| 3464 | /* | 
|---|
| 3465 | *@@ winhAddToTasklist: | 
|---|
| 3466 | *      this adds the specified window to the tasklist | 
|---|
| 3467 | *      with hIcon as its program icon (which is also | 
|---|
| 3468 | *      set for the main window). This is useful for | 
|---|
| 3469 | *      the old "dialog as main window" trick. | 
|---|
| 3470 | * | 
|---|
| 3471 | *      Returns the HSWITCH of the added entry. | 
|---|
| 3472 | */ | 
|---|
| 3473 |  | 
|---|
| 3474 | HSWITCH winhAddToTasklist(HWND hwnd,       // in: window to add | 
|---|
| 3475 | HPOINTER hIcon)  // in: icon for main window | 
|---|
| 3476 | { | 
|---|
| 3477 | SWCNTRL     swctl; | 
|---|
| 3478 | HSWITCH hswitch = 0; | 
|---|
| 3479 | swctl.hwnd = hwnd;                     // window handle | 
|---|
| 3480 | swctl.hwndIcon = hIcon;                // icon handle | 
|---|
| 3481 | swctl.hprog = NULLHANDLE;              // program handle (use default) | 
|---|
| 3482 | WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL); | 
|---|
| 3483 | // process identifier | 
|---|
| 3484 | swctl.idSession = 0;                   // session identifier ? | 
|---|
| 3485 | swctl.uchVisibility = SWL_VISIBLE;     // visibility | 
|---|
| 3486 | swctl.fbJump = SWL_JUMPABLE;           // jump indicator | 
|---|
| 3487 | // get window title from window titlebar | 
|---|
| 3488 | if (hwnd) | 
|---|
| 3489 | WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle); | 
|---|
| 3490 | swctl.bProgType = PROG_DEFAULT;        // program type | 
|---|
| 3491 | hswitch = WinAddSwitchEntry(&swctl); | 
|---|
| 3492 |  | 
|---|
| 3493 | // give the main window the icon | 
|---|
| 3494 | if ((hwnd) && (hIcon)) | 
|---|
| 3495 | WinSendMsg(hwnd, | 
|---|
| 3496 | WM_SETICON, | 
|---|
| 3497 | (MPARAM)hIcon, | 
|---|
| 3498 | NULL); | 
|---|
| 3499 |  | 
|---|
| 3500 | return hswitch; | 
|---|
| 3501 | } | 
|---|
| 3502 |  | 
|---|
| 3503 | /* | 
|---|
| 3504 | *@@category: Helpers\PM helpers\Miscellaneous | 
|---|
| 3505 | */ | 
|---|
| 3506 |  | 
|---|
| 3507 | /* ****************************************************************** | 
|---|
| 3508 | * | 
|---|
| 3509 | *   Miscellaneous | 
|---|
| 3510 | * | 
|---|
| 3511 | ********************************************************************/ | 
|---|
| 3512 |  | 
|---|
| 3513 | /* | 
|---|
| 3514 | *@@ winhMyAnchorBlock: | 
|---|
| 3515 | *      returns the proper anchor block (HAB) | 
|---|
| 3516 | *      for the calling thread. | 
|---|
| 3517 | * | 
|---|
| 3518 | *      Many Win* functions require an HAB to be | 
|---|
| 3519 | *      passed in. While many of them will work | 
|---|
| 3520 | *      when passing in NULLHANDLE, some (such as | 
|---|
| 3521 | *      WinGetMsg) won't. If you don't know the | 
|---|
| 3522 | *      anchor block of the calling thread, use | 
|---|
| 3523 | *      this function. | 
|---|
| 3524 | * | 
|---|
| 3525 | *      This creates a temporary object window to | 
|---|
| 3526 | *      find out the anchor block. This is quite | 
|---|
| 3527 | *      expensive so only use this if there's no | 
|---|
| 3528 | *      other way to find out. | 
|---|
| 3529 | * | 
|---|
| 3530 | *@@added V0.9.11 (2001-04-20) [umoeller] | 
|---|
| 3531 | */ | 
|---|
| 3532 |  | 
|---|
| 3533 | HAB winhMyAnchorBlock(VOID) | 
|---|
| 3534 | { | 
|---|
| 3535 | HAB hab = NULLHANDLE; | 
|---|
| 3536 | HWND hwnd; | 
|---|
| 3537 | if (hwnd = winhCreateObjectWindow(WC_BUTTON, NULL)) | 
|---|
| 3538 | { | 
|---|
| 3539 | hab = WinQueryAnchorBlock(hwnd); | 
|---|
| 3540 | WinDestroyWindow(hwnd); | 
|---|
| 3541 | } | 
|---|
| 3542 |  | 
|---|
| 3543 | return hab; | 
|---|
| 3544 | } | 
|---|
| 3545 |  | 
|---|
| 3546 | /* | 
|---|
| 3547 | *@@ winhFree: | 
|---|
| 3548 | *      frees a block of memory allocated by the | 
|---|
| 3549 | *      winh* functions. | 
|---|
| 3550 | * | 
|---|
| 3551 | *      Since the winh* functions use malloc(), | 
|---|
| 3552 | *      you can also use free() directly on such | 
|---|
| 3553 | *      blocks. However, you must use winhFree | 
|---|
| 3554 | *      if the winh* functions are in a module | 
|---|
| 3555 | *      with a different C runtime. | 
|---|
| 3556 | * | 
|---|
| 3557 | *@@added V0.9.7 (2000-12-06) [umoeller] | 
|---|
| 3558 | */ | 
|---|
| 3559 |  | 
|---|
| 3560 | VOID winhFree(PVOID p) | 
|---|
| 3561 | { | 
|---|
| 3562 | if (p) | 
|---|
| 3563 | free(p); | 
|---|
| 3564 | } | 
|---|
| 3565 |  | 
|---|
| 3566 | /* | 
|---|
| 3567 | *@@ winhSleep: | 
|---|
| 3568 | *      sleeps at least the specified amount of time, | 
|---|
| 3569 | *      without blocking the message queue. | 
|---|
| 3570 | * | 
|---|
| 3571 | *      NOTE: This function is a bit expensive because | 
|---|
| 3572 | *      it creates a temporary object window. If you | 
|---|
| 3573 | *      need to sleep several times, you should rather | 
|---|
| 3574 | *      use a private timer. | 
|---|
| 3575 | * | 
|---|
| 3576 | *@@added V0.9.4 (2000-07-11) [umoeller] | 
|---|
| 3577 | *@@changed V0.9.9 (2001-03-11) [umoeller]: rewritten | 
|---|
| 3578 | */ | 
|---|
| 3579 |  | 
|---|
| 3580 | VOID winhSleep(ULONG ulSleep)    // in: sleep time in milliseconds | 
|---|
| 3581 | { | 
|---|
| 3582 | HWND    hwnd; | 
|---|
| 3583 |  | 
|---|
| 3584 | if (hwnd = winhCreateObjectWindow(WC_STATIC, NULL)) | 
|---|
| 3585 | { | 
|---|
| 3586 | QMSG    qmsg; | 
|---|
| 3587 | HAB     hab; | 
|---|
| 3588 |  | 
|---|
| 3589 | if (    (hab = WinQueryAnchorBlock(hwnd)) | 
|---|
| 3590 | && (WinStartTimer(hab, | 
|---|
| 3591 | hwnd, | 
|---|
| 3592 | 1, | 
|---|
| 3593 | ulSleep)) | 
|---|
| 3594 | ) | 
|---|
| 3595 | { | 
|---|
| 3596 | while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0)) | 
|---|
| 3597 | { | 
|---|
| 3598 | if (    (qmsg.hwnd == hwnd) | 
|---|
| 3599 | && (qmsg.msg == WM_TIMER) | 
|---|
| 3600 | && (qmsg.mp1 == (MPARAM)1)     // timer ID | 
|---|
| 3601 | ) | 
|---|
| 3602 | break; | 
|---|
| 3603 |  | 
|---|
| 3604 | WinDispatchMsg(hab, &qmsg); | 
|---|
| 3605 | } | 
|---|
| 3606 | WinStopTimer(hab, | 
|---|
| 3607 | hwnd, | 
|---|
| 3608 | 1); | 
|---|
| 3609 | } | 
|---|
| 3610 | else | 
|---|
| 3611 | // timer creation failed: | 
|---|
| 3612 | DosSleep(ulSleep); | 
|---|
| 3613 |  | 
|---|
| 3614 | WinDestroyWindow(hwnd); | 
|---|
| 3615 | } | 
|---|
| 3616 | else | 
|---|
| 3617 | DosSleep(ulSleep); | 
|---|
| 3618 | } | 
|---|
| 3619 |  | 
|---|
| 3620 | /* | 
|---|
| 3621 | *@@ winhFileDlg: | 
|---|
| 3622 | *      one-short function for opening an "Open" file | 
|---|
| 3623 | *      dialog. | 
|---|
| 3624 | * | 
|---|
| 3625 | *      On input, pszFile specifies the directory and | 
|---|
| 3626 | *      file specification (e.g. "F:\*.txt"). | 
|---|
| 3627 | * | 
|---|
| 3628 | *      Returns TRUE if the user pressed OK. In that | 
|---|
| 3629 | *      case, the fully qualified filename is written | 
|---|
| 3630 | *      into pszFile again. | 
|---|
| 3631 | * | 
|---|
| 3632 | *      Returns FALSE if the user pressed Cancel. | 
|---|
| 3633 | * | 
|---|
| 3634 | *      Notes about flFlags: | 
|---|
| 3635 | * | 
|---|
| 3636 | *      -- WINH_FOD_SAVEDLG: display a "Save As" dialog. | 
|---|
| 3637 | *         Otherwise an "Open" dialog is displayed. | 
|---|
| 3638 | * | 
|---|
| 3639 | *      -- WINH_FOD_INILOADDIR: load a directory from the | 
|---|
| 3640 | *         specified INI key and switch the dlg to it. | 
|---|
| 3641 | *         In that case, on input, pszFile must only | 
|---|
| 3642 | *         contain the file filter without any path | 
|---|
| 3643 | *         specification, because that is loaded from | 
|---|
| 3644 | *         the INI key. If the INI key does not exist, | 
|---|
| 3645 | *         the current process directory will be used. | 
|---|
| 3646 | * | 
|---|
| 3647 | *      -- WINH_FOD_INISAVEDIR: if the user presses OK, | 
|---|
| 3648 | *         the directory of the selected file is written | 
|---|
| 3649 | *         to the specified INI key so that it can be | 
|---|
| 3650 | *         reused later. This flag is independent of | 
|---|
| 3651 | *         WINH_FOD_INISAVEDIR: you can specify none, | 
|---|
| 3652 | *         one, or both of them. | 
|---|
| 3653 | * | 
|---|
| 3654 | *@@added V0.9.3 (2000-04-29) [umoeller] | 
|---|
| 3655 | *@@changed V0.9.12 (2001-05-21) [umoeller]: this failed if INI data had root dir, fixed | 
|---|
| 3656 | */ | 
|---|
| 3657 |  | 
|---|
| 3658 | BOOL winhFileDlg(HWND hwndOwner,    // in: owner for file dlg | 
|---|
| 3659 | PSZ pszFile,       // in: file mask; out: fully q'd filename | 
|---|
| 3660 | //    (should be CCHMAXPATH in size) | 
|---|
| 3661 | ULONG flFlags,     // in: any combination of the following: | 
|---|
| 3662 | // -- WINH_FOD_SAVEDLG: save dlg; else open dlg | 
|---|
| 3663 | // -- WINH_FOD_INILOADDIR: load FOD path from INI | 
|---|
| 3664 | // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK | 
|---|
| 3665 | HINI hini,         // in: INI file to load/store last path from (can be HINI_USER) | 
|---|
| 3666 | const char *pcszApplication, // in: INI application to load/store last path from | 
|---|
| 3667 | const char *pcszKey)        // in: INI key to load/store last path from | 
|---|
| 3668 | { | 
|---|
| 3669 | FILEDLG fd; | 
|---|
| 3670 | FILESTATUS3 fs3; | 
|---|
| 3671 |  | 
|---|
| 3672 | memset(&fd, 0, sizeof(FILEDLG)); | 
|---|
| 3673 | fd.cbSize = sizeof(FILEDLG); | 
|---|
| 3674 | fd.fl = FDS_CENTER; | 
|---|
| 3675 |  | 
|---|
| 3676 | if (flFlags & WINH_FOD_SAVEDLG) | 
|---|
| 3677 | fd.fl |= FDS_SAVEAS_DIALOG; | 
|---|
| 3678 | else | 
|---|
| 3679 | fd.fl |= FDS_OPEN_DIALOG; | 
|---|
| 3680 |  | 
|---|
| 3681 | if (    (hini) | 
|---|
| 3682 | && (flFlags & WINH_FOD_INILOADDIR) | 
|---|
| 3683 | && (PrfQueryProfileString(hini, | 
|---|
| 3684 | (PSZ)pcszApplication, | 
|---|
| 3685 | (PSZ)pcszKey, | 
|---|
| 3686 | "",      // default string V0.9.9 (2001-02-10) [umoeller] | 
|---|
| 3687 | fd.szFullFile, | 
|---|
| 3688 | sizeof(fd.szFullFile)-10) | 
|---|
| 3689 | > 2) | 
|---|
| 3690 | // added these checks V0.9.12 (2001-05-21) [umoeller] | 
|---|
| 3691 | && (!DosQueryPathInfo(fd.szFullFile, | 
|---|
| 3692 | FIL_STANDARD, | 
|---|
| 3693 | &fs3, | 
|---|
| 3694 | sizeof(fs3))) | 
|---|
| 3695 | && (fs3.attrFile & FILE_DIRECTORY) | 
|---|
| 3696 | ) | 
|---|
| 3697 | { | 
|---|
| 3698 | // found: append "\*" | 
|---|
| 3699 | strcat(fd.szFullFile, "\\"); | 
|---|
| 3700 | strcat(fd.szFullFile, pszFile); | 
|---|
| 3701 | } | 
|---|
| 3702 | else | 
|---|
| 3703 | // default: copy pszFile | 
|---|
| 3704 | strcpy(fd.szFullFile, pszFile); | 
|---|
| 3705 | // fixed V0.9.12 (2001-05-21) [umoeller] | 
|---|
| 3706 |  | 
|---|
| 3707 | if (    WinFileDlg(HWND_DESKTOP,    // parent | 
|---|
| 3708 | hwndOwner, // owner | 
|---|
| 3709 | &fd) | 
|---|
| 3710 | && (fd.lReturn == DID_OK) | 
|---|
| 3711 | ) | 
|---|
| 3712 | { | 
|---|
| 3713 | // save path back? | 
|---|
| 3714 | if (    (hini) | 
|---|
| 3715 | && (flFlags & WINH_FOD_INISAVEDIR) | 
|---|
| 3716 | ) | 
|---|
| 3717 | { | 
|---|
| 3718 | // get the directory that was used | 
|---|
| 3719 | PSZ p = strrchr(fd.szFullFile, '\\'); | 
|---|
| 3720 | if (p) | 
|---|
| 3721 | { | 
|---|
| 3722 | // contains directory: | 
|---|
| 3723 | // copy to OS2.INI | 
|---|
| 3724 | PSZ pszDir = strhSubstr(fd.szFullFile, p); | 
|---|
| 3725 | if (pszDir) | 
|---|
| 3726 | { | 
|---|
| 3727 | PrfWriteProfileString(hini, | 
|---|
| 3728 | (PSZ)pcszApplication, | 
|---|
| 3729 | (PSZ)pcszKey, | 
|---|
| 3730 | pszDir); | 
|---|
| 3731 | free(pszDir); | 
|---|
| 3732 | } | 
|---|
| 3733 | } | 
|---|
| 3734 | } | 
|---|
| 3735 |  | 
|---|
| 3736 | strcpy(pszFile, fd.szFullFile); | 
|---|
| 3737 |  | 
|---|
| 3738 | return TRUE; | 
|---|
| 3739 | } | 
|---|
| 3740 |  | 
|---|
| 3741 | return FALSE; | 
|---|
| 3742 | } | 
|---|
| 3743 |  | 
|---|
| 3744 | /* | 
|---|
| 3745 | *@@ winhSetWaitPointer: | 
|---|
| 3746 | *      this sets the mouse pointer to "Wait". | 
|---|
| 3747 | *      Returns the previous pointer (HPOINTER), | 
|---|
| 3748 | *      which should be stored somewhere to be | 
|---|
| 3749 | *      restored later. Example: | 
|---|
| 3750 | +          HPOINTER hptrOld = winhSetWaitPointer(); | 
|---|
| 3751 | +          ... | 
|---|
| 3752 | +          WinSetPointer(HWND_DESKTOP, hptrOld); | 
|---|
| 3753 | */ | 
|---|
| 3754 |  | 
|---|
| 3755 | HPOINTER winhSetWaitPointer(VOID) | 
|---|
| 3756 | { | 
|---|
| 3757 | HPOINTER hptr = WinQueryPointer(HWND_DESKTOP); | 
|---|
| 3758 | WinSetPointer(HWND_DESKTOP, | 
|---|
| 3759 | WinQuerySysPointer(HWND_DESKTOP, | 
|---|
| 3760 | SPTR_WAIT, | 
|---|
| 3761 | FALSE));   // no copy | 
|---|
| 3762 | return hptr; | 
|---|
| 3763 | } | 
|---|
| 3764 |  | 
|---|
| 3765 | /* | 
|---|
| 3766 | *@@ winhQueryWindowText: | 
|---|
| 3767 | *      this returns the window text of the specified | 
|---|
| 3768 | *      HWND in a newly allocated buffer. | 
|---|
| 3769 | * | 
|---|
| 3770 | *      Returns NULL on error. Use free() | 
|---|
| 3771 | *      to free the return value. | 
|---|
| 3772 | */ | 
|---|
| 3773 |  | 
|---|
| 3774 | PSZ winhQueryWindowText(HWND hwnd) | 
|---|
| 3775 | { | 
|---|
| 3776 | PSZ     pszText = NULL; | 
|---|
| 3777 | ULONG   cbText = WinQueryWindowTextLength(hwnd); | 
|---|
| 3778 | // additional null character | 
|---|
| 3779 | if (cbText) | 
|---|
| 3780 | { | 
|---|
| 3781 | if (pszText = (PSZ)malloc(cbText + 1)) | 
|---|
| 3782 | WinQueryWindowText(hwnd, | 
|---|
| 3783 | cbText + 1, | 
|---|
| 3784 | pszText); | 
|---|
| 3785 | } | 
|---|
| 3786 | return pszText; | 
|---|
| 3787 | } | 
|---|
| 3788 |  | 
|---|
| 3789 | /* | 
|---|
| 3790 | *@@ winhSetWindowText: | 
|---|
| 3791 | *      like WinSetWindowText, but this one accepts | 
|---|
| 3792 | *      printf-like arguments. | 
|---|
| 3793 | * | 
|---|
| 3794 | *      Note that the total string is limited to | 
|---|
| 3795 | *      1000 characters. | 
|---|
| 3796 | * | 
|---|
| 3797 | *@@added V0.9.16 (2001-10-08) [umoeller] | 
|---|
| 3798 | */ | 
|---|
| 3799 |  | 
|---|
| 3800 | BOOL winhSetWindowText(HWND hwnd, | 
|---|
| 3801 | const char *pcszFormat, | 
|---|
| 3802 | ...) | 
|---|
| 3803 | { | 
|---|
| 3804 | CHAR szBuf[1000]; | 
|---|
| 3805 | va_list     args; | 
|---|
| 3806 | int         i; | 
|---|
| 3807 | va_start(args, pcszFormat); | 
|---|
| 3808 | i = vsprintf(szBuf, pcszFormat, args); | 
|---|
| 3809 | va_end(args); | 
|---|
| 3810 |  | 
|---|
| 3811 | return WinSetWindowText(hwnd, | 
|---|
| 3812 | szBuf); | 
|---|
| 3813 | } | 
|---|
| 3814 |  | 
|---|
| 3815 | /* | 
|---|
| 3816 | *@@ winhReplaceWindowText: | 
|---|
| 3817 | *      this is a combination of winhQueryWindowText | 
|---|
| 3818 | *      and strhFindReplace to replace substrings in a window. | 
|---|
| 3819 | * | 
|---|
| 3820 | *      This is useful for filling in placeholders | 
|---|
| 3821 | *      a la "%1" in control windows, e.g. static | 
|---|
| 3822 | *      texts. | 
|---|
| 3823 | * | 
|---|
| 3824 | *      This replaces only the first occurence of | 
|---|
| 3825 | *      pszSearch. | 
|---|
| 3826 | * | 
|---|
| 3827 | *      Returns TRUE only if the window exists and | 
|---|
| 3828 | *      the search string was replaced. | 
|---|
| 3829 | * | 
|---|
| 3830 | *@@added V0.9.0 [umoeller] | 
|---|
| 3831 | */ | 
|---|
| 3832 |  | 
|---|
| 3833 | BOOL winhReplaceWindowText(HWND hwnd,           // in: window whose text is to be modified | 
|---|
| 3834 | const char *pcszSearch,       // in: search string (e.g. "%1") | 
|---|
| 3835 | const char *pcszReplaceWith)  // in: replacement string for pszSearch | 
|---|
| 3836 | { | 
|---|
| 3837 | BOOL    brc = FALSE; | 
|---|
| 3838 | PSZ     pszText = winhQueryWindowText(hwnd); | 
|---|
| 3839 | if (pszText) | 
|---|
| 3840 | { | 
|---|
| 3841 | ULONG ulOfs = 0; | 
|---|
| 3842 | if (strhFindReplace(&pszText, &ulOfs, pcszSearch, pcszReplaceWith) > 0) | 
|---|
| 3843 | { | 
|---|
| 3844 | WinSetWindowText(hwnd, pszText); | 
|---|
| 3845 | brc = TRUE; | 
|---|
| 3846 | } | 
|---|
| 3847 | free(pszText); | 
|---|
| 3848 | } | 
|---|
| 3849 | return brc; | 
|---|
| 3850 | } | 
|---|
| 3851 |  | 
|---|
| 3852 | /* | 
|---|
| 3853 | *@@ winhEnableDlgItems: | 
|---|
| 3854 | *      this enables/disables a whole range of controls | 
|---|
| 3855 | *      in a window by enumerating the child windows | 
|---|
| 3856 | *      until usIDFirst is found. If so, that subwindow | 
|---|
| 3857 | *      is enabled/disabled and all the following windows | 
|---|
| 3858 | *      in the enumeration also, until usIDLast is found. | 
|---|
| 3859 | * | 
|---|
| 3860 | *      Note that this affects _all_ controls following | 
|---|
| 3861 | *      the usIDFirst window, no matter what ID they have | 
|---|
| 3862 | *      (even if "-1"), until usIDLast is found. | 
|---|
| 3863 | * | 
|---|
| 3864 | *      Returns the no. of controls which were enabled/disabled | 
|---|
| 3865 | *      (null if none). | 
|---|
| 3866 | * | 
|---|
| 3867 | *@@added V0.9.0 [umoeller] | 
|---|
| 3868 | *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems | 
|---|
| 3869 | */ | 
|---|
| 3870 |  | 
|---|
| 3871 | ULONG winhEnableControls(HWND hwndDlg,                  // in: dialog window | 
|---|
| 3872 | USHORT usIDFirst,              // in: first affected control ID | 
|---|
| 3873 | USHORT usIDLast,               // in: last affected  control ID (inclusive) | 
|---|
| 3874 | BOOL fEnable)                  // in: enable or disable? | 
|---|
| 3875 | { | 
|---|
| 3876 | HENUM   henum1 = NULLHANDLE; | 
|---|
| 3877 | HWND    hwndThis = NULLHANDLE; | 
|---|
| 3878 | ULONG   ulCount = 0; | 
|---|
| 3879 |  | 
|---|
| 3880 | henum1 = WinBeginEnumWindows(hwndDlg); | 
|---|
| 3881 | while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE) | 
|---|
| 3882 | { | 
|---|
| 3883 | USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID), | 
|---|
| 3884 | usIDCheckLast; | 
|---|
| 3885 | if (usIDCheckFirst == usIDFirst) | 
|---|
| 3886 | { | 
|---|
| 3887 | WinEnableWindow(hwndThis, fEnable); | 
|---|
| 3888 | ulCount++; | 
|---|
| 3889 |  | 
|---|
| 3890 | while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE) | 
|---|
| 3891 | { | 
|---|
| 3892 | WinEnableWindow(hwndThis, fEnable); | 
|---|
| 3893 | ulCount++; | 
|---|
| 3894 | usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID); | 
|---|
| 3895 | if (usIDCheckLast == usIDLast) | 
|---|
| 3896 | break; | 
|---|
| 3897 | } | 
|---|
| 3898 |  | 
|---|
| 3899 | break;  // outer loop | 
|---|
| 3900 | } | 
|---|
| 3901 | } | 
|---|
| 3902 | WinEndEnumWindows(henum1); | 
|---|
| 3903 |  | 
|---|
| 3904 | return ulCount; | 
|---|
| 3905 | } | 
|---|
| 3906 |  | 
|---|
| 3907 | /* | 
|---|
| 3908 | *@@ winhEnableControls2: | 
|---|
| 3909 | *      like winhEnableControls, but instead this | 
|---|
| 3910 | *      takes an array of ULONGs as input, which | 
|---|
| 3911 | *      is assumed to contain the dialog IDs of | 
|---|
| 3912 | *      the controls to be enabled/disabled. | 
|---|
| 3913 | * | 
|---|
| 3914 | *@@added V0.9.19 (2002-05-28) [umoeller] | 
|---|
| 3915 | */ | 
|---|
| 3916 |  | 
|---|
| 3917 | ULONG winhEnableControls2(HWND hwndDlg,             // in: dialog window | 
|---|
| 3918 | const ULONG *paulIDs,     // in: array of dialog IDs | 
|---|
| 3919 | ULONG cIDs,               // in: array item count (NOT array size) | 
|---|
| 3920 | BOOL fEnable)             // in: enable or disable? | 
|---|
| 3921 | { | 
|---|
| 3922 | ULONG   ul, | 
|---|
| 3923 | ulrc = 0; | 
|---|
| 3924 | for (ul = 0; | 
|---|
| 3925 | ul < cIDs; | 
|---|
| 3926 | ++ul) | 
|---|
| 3927 | { | 
|---|
| 3928 | if (WinEnableControl(hwndDlg, paulIDs[ul], fEnable)) | 
|---|
| 3929 | ++ulrc; | 
|---|
| 3930 | } | 
|---|
| 3931 |  | 
|---|
| 3932 | return ulrc; | 
|---|
| 3933 | } | 
|---|
| 3934 |  | 
|---|
| 3935 | /* | 
|---|
| 3936 | *@@ winhCreateStdWindow: | 
|---|
| 3937 | *      much like WinCreateStdWindow, but this one | 
|---|
| 3938 | *      allows you to have the standard window | 
|---|
| 3939 | *      positioned automatically, using a given | 
|---|
| 3940 | *      SWP structure (*pswpFrame). | 
|---|
| 3941 | * | 
|---|
| 3942 | *      The frame is created with the specified parent | 
|---|
| 3943 | *      (usually HWND_DESKTOP), but no owner. | 
|---|
| 3944 | * | 
|---|
| 3945 | *      The client window is created with the frame as | 
|---|
| 3946 | *      its parent and owner and gets an ID of FID_CLIENT. | 
|---|
| 3947 | * | 
|---|
| 3948 | *      Alternatively, you can set pswpFrame to NULL | 
|---|
| 3949 | *      and specify FCF_SHELLPOSITION with flFrameCreateFlags. | 
|---|
| 3950 | *      If you want the window to be shown, specify | 
|---|
| 3951 | *      SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame. | 
|---|
| 3952 | * | 
|---|
| 3953 | *@@added V0.9.0 [umoeller] | 
|---|
| 3954 | *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed | 
|---|
| 3955 | *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window | 
|---|
| 3956 | */ | 
|---|
| 3957 |  | 
|---|
| 3958 | HWND winhCreateStdWindow(HWND hwndFrameParent,      // in: normally HWND_DESKTOP | 
|---|
| 3959 | PSWP pswpFrame,            // in: frame wnd pos (ptr can be NULL) | 
|---|
| 3960 | ULONG flFrameCreateFlags,  // in: FCF_* flags | 
|---|
| 3961 | ULONG ulFrameStyle,        // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE) | 
|---|
| 3962 | const char *pcszFrameTitle, // in: frame title (title bar) | 
|---|
| 3963 | ULONG ulResourcesID,       // in: according to FCF_* flags | 
|---|
| 3964 | const char *pcszClassClient, // in: client class name | 
|---|
| 3965 | ULONG flStyleClient,       // in: client style | 
|---|
| 3966 | ULONG ulID,                // in: frame window ID | 
|---|
| 3967 | PVOID pClientCtlData,      // in: pCtlData structure pointer for client | 
|---|
| 3968 | PHWND phwndClient)         // out: created client wnd | 
|---|
| 3969 | { | 
|---|
| 3970 | FRAMECDATA  fcdata; | 
|---|
| 3971 | HWND        hwndFrame; | 
|---|
| 3972 | RECTL       rclClient; | 
|---|
| 3973 |  | 
|---|
| 3974 | fcdata.cb            = sizeof(FRAMECDATA); | 
|---|
| 3975 | fcdata.flCreateFlags = flFrameCreateFlags; | 
|---|
| 3976 | fcdata.hmodResources = (HMODULE)NULL; | 
|---|
| 3977 | fcdata.idResources   = ulResourcesID; | 
|---|
| 3978 |  | 
|---|
| 3979 | /* Create the frame and client windows.  */ | 
|---|
| 3980 | hwndFrame = WinCreateWindow(hwndFrameParent, | 
|---|
| 3981 | WC_FRAME, | 
|---|
| 3982 | (PSZ)pcszFrameTitle, | 
|---|
| 3983 | ulFrameStyle, | 
|---|
| 3984 | 0,0,0,0,         // size and position = 0 | 
|---|
| 3985 | NULLHANDLE,      // no owner | 
|---|
| 3986 | HWND_TOP,        // z-order | 
|---|
| 3987 | ulID,            // frame window ID | 
|---|
| 3988 | &fcdata,         // frame class data | 
|---|
| 3989 | NULL);           // no presparams | 
|---|
| 3990 |  | 
|---|
| 3991 | if (hwndFrame) | 
|---|
| 3992 | { | 
|---|
| 3993 | if (*phwndClient = WinCreateWindow(hwndFrame,      // parent | 
|---|
| 3994 | (PSZ)pcszClassClient, // class | 
|---|
| 3995 | NULL,           // no title | 
|---|
| 3996 | flStyleClient,  // style | 
|---|
| 3997 | 0,0,0,0,        // size and position = 0 | 
|---|
| 3998 | hwndFrame,      // owner | 
|---|
| 3999 | HWND_BOTTOM,    // bottom z-order | 
|---|
| 4000 | FID_CLIENT,     // frame window ID | 
|---|
| 4001 | pClientCtlData, // class data | 
|---|
| 4002 | NULL))          // no presparams | 
|---|
| 4003 | { | 
|---|
| 4004 | if (pswpFrame) | 
|---|
| 4005 | { | 
|---|
| 4006 | // position frame | 
|---|
| 4007 | WinSetWindowPos(hwndFrame, | 
|---|
| 4008 | pswpFrame->hwndInsertBehind, | 
|---|
| 4009 | pswpFrame->x, | 
|---|
| 4010 | pswpFrame->y, | 
|---|
| 4011 | pswpFrame->cx, | 
|---|
| 4012 | pswpFrame->cy, | 
|---|
| 4013 | pswpFrame->fl); | 
|---|
| 4014 |  | 
|---|
| 4015 | // position client | 
|---|
| 4016 | // WinQueryWindowRect(hwndFrame, &rclClient); | 
|---|
| 4017 | // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller] | 
|---|
| 4018 | rclClient.xLeft = 0; | 
|---|
| 4019 | rclClient.yBottom = 0; | 
|---|
| 4020 | rclClient.xRight = pswpFrame->cx; | 
|---|
| 4021 | rclClient.yTop = pswpFrame->cy; | 
|---|
| 4022 | WinCalcFrameRect(hwndFrame, | 
|---|
| 4023 | &rclClient, | 
|---|
| 4024 | TRUE);     // calc client from frame | 
|---|
| 4025 | WinSetWindowPos(*phwndClient, | 
|---|
| 4026 | HWND_TOP, | 
|---|
| 4027 | rclClient.xLeft, | 
|---|
| 4028 | rclClient.yBottom, | 
|---|
| 4029 | rclClient.xRight - rclClient.xLeft, | 
|---|
| 4030 | rclClient.yTop - rclClient.yBottom, | 
|---|
| 4031 | SWP_MOVE | SWP_SIZE | SWP_SHOW); | 
|---|
| 4032 | } | 
|---|
| 4033 | } | 
|---|
| 4034 | } | 
|---|
| 4035 |  | 
|---|
| 4036 | return hwndFrame; | 
|---|
| 4037 | } | 
|---|
| 4038 |  | 
|---|
| 4039 | /* | 
|---|
| 4040 | *@@ winhCreateObjectWindow: | 
|---|
| 4041 | *      creates an object window of the specified | 
|---|
| 4042 | *      window class, which you should have registered | 
|---|
| 4043 | *      before calling this. pvCreateParam will be | 
|---|
| 4044 | *      given to the window on WM_CREATE. | 
|---|
| 4045 | * | 
|---|
| 4046 | *      Returns the HWND of the object window or | 
|---|
| 4047 | *      NULLHANDLE on errors. | 
|---|
| 4048 | * | 
|---|
| 4049 | *@@added V0.9.3 (2000-04-17) [umoeller] | 
|---|
| 4050 | *@@changed V0.9.7 (2001-01-17) [umoeller]: made this a function from a macro | 
|---|
| 4051 | */ | 
|---|
| 4052 |  | 
|---|
| 4053 | HWND winhCreateObjectWindow(const char *pcszWindowClass,    // in: PM window class name | 
|---|
| 4054 | PVOID pvCreateParam)            // in: create param | 
|---|
| 4055 | { | 
|---|
| 4056 | return WinCreateWindow(HWND_OBJECT, | 
|---|
| 4057 | (PSZ)pcszWindowClass, | 
|---|
| 4058 | (PSZ)"", | 
|---|
| 4059 | 0, | 
|---|
| 4060 | 0,0,0,0, | 
|---|
| 4061 | 0, | 
|---|
| 4062 | HWND_BOTTOM, | 
|---|
| 4063 | 0, | 
|---|
| 4064 | pvCreateParam, | 
|---|
| 4065 | NULL); | 
|---|
| 4066 | } | 
|---|
| 4067 |  | 
|---|
| 4068 | /* | 
|---|
| 4069 | *@@ winhCreateControl: | 
|---|
| 4070 | *      creates a control with a size and position of 0. | 
|---|
| 4071 | * | 
|---|
| 4072 | *@@added V0.9.9 (2001-03-13) [umoeller] | 
|---|
| 4073 | *@@changed V1.0.0 (2002-08-26) [umoeller]: added separate hwndOwner | 
|---|
| 4074 | */ | 
|---|
| 4075 |  | 
|---|
| 4076 | HWND winhCreateControl(HWND hwndParent,             // in: parent window | 
|---|
| 4077 | HWND hwndOwner,              // in: owner window | 
|---|
| 4078 | const char *pcszClass,       // in: window class (e.g. WC_BUTTON) | 
|---|
| 4079 | const char *pcszText,        // in: window title | 
|---|
| 4080 | ULONG ulStyle,               // in: control style | 
|---|
| 4081 | ULONG ulID)                  // in: control ID | 
|---|
| 4082 | { | 
|---|
| 4083 | return WinCreateWindow(hwndParent, | 
|---|
| 4084 | (PSZ)pcszClass, | 
|---|
| 4085 | (PSZ)pcszText, | 
|---|
| 4086 | ulStyle, | 
|---|
| 4087 | 0, 0, 0, 0, | 
|---|
| 4088 | hwndOwner, | 
|---|
| 4089 | HWND_TOP, | 
|---|
| 4090 | ulID, | 
|---|
| 4091 | NULL, | 
|---|
| 4092 | NULL); | 
|---|
| 4093 | } | 
|---|
| 4094 |  | 
|---|
| 4095 | /* | 
|---|
| 4096 | *@@ winhRepaintWindows: | 
|---|
| 4097 | *      this repaints all children of hwndParent. | 
|---|
| 4098 | *      If this is passed as HWND_DESKTOP, the | 
|---|
| 4099 | *      whole screen is repainted. | 
|---|
| 4100 | * | 
|---|
| 4101 | *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed | 
|---|
| 4102 | */ | 
|---|
| 4103 |  | 
|---|
| 4104 | VOID winhRepaintWindows(HWND hwndParent) | 
|---|
| 4105 | { | 
|---|
| 4106 | HWND    hwndTop; | 
|---|
| 4107 | HENUM   henum = WinBeginEnumWindows(hwndParent); | 
|---|
| 4108 | while ((hwndTop = WinGetNextWindow(henum))) | 
|---|
| 4109 | if (WinIsWindowShowing(hwndTop)) | 
|---|
| 4110 | WinInvalidateRect(hwndTop, NULL, TRUE); | 
|---|
| 4111 | WinEndEnumWindows(henum); | 
|---|
| 4112 | } | 
|---|
| 4113 |  | 
|---|
| 4114 | /* | 
|---|
| 4115 | *@@ winhFindMsgQueue: | 
|---|
| 4116 | *      returns the message queue which matches | 
|---|
| 4117 | *      the given process and thread IDs. Since, | 
|---|
| 4118 | *      per IBM definition, every thread may only | 
|---|
| 4119 | *      have one MQ, this should be unique. | 
|---|
| 4120 | * | 
|---|
| 4121 | *@@added V0.9.2 (2000-03-08) [umoeller] | 
|---|
| 4122 | */ | 
|---|
| 4123 |  | 
|---|
| 4124 | HMQ winhFindMsgQueue(PID pid,           // in: process ID | 
|---|
| 4125 | TID tid,           // in: thread ID | 
|---|
| 4126 | HAB* phab)         // out: anchor block | 
|---|
| 4127 | { | 
|---|
| 4128 | HWND    hwndThis = 0, | 
|---|
| 4129 | rc = 0; | 
|---|
| 4130 | HENUM   henum = WinBeginEnumWindows(HWND_OBJECT); | 
|---|
| 4131 | while ((hwndThis = WinGetNextWindow(henum))) | 
|---|
| 4132 | { | 
|---|
| 4133 | CHAR    szClass[200]; | 
|---|
| 4134 | if (WinQueryClassName(hwndThis, sizeof(szClass), szClass)) | 
|---|
| 4135 | { | 
|---|
| 4136 | if (strcmp(szClass, "#32767") == 0) | 
|---|
| 4137 | { | 
|---|
| 4138 | // message queue window: | 
|---|
| 4139 | PID pidWin = 0; | 
|---|
| 4140 | TID tidWin = 0; | 
|---|
| 4141 | WinQueryWindowProcess(hwndThis, | 
|---|
| 4142 | &pidWin, | 
|---|
| 4143 | &tidWin); | 
|---|
| 4144 | if (    (pidWin == pid) | 
|---|
| 4145 | && (tidWin == tid) | 
|---|
| 4146 | ) | 
|---|
| 4147 | { | 
|---|
| 4148 | // get HMQ from window words | 
|---|
| 4149 | rc = WinQueryWindowULong(hwndThis, QWL_HMQ); | 
|---|
| 4150 | if (rc) | 
|---|
| 4151 | if (phab) | 
|---|
| 4152 | *phab = WinQueryAnchorBlock(hwndThis); | 
|---|
| 4153 | break; | 
|---|
| 4154 | } | 
|---|
| 4155 | } | 
|---|
| 4156 | } | 
|---|
| 4157 | } | 
|---|
| 4158 | WinEndEnumWindows(henum); | 
|---|
| 4159 |  | 
|---|
| 4160 | return rc; | 
|---|
| 4161 | } | 
|---|
| 4162 |  | 
|---|
| 4163 | /* | 
|---|
| 4164 | *@@ winhFindHardErrorWindow: | 
|---|
| 4165 | *      this searches all children of HWND_OBJECT | 
|---|
| 4166 | *      for the PM hard error windows, which are | 
|---|
| 4167 | *      invisible most of the time. When a hard | 
|---|
| 4168 | *      error occurs, that window is made a child | 
|---|
| 4169 | *      of HWND_DESKTOP instead. | 
|---|
| 4170 | * | 
|---|
| 4171 | *      Stolen from ProgramCommander/2 (C) Roman Stangl. | 
|---|
| 4172 | * | 
|---|
| 4173 | *@@added V0.9.3 (2000-04-27) [umoeller] | 
|---|
| 4174 | */ | 
|---|
| 4175 |  | 
|---|
| 4176 | VOID winhFindPMErrorWindows(HWND *phwndHardError,  // out: hard error window | 
|---|
| 4177 | HWND *phwndSysError)   // out: system error window | 
|---|
| 4178 | { | 
|---|
| 4179 | PID     pidObject;  // HWND_OBJECT's process and thread id | 
|---|
| 4180 | TID     tidObject; | 
|---|
| 4181 | PID     pidObjectChild;     // HWND_OBJECT's child window process and thread id | 
|---|
| 4182 | TID     tidObjectChild; | 
|---|
| 4183 | HENUM   henumObject;  // HWND_OBJECT enumeration handle | 
|---|
| 4184 | HWND    hwndObjectChild;   // Window handle of current HWND_OBJECT child | 
|---|
| 4185 | UCHAR   ucClassName[32];  // Window class e.g. #1 for WC_FRAME | 
|---|
| 4186 | CLASSINFO classinfoWindow;  // Class info of current HWND_OBJECT child | 
|---|
| 4187 |  | 
|---|
| 4188 | *phwndHardError = NULLHANDLE; | 
|---|
| 4189 | *phwndSysError = NULLHANDLE; | 
|---|
| 4190 |  | 
|---|
| 4191 | // query HWND_OBJECT's window process | 
|---|
| 4192 | WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject); | 
|---|
| 4193 | // enumerate all child windows of HWND_OBJECT | 
|---|
| 4194 | henumObject = WinBeginEnumWindows(HWND_OBJECT); | 
|---|
| 4195 | while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE) | 
|---|
| 4196 | { | 
|---|
| 4197 | // see if the current HWND_OBJECT child window runs in the | 
|---|
| 4198 | // process of HWND_OBJECT (PM) | 
|---|
| 4199 | WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild); | 
|---|
| 4200 | if (pidObject == pidObjectChild) | 
|---|
| 4201 | { | 
|---|
| 4202 | // get the child window's data | 
|---|
| 4203 | WinQueryClassName(hwndObjectChild, | 
|---|
| 4204 | sizeof(ucClassName), | 
|---|
| 4205 | (PCH)ucClassName); | 
|---|
| 4206 | WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild), | 
|---|
| 4207 | (PSZ)ucClassName, | 
|---|
| 4208 | &classinfoWindow); | 
|---|
| 4209 | if (    (!strcmp((PSZ)ucClassName, "#1") | 
|---|
| 4210 | || (classinfoWindow.flClassStyle & CS_FRAME)) | 
|---|
| 4211 | ) | 
|---|
| 4212 | { | 
|---|
| 4213 | // if the child window is a frame window and running in | 
|---|
| 4214 | // HWND_OBJECT's (PM's) window process, it must be the | 
|---|
| 4215 | // PM Hard Error or System Error window | 
|---|
| 4216 | WinQueryClassName(WinWindowFromID(hwndObjectChild, | 
|---|
| 4217 | FID_CLIENT), | 
|---|
| 4218 | sizeof(ucClassName), | 
|---|
| 4219 | (PSZ)ucClassName); | 
|---|
| 4220 | if (!strcmp((PSZ)ucClassName, "PM Hard Error")) | 
|---|
| 4221 | { | 
|---|
| 4222 | *phwndHardError = hwndObjectChild; | 
|---|
| 4223 | if (*phwndSysError) | 
|---|
| 4224 | // we found the other one already: | 
|---|
| 4225 | // stop searching, we got both | 
|---|
| 4226 | break; | 
|---|
| 4227 | } | 
|---|
| 4228 | else | 
|---|
| 4229 | { | 
|---|
| 4230 | printf("Utility: Found System Error %08X\n", (int)hwndObjectChild); | 
|---|
| 4231 | *phwndSysError = hwndObjectChild; | 
|---|
| 4232 | if (*phwndHardError) | 
|---|
| 4233 | // we found the other one already: | 
|---|
| 4234 | // stop searching, we got both | 
|---|
| 4235 | break; | 
|---|
| 4236 | } | 
|---|
| 4237 | } | 
|---|
| 4238 | } // end if (pidObject == pidObjectChild) | 
|---|
| 4239 | } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE) | 
|---|
| 4240 | WinEndEnumWindows(henumObject); | 
|---|
| 4241 | } | 
|---|
| 4242 |  | 
|---|
| 4243 | /* | 
|---|
| 4244 | *@@ winhCreateFakeDesktop: | 
|---|
| 4245 | *      this routine creates and displays a frameless window over | 
|---|
| 4246 | *      the whole screen in the color of PM's Desktop to fool the | 
|---|
| 4247 | *      user that all windows have been closed (which in fact might | 
|---|
| 4248 | *      not be the case). | 
|---|
| 4249 | * | 
|---|
| 4250 | *      This window's background color is set to the Desktop's | 
|---|
| 4251 | *      (PM's one, not the WPS's one). | 
|---|
| 4252 | * | 
|---|
| 4253 | *      Returns the HWND of this window. | 
|---|
| 4254 | */ | 
|---|
| 4255 |  | 
|---|
| 4256 | HWND winhCreateFakeDesktop(HWND hwndSibling) | 
|---|
| 4257 | { | 
|---|
| 4258 | // presparam for background | 
|---|
| 4259 | typedef struct _BACKGROUND | 
|---|
| 4260 | { | 
|---|
| 4261 | ULONG   cb;     // length of the aparam parameter, in bytes | 
|---|
| 4262 | ULONG   id;     // attribute type identity | 
|---|
| 4263 | ULONG   cb2;    // byte count of the ab parameter | 
|---|
| 4264 | RGB     rgb;    // attribute value | 
|---|
| 4265 | } BACKGROUND; | 
|---|
| 4266 |  | 
|---|
| 4267 | BACKGROUND  background; | 
|---|
| 4268 | LONG        lDesktopColor; | 
|---|
| 4269 |  | 
|---|
| 4270 | // create fake desktop window = empty window with | 
|---|
| 4271 | // the size of full screen | 
|---|
| 4272 | lDesktopColor = WinQuerySysColor(HWND_DESKTOP, | 
|---|
| 4273 | SYSCLR_BACKGROUND, | 
|---|
| 4274 | 0); | 
|---|
| 4275 | background.cb = sizeof(background.id) | 
|---|
| 4276 | + sizeof(background.cb) | 
|---|
| 4277 | + sizeof(background.rgb); | 
|---|
| 4278 | background.id = PP_BACKGROUNDCOLOR; | 
|---|
| 4279 | background.cb2 = sizeof(RGB); | 
|---|
| 4280 | background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor)); | 
|---|
| 4281 | background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor)); | 
|---|
| 4282 | background.rgb.bRed  = (CHAR3FROMMP(lDesktopColor)); | 
|---|
| 4283 |  | 
|---|
| 4284 | return WinCreateWindow(HWND_DESKTOP,  // parent window | 
|---|
| 4285 | WC_FRAME,      // class name | 
|---|
| 4286 | "",            // window text | 
|---|
| 4287 | WS_VISIBLE,    // window style | 
|---|
| 4288 | 0, 0,          // position and size | 
|---|
| 4289 | WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN), | 
|---|
| 4290 | WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN), | 
|---|
| 4291 | NULLHANDLE,    // owner window | 
|---|
| 4292 | hwndSibling,   // sibling window | 
|---|
| 4293 | 1,             // window id | 
|---|
| 4294 | NULL,          // control data | 
|---|
| 4295 | &background); // presentation parms | 
|---|
| 4296 | } | 
|---|
| 4297 |  | 
|---|
| 4298 | /* | 
|---|
| 4299 | *@@ winhAssertWarp4Notebook: | 
|---|
| 4300 | *      this takes hwndDlg as a notebook dialog page and | 
|---|
| 4301 | *      goes thru all its controls. If a control with an | 
|---|
| 4302 | *      ID <= udIdThreshold is found, this is assumed to | 
|---|
| 4303 | *      be a button which is to be given the BS_NOTEBOOKBUTTON | 
|---|
| 4304 | *      style. You should therefore give all your button | 
|---|
| 4305 | *      controls which should be moved such an ID. | 
|---|
| 4306 | * | 
|---|
| 4307 | *      Note that this function will now automatically | 
|---|
| 4308 | *      find out the lowest y coordinate that was used | 
|---|
| 4309 | *      for a non-notebook button and move all controls | 
|---|
| 4310 | *      down accordingly. As a result, ulDownUnit must | 
|---|
| 4311 | *      no longer be specified (V0.9.19). | 
|---|
| 4312 | * | 
|---|
| 4313 | *      This function is useful if you wish to create | 
|---|
| 4314 | *      notebook pages using dlgedit.exe which are compatible | 
|---|
| 4315 | *      with both Warp 3 and Warp 4. This should be executed | 
|---|
| 4316 | *      in WM_INITDLG of the notebook dlg function if the app | 
|---|
| 4317 | *      has determined that it is running on Warp 4. | 
|---|
| 4318 | * | 
|---|
| 4319 | *@@changed V0.9.16 (2002-02-02) [umoeller]: fixed entry fields | 
|---|
| 4320 | *@@changed V0.9.19 (2002-04-24) [umoeller]: removed ulDownUnits | 
|---|
| 4321 | *@@changed V0.9.19 (2002-05-02) [umoeller]: fix for combobox | 
|---|
| 4322 | */ | 
|---|
| 4323 |  | 
|---|
| 4324 | BOOL winhAssertWarp4Notebook(HWND hwndDlg, | 
|---|
| 4325 | USHORT usIdThreshold)  // in: ID threshold | 
|---|
| 4326 | { | 
|---|
| 4327 | BOOL brc = FALSE; | 
|---|
| 4328 |  | 
|---|
| 4329 | if (doshIsWarp4()) | 
|---|
| 4330 | { | 
|---|
| 4331 | LONG    yLowest = 10000; | 
|---|
| 4332 | HWND    hwndItem; | 
|---|
| 4333 | HENUM   henum = 0; | 
|---|
| 4334 | PSWP    paswp, | 
|---|
| 4335 | pswpThis; | 
|---|
| 4336 | ULONG   cWindows = 0, | 
|---|
| 4337 | ul; | 
|---|
| 4338 |  | 
|---|
| 4339 | BOOL    fIsVisible; | 
|---|
| 4340 |  | 
|---|
| 4341 | if (fIsVisible = WinIsWindowVisible(hwndDlg)) | 
|---|
| 4342 | // avoid flicker | 
|---|
| 4343 | WinEnableWindowUpdate(hwndDlg, FALSE); | 
|---|
| 4344 |  | 
|---|
| 4345 | if (paswp = (PSWP)malloc(sizeof(SWP) * 100)) | 
|---|
| 4346 | { | 
|---|
| 4347 | pswpThis = paswp; | 
|---|
| 4348 |  | 
|---|
| 4349 | // loop 1: set notebook buttons, find lowest y used | 
|---|
| 4350 | henum = WinBeginEnumWindows(hwndDlg); | 
|---|
| 4351 | while ((hwndItem = WinGetNextWindow(henum))) | 
|---|
| 4352 | { | 
|---|
| 4353 | USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID); | 
|---|
| 4354 | // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId)); | 
|---|
| 4355 | if (usId <= usIdThreshold) | 
|---|
| 4356 | { | 
|---|
| 4357 | // pushbutton to change: | 
|---|
| 4358 | WinSetWindowBits(hwndItem, | 
|---|
| 4359 | QWL_STYLE, | 
|---|
| 4360 | BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON); | 
|---|
| 4361 | brc = TRUE; | 
|---|
| 4362 | } | 
|---|
| 4363 | else | 
|---|
| 4364 | { | 
|---|
| 4365 | // no pushbutton to change: | 
|---|
| 4366 | CHAR szClass[10]; | 
|---|
| 4367 |  | 
|---|
| 4368 | WinQueryWindowPos(hwndItem, pswpThis); | 
|---|
| 4369 |  | 
|---|
| 4370 | // special handling for entry fields | 
|---|
| 4371 | // V0.9.16 (2002-02-02) [umoeller] | 
|---|
| 4372 | WinQueryClassName(hwndItem, sizeof(szClass), szClass); | 
|---|
| 4373 | if (!strcmp(szClass, "#6")) | 
|---|
| 4374 | { | 
|---|
| 4375 | pswpThis->x += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER); | 
|---|
| 4376 | pswpThis->y += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER); | 
|---|
| 4377 | } | 
|---|
| 4378 |  | 
|---|
| 4379 | // check lowest y | 
|---|
| 4380 | if (    (pswpThis->y < yLowest) | 
|---|
| 4381 | // ignore combobox, this will distort everything | 
|---|
| 4382 | // AGAIN ... sigh V0.9.19 (2002-05-02) [umoeller] | 
|---|
| 4383 | && (strcmp(szClass, "#2")) | 
|---|
| 4384 | ) | 
|---|
| 4385 | yLowest = pswpThis->y ; | 
|---|
| 4386 |  | 
|---|
| 4387 | ++pswpThis; | 
|---|
| 4388 | if (++cWindows == 100) | 
|---|
| 4389 | break; | 
|---|
| 4390 | } | 
|---|
| 4391 | } // end while ((hwndItem = WinGetNextWindow(henum))) | 
|---|
| 4392 | WinEndEnumWindows(henum); | 
|---|
| 4393 |  | 
|---|
| 4394 | // now adjust window positions | 
|---|
| 4395 | pswpThis = paswp; | 
|---|
| 4396 | for (ul = 0; | 
|---|
| 4397 | ul < cWindows; | 
|---|
| 4398 | ++ul, ++pswpThis) | 
|---|
| 4399 | { | 
|---|
| 4400 | pswpThis->y -= (yLowest - 8); | 
|---|
| 4401 | // 8 is magic to match the lower border of the | 
|---|
| 4402 | // standard WPS notebook pages V0.9.19 (2002-04-24) [umoeller] | 
|---|
| 4403 | pswpThis->fl = SWP_MOVE; | 
|---|
| 4404 | } | 
|---|
| 4405 |  | 
|---|
| 4406 | WinSetMultWindowPos(WinQueryAnchorBlock(hwndDlg), | 
|---|
| 4407 | paswp, | 
|---|
| 4408 | cWindows); | 
|---|
| 4409 |  | 
|---|
| 4410 | free(paswp); | 
|---|
| 4411 | } | 
|---|
| 4412 |  | 
|---|
| 4413 | if (fIsVisible) | 
|---|
| 4414 | WinShowWindow(hwndDlg, TRUE); | 
|---|
| 4415 | } | 
|---|
| 4416 |  | 
|---|
| 4417 | return brc; | 
|---|
| 4418 | } | 
|---|
| 4419 |  | 
|---|
| 4420 | /* | 
|---|
| 4421 | *@@ winhDrawFormattedText: | 
|---|
| 4422 | *      this func takes a rectangle and draws pszText into | 
|---|
| 4423 | *      it, breaking the words as neccessary. The line spacing | 
|---|
| 4424 | *      is determined from the font currently selected in hps. | 
|---|
| 4425 | * | 
|---|
| 4426 | *      As opposed to WinDrawText, this can draw several lines | 
|---|
| 4427 | *      at once, and format the _complete_ text according to the | 
|---|
| 4428 | *      flCmd parameter, which is like with WinDrawText. | 
|---|
| 4429 | * | 
|---|
| 4430 | *      After this function returns, *prcl is modified like this: | 
|---|
| 4431 | * | 
|---|
| 4432 | *      -- yTop and yBottom contain the upper and lower boundaries | 
|---|
| 4433 | *         which were needed to draw the text. This depends on | 
|---|
| 4434 | *         whether DT_TOP etc. were specified. | 
|---|
| 4435 | *         To get the height of the rectangle used, calculate the | 
|---|
| 4436 | *         delta between yTop and yBottom. | 
|---|
| 4437 | * | 
|---|
| 4438 | *      -- xLeft and xRight are modified to contain the outmost | 
|---|
| 4439 | *         left and right coordinates which were needed to draw | 
|---|
| 4440 | *         the text. This will be set to the longest line which | 
|---|
| 4441 | *         was encountered. | 
|---|
| 4442 | * | 
|---|
| 4443 | *      You can specify DT_QUERYEXTENT with flDraw to only have | 
|---|
| 4444 | *      these text boundaries calculated without actually drawing. | 
|---|
| 4445 | * | 
|---|
| 4446 | *      This returns the number of lines drawn. | 
|---|
| 4447 | * | 
|---|
| 4448 | *      Note that this calls WinDrawText with DT_TEXTATTRS set, | 
|---|
| 4449 | *      that is, the current text primitive attributes will be | 
|---|
| 4450 | *      used (fonts and colors). | 
|---|
| 4451 | * | 
|---|
| 4452 | *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return | 
|---|
| 4453 | */ | 
|---|
| 4454 |  | 
|---|
| 4455 | ULONG winhDrawFormattedText(HPS hps,     // in: presentation space; its settings | 
|---|
| 4456 | // are used, but not altered | 
|---|
| 4457 | PRECTL prcl, // in/out: rectangle to use for drawing | 
|---|
| 4458 | // (modified) | 
|---|
| 4459 | const char *pcszText, // in: text to draw (zero-terminated) | 
|---|
| 4460 | ULONG flCmd) // in: flags like in WinDrawText; I have | 
|---|
| 4461 | // only tested DT_TOP and DT_LEFT though. | 
|---|
| 4462 | // DT_WORDBREAK | DT_TEXTATTRS are always | 
|---|
| 4463 | // set. | 
|---|
| 4464 | // You can specify DT_QUERYEXTENT to only | 
|---|
| 4465 | // have prcl calculated without drawing. | 
|---|
| 4466 | { | 
|---|
| 4467 | PSZ     p = (PSZ)pcszText; | 
|---|
| 4468 | LONG    lDrawn = 1, | 
|---|
| 4469 | lTotalDrawn = 0, | 
|---|
| 4470 | lLineCount = 0, | 
|---|
| 4471 | lOrigYTop = prcl->yTop; | 
|---|
| 4472 | ULONG   ulTextLen = strlen(pcszText), | 
|---|
| 4473 | ulCharHeight, | 
|---|
| 4474 | flCmd2, | 
|---|
| 4475 | xLeftmost = prcl->xRight, | 
|---|
| 4476 | xRightmost = prcl->xLeft; | 
|---|
| 4477 | RECTL   rcl2; | 
|---|
| 4478 |  | 
|---|
| 4479 | flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS; | 
|---|
| 4480 |  | 
|---|
| 4481 | ulCharHeight = gpihQueryLineSpacing(hps); | 
|---|
| 4482 |  | 
|---|
| 4483 | while (    (lDrawn) | 
|---|
| 4484 | && (lTotalDrawn < ulTextLen) | 
|---|
| 4485 | ) | 
|---|
| 4486 | { | 
|---|
| 4487 | memcpy(&rcl2, prcl, sizeof(rcl2)); | 
|---|
| 4488 | lDrawn = WinDrawText(hps, | 
|---|
| 4489 | ulTextLen-lTotalDrawn, | 
|---|
| 4490 | p, | 
|---|
| 4491 | &rcl2, | 
|---|
| 4492 | 0, 0,                       // colors | 
|---|
| 4493 | flCmd2); | 
|---|
| 4494 |  | 
|---|
| 4495 | // update char counters | 
|---|
| 4496 | p += lDrawn; | 
|---|
| 4497 | lTotalDrawn += lDrawn; | 
|---|
| 4498 |  | 
|---|
| 4499 | // update x extents | 
|---|
| 4500 | if (rcl2.xLeft < xLeftmost) | 
|---|
| 4501 | xLeftmost = rcl2.xLeft; | 
|---|
| 4502 | if (rcl2.xRight > xRightmost) | 
|---|
| 4503 | xRightmost = rcl2.xRight; | 
|---|
| 4504 |  | 
|---|
| 4505 | // update y for next line | 
|---|
| 4506 | prcl->yTop -= ulCharHeight; | 
|---|
| 4507 |  | 
|---|
| 4508 | // increase line count | 
|---|
| 4509 | lLineCount++; | 
|---|
| 4510 | } | 
|---|
| 4511 | prcl->xLeft = xLeftmost; | 
|---|
| 4512 | prcl->xRight = xRightmost; | 
|---|
| 4513 | prcl->yBottom = prcl->yTop; | 
|---|
| 4514 | prcl->yTop = lOrigYTop; | 
|---|
| 4515 |  | 
|---|
| 4516 | return lLineCount; | 
|---|
| 4517 | } | 
|---|
| 4518 |  | 
|---|
| 4519 | /* | 
|---|
| 4520 | *@@ winhQuerySwitchList: | 
|---|
| 4521 | *      returns the switch list in a newly | 
|---|
| 4522 | *      allocated buffer. This does the | 
|---|
| 4523 | *      regular double WinQuerySwitchList | 
|---|
| 4524 | *      call to first get the no. of items | 
|---|
| 4525 | *      and then get the items. | 
|---|
| 4526 | * | 
|---|
| 4527 | *      The no. of items can be found in | 
|---|
| 4528 | *      the returned SWBLOCK.cwsentry. | 
|---|
| 4529 | * | 
|---|
| 4530 | *      Returns NULL on errors. Use | 
|---|
| 4531 | *      free() to free the return value. | 
|---|
| 4532 | * | 
|---|
| 4533 | *@@added V0.9.7 (2000-12-06) [umoeller] | 
|---|
| 4534 | */ | 
|---|
| 4535 |  | 
|---|
| 4536 | PSWBLOCK winhQuerySwitchList(HAB hab) | 
|---|
| 4537 | { | 
|---|
| 4538 | ULONG   cItems = WinQuerySwitchList(hab, NULL, 0); | 
|---|
| 4539 | ULONG   ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH); | 
|---|
| 4540 | PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize); | 
|---|
| 4541 | if (pSwBlock) | 
|---|
| 4542 | { | 
|---|
| 4543 | cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize); | 
|---|
| 4544 | if (!cItems) | 
|---|
| 4545 | { | 
|---|
| 4546 | free(pSwBlock); | 
|---|
| 4547 | pSwBlock = NULL; | 
|---|
| 4548 | } | 
|---|
| 4549 | } | 
|---|
| 4550 |  | 
|---|
| 4551 | return pSwBlock; | 
|---|
| 4552 | } | 
|---|
| 4553 |  | 
|---|
| 4554 | typedef HSWITCH APIENTRY WINHSWITCHFROMHAPP(HAPP happ); | 
|---|
| 4555 |  | 
|---|
| 4556 | /* | 
|---|
| 4557 | *@@ winhHSWITCHfromHAPP: | 
|---|
| 4558 | *      resolves and calls the undocumented | 
|---|
| 4559 | *      WinHSWITCHfromHAPP API. | 
|---|
| 4560 | * | 
|---|
| 4561 | *@@added V0.9.19 (2002-04-17) [umoeller] | 
|---|
| 4562 | */ | 
|---|
| 4563 |  | 
|---|
| 4564 | HSWITCH winhHSWITCHfromHAPP(HAPP happ) | 
|---|
| 4565 | { | 
|---|
| 4566 | static WINHSWITCHFROMHAPP *pWinHSWITCHfromHAPP = NULL; | 
|---|
| 4567 |  | 
|---|
| 4568 | if (!pWinHSWITCHfromHAPP) | 
|---|
| 4569 | // first call: import WinHSWITCHfromHAPP | 
|---|
| 4570 | // WinHSWITCHfromHAPP PMMERGE.5199 | 
|---|
| 4571 | doshQueryProcAddr("PMMERGE", | 
|---|
| 4572 | 5199, | 
|---|
| 4573 | (PFN*)&pWinHSWITCHfromHAPP); | 
|---|
| 4574 |  | 
|---|
| 4575 | if (pWinHSWITCHfromHAPP) | 
|---|
| 4576 | return pWinHSWITCHfromHAPP(happ); | 
|---|
| 4577 |  | 
|---|
| 4578 | return NULLHANDLE; | 
|---|
| 4579 | } | 
|---|
| 4580 |  | 
|---|
| 4581 | /* | 
|---|
| 4582 | *@@ winhQueryTasklistWindow: | 
|---|
| 4583 | *      returns the window handle of the PM task list. | 
|---|
| 4584 | * | 
|---|
| 4585 | *@@added V0.9.7 (2000-12-07) [umoeller] | 
|---|
| 4586 | */ | 
|---|
| 4587 |  | 
|---|
| 4588 | HWND winhQueryTasklistWindow(VOID) | 
|---|
| 4589 | { | 
|---|
| 4590 | SWBLOCK  swblock; | 
|---|
| 4591 |  | 
|---|
| 4592 | // the tasklist has entry #0 in the SWBLOCK | 
|---|
| 4593 | WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK)); | 
|---|
| 4594 |  | 
|---|
| 4595 | return swblock.aswentry[0].swctl.hwnd; | 
|---|
| 4596 | } | 
|---|
| 4597 |  | 
|---|
| 4598 | /* | 
|---|
| 4599 | *@@ winhKillTasklist: | 
|---|
| 4600 | *      this will destroy the Tasklist (window list) window. | 
|---|
| 4601 | *      Note: you will only be able to get it back after a | 
|---|
| 4602 | *      reboot, not a WPS restart. Only for use at shutdown and such. | 
|---|
| 4603 | *      This trick by Uri J. Stern at | 
|---|
| 4604 | *      http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML | 
|---|
| 4605 | */ | 
|---|
| 4606 |  | 
|---|
| 4607 | VOID winhKillTasklist(VOID) | 
|---|
| 4608 | { | 
|---|
| 4609 | HWND     hwndTasklist = winhQueryTasklistWindow(); | 
|---|
| 4610 | WinPostMsg(hwndTasklist, | 
|---|
| 4611 | 0x0454,     // undocumented msg for killing tasklist | 
|---|
| 4612 | NULL, NULL); | 
|---|
| 4613 | } | 
|---|
| 4614 |  | 
|---|
| 4615 | // the following must be added for EMX (99-10-22) [umoeller] | 
|---|
| 4616 | #ifndef NERR_BufTooSmall | 
|---|
| 4617 | #define NERR_BASE       2100 | 
|---|
| 4618 | #define NERR_BufTooSmall        (NERR_BASE+23) | 
|---|
| 4619 | // the API return buffer is too small | 
|---|
| 4620 | #endif | 
|---|
| 4621 |  | 
|---|
| 4622 | /* | 
|---|
| 4623 | *@@ winhQueryPendingSpoolJobs: | 
|---|
| 4624 | *      returns the number of pending print jobs in the spooler | 
|---|
| 4625 | *      or 0 if none. Useful for testing before shutdown. | 
|---|
| 4626 | */ | 
|---|
| 4627 |  | 
|---|
| 4628 | ULONG winhQueryPendingSpoolJobs(VOID) | 
|---|
| 4629 | { | 
|---|
| 4630 | // BOOL    rcPending = FALSE; | 
|---|
| 4631 | ULONG       ulTotalJobCount = 0; | 
|---|
| 4632 |  | 
|---|
| 4633 | SPLERR      splerr; | 
|---|
| 4634 | USHORT      jobCount; | 
|---|
| 4635 | ULONG       cbBuf; | 
|---|
| 4636 | ULONG       cTotal; | 
|---|
| 4637 | ULONG       cReturned; | 
|---|
| 4638 | ULONG       cbNeeded; | 
|---|
| 4639 | ULONG       ulLevel; | 
|---|
| 4640 | ULONG       i,j; | 
|---|
| 4641 | PSZ         pszComputerName; | 
|---|
| 4642 | PBYTE       pBuf = NULL; | 
|---|
| 4643 | PPRQINFO3   prq; | 
|---|
| 4644 | PPRJINFO2   prj2; | 
|---|
| 4645 |  | 
|---|
| 4646 | ulLevel = 4L; | 
|---|
| 4647 | pszComputerName = (PSZ)NULL; | 
|---|
| 4648 | splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf | 
|---|
| 4649 | &cReturned, &cTotal, | 
|---|
| 4650 | &cbNeeded, NULL); | 
|---|
| 4651 | if (    (splerr == ERROR_MORE_DATA) | 
|---|
| 4652 | || (splerr == NERR_BufTooSmall) | 
|---|
| 4653 | ) | 
|---|
| 4654 | { | 
|---|
| 4655 | if (!DosAllocMem((PPVOID)&pBuf, | 
|---|
| 4656 | cbNeeded, | 
|---|
| 4657 | PAG_READ | PAG_WRITE | PAG_COMMIT)) | 
|---|
| 4658 | { | 
|---|
| 4659 | cbBuf = cbNeeded; | 
|---|
| 4660 | splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf, | 
|---|
| 4661 | &cReturned, &cTotal, | 
|---|
| 4662 | &cbNeeded, NULL); | 
|---|
| 4663 | if (splerr == NO_ERROR) | 
|---|
| 4664 | { | 
|---|
| 4665 | // set pointer to point to the beginning of the buffer | 
|---|
| 4666 | prq = (PPRQINFO3)pBuf; | 
|---|
| 4667 |  | 
|---|
| 4668 | // cReturned has the count of the number of PRQINFO3 structures | 
|---|
| 4669 | for (i = 0; | 
|---|
| 4670 | i < cReturned; | 
|---|
| 4671 | i++) | 
|---|
| 4672 | { | 
|---|
| 4673 | // save the count of jobs; there are this many PRJINFO2 | 
|---|
| 4674 | // structures following the PRQINFO3 structure | 
|---|
| 4675 | jobCount = prq->cJobs; | 
|---|
| 4676 | // _Pmpf(( "Job count in this queue is %d",jobCount )); | 
|---|
| 4677 |  | 
|---|
| 4678 | // increment the pointer past the PRQINFO3 structure | 
|---|
| 4679 | prq++; | 
|---|
| 4680 |  | 
|---|
| 4681 | // set a pointer to point to the first PRJINFO2 structure | 
|---|
| 4682 | prj2=(PPRJINFO2)prq; | 
|---|
| 4683 | for (j = 0; | 
|---|
| 4684 | j < jobCount; | 
|---|
| 4685 | j++) | 
|---|
| 4686 | { | 
|---|
| 4687 | // increment the pointer to point to the next structure | 
|---|
| 4688 | prj2++; | 
|---|
| 4689 | // increase the job count, which we'll return | 
|---|
| 4690 | ulTotalJobCount++; | 
|---|
| 4691 |  | 
|---|
| 4692 | } // endfor jobCount | 
|---|
| 4693 |  | 
|---|
| 4694 | // after doing all the job structures, prj2 points to the next | 
|---|
| 4695 | // queue structure; set the pointer for a PRQINFO3 structure | 
|---|
| 4696 | prq = (PPRQINFO3)prj2; | 
|---|
| 4697 | } //endfor cReturned | 
|---|
| 4698 | } // endif NO_ERROR | 
|---|
| 4699 | DosFreeMem(pBuf); | 
|---|
| 4700 | } | 
|---|
| 4701 | } // end if Q level given | 
|---|
| 4702 |  | 
|---|
| 4703 | return ulTotalJobCount; | 
|---|
| 4704 | } | 
|---|
| 4705 |  | 
|---|
| 4706 | /* | 
|---|
| 4707 | *@@ winhSetNumLock: | 
|---|
| 4708 | *      this sets the NumLock key on or off, depending | 
|---|
| 4709 | *      on fState. | 
|---|
| 4710 | * | 
|---|
| 4711 | *      Based on code from WarpEnhancer, (C) Achim Hasenmller. | 
|---|
| 4712 | * | 
|---|
| 4713 | *@@added V0.9.1 (99-12-18) [umoeller] | 
|---|
| 4714 | */ | 
|---|
| 4715 |  | 
|---|
| 4716 | VOID winhSetNumLock(BOOL fState) | 
|---|
| 4717 | { | 
|---|
| 4718 | // BOOL  fRestoreKBD = FALSE;  //  Assume we're not going to close Kbd | 
|---|
| 4719 | BYTE KeyStateTable[256]; | 
|---|
| 4720 | ULONG ulActionTaken; //  Used by DosOpen | 
|---|
| 4721 | HFILE hKbd; | 
|---|
| 4722 |  | 
|---|
| 4723 | // read keyboard state table | 
|---|
| 4724 | if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], | 
|---|
| 4725 | FALSE)) | 
|---|
| 4726 | { | 
|---|
| 4727 | // first set the PM state | 
|---|
| 4728 | if (fState) | 
|---|
| 4729 | KeyStateTable[VK_NUMLOCK] |= 0x01; //  Turn numlock on | 
|---|
| 4730 | else | 
|---|
| 4731 | KeyStateTable[VK_NUMLOCK] &= 0xFE; //  Turn numlock off | 
|---|
| 4732 |  | 
|---|
| 4733 | // set keyboard state table with new state values | 
|---|
| 4734 | WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE); | 
|---|
| 4735 | } | 
|---|
| 4736 |  | 
|---|
| 4737 | // now set the OS/2 keyboard state | 
|---|
| 4738 |  | 
|---|
| 4739 | // try to open OS/2 keyboard driver | 
|---|
| 4740 | if (!DosOpen("KBD$", | 
|---|
| 4741 | &hKbd, &ulActionTaken, | 
|---|
| 4742 | 0,     // cbFile | 
|---|
| 4743 | FILE_NORMAL, | 
|---|
| 4744 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS, | 
|---|
| 4745 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE, | 
|---|
| 4746 | NULL)) | 
|---|
| 4747 | { | 
|---|
| 4748 | SHIFTSTATE ShiftState; | 
|---|
| 4749 | ULONG DataLen = sizeof(SHIFTSTATE); | 
|---|
| 4750 |  | 
|---|
| 4751 | memset(&ShiftState, '\0', DataLen); | 
|---|
| 4752 | DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE, | 
|---|
| 4753 | NULL, 0L, NULL, | 
|---|
| 4754 | &ShiftState, DataLen, &DataLen); | 
|---|
| 4755 |  | 
|---|
| 4756 | if (fState) | 
|---|
| 4757 | ShiftState.fsState |= 0x0020; // turn NumLock on | 
|---|
| 4758 | else | 
|---|
| 4759 | ShiftState.fsState &= 0xFFDF; // turn NumLock off | 
|---|
| 4760 |  | 
|---|
| 4761 | DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE, | 
|---|
| 4762 | &ShiftState, DataLen, &DataLen, | 
|---|
| 4763 | NULL, 0L, NULL); | 
|---|
| 4764 | // now close OS/2 keyboard driver | 
|---|
| 4765 | DosClose(hKbd); | 
|---|
| 4766 | } | 
|---|
| 4767 | return; | 
|---|
| 4768 | } | 
|---|
| 4769 |  | 
|---|
| 4770 | /* | 
|---|
| 4771 | *@@ winhSetClipboardText: | 
|---|
| 4772 | *      sets the clipboard data to the given text, | 
|---|
| 4773 | *      replacing the current clipboard contents. | 
|---|
| 4774 | * | 
|---|
| 4775 | *@@added V1.0.0 (2002-08-28) [umoeller] | 
|---|
| 4776 | */ | 
|---|
| 4777 |  | 
|---|
| 4778 | BOOL winhSetClipboardText(HAB hab, | 
|---|
| 4779 | PCSZ pcsz, | 
|---|
| 4780 | ULONG cbSize)     // in: size of buffer INCLUDING null byte | 
|---|
| 4781 | { | 
|---|
| 4782 | BOOL    fSuccess = FALSE; | 
|---|
| 4783 |  | 
|---|
| 4784 | if (WinOpenClipbrd(hab)) | 
|---|
| 4785 | { | 
|---|
| 4786 | PSZ pszDest; | 
|---|
| 4787 | if (!DosAllocSharedMem((PVOID*)&pszDest, | 
|---|
| 4788 | NULL, | 
|---|
| 4789 | cbSize, | 
|---|
| 4790 | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE)) | 
|---|
| 4791 | { | 
|---|
| 4792 | memcpy(pszDest, | 
|---|
| 4793 | pcsz, | 
|---|
| 4794 | cbSize); | 
|---|
| 4795 |  | 
|---|
| 4796 | WinEmptyClipbrd(hab); | 
|---|
| 4797 |  | 
|---|
| 4798 | fSuccess = WinSetClipbrdData(hab,       // anchor-block handle | 
|---|
| 4799 | (ULONG)pszDest, // pointer to text data | 
|---|
| 4800 | CF_TEXT,        // data is in text format | 
|---|
| 4801 | CFI_POINTER);   // passing a pointer | 
|---|
| 4802 |  | 
|---|
| 4803 | // PMREF says (implicitly) it is not necessary to call | 
|---|
| 4804 | // DosFreeMem. I hope that is correct. | 
|---|
| 4805 | // V0.9.19 (2002-06-02) [umoeller] | 
|---|
| 4806 | } | 
|---|
| 4807 |  | 
|---|
| 4808 | WinCloseClipbrd(hab); | 
|---|
| 4809 | } | 
|---|
| 4810 |  | 
|---|
| 4811 | return fSuccess; | 
|---|
| 4812 | } | 
|---|
| 4813 |  | 
|---|
| 4814 | /* | 
|---|
| 4815 | *@@category: Helpers\PM helpers\Extended frame windows | 
|---|
| 4816 | */ | 
|---|
| 4817 |  | 
|---|
| 4818 | /* ****************************************************************** | 
|---|
| 4819 | * | 
|---|
| 4820 | *   Extended frame | 
|---|
| 4821 | * | 
|---|
| 4822 | ********************************************************************/ | 
|---|
| 4823 |  | 
|---|
| 4824 | /* | 
|---|
| 4825 | *@@ winhCalcExtFrameRect: | 
|---|
| 4826 | *      implementation for WM_CALCFRAMERECT in fnwpSubclExtFrame. | 
|---|
| 4827 | *      This is exported so it can be used independently | 
|---|
| 4828 | *      (XWorkplace status bars). | 
|---|
| 4829 | * | 
|---|
| 4830 | *@@added V1.0.0 (2002-08-28) [umoeller] | 
|---|
| 4831 | */ | 
|---|
| 4832 |  | 
|---|
| 4833 | VOID winhCalcExtFrameRect(MPARAM mp1, | 
|---|
| 4834 | MPARAM mp2, | 
|---|
| 4835 | LONG lStatusBarHeight) | 
|---|
| 4836 | { | 
|---|
| 4837 | PRECTL prclPassed = (PRECTL)mp1; | 
|---|
| 4838 |  | 
|---|
| 4839 | // mp2 == TRUE:  Frame rectangle provided, calculate client | 
|---|
| 4840 | // mp2 == FALSE: Client area rectangle provided, calculate frame | 
|---|
| 4841 | if (mp2) | 
|---|
| 4842 | { | 
|---|
| 4843 | //  TRUE: calculate the rectl of the client; | 
|---|
| 4844 | //  call default window procedure to subtract child frame | 
|---|
| 4845 | //  controls from the rectangle's height | 
|---|
| 4846 | LONG lClientHeight; | 
|---|
| 4847 |  | 
|---|
| 4848 | //  position the static text frame extension below the client | 
|---|
| 4849 | lClientHeight = prclPassed->yTop - prclPassed->yBottom; | 
|---|
| 4850 | if (lStatusBarHeight > lClientHeight) | 
|---|
| 4851 | // extension is taller than client, so set client height to 0 | 
|---|
| 4852 | prclPassed->yTop = prclPassed->yBottom; | 
|---|
| 4853 | else | 
|---|
| 4854 | { | 
|---|
| 4855 | //  set the origin of the client and shrink it based upon the | 
|---|
| 4856 | //  static text control's height | 
|---|
| 4857 | prclPassed->yBottom += lStatusBarHeight; | 
|---|
| 4858 | prclPassed->yTop -= lStatusBarHeight; | 
|---|
| 4859 | } | 
|---|
| 4860 | } | 
|---|
| 4861 | else | 
|---|
| 4862 | { | 
|---|
| 4863 | //  FALSE: calculate the rectl of the frame; | 
|---|
| 4864 | //  call default window procedure to subtract child frame | 
|---|
| 4865 | //  controls from the rectangle's height; | 
|---|
| 4866 | //  set the origin of the frame and increase it based upon the | 
|---|
| 4867 | //  static text control's height | 
|---|
| 4868 | prclPassed->yBottom -= lStatusBarHeight; | 
|---|
| 4869 | prclPassed->yTop += lStatusBarHeight; | 
|---|
| 4870 | } | 
|---|
| 4871 | } | 
|---|
| 4872 |  | 
|---|
| 4873 | #define STATUS_BAR_HEIGHT       20 | 
|---|
| 4874 |  | 
|---|
| 4875 | /* | 
|---|
| 4876 | *@@ fnwpSubclExtFrame: | 
|---|
| 4877 | *      subclassed frame window proc. | 
|---|
| 4878 | * | 
|---|
| 4879 | *@@added V0.9.16 (2001-09-29) [umoeller] | 
|---|
| 4880 | */ | 
|---|
| 4881 |  | 
|---|
| 4882 | MRESULT EXPENTRY fnwpSubclExtFrame(HWND hwndFrame, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 4883 | { | 
|---|
| 4884 | MRESULT mrc = 0; | 
|---|
| 4885 |  | 
|---|
| 4886 | PEXTFRAMEDATA pData = (PEXTFRAMEDATA)WinQueryWindowPtr(hwndFrame, QWL_USER); | 
|---|
| 4887 |  | 
|---|
| 4888 | switch (msg) | 
|---|
| 4889 | { | 
|---|
| 4890 | case WM_QUERYFRAMECTLCOUNT: | 
|---|
| 4891 | { | 
|---|
| 4892 | // query the standard frame controls count | 
|---|
| 4893 | ULONG ulrc = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2); | 
|---|
| 4894 |  | 
|---|
| 4895 | // if we have a status bar, increment the count | 
|---|
| 4896 | ulrc++; | 
|---|
| 4897 |  | 
|---|
| 4898 | mrc = (MPARAM)ulrc; | 
|---|
| 4899 | } | 
|---|
| 4900 | break; | 
|---|
| 4901 |  | 
|---|
| 4902 | case WM_FORMATFRAME: | 
|---|
| 4903 | { | 
|---|
| 4904 | // query the number of standard frame controls | 
|---|
| 4905 | ULONG ulCount = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2); | 
|---|
| 4906 |  | 
|---|
| 4907 | // we have a status bar: | 
|---|
| 4908 | // format the frame | 
|---|
| 4909 | ULONG       ul; | 
|---|
| 4910 | PSWP        swpArr = (PSWP)mp1; | 
|---|
| 4911 |  | 
|---|
| 4912 | for (ul = 0; ul < ulCount; ul++) | 
|---|
| 4913 | { | 
|---|
| 4914 | if (WinQueryWindowUShort(swpArr[ul].hwnd, QWS_ID) == 0x8008) | 
|---|
| 4915 | // FID_CLIENT | 
|---|
| 4916 | { | 
|---|
| 4917 | POINTL      ptlBorderSizes; | 
|---|
| 4918 | WinSendMsg(hwndFrame, | 
|---|
| 4919 | WM_QUERYBORDERSIZE, | 
|---|
| 4920 | (MPARAM)&ptlBorderSizes, | 
|---|
| 4921 | 0); | 
|---|
| 4922 |  | 
|---|
| 4923 | // first initialize the _new_ SWP for the status bar. | 
|---|
| 4924 | // Since the SWP array for the std frame controls is | 
|---|
| 4925 | // zero-based, and the standard frame controls occupy | 
|---|
| 4926 | // indices 0 thru ulCount-1 (where ulCount is the total | 
|---|
| 4927 | // count), we use ulCount for our static text control. | 
|---|
| 4928 | swpArr[ulCount].fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER; | 
|---|
| 4929 | swpArr[ulCount].x  = ptlBorderSizes.x; | 
|---|
| 4930 | swpArr[ulCount].y  = ptlBorderSizes.y; | 
|---|
| 4931 | swpArr[ulCount].cx = swpArr[ul].cx;  // same as cnr's width | 
|---|
| 4932 | swpArr[ulCount].cy = STATUS_BAR_HEIGHT; | 
|---|
| 4933 | swpArr[ulCount].hwndInsertBehind = HWND_BOTTOM; // HWND_TOP; | 
|---|
| 4934 | swpArr[ulCount].hwnd = WinWindowFromID(hwndFrame, FID_STATUSBAR); | 
|---|
| 4935 |  | 
|---|
| 4936 | // adjust the origin and height of the container to | 
|---|
| 4937 | // accomodate our static text control | 
|---|
| 4938 | swpArr[ul].y  += swpArr[ulCount].cy; | 
|---|
| 4939 | swpArr[ul].cy -= swpArr[ulCount].cy; | 
|---|
| 4940 | } | 
|---|
| 4941 | } | 
|---|
| 4942 |  | 
|---|
| 4943 | // increment the number of frame controls | 
|---|
| 4944 | // to include our status bar | 
|---|
| 4945 | mrc = (MRESULT)(ulCount + 1); | 
|---|
| 4946 | } | 
|---|
| 4947 | break; | 
|---|
| 4948 |  | 
|---|
| 4949 | case WM_CALCFRAMERECT: | 
|---|
| 4950 | mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2); | 
|---|
| 4951 |  | 
|---|
| 4952 | // we have a status bar: calculate its rectangle | 
|---|
| 4953 | winhCalcExtFrameRect(mp1, | 
|---|
| 4954 | mp2, | 
|---|
| 4955 | STATUS_BAR_HEIGHT); | 
|---|
| 4956 | break; | 
|---|
| 4957 |  | 
|---|
| 4958 | case WM_DESTROY: | 
|---|
| 4959 | WinSubclassWindow(hwndFrame, pData->pfnwpOrig); | 
|---|
| 4960 | free(pData); | 
|---|
| 4961 | WinSetWindowPtr(hwndFrame, QWL_USER, NULL); | 
|---|
| 4962 | break; | 
|---|
| 4963 |  | 
|---|
| 4964 | default: | 
|---|
| 4965 | mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2); | 
|---|
| 4966 | } | 
|---|
| 4967 |  | 
|---|
| 4968 | return mrc; | 
|---|
| 4969 | } | 
|---|
| 4970 |  | 
|---|
| 4971 | /* | 
|---|
| 4972 | *@@ winhCreateStatusBar: | 
|---|
| 4973 | *      creates a status bar for a frame window. | 
|---|
| 4974 | * | 
|---|
| 4975 | *      Normally there's no need to call this manually, | 
|---|
| 4976 | *      this gets called by winhCreateExtStdWindow | 
|---|
| 4977 | *      automatically. | 
|---|
| 4978 | * | 
|---|
| 4979 | *@@added V0.9.16 (2001-09-29) [umoeller] | 
|---|
| 4980 | */ | 
|---|
| 4981 |  | 
|---|
| 4982 | HWND winhCreateStatusBar(HWND hwndFrame, | 
|---|
| 4983 | HWND hwndOwner, | 
|---|
| 4984 | const char *pcszText,      // in: initial status bar text | 
|---|
| 4985 | const char *pcszFont,      // in: font to use for status bar | 
|---|
| 4986 | LONG lColor)               // in: foreground color for status bar | 
|---|
| 4987 | { | 
|---|
| 4988 | // create status bar | 
|---|
| 4989 | HWND        hwndReturn = NULLHANDLE; | 
|---|
| 4990 | PPRESPARAMS ppp = NULL; | 
|---|
| 4991 |  | 
|---|
| 4992 | winhStorePresParam(&ppp, | 
|---|
| 4993 | PP_FONTNAMESIZE, | 
|---|
| 4994 | strlen(pcszFont) + 1, | 
|---|
| 4995 | (PVOID)pcszFont); | 
|---|
| 4996 |  | 
|---|
| 4997 | lColor = WinQuerySysColor(HWND_DESKTOP, | 
|---|
| 4998 | SYSCLR_DIALOGBACKGROUND, | 
|---|
| 4999 | 0); | 
|---|
| 5000 | winhStorePresParam(&ppp, | 
|---|
| 5001 | PP_BACKGROUNDCOLOR, | 
|---|
| 5002 | sizeof(lColor), | 
|---|
| 5003 | &lColor); | 
|---|
| 5004 |  | 
|---|
| 5005 | lColor = CLR_BLACK; | 
|---|
| 5006 | winhStorePresParam(&ppp, | 
|---|
| 5007 | PP_FOREGROUNDCOLOR, | 
|---|
| 5008 | sizeof(lColor), | 
|---|
| 5009 | &lColor); | 
|---|
| 5010 |  | 
|---|
| 5011 | hwndReturn = WinCreateWindow(hwndFrame, | 
|---|
| 5012 | WC_STATIC, | 
|---|
| 5013 | (PSZ)pcszText, | 
|---|
| 5014 | SS_TEXT | DT_VCENTER | WS_VISIBLE, | 
|---|
| 5015 | 0, 0, 0, 0, | 
|---|
| 5016 | hwndOwner, | 
|---|
| 5017 | HWND_TOP, | 
|---|
| 5018 | FID_STATUSBAR, | 
|---|
| 5019 | NULL, | 
|---|
| 5020 | ppp); | 
|---|
| 5021 | free(ppp); | 
|---|
| 5022 |  | 
|---|
| 5023 | return hwndReturn; | 
|---|
| 5024 | } | 
|---|
| 5025 |  | 
|---|
| 5026 | /* | 
|---|
| 5027 | *@@ winhCreateExtStdWindow: | 
|---|
| 5028 | *      creates an extended frame window. | 
|---|
| 5029 | * | 
|---|
| 5030 | *      pData must point to an EXTFRAMECDATA structure | 
|---|
| 5031 | *      which contains a copy of the parameters to be | 
|---|
| 5032 | *      passed to winhCreateStdWindow. In addition, | 
|---|
| 5033 | *      this contains the flExtFlags field, which allows | 
|---|
| 5034 | *      you to automatically create a status bar for | 
|---|
| 5035 | *      the window. | 
|---|
| 5036 | * | 
|---|
| 5037 | *      Note that we subclass the frame here and require | 
|---|
| 5038 | *      QWL_USER for that. The frame's QWL_USER points | 
|---|
| 5039 | *      to an EXTFRAMEDATA structure whose pUser parameter | 
|---|
| 5040 | *      you may use for additional data, if you want to | 
|---|
| 5041 | *      do further subclassing. | 
|---|
| 5042 | * | 
|---|
| 5043 | *@@added V0.9.16 (2001-09-29) [umoeller] | 
|---|
| 5044 | */ | 
|---|
| 5045 |  | 
|---|
| 5046 | HWND winhCreateExtStdWindow(PEXTFRAMECDATA pData,        // in: extended frame data | 
|---|
| 5047 | PHWND phwndClient)          // out: created client wnd | 
|---|
| 5048 | { | 
|---|
| 5049 | HWND hwndFrame; | 
|---|
| 5050 |  | 
|---|
| 5051 | if (hwndFrame = winhCreateStdWindow(HWND_DESKTOP, | 
|---|
| 5052 | pData->pswpFrame, | 
|---|
| 5053 | pData->flFrameCreateFlags, | 
|---|
| 5054 | pData->ulFrameStyle, | 
|---|
| 5055 | pData->pcszFrameTitle, | 
|---|
| 5056 | pData->ulResourcesID, | 
|---|
| 5057 | pData->pcszClassClient, | 
|---|
| 5058 | pData->flStyleClient, | 
|---|
| 5059 | pData->ulID, | 
|---|
| 5060 | pData->pClientCtlData, | 
|---|
| 5061 | phwndClient)) | 
|---|
| 5062 | { | 
|---|
| 5063 | if (pData->flExtFlags & XFCF_STATUSBAR) | 
|---|
| 5064 | { | 
|---|
| 5065 | // create status bar as child of the frame | 
|---|
| 5066 | HWND hwndStatusBar = winhCreateStatusBar(hwndFrame, | 
|---|
| 5067 | hwndFrame, | 
|---|
| 5068 | "", | 
|---|
| 5069 | "9.WarpSans", | 
|---|
| 5070 | CLR_BLACK); | 
|---|
| 5071 |  | 
|---|
| 5072 | // subclass frame for supporting status bar and msgs | 
|---|
| 5073 | PEXTFRAMEDATA pFrameData; | 
|---|
| 5074 | if (pFrameData = NEW(EXTFRAMEDATA)) | 
|---|
| 5075 | { | 
|---|
| 5076 | ZERO(pFrameData), | 
|---|
| 5077 | memcpy(&pFrameData->CData, pData, sizeof(pFrameData->CData)); | 
|---|
| 5078 | if (pFrameData->pfnwpOrig = WinSubclassWindow(hwndFrame, | 
|---|
| 5079 | fnwpSubclExtFrame)) | 
|---|
| 5080 | { | 
|---|
| 5081 | WinSetWindowPtr(hwndFrame, QWL_USER, pFrameData); | 
|---|
| 5082 | } | 
|---|
| 5083 | else | 
|---|
| 5084 | free(pFrameData); | 
|---|
| 5085 | } | 
|---|
| 5086 | } | 
|---|
| 5087 | } | 
|---|
| 5088 |  | 
|---|
| 5089 | return hwndFrame; | 
|---|
| 5090 | } | 
|---|
| 5091 |  | 
|---|
| 5092 | /* | 
|---|
| 5093 | *@@category: Helpers\PM helpers\Workplace Shell\WPS class list | 
|---|
| 5094 | */ | 
|---|
| 5095 |  | 
|---|
| 5096 | /* ****************************************************************** | 
|---|
| 5097 | * | 
|---|
| 5098 | *   WPS Class List helpers | 
|---|
| 5099 | * | 
|---|
| 5100 | ********************************************************************/ | 
|---|
| 5101 |  | 
|---|
| 5102 | /* | 
|---|
| 5103 | *@@ winhQueryWPSClassList: | 
|---|
| 5104 | *      this returns the WPS class list in a newly | 
|---|
| 5105 | *      allocated buffer. This is just a shortcut to | 
|---|
| 5106 | *      the usual double WinEnumObjectClasses call. | 
|---|
| 5107 | * | 
|---|
| 5108 | *      The return value is actually of the POBJCLASS type, | 
|---|
| 5109 | *      so you better cast this manually. We declare this | 
|---|
| 5110 | *      this as PBYTE though because POBJCLASS requires | 
|---|
| 5111 | *      INCL_WINWORKPLACE. | 
|---|
| 5112 | *      See WinEnumObjectClasses() for details. | 
|---|
| 5113 | * | 
|---|
| 5114 | *      Returns NULL on error. Use free() | 
|---|
| 5115 | *      to free the return value. | 
|---|
| 5116 | * | 
|---|
| 5117 | *@@added V0.9.0 [umoeller] | 
|---|
| 5118 | */ | 
|---|
| 5119 |  | 
|---|
| 5120 | PBYTE winhQueryWPSClassList(VOID) | 
|---|
| 5121 | { | 
|---|
| 5122 | ULONG       ulSize; | 
|---|
| 5123 | POBJCLASS   pObjClass = 0; | 
|---|
| 5124 |  | 
|---|
| 5125 | // get WPS class list size | 
|---|
| 5126 | if (WinEnumObjectClasses(NULL, &ulSize)) | 
|---|
| 5127 | { | 
|---|
| 5128 | // allocate buffer | 
|---|
| 5129 | pObjClass = (POBJCLASS)malloc(ulSize + 1); | 
|---|
| 5130 | // and load the classes into it | 
|---|
| 5131 | WinEnumObjectClasses(pObjClass, &ulSize); | 
|---|
| 5132 | } | 
|---|
| 5133 |  | 
|---|
| 5134 | return (PBYTE)pObjClass; | 
|---|
| 5135 | } | 
|---|
| 5136 |  | 
|---|
| 5137 | /* | 
|---|
| 5138 | *@@ winhQueryWPSClass: | 
|---|
| 5139 | *      this returns the POBJCLASS item if pszClass is registered | 
|---|
| 5140 | *      with the WPS or NULL if the class could not be found. | 
|---|
| 5141 | * | 
|---|
| 5142 | *      The return value is actually of the POBJCLASS type, | 
|---|
| 5143 | *      so you better cast this manually. We declare this | 
|---|
| 5144 | *      this as PBYTE though because POBJCLASS requires | 
|---|
| 5145 | *      INCL_WINWORKPLACE. | 
|---|
| 5146 | * | 
|---|
| 5147 | *      This takes as input the return value of winhQueryWPSClassList, | 
|---|
| 5148 | *      which you must call first. | 
|---|
| 5149 | * | 
|---|
| 5150 | *      <B>Usage:</B> | 
|---|
| 5151 | +          PBYTE   pClassList = winhQueryWPSClassList(), | 
|---|
| 5152 | +                  pWPFolder; | 
|---|
| 5153 | +          if (pClassList) | 
|---|
| 5154 | +          { | 
|---|
| 5155 | +              if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder")) | 
|---|
| 5156 | +                  ... | 
|---|
| 5157 | +              free(pClassList); | 
|---|
| 5158 | +          } | 
|---|
| 5159 | * | 
|---|
| 5160 | *@@added V0.9.0 [umoeller] | 
|---|
| 5161 | */ | 
|---|
| 5162 |  | 
|---|
| 5163 | PBYTE winhQueryWPSClass(PBYTE pObjClass,  // in: buffer returned by | 
|---|
| 5164 | // winhQueryWPSClassList | 
|---|
| 5165 | const char *pszClass)     // in: class name to query | 
|---|
| 5166 | { | 
|---|
| 5167 | PBYTE   pbReturn = 0; | 
|---|
| 5168 |  | 
|---|
| 5169 | POBJCLASS pocThis = (POBJCLASS)pObjClass; | 
|---|
| 5170 | // now go thru the WPS class list | 
|---|
| 5171 | while (pocThis) | 
|---|
| 5172 | { | 
|---|
| 5173 | if (strcmp(pocThis->pszClassName, pszClass) == 0) | 
|---|
| 5174 | { | 
|---|
| 5175 | pbReturn = (PBYTE)pocThis; | 
|---|
| 5176 | break; | 
|---|
| 5177 | } | 
|---|
| 5178 | // next class | 
|---|
| 5179 | pocThis = pocThis->pNext; | 
|---|
| 5180 | } // end while (pocThis) | 
|---|
| 5181 |  | 
|---|
| 5182 | return pbReturn; | 
|---|
| 5183 | } | 
|---|
| 5184 |  | 
|---|
| 5185 | /* | 
|---|
| 5186 | *@@ winhRegisterClass: | 
|---|
| 5187 | *      this works just like WinRegisterObjectClass, | 
|---|
| 5188 | *      except that it returns a more meaningful | 
|---|
| 5189 | *      error code than just FALSE in case registering | 
|---|
| 5190 | *      fails. | 
|---|
| 5191 | * | 
|---|
| 5192 | *      This returns NO_ERROR if the class was successfully | 
|---|
| 5193 | *      registered (WinRegisterObjectClass returned TRUE). | 
|---|
| 5194 | * | 
|---|
| 5195 | *      Otherwise, we do a DosLoadModule if maybe the DLL | 
|---|
| 5196 | *      couldn't be loaded in the first place. If DosLoadModule | 
|---|
| 5197 | *      did not return NO_ERROR, this function returns that | 
|---|
| 5198 | *      return code, which can be: | 
|---|
| 5199 | * | 
|---|
| 5200 | *      --  2   ERROR_FILE_NOT_FOUND: pcszModule does not exist | 
|---|
| 5201 | *      --  2   ERROR_FILE_NOT_FOUND | 
|---|
| 5202 | *      --  3   ERROR_PATH_NOT_FOUND | 
|---|
| 5203 | *      --  4   ERROR_TOO_MANY_OPEN_FILES | 
|---|
| 5204 | *      --  5   ERROR_ACCESS_DENIED | 
|---|
| 5205 | *      --  8   ERROR_NOT_ENOUGH_MEMORY | 
|---|
| 5206 | *      --  11  ERROR_BAD_FORMAT | 
|---|
| 5207 | *      --  26  ERROR_NOT_DOS_DISK (unknown media type) | 
|---|
| 5208 | *      --  32  ERROR_SHARING_VIOLATION | 
|---|
| 5209 | *      --  33  ERROR_LOCK_VIOLATION | 
|---|
| 5210 | *      --  36  ERROR_SHARING_BUFFER_EXCEEDED | 
|---|
| 5211 | *      --  95  ERROR_INTERRUPT (interrupted system call) | 
|---|
| 5212 | *      --  108 ERROR_DRIVE_LOCKED (by another process) | 
|---|
| 5213 | *      --  123 ERROR_INVALID_NAME (illegal character or FS name not valid) | 
|---|
| 5214 | *      --  127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error) | 
|---|
| 5215 | *      --  180 ERROR_INVALID_SEGMENT_NUMBER | 
|---|
| 5216 | *      --  182 ERROR_INVALID_ORDINAL | 
|---|
| 5217 | *      --  190 ERROR_INVALID_MODULETYPE (probably an application) | 
|---|
| 5218 | *      --  191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL) | 
|---|
| 5219 | *      --  192 ERROR_EXE_MARKED_INVALID (by linker) | 
|---|
| 5220 | *      --  194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment) | 
|---|
| 5221 | *      --  195 ERROR_INVALID_MINALLOCSIZE | 
|---|
| 5222 | *      --  196 ERROR_DYNLINK_FROM_INVALID_RING | 
|---|
| 5223 | *      --  198 ERROR_INVALID_SEGDPL | 
|---|
| 5224 | *      --  199 ERROR_AUTODATASEG_EXCEEDS_64K | 
|---|
| 5225 | *      --  201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT | 
|---|
| 5226 | *      --  206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec) | 
|---|
| 5227 | *      --  295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed) | 
|---|
| 5228 | * | 
|---|
| 5229 | *      In all these cases, pszBuf may contain a meaningful | 
|---|
| 5230 | *      error message from DosLoadModule, especially if an import | 
|---|
| 5231 | *      could not be resolved. | 
|---|
| 5232 | * | 
|---|
| 5233 | *      Still worse, if DosLoadModule returned NO_ERROR, we | 
|---|
| 5234 | *      probably have some SOM internal error. A probable | 
|---|
| 5235 | *      reason is that the parent class of pcszClassName | 
|---|
| 5236 | *      is not installed, but that's WPS/SOM internal | 
|---|
| 5237 | *      and cannot be queried from outside the WPS context. | 
|---|
| 5238 | * | 
|---|
| 5239 | *      In that case, ERROR_OPEN_FAILED (110) is returned. | 
|---|
| 5240 | *      That one sounded good to me. ;-) | 
|---|
| 5241 | */ | 
|---|
| 5242 |  | 
|---|
| 5243 | APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder" | 
|---|
| 5244 | const char* pcszModule,    // in: e.g. "C:\XFOLDER\XFLDR.DLL" | 
|---|
| 5245 | PSZ pszBuf,                // out: error message from DosLoadModule | 
|---|
| 5246 | ULONG cbBuf)               // in: sizeof(*pszBuf), passed to DosLoadModule | 
|---|
| 5247 | { | 
|---|
| 5248 | APIRET arc = NO_ERROR; | 
|---|
| 5249 |  | 
|---|
| 5250 | if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule)) | 
|---|
| 5251 | { | 
|---|
| 5252 | // failed: do more error checking then, try DosLoadModule | 
|---|
| 5253 | HMODULE hmod = NULLHANDLE; | 
|---|
| 5254 | arc = DosLoadModule(pszBuf, cbBuf, | 
|---|
| 5255 | (PSZ)pcszModule, | 
|---|
| 5256 | &hmod); | 
|---|
| 5257 | if (arc == NO_ERROR) | 
|---|
| 5258 | { | 
|---|
| 5259 | // DosLoadModule succeeded: | 
|---|
| 5260 | // some SOM error then | 
|---|
| 5261 | DosFreeModule(hmod); | 
|---|
| 5262 | arc = ERROR_OPEN_FAILED; | 
|---|
| 5263 | } | 
|---|
| 5264 | } | 
|---|
| 5265 | // else: ulrc still 0 (== no error) | 
|---|
| 5266 |  | 
|---|
| 5267 | return arc; | 
|---|
| 5268 | } | 
|---|
| 5269 |  | 
|---|
| 5270 | /* | 
|---|
| 5271 | *@@ winhIsClassRegistered: | 
|---|
| 5272 | *      quick one-shot function which checks if | 
|---|
| 5273 | *      a class is currently registered. Calls | 
|---|
| 5274 | *      winhQueryWPSClassList and winhQueryWPSClass | 
|---|
| 5275 | *      in turn. | 
|---|
| 5276 | * | 
|---|
| 5277 | *@@added V0.9.2 (2000-02-26) [umoeller] | 
|---|
| 5278 | */ | 
|---|
| 5279 |  | 
|---|
| 5280 | BOOL winhIsClassRegistered(const char *pcszClass) | 
|---|
| 5281 | { | 
|---|
| 5282 | BOOL    brc = FALSE; | 
|---|
| 5283 | PBYTE   pClassList = winhQueryWPSClassList(); | 
|---|
| 5284 | if (pClassList) | 
|---|
| 5285 | { | 
|---|
| 5286 | if (winhQueryWPSClass(pClassList, pcszClass)) | 
|---|
| 5287 | brc = TRUE; | 
|---|
| 5288 | free(pClassList); | 
|---|
| 5289 | } | 
|---|
| 5290 |  | 
|---|
| 5291 | return brc; | 
|---|
| 5292 | } | 
|---|
| 5293 |  | 
|---|
| 5294 | /* | 
|---|
| 5295 | *@@category: Helpers\PM helpers\Workplace Shell | 
|---|
| 5296 | */ | 
|---|
| 5297 |  | 
|---|
| 5298 | /* | 
|---|
| 5299 | *@@ winhResetWPS: | 
|---|
| 5300 | *      restarts the WPS using PrfReset. Returns | 
|---|
| 5301 | *      one of the following: | 
|---|
| 5302 | * | 
|---|
| 5303 | *      -- 0: no error. | 
|---|
| 5304 | *      -- 1: PrfReset failed. | 
|---|
| 5305 | *      -- 2 or 4: PrfQueryProfile failed. | 
|---|
| 5306 | *      -- 3: malloc() failed. | 
|---|
| 5307 | * | 
|---|
| 5308 | *@@added V0.9.4 (2000-07-01) [umoeller] | 
|---|
| 5309 | *@@changed V1.0.5 (2005-02-17) [pr]: replaced this with something less brutal | 
|---|
| 5310 | */ | 
|---|
| 5311 |  | 
|---|
| 5312 | ULONG winhResetWPS(HAB hab) | 
|---|
| 5313 | { | 
|---|
| 5314 | ULONG ulrc = 0; | 
|---|
| 5315 |  | 
|---|
| 5316 | #if 1 | 
|---|
| 5317 | WinRestartWorkplace(); | 
|---|
| 5318 | #else | 
|---|
| 5319 | // find out current profile names | 
|---|
| 5320 | PRFPROFILE Profiles; | 
|---|
| 5321 | Profiles.cchUserName = Profiles.cchSysName = 0; | 
|---|
| 5322 | // first query their file name lengths | 
|---|
| 5323 | if (PrfQueryProfile(hab, &Profiles)) | 
|---|
| 5324 | { | 
|---|
| 5325 | // allocate memory for filenames | 
|---|
| 5326 | Profiles.pszUserName  = (PSZ)malloc(Profiles.cchUserName); | 
|---|
| 5327 | Profiles.pszSysName  = (PSZ)malloc(Profiles.cchSysName); | 
|---|
| 5328 |  | 
|---|
| 5329 | if (Profiles.pszSysName) | 
|---|
| 5330 | { | 
|---|
| 5331 | // get filenames | 
|---|
| 5332 | if (PrfQueryProfile(hab, &Profiles)) | 
|---|
| 5333 | { | 
|---|
| 5334 |  | 
|---|
| 5335 | // "change" INIs to these filenames: | 
|---|
| 5336 | // THIS WILL RESET THE WPS | 
|---|
| 5337 | if (PrfReset(hab, &Profiles) == FALSE) | 
|---|
| 5338 | ulrc = 1; | 
|---|
| 5339 | free(Profiles.pszSysName); | 
|---|
| 5340 | free(Profiles.pszUserName); | 
|---|
| 5341 | } | 
|---|
| 5342 | else | 
|---|
| 5343 | ulrc = 2; | 
|---|
| 5344 | } | 
|---|
| 5345 | else | 
|---|
| 5346 | ulrc = 3; | 
|---|
| 5347 | } | 
|---|
| 5348 | else | 
|---|
| 5349 | ulrc = 4; | 
|---|
| 5350 | #endif | 
|---|
| 5351 |  | 
|---|
| 5352 | return ulrc; | 
|---|
| 5353 | } | 
|---|