| 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-2006 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 | *@@ winhStoreWindowPos:
|
|---|
| 2473 | * saves the position of a certain window in the same format
|
|---|
| 2474 | * as the barely documented WinStoreWindowPos API.
|
|---|
| 2475 | * This uses the completely undocumented calls
|
|---|
| 2476 | * WinGetFrameTreePPSize and WinGetFrameTreePPs imported
|
|---|
| 2477 | * from PMWIN.DLL ordinals 972 and 973.
|
|---|
| 2478 | *
|
|---|
| 2479 | * The window should still be visible on the screen
|
|---|
| 2480 | * when calling this function. Do not call it in WM_DESTROY,
|
|---|
| 2481 | * because then the SWP data is no longer valid.
|
|---|
| 2482 | *
|
|---|
| 2483 | * This returns TRUE if saving was successful.
|
|---|
| 2484 | *
|
|---|
| 2485 | *@@added XWP V1.0.6 (2006-10-31) [pr]: @@fixes 458
|
|---|
| 2486 | *@@changed XWP V1.0.7 (2006-12-16) [pr]: detect screen height/width @@fixes 903
|
|---|
| 2487 | */
|
|---|
| 2488 |
|
|---|
| 2489 | BOOL winhStoreWindowPos(HWND hwnd, // in: window to save
|
|---|
| 2490 | HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
|
|---|
| 2491 | const char *pcszApp, // in: INI application name
|
|---|
| 2492 | const char *pcszKey) // in: INI key name
|
|---|
| 2493 | {
|
|---|
| 2494 | BOOL brc = FALSE;
|
|---|
| 2495 | SWP swp;
|
|---|
| 2496 |
|
|---|
| 2497 | if (WinQueryWindowPos(hwnd, &swp))
|
|---|
| 2498 | {
|
|---|
| 2499 | ULONG ulSizePP = WinGetFrameTreePPSize(hwnd);
|
|---|
| 2500 | ULONG ulSize = sizeof(STOREPOS) + ulSizePP;
|
|---|
| 2501 | PSTOREPOS pStorePos;
|
|---|
| 2502 |
|
|---|
| 2503 | if ((pStorePos = malloc(ulSize)))
|
|---|
| 2504 | {
|
|---|
| 2505 | // This first bit is guesswork as I don't know what it all means,
|
|---|
| 2506 | // but it always seems to be the same everywhere I've looked.
|
|---|
| 2507 | pStorePos->usMagic = 0x7B6A;
|
|---|
| 2508 | pStorePos->ulRes1 = 1;
|
|---|
| 2509 | pStorePos->ulRes2 = 1;
|
|---|
| 2510 | pStorePos->ulRes3 = 0xFFFFFFFF;
|
|---|
| 2511 | pStorePos->ulRes4 = 0xFFFFFFFF;
|
|---|
| 2512 |
|
|---|
| 2513 | pStorePos->ulFlags = swp.fl;
|
|---|
| 2514 | pStorePos->usXPos = pStorePos->usRestoreXPos = swp.x;
|
|---|
| 2515 | pStorePos->usYPos = pStorePos->usRestoreYPos = swp.y;
|
|---|
| 2516 | pStorePos->usWidth = pStorePos->usRestoreWidth = swp.cx;
|
|---|
| 2517 | pStorePos->usHeight = pStorePos->usRestoreHeight = swp.cy;
|
|---|
| 2518 | if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
|
|---|
| 2519 | {
|
|---|
| 2520 | pStorePos->usRestoreXPos = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
|
|---|
| 2521 | pStorePos->usRestoreYPos = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
|
|---|
| 2522 | pStorePos->usRestoreWidth = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
|
|---|
| 2523 | pStorePos->usRestoreHeight = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
|
|---|
| 2524 | }
|
|---|
| 2525 |
|
|---|
| 2526 | pStorePos->usMinXPos = WinQueryWindowUShort(hwnd, QWS_XMINIMIZE);
|
|---|
| 2527 | pStorePos->usMinYPos = WinQueryWindowUShort(hwnd, QWS_YMINIMIZE);
|
|---|
| 2528 | pStorePos->ulScreenWidth = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);;
|
|---|
| 2529 | pStorePos->ulScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);;
|
|---|
| 2530 | pStorePos->ulPPLen = WinGetFrameTreePPs(hwnd, ulSizePP, (PSZ)(pStorePos + 1));
|
|---|
| 2531 | ulSize = pStorePos->ulPPLen + sizeof(STOREPOS);
|
|---|
| 2532 | brc = PrfWriteProfileData(hIni, (PSZ)pcszApp, (PSZ)pcszKey, pStorePos, ulSize);
|
|---|
| 2533 | free(pStorePos);
|
|---|
| 2534 | }
|
|---|
| 2535 | }
|
|---|
| 2536 | return brc;
|
|---|
| 2537 | }
|
|---|
| 2538 |
|
|---|
| 2539 | /*
|
|---|
| 2540 | *@@ winhAdjustControls:
|
|---|
| 2541 | * helper function for dynamically adjusting a window's
|
|---|
| 2542 | * controls when the window is resized.
|
|---|
| 2543 | *
|
|---|
| 2544 | * This is most useful with dialogs loaded from resources
|
|---|
| 2545 | * which should be sizeable. Normally, when the dialog
|
|---|
| 2546 | * frame is resized, the controls stick to their positions,
|
|---|
| 2547 | * and for dialogs with many controls, programming the
|
|---|
| 2548 | * changes can be tiresome.
|
|---|
| 2549 | *
|
|---|
| 2550 | * Enter this function. ;-) Basically, this takes a
|
|---|
| 2551 | * static array of MPARAM's as input (plus one dynamic
|
|---|
| 2552 | * storage area for the window positions).
|
|---|
| 2553 | *
|
|---|
| 2554 | * This function must get called in three contexts:
|
|---|
| 2555 | * during WM_INITDLG, during WM_WINDOWPOSCHANGED, and
|
|---|
| 2556 | * during WM_DESTROY, with varying parameters.
|
|---|
| 2557 | *
|
|---|
| 2558 | * In detail, there are four things you need to do to make
|
|---|
| 2559 | * this work:
|
|---|
| 2560 | *
|
|---|
| 2561 | * 1) Set up a static array (as a global variable) of
|
|---|
| 2562 | * MPARAM's, one for each control in your array.
|
|---|
| 2563 | * Each MPARAM will have the control's ID and the
|
|---|
| 2564 | * XAC_* flags (winh.h) how the control shall be moved.
|
|---|
| 2565 | * Use MPFROM2SHORT to easily create this. Example:
|
|---|
| 2566 | *
|
|---|
| 2567 | + MPARAM ampControlFlags[] =
|
|---|
| 2568 | + { MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX),
|
|---|
| 2569 | + MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY),
|
|---|
| 2570 | + ...
|
|---|
| 2571 | + }
|
|---|
| 2572 | *
|
|---|
| 2573 | * This can safely be declared as a global variable
|
|---|
| 2574 | * because this data will only be read and never
|
|---|
| 2575 | * changed by this function.
|
|---|
| 2576 | *
|
|---|
| 2577 | * 2) In WM_INITDLG of your dialog function, set up
|
|---|
| 2578 | * an XADJUSTCTRLS structure, preferrably in your
|
|---|
| 2579 | * window words (QWL_USER).
|
|---|
| 2580 | *
|
|---|
| 2581 | * ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS),
|
|---|
| 2582 | * or this func will not work (because it will intialize
|
|---|
| 2583 | * things on the first WM_WINDOWPOSCHANGED).
|
|---|
| 2584 | *
|
|---|
| 2585 | * 3) Intercept WM_WINDOWPOSCHANGED:
|
|---|
| 2586 | *
|
|---|
| 2587 | + case WM_WINDOWPOSCHANGED:
|
|---|
| 2588 | + {
|
|---|
| 2589 | + // this msg is passed two SWP structs:
|
|---|
| 2590 | + // one for the old, one for the new data
|
|---|
| 2591 | + // (from PM docs)
|
|---|
| 2592 | + PSWP pswpNew = PVOIDFROMMP(mp1);
|
|---|
| 2593 | + PSWP pswpOld = pswpNew + 1;
|
|---|
| 2594 | +
|
|---|
| 2595 | + // resizing?
|
|---|
| 2596 | + if (pswpNew->fl & SWP_SIZE)
|
|---|
| 2597 | + {
|
|---|
| 2598 | + PXADJUSTCTRLS pxac = ... // get it from your window words
|
|---|
| 2599 | +
|
|---|
| 2600 | + winhAdjustControls(hwndDlg, // dialog
|
|---|
| 2601 | + ampControlFlags, // MPARAMs array
|
|---|
| 2602 | + sizeof(ampControlFlags) / sizeof(MPARAM),
|
|---|
| 2603 | + // items count
|
|---|
| 2604 | + pswpNew, // mp1
|
|---|
| 2605 | + pxac); // storage area
|
|---|
| 2606 | + }
|
|---|
| 2607 | + mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ...
|
|---|
| 2608 | *
|
|---|
| 2609 | * 4) In WM_DESTROY, call this function again with pmpFlags,
|
|---|
| 2610 | * pswpNew, and pswpNew set to NULL. This will clean up the
|
|---|
| 2611 | * data which has been allocated internally (pointed to from
|
|---|
| 2612 | * the XADJUSTCTRLS structure).
|
|---|
| 2613 | * Don't forget to free your storage for XADJUSTCTLRS
|
|---|
| 2614 | * _itself_, that's the job of the caller.
|
|---|
| 2615 | *
|
|---|
| 2616 | * This might sound complicated, but it's a lot easier than
|
|---|
| 2617 | * having to write dozens of WinSetWindowPos calls oneself.
|
|---|
| 2618 | *
|
|---|
| 2619 | *@@added V0.9.0 [umoeller]
|
|---|
| 2620 | *@@changed V0.9.19 (2002-04-13) [umoeller]: added correlation for entry field repositioning, this was always off
|
|---|
| 2621 | */
|
|---|
| 2622 |
|
|---|
| 2623 | BOOL winhAdjustControls(HWND hwndDlg, // in: dialog (req.)
|
|---|
| 2624 | const MPARAM *pmpFlags, // in: init flags or NULL for cleanup
|
|---|
| 2625 | ULONG ulCount, // in: item count (req.)
|
|---|
| 2626 | PSWP pswpNew, // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
|
|---|
| 2627 | PXADJUSTCTRLS pxac) // in: adjust-controls storage area (req.)
|
|---|
| 2628 | {
|
|---|
| 2629 | BOOL brc = FALSE;
|
|---|
| 2630 | ULONG ul = 0;
|
|---|
| 2631 |
|
|---|
| 2632 | /* if (!WinIsWindowVisible(hwndDlg))
|
|---|
| 2633 | return (FALSE); */
|
|---|
| 2634 |
|
|---|
| 2635 | if ((pmpFlags) && (pxac))
|
|---|
| 2636 | {
|
|---|
| 2637 | PSWP pswpThis;
|
|---|
| 2638 | const MPARAM *pmpThis;
|
|---|
| 2639 | LONG ldcx, ldcy;
|
|---|
| 2640 | ULONG cWindows = 0;
|
|---|
| 2641 |
|
|---|
| 2642 | // V0.9.19 (2002-04-13) [umoeller]
|
|---|
| 2643 | LONG cxMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
|
|---|
| 2644 | LONG cyMarginEF = 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
|
|---|
| 2645 |
|
|---|
| 2646 | // setup mode:
|
|---|
| 2647 | if (pxac->fInitialized == FALSE)
|
|---|
| 2648 | {
|
|---|
| 2649 | // first call: get all the SWP's
|
|---|
| 2650 | WinQueryWindowPos(hwndDlg, &pxac->swpMain);
|
|---|
| 2651 | // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d",
|
|---|
| 2652 | // pxac->swpMain.cx, pxac->swpMain.cy));
|
|---|
| 2653 |
|
|---|
| 2654 | pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount);
|
|---|
| 2655 |
|
|---|
| 2656 | pswpThis = pxac->paswp;
|
|---|
| 2657 | pmpThis = pmpFlags;
|
|---|
| 2658 |
|
|---|
| 2659 | for (ul = 0;
|
|---|
| 2660 | ul < ulCount;
|
|---|
| 2661 | ul++)
|
|---|
| 2662 | {
|
|---|
| 2663 | HWND hwndThis;
|
|---|
| 2664 | CHAR szClass[10];
|
|---|
| 2665 | if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
|
|---|
| 2666 | {
|
|---|
| 2667 | WinQueryWindowPos(hwndThis, pswpThis);
|
|---|
| 2668 |
|
|---|
| 2669 | // correlate the stupid repositioning of entry fields
|
|---|
| 2670 | // V0.9.19 (2002-04-13) [umoeller]
|
|---|
| 2671 | if ( (WinQueryClassName(hwndThis, sizeof(szClass), szClass)
|
|---|
| 2672 | && (!strcmp(szClass, "#6"))
|
|---|
| 2673 | && (WinQueryWindowULong(hwndThis, QWL_STYLE) & ES_MARGIN))
|
|---|
| 2674 | )
|
|---|
| 2675 | {
|
|---|
| 2676 | pswpThis->x += cxMarginEF;
|
|---|
| 2677 | pswpThis->y += cyMarginEF;
|
|---|
| 2678 | pswpThis->cx -= 2 * cxMarginEF;
|
|---|
| 2679 | pswpThis->cy -= 2 * cyMarginEF;
|
|---|
| 2680 | }
|
|---|
| 2681 |
|
|---|
| 2682 | cWindows++;
|
|---|
| 2683 | }
|
|---|
| 2684 |
|
|---|
| 2685 | pswpThis++;
|
|---|
| 2686 | pmpThis++;
|
|---|
| 2687 | }
|
|---|
| 2688 |
|
|---|
| 2689 | pxac->fInitialized = TRUE;
|
|---|
| 2690 | // _Pmpf(("winhAdjustControls: queried %d controls", cWindows));
|
|---|
| 2691 | }
|
|---|
| 2692 |
|
|---|
| 2693 | if (pswpNew)
|
|---|
| 2694 | {
|
|---|
| 2695 | // compute width and height delta
|
|---|
| 2696 | ldcx = (pswpNew->cx - pxac->swpMain.cx);
|
|---|
| 2697 | ldcy = (pswpNew->cy - pxac->swpMain.cy);
|
|---|
| 2698 |
|
|---|
| 2699 | // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d",
|
|---|
| 2700 | // pswpNew->cx, pswpNew->cy));
|
|---|
| 2701 |
|
|---|
| 2702 | // now adjust the controls
|
|---|
| 2703 | cWindows = 0;
|
|---|
| 2704 | pswpThis = pxac->paswp;
|
|---|
| 2705 | pmpThis = pmpFlags;
|
|---|
| 2706 | for (ul = 0;
|
|---|
| 2707 | ul < ulCount;
|
|---|
| 2708 | ul++)
|
|---|
| 2709 | {
|
|---|
| 2710 | HWND hwndThis;
|
|---|
| 2711 | if (hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis)))
|
|---|
| 2712 | {
|
|---|
| 2713 | LONG x = pswpThis->x,
|
|---|
| 2714 | y = pswpThis->y,
|
|---|
| 2715 | cx = pswpThis->cx,
|
|---|
| 2716 | cy = pswpThis->cy;
|
|---|
| 2717 |
|
|---|
| 2718 | ULONG ulSwpFlags = 0;
|
|---|
| 2719 | // get flags for this control
|
|---|
| 2720 | USHORT usFlags = SHORT2FROMMP(*pmpThis);
|
|---|
| 2721 |
|
|---|
| 2722 | if (usFlags & XAC_MOVEX)
|
|---|
| 2723 | {
|
|---|
| 2724 | x += ldcx;
|
|---|
| 2725 | ulSwpFlags |= SWP_MOVE;
|
|---|
| 2726 | }
|
|---|
| 2727 | if (usFlags & XAC_MOVEY)
|
|---|
| 2728 | {
|
|---|
| 2729 | y += ldcy;
|
|---|
| 2730 | ulSwpFlags |= SWP_MOVE;
|
|---|
| 2731 | }
|
|---|
| 2732 | if (usFlags & XAC_SIZEX)
|
|---|
| 2733 | {
|
|---|
| 2734 | cx += ldcx;
|
|---|
| 2735 | ulSwpFlags |= SWP_SIZE;
|
|---|
| 2736 | }
|
|---|
| 2737 | if (usFlags & XAC_SIZEY)
|
|---|
| 2738 | {
|
|---|
| 2739 | cy += ldcy;
|
|---|
| 2740 | ulSwpFlags |= SWP_SIZE;
|
|---|
| 2741 | }
|
|---|
| 2742 |
|
|---|
| 2743 | if (ulSwpFlags)
|
|---|
| 2744 | {
|
|---|
| 2745 | WinSetWindowPos(hwndThis,
|
|---|
| 2746 | NULLHANDLE, // hwndInsertBehind
|
|---|
| 2747 | x, y, cx, cy,
|
|---|
| 2748 | ulSwpFlags);
|
|---|
| 2749 | cWindows++;
|
|---|
| 2750 | brc = TRUE;
|
|---|
| 2751 | }
|
|---|
| 2752 | }
|
|---|
| 2753 |
|
|---|
| 2754 | pswpThis++;
|
|---|
| 2755 | pmpThis++;
|
|---|
| 2756 | }
|
|---|
| 2757 |
|
|---|
| 2758 | // _Pmpf(("winhAdjustControls: set %d windows", cWindows));
|
|---|
| 2759 | }
|
|---|
| 2760 | }
|
|---|
| 2761 | else
|
|---|
| 2762 | {
|
|---|
| 2763 | // pxac == NULL:
|
|---|
| 2764 | // cleanup mode
|
|---|
| 2765 | if (pxac->paswp)
|
|---|
| 2766 | free(pxac->paswp);
|
|---|
| 2767 | }
|
|---|
| 2768 |
|
|---|
| 2769 | return brc;
|
|---|
| 2770 | }
|
|---|
| 2771 |
|
|---|
| 2772 | /*
|
|---|
| 2773 | *@@ winhCenterWindow:
|
|---|
| 2774 | * centers a window within its parent window. If that's
|
|---|
| 2775 | * the PM desktop, it will be centered according to the
|
|---|
| 2776 | * whole screen.
|
|---|
| 2777 | * For dialog boxes, use WinCenteredDlgBox as a one-shot
|
|---|
| 2778 | * function.
|
|---|
| 2779 | *
|
|---|
| 2780 | * Note: When calling this function, the window should
|
|---|
| 2781 | * not be visible to avoid flickering.
|
|---|
| 2782 | * This func does not show the window either, so call
|
|---|
| 2783 | * WinShowWindow afterwards.
|
|---|
| 2784 | */
|
|---|
| 2785 |
|
|---|
| 2786 | void winhCenterWindow(HWND hwnd)
|
|---|
| 2787 | {
|
|---|
| 2788 | RECTL rclParent;
|
|---|
| 2789 | RECTL rclWindow;
|
|---|
| 2790 |
|
|---|
| 2791 | WinQueryWindowRect(hwnd, &rclWindow);
|
|---|
| 2792 | WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent);
|
|---|
| 2793 |
|
|---|
| 2794 | rclWindow.xLeft = (rclParent.xRight - rclWindow.xRight) / 2;
|
|---|
| 2795 | rclWindow.yBottom = (rclParent.yTop - rclWindow.yTop ) / 2;
|
|---|
| 2796 |
|
|---|
| 2797 | WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom,
|
|---|
| 2798 | 0, 0, SWP_MOVE);
|
|---|
| 2799 | }
|
|---|
| 2800 |
|
|---|
| 2801 | /*
|
|---|
| 2802 | *@@ winhCenteredDlgBox:
|
|---|
| 2803 | * just like WinDlgBox, but the dlg box is centered on the screen;
|
|---|
| 2804 | * you should mark the dlg template as not visible in the dlg
|
|---|
| 2805 | * editor, or display will flicker.
|
|---|
| 2806 | * As opposed to winhCenterWindow, this _does_ show the window.
|
|---|
| 2807 | */
|
|---|
| 2808 |
|
|---|
| 2809 | ULONG winhCenteredDlgBox(HWND hwndParent,
|
|---|
| 2810 | HWND hwndOwner,
|
|---|
| 2811 | PFNWP pfnDlgProc,
|
|---|
| 2812 | HMODULE hmod,
|
|---|
| 2813 | ULONG idDlg,
|
|---|
| 2814 | PVOID pCreateParams)
|
|---|
| 2815 | {
|
|---|
| 2816 | ULONG ulReply;
|
|---|
| 2817 | HWND hwndDlg = WinLoadDlg(hwndParent,
|
|---|
| 2818 | hwndOwner,
|
|---|
| 2819 | pfnDlgProc,
|
|---|
| 2820 | hmod,
|
|---|
| 2821 | idDlg,
|
|---|
| 2822 | pCreateParams);
|
|---|
| 2823 | winhCenterWindow(hwndDlg);
|
|---|
| 2824 | ulReply = WinProcessDlg(hwndDlg);
|
|---|
| 2825 | WinDestroyWindow(hwndDlg);
|
|---|
| 2826 | return ulReply;
|
|---|
| 2827 | }
|
|---|
| 2828 |
|
|---|
| 2829 | /*
|
|---|
| 2830 | *@@ winhPlaceBesides:
|
|---|
| 2831 | * attempts to place hwnd somewhere besides
|
|---|
| 2832 | * hwndRelative.
|
|---|
| 2833 | *
|
|---|
| 2834 | * fl is presently ignored, but should be
|
|---|
| 2835 | * PLF_SMART for future extensions.
|
|---|
| 2836 | *
|
|---|
| 2837 | * Works only if hwnd is a desktop child.
|
|---|
| 2838 | *
|
|---|
| 2839 | *@@added V0.9.19 (2002-04-17) [umoeller]
|
|---|
| 2840 | *@@changed V1.0.0 (2002-08-26) [umoeller]: fixed cx and cy confusion
|
|---|
| 2841 | */
|
|---|
| 2842 |
|
|---|
| 2843 | BOOL winhPlaceBesides(HWND hwnd,
|
|---|
| 2844 | HWND hwndRelative,
|
|---|
| 2845 | ULONG fl)
|
|---|
| 2846 | {
|
|---|
| 2847 | SWP swpRel,
|
|---|
| 2848 | swpThis;
|
|---|
| 2849 | LONG xNew, yNew;
|
|---|
| 2850 |
|
|---|
| 2851 | if ( (WinQueryWindowPos(hwndRelative, &swpRel))
|
|---|
| 2852 | && (WinQueryWindowPos(hwnd, &swpThis))
|
|---|
| 2853 | )
|
|---|
| 2854 | {
|
|---|
| 2855 | HWND hwndRelParent,
|
|---|
| 2856 | hwndThisParent;
|
|---|
| 2857 | POINTL ptlRel = {swpRel.x, swpRel.y};
|
|---|
| 2858 | if ( (hwndRelParent = WinQueryWindow(hwndRelative, QW_PARENT))
|
|---|
| 2859 | && (hwndThisParent = WinQueryWindow(hwnd, QW_PARENT))
|
|---|
| 2860 | && (hwndRelParent != hwndThisParent)
|
|---|
| 2861 | )
|
|---|
| 2862 | {
|
|---|
| 2863 | WinMapWindowPoints(hwndRelParent,
|
|---|
| 2864 | hwndThisParent,
|
|---|
| 2865 | &ptlRel,
|
|---|
| 2866 | 1);
|
|---|
| 2867 | }
|
|---|
| 2868 |
|
|---|
| 2869 | // place right first
|
|---|
| 2870 | xNew = ptlRel.x + swpRel.cx;
|
|---|
| 2871 | // center vertically
|
|---|
| 2872 | yNew = ptlRel.y + ((swpRel.cy - swpThis.cy) / 2);
|
|---|
| 2873 |
|
|---|
| 2874 | // if (xNew + swpThis.cy > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
|
|---|
| 2875 | // not cy, but cx V1.0.0 (2002-08-26) [umoeller]
|
|---|
| 2876 | if (xNew + swpThis.cx > WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN))
|
|---|
| 2877 | {
|
|---|
| 2878 | // place left then
|
|---|
| 2879 | xNew = ptlRel.x - swpThis.cx;
|
|---|
| 2880 |
|
|---|
| 2881 | if (xNew < 0)
|
|---|
| 2882 | {
|
|---|
| 2883 | // center then
|
|---|
| 2884 | winhCenterWindow(hwnd);
|
|---|
| 2885 | return TRUE;
|
|---|
| 2886 | }
|
|---|
| 2887 | }
|
|---|
| 2888 |
|
|---|
| 2889 | return WinSetWindowPos(hwnd,
|
|---|
| 2890 | 0,
|
|---|
| 2891 | xNew,
|
|---|
| 2892 | yNew,
|
|---|
| 2893 | 0,
|
|---|
| 2894 | 0,
|
|---|
| 2895 | SWP_MOVE);
|
|---|
| 2896 | }
|
|---|
| 2897 |
|
|---|
| 2898 | return FALSE;
|
|---|
| 2899 | }
|
|---|
| 2900 |
|
|---|
| 2901 | /*
|
|---|
| 2902 | *@@ winhFindWindowBelow:
|
|---|
| 2903 | * finds the window with the same parent
|
|---|
| 2904 | * which sits right below hwndFind in the
|
|---|
| 2905 | * window Z-order.
|
|---|
| 2906 | *
|
|---|
| 2907 | *@@added V0.9.7 (2000-12-04) [umoeller]
|
|---|
| 2908 | */
|
|---|
| 2909 |
|
|---|
| 2910 | HWND winhFindWindowBelow(HWND hwndFind)
|
|---|
| 2911 | {
|
|---|
| 2912 | HWND hwnd = NULLHANDLE,
|
|---|
| 2913 | hwndParent = WinQueryWindow(hwndFind, QW_PARENT);
|
|---|
| 2914 |
|
|---|
| 2915 | if (hwndParent)
|
|---|
| 2916 | {
|
|---|
| 2917 | HENUM henum = WinBeginEnumWindows(hwndParent);
|
|---|
| 2918 | HWND hwndThis;
|
|---|
| 2919 | while (hwndThis = WinGetNextWindow(henum))
|
|---|
| 2920 | {
|
|---|
| 2921 | SWP swp;
|
|---|
| 2922 | WinQueryWindowPos(hwndThis, &swp);
|
|---|
| 2923 | if (swp.hwndInsertBehind == hwndFind)
|
|---|
| 2924 | {
|
|---|
| 2925 | hwnd = hwndThis;
|
|---|
| 2926 | break;
|
|---|
| 2927 | }
|
|---|
| 2928 | }
|
|---|
| 2929 | WinEndEnumWindows(henum);
|
|---|
| 2930 | }
|
|---|
| 2931 |
|
|---|
| 2932 | return hwnd;
|
|---|
| 2933 | }
|
|---|
| 2934 |
|
|---|
| 2935 | /*
|
|---|
| 2936 | *@@category: Helpers\PM helpers\Presentation parameters
|
|---|
| 2937 | */
|
|---|
| 2938 |
|
|---|
| 2939 | /* ******************************************************************
|
|---|
| 2940 | *
|
|---|
| 2941 | * Presparams helpers
|
|---|
| 2942 | *
|
|---|
| 2943 | ********************************************************************/
|
|---|
| 2944 |
|
|---|
| 2945 | /*
|
|---|
| 2946 | *@@ winhQueryWindowFont:
|
|---|
| 2947 | * returns the window font presentation parameter
|
|---|
| 2948 | * in a newly allocated buffer.
|
|---|
| 2949 | *
|
|---|
| 2950 | * Returns NULL on error. Use free()
|
|---|
| 2951 | * to free the return value.
|
|---|
| 2952 | *
|
|---|
| 2953 | *@@added V0.9.1 (2000-02-14) [umoeller]
|
|---|
| 2954 | */
|
|---|
| 2955 |
|
|---|
| 2956 | PSZ winhQueryWindowFont(HWND hwnd)
|
|---|
| 2957 | {
|
|---|
| 2958 | CHAR szNewFont[100] = "";
|
|---|
| 2959 | WinQueryPresParam(hwnd,
|
|---|
| 2960 | PP_FONTNAMESIZE,
|
|---|
| 2961 | 0,
|
|---|
| 2962 | NULL,
|
|---|
| 2963 | (ULONG)sizeof(szNewFont),
|
|---|
| 2964 | (PVOID)&szNewFont,
|
|---|
| 2965 | QPF_NOINHERIT);
|
|---|
| 2966 | if (szNewFont[0] != 0)
|
|---|
| 2967 | return strdup(szNewFont);
|
|---|
| 2968 |
|
|---|
| 2969 | return NULL;
|
|---|
| 2970 | }
|
|---|
| 2971 |
|
|---|
| 2972 | /*
|
|---|
| 2973 | *@@ winhSetWindowFont:
|
|---|
| 2974 | * this sets a window's font by invoking
|
|---|
| 2975 | * WinSetPresParam on it.
|
|---|
| 2976 | *
|
|---|
| 2977 | * If (pszFont == NULL), a default font will be set
|
|---|
| 2978 | * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
|
|---|
| 2979 | *
|
|---|
| 2980 | * winh.h also defines the winhSetDlgItemFont macro.
|
|---|
| 2981 | *
|
|---|
| 2982 | * Returns TRUE if successful or FALSE otherwise.
|
|---|
| 2983 | *
|
|---|
| 2984 | *@@added V0.9.0 [umoeller]
|
|---|
| 2985 | *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
|
|---|
| 2986 | */
|
|---|
| 2987 |
|
|---|
| 2988 | BOOL winhSetWindowFont(HWND hwnd,
|
|---|
| 2989 | const char *pcszFont)
|
|---|
| 2990 | {
|
|---|
| 2991 | CHAR szFont[256];
|
|---|
| 2992 |
|
|---|
| 2993 | if (pcszFont == NULL)
|
|---|
| 2994 | {
|
|---|
| 2995 | if (doshIsWarp4())
|
|---|
| 2996 | if(nlsDBCS())
|
|---|
| 2997 | strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
|
|---|
| 2998 | else
|
|---|
| 2999 | strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
|
|---|
| 3000 | else
|
|---|
| 3001 | if(nlsDBCS())
|
|---|
| 3002 | strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
|
|---|
| 3003 | else
|
|---|
| 3004 | strhncpy0(szFont, "8.Helv", sizeof(szFont));
|
|---|
| 3005 | }
|
|---|
| 3006 | else
|
|---|
| 3007 | strhncpy0(szFont, pcszFont, sizeof(szFont));
|
|---|
| 3008 |
|
|---|
| 3009 | return WinSetPresParam(hwnd,
|
|---|
| 3010 | PP_FONTNAMESIZE,
|
|---|
| 3011 | strlen(szFont)+1,
|
|---|
| 3012 | szFont);
|
|---|
| 3013 | }
|
|---|
| 3014 |
|
|---|
| 3015 | /*
|
|---|
| 3016 | *@@ winhSetControlsFont:
|
|---|
| 3017 | * this sets the font for all the controls of hwndDlg
|
|---|
| 3018 | * which have a control ID in the range of usIDMin to
|
|---|
| 3019 | * usIDMax. "Unused" IDs (i.e. -1) will also be set.
|
|---|
| 3020 | *
|
|---|
| 3021 | * If (pszFont == NULL), a default font will be set
|
|---|
| 3022 | * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
|
|---|
| 3023 | *
|
|---|
| 3024 | * Returns the no. of controls set.
|
|---|
| 3025 | *
|
|---|
| 3026 | *@@added V0.9.0 [umoeller]
|
|---|
| 3027 | *@@changed V1.0.4 (2005-09-02) [bvl]: Return 'Combined' fonts on DBCS systems to show DBCS characters properly @@fixes 655
|
|---|
| 3028 | */
|
|---|
| 3029 |
|
|---|
| 3030 | ULONG winhSetControlsFont(HWND hwndDlg, // in: dlg to set
|
|---|
| 3031 | SHORT usIDMin, // in: minimum control ID to be set (inclusive)
|
|---|
| 3032 | SHORT usIDMax, // in: maximum control ID to be set (inclusive)
|
|---|
| 3033 | const char *pcszFont) // in: font to use (e.g. "9.WarpSans") or NULL
|
|---|
| 3034 | {
|
|---|
| 3035 | ULONG ulrc = 0;
|
|---|
| 3036 | HENUM henum;
|
|---|
| 3037 | HWND hwndItem;
|
|---|
| 3038 | CHAR szFont[256];
|
|---|
| 3039 | ULONG cbFont;
|
|---|
| 3040 |
|
|---|
| 3041 | if (pcszFont == NULL)
|
|---|
| 3042 | {
|
|---|
| 3043 | if (doshIsWarp4())
|
|---|
| 3044 | if(nlsDBCS())
|
|---|
| 3045 | strhncpy0(szFont, "9.WarpSans Combined", sizeof(szFont));
|
|---|
| 3046 | else
|
|---|
| 3047 | strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
|
|---|
| 3048 | else
|
|---|
| 3049 | if(nlsDBCS())
|
|---|
| 3050 | strhncpy0(szFont, "8.Helv Combined", sizeof(szFont));
|
|---|
| 3051 | else
|
|---|
| 3052 | strhncpy0(szFont, "8.Helv", sizeof(szFont));
|
|---|
| 3053 | }
|
|---|
| 3054 | else
|
|---|
| 3055 | strhncpy0(szFont, pcszFont, sizeof(szFont));
|
|---|
| 3056 |
|
|---|
| 3057 | cbFont = strlen(szFont) + 1;
|
|---|
| 3058 |
|
|---|
| 3059 | // set font for all the dialog controls
|
|---|
| 3060 | henum = WinBeginEnumWindows(hwndDlg);
|
|---|
| 3061 | while ((hwndItem = WinGetNextWindow(henum)))
|
|---|
| 3062 | {
|
|---|
| 3063 | SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID);
|
|---|
| 3064 | if ( (sID == -1)
|
|---|
| 3065 | || ((sID >= usIDMin) && (sID <= usIDMax))
|
|---|
| 3066 | )
|
|---|
| 3067 | if (WinSetPresParam(hwndItem,
|
|---|
| 3068 | PP_FONTNAMESIZE,
|
|---|
| 3069 | cbFont,
|
|---|
| 3070 | szFont))
|
|---|
| 3071 | // successful:
|
|---|
| 3072 | ulrc++;
|
|---|
| 3073 | }
|
|---|
| 3074 | WinEndEnumWindows(henum);
|
|---|
| 3075 |
|
|---|
| 3076 | return ulrc;
|
|---|
| 3077 | }
|
|---|
| 3078 |
|
|---|
| 3079 | /*
|
|---|
| 3080 | *@@ winhStorePresParam:
|
|---|
| 3081 | * this appends a new presentation parameter to an
|
|---|
| 3082 | * array of presentation parameters which can be
|
|---|
| 3083 | * passed to WinCreateWindow. This is preferred
|
|---|
| 3084 | * over setting the presparams using WinSetPresParams,
|
|---|
| 3085 | * because that call will cause a lot of messages.
|
|---|
| 3086 | *
|
|---|
| 3087 | * On the first call, pppp _must_ be NULL. This
|
|---|
| 3088 | * will allocate memory for storing the given
|
|---|
| 3089 | * data as necessary and modify *pppp to point
|
|---|
| 3090 | * to the new array.
|
|---|
| 3091 | *
|
|---|
| 3092 | * On subsequent calls with the same pppp, memory
|
|---|
| 3093 | * will be reallocated, the old data will be copied,
|
|---|
| 3094 | * and the new given data will be appended.
|
|---|
| 3095 | *
|
|---|
| 3096 | * Use free() on your PPRESPARAMS pointer (whose
|
|---|
| 3097 | * address was passed) after WinCreateWindow.
|
|---|
| 3098 | *
|
|---|
| 3099 | * See winhQueryPresColor for typical presparams
|
|---|
| 3100 | * used in OS/2.
|
|---|
| 3101 | *
|
|---|
| 3102 | * Example:
|
|---|
| 3103 | *
|
|---|
| 3104 | + PPRESPARAMS ppp = NULL;
|
|---|
| 3105 | + CHAR szFont[] = "9.WarpSans";
|
|---|
| 3106 | + LONG lColor = CLR_WHITE;
|
|---|
| 3107 | + winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont);
|
|---|
| 3108 | + winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor);
|
|---|
| 3109 | + WinCreateWindow(...., ppp);
|
|---|
| 3110 | + free(ppp);
|
|---|
| 3111 | *
|
|---|
| 3112 | *@@added V0.9.0 [umoeller]
|
|---|
| 3113 | */
|
|---|
| 3114 |
|
|---|
| 3115 | BOOL winhStorePresParam(PPRESPARAMS *pppp, // in: data pointer (modified)
|
|---|
| 3116 | ULONG ulAttrType, // in: PP_* index
|
|---|
| 3117 | ULONG cbData, // in: sizeof(*pData), e.g. sizeof(LONG)
|
|---|
| 3118 | PVOID pData) // in: presparam data (e.g. a PLONG to a color)
|
|---|
| 3119 | {
|
|---|
| 3120 | BOOL brc = FALSE;
|
|---|
| 3121 | if (pppp)
|
|---|
| 3122 | {
|
|---|
| 3123 | ULONG cbOld = 0,
|
|---|
| 3124 | cbNew;
|
|---|
| 3125 | PBYTE pbTemp = 0;
|
|---|
| 3126 | PPRESPARAMS pppTemp = 0;
|
|---|
| 3127 | PPARAM pppCopyTo = 0;
|
|---|
| 3128 |
|
|---|
| 3129 | if (*pppp != NULL)
|
|---|
| 3130 | // subsequent calls:
|
|---|
| 3131 | cbOld = (**pppp).cb;
|
|---|
| 3132 |
|
|---|
| 3133 | cbNew = sizeof(ULONG) // PRESPARAMS.cb
|
|---|
| 3134 | + cbOld // old count, which does not include PRESPARAMS.cb
|
|---|
| 3135 | + sizeof(ULONG) // PRESPARAMS.aparam[0].id
|
|---|
| 3136 | + sizeof(ULONG) // PRESPARAMS.aparam[0].cb
|
|---|
| 3137 | + cbData; // PRESPARAMS.aparam[0].ab[]
|
|---|
| 3138 |
|
|---|
| 3139 | pbTemp = (PBYTE)malloc(cbNew);
|
|---|
| 3140 | if (pbTemp)
|
|---|
| 3141 | {
|
|---|
| 3142 | pppTemp = (PPRESPARAMS)pbTemp;
|
|---|
| 3143 |
|
|---|
| 3144 | if (*pppp != NULL)
|
|---|
| 3145 | {
|
|---|
| 3146 | // copy old data
|
|---|
| 3147 | memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb
|
|---|
| 3148 | pppCopyTo = (PPARAM)(pbTemp // new buffer
|
|---|
| 3149 | + sizeof(ULONG) // skipping PRESPARAMS.cb
|
|---|
| 3150 | + cbOld); // old PARAM array
|
|---|
| 3151 | }
|
|---|
| 3152 | else
|
|---|
| 3153 | // first call:
|
|---|
| 3154 | pppCopyTo = pppTemp->aparam;
|
|---|
| 3155 |
|
|---|
| 3156 | pppTemp->cb = cbNew - sizeof(ULONG); // excluding PRESPARAMS.cb
|
|---|
| 3157 | pppCopyTo->id = ulAttrType;
|
|---|
| 3158 | pppCopyTo->cb = cbData; // byte count of PARAM.ab[]
|
|---|
| 3159 | memcpy(pppCopyTo->ab, pData, cbData);
|
|---|
| 3160 |
|
|---|
| 3161 | free(*pppp);
|
|---|
| 3162 | *pppp = pppTemp;
|
|---|
| 3163 |
|
|---|
| 3164 | brc = TRUE;
|
|---|
| 3165 | }
|
|---|
| 3166 | }
|
|---|
| 3167 | return brc;
|
|---|
| 3168 | }
|
|---|
| 3169 |
|
|---|
| 3170 | /*
|
|---|
| 3171 | *@@ winhQueryPresColor2:
|
|---|
| 3172 | * returns the specified color. This is queried in the
|
|---|
| 3173 | * following order:
|
|---|
| 3174 | *
|
|---|
| 3175 | * 1) hwnd's pres params are searched for ulPP
|
|---|
| 3176 | * (which should be a PP_* index);
|
|---|
| 3177 | * 2) if (fInherit == TRUE), the parent windows
|
|---|
| 3178 | * are searched also;
|
|---|
| 3179 | * 3) if this fails or (fInherit == FALSE), WinQuerySysColor
|
|---|
| 3180 | * is called to get lSysColor (which should be a SYSCLR_*
|
|---|
| 3181 | * index), if lSysColor != -1;
|
|---|
| 3182 | * 4) if (lSysColor == -1), -1 is returned.
|
|---|
| 3183 | *
|
|---|
| 3184 | * The return value is always an RGB LONG, _not_ a color index.
|
|---|
| 3185 | * This is even true for the returned system colors, which are
|
|---|
| 3186 | * converted to RGB.
|
|---|
| 3187 | *
|
|---|
| 3188 | * If you do any painting with this value, you should switch
|
|---|
| 3189 | * the HPS you're using to RGB mode (use gpihSwitchToRGB for that).
|
|---|
| 3190 | *
|
|---|
| 3191 | * Some useful ulPP / lSysColor pairs
|
|---|
| 3192 | * (default values as in PMREF):
|
|---|
| 3193 | *
|
|---|
| 3194 | + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT (for most controls also)
|
|---|
| 3195 | + SYSCLR_WINDOWSTATICTEXT (for static controls)
|
|---|
| 3196 | + Foreground color (default: black)
|
|---|
| 3197 | + -- PP_BACKGROUNDCOLOR SYSCLR_BACKGROUND
|
|---|
| 3198 | + SYSCLR_DIALOGBACKGROUND
|
|---|
| 3199 | + SYSCLR_FIELDBACKGROUND (for disabled scrollbars)
|
|---|
| 3200 | + SYSCLR_WINDOW (application surface -- empty clients)
|
|---|
| 3201 | + Background color (default: light gray)
|
|---|
| 3202 | + -- PP_ACTIVETEXTFGNDCOLOR
|
|---|
| 3203 | + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
|
|---|
| 3204 | + Highlighted foreground color, for example for selected menu
|
|---|
| 3205 | + (def.: white)
|
|---|
| 3206 | + -- PP_ACTIVETEXTBGNDCOLOR
|
|---|
| 3207 | + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
|
|---|
| 3208 | + Highlighted background color (def.: dark gray)
|
|---|
| 3209 | + -- PP_INACTIVETEXTFGNDCOLOR
|
|---|
| 3210 | + -- PP_DISABLEDFOREGROUNDCOLOR SYSCLR_MENUDISABLEDTEXT
|
|---|
| 3211 | + Disabled foreground color (dark gray)
|
|---|
| 3212 | + -- PP_INACTIVETEXTBGNDCOLOR
|
|---|
| 3213 | + -- PP_DISABLEDBACKGROUNDCOLOR
|
|---|
| 3214 | + Disabled background color
|
|---|
| 3215 | + -- PP_BORDERCOLOR SYSCLR_WINDOWFRAME
|
|---|
| 3216 | + SYSCLR_INACTIVEBORDER
|
|---|
| 3217 | + Border color (around pushbuttons, in addition to
|
|---|
| 3218 | + the 3D colors)
|
|---|
| 3219 | + -- PP_ACTIVECOLOR SYSCLR_ACTIVETITLE
|
|---|
| 3220 | + Active color
|
|---|
| 3221 | + -- PP_INACTIVECOLOR SYSCLR_INACTIVETITLE
|
|---|
| 3222 | + Inactive color
|
|---|
| 3223 | *
|
|---|
| 3224 | * For menus:
|
|---|
| 3225 | + -- PP_MENUBACKGROUNDCOLOR SYSCLR_MENU
|
|---|
| 3226 | + -- PP_MENUFOREGROUNDCOLOR SYSCLR_MENUTEXT
|
|---|
| 3227 | + -- PP_MENUHILITEBGNDCOLOR SYSCLR_MENUHILITEBGND
|
|---|
| 3228 | + -- PP_MENUHILITEFGNDCOLOR SYSCLR_MENUHILITE
|
|---|
| 3229 | + -- ?? SYSCLR_MENUDISABLEDTEXT
|
|---|
| 3230 | +
|
|---|
| 3231 | * For containers (according to the API ref. at EDM/2):
|
|---|
| 3232 | + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT
|
|---|
| 3233 | + -- PP_BACKGROUNDCOLOR SYSCLR_WINDOW
|
|---|
| 3234 | + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
|
|---|
| 3235 | + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
|
|---|
| 3236 | + -- PP_BORDERCOLOR
|
|---|
| 3237 | + (used for separator lines, eg. in Details view)
|
|---|
| 3238 | + -- PP_ICONTEXTBACKGROUNDCOLOR
|
|---|
| 3239 | + (column titles in Details view?!?)
|
|---|
| 3240 | +
|
|---|
| 3241 | * For listboxes / entryfields / MLE's:
|
|---|
| 3242 | + -- PP_BACKGROUNDCOLOR SYSCLR_ENTRYFIELD
|
|---|
| 3243 | *
|
|---|
| 3244 | * PMREF has more of these.
|
|---|
| 3245 | *
|
|---|
| 3246 | *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed
|
|---|
| 3247 | *@@changed V0.9.0 [umoeller]: added fInherit parameter
|
|---|
| 3248 | *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support
|
|---|
| 3249 | *@@changed V0.9.20 (2002-08-04) [umoeller]: added ulPPIndex, renamed func
|
|---|
| 3250 | */
|
|---|
| 3251 |
|
|---|
| 3252 | LONG winhQueryPresColor2(HWND hwnd, // in: window to query
|
|---|
| 3253 | ULONG ulppRGB, // in: PP_* index for RGB color
|
|---|
| 3254 | ULONG ulppIndex, // in: PP_* index for color _index_ (can be null)
|
|---|
| 3255 | BOOL fInherit, // in: search parent windows too?
|
|---|
| 3256 | LONG lSysColor) // in: SYSCLR_* index or -1
|
|---|
| 3257 | {
|
|---|
| 3258 | ULONG ul,
|
|---|
| 3259 | attrFound;
|
|---|
| 3260 | LONG lColorFound;
|
|---|
| 3261 |
|
|---|
| 3262 | if (ulppRGB != (ULONG)-1)
|
|---|
| 3263 | {
|
|---|
| 3264 | ULONG fl = 0;
|
|---|
| 3265 | if (!fInherit)
|
|---|
| 3266 | fl = QPF_NOINHERIT;
|
|---|
| 3267 | if (ulppIndex)
|
|---|
| 3268 | fl |= QPF_ID2COLORINDEX; // convert indexed color 2 to RGB V0.9.20 (2002-08-04) [umoeller]
|
|---|
| 3269 |
|
|---|
| 3270 | if ((ul = WinQueryPresParam(hwnd,
|
|---|
| 3271 | ulppRGB,
|
|---|
| 3272 | ulppIndex,
|
|---|
| 3273 | &attrFound,
|
|---|
| 3274 | sizeof(lColorFound),
|
|---|
| 3275 | &lColorFound,
|
|---|
| 3276 | fl)))
|
|---|
| 3277 | return lColorFound;
|
|---|
| 3278 | }
|
|---|
| 3279 |
|
|---|
| 3280 | // not found: get system color
|
|---|
| 3281 | if (lSysColor != -1)
|
|---|
| 3282 | return WinQuerySysColor(HWND_DESKTOP, lSysColor, 0);
|
|---|
| 3283 |
|
|---|
| 3284 | return -1;
|
|---|
| 3285 | }
|
|---|
| 3286 |
|
|---|
| 3287 | /*
|
|---|
| 3288 | *@@ winhQueryPresColor:
|
|---|
| 3289 | * compatibility function because this one was
|
|---|
| 3290 | * exported.
|
|---|
| 3291 | *
|
|---|
| 3292 | *@@added V0.9.20 (2002-08-04) [umoeller]
|
|---|
| 3293 | */
|
|---|
| 3294 |
|
|---|
| 3295 | LONG XWPENTRY winhQueryPresColor(HWND hwnd,
|
|---|
| 3296 | ULONG ulPP,
|
|---|
| 3297 | BOOL fInherit,
|
|---|
| 3298 | LONG lSysColor)
|
|---|
| 3299 | {
|
|---|
| 3300 | return winhQueryPresColor2(hwnd,
|
|---|
| 3301 | ulPP,
|
|---|
| 3302 | 0,
|
|---|
| 3303 | fInherit,
|
|---|
| 3304 | lSysColor);
|
|---|
| 3305 | }
|
|---|
| 3306 |
|
|---|
| 3307 | /*
|
|---|
| 3308 | *@@ winhSetPresColor:
|
|---|
| 3309 | * sets a color presparam. ulIndex specifies
|
|---|
| 3310 | * the presparam to be set and would normally
|
|---|
| 3311 | * be either PP_BACKGROUNDCOLOR or PP_FOREGROUNDCOLOR.
|
|---|
| 3312 | *
|
|---|
| 3313 | *@@added V0.9.16 (2001-10-15) [umoeller]
|
|---|
| 3314 | */
|
|---|
| 3315 |
|
|---|
| 3316 | BOOL winhSetPresColor(HWND hwnd,
|
|---|
| 3317 | ULONG ulIndex,
|
|---|
| 3318 | LONG lColor)
|
|---|
| 3319 | {
|
|---|
| 3320 | return WinSetPresParam(hwnd,
|
|---|
| 3321 | ulIndex,
|
|---|
| 3322 | sizeof(LONG),
|
|---|
| 3323 | &lColor);
|
|---|
| 3324 | }
|
|---|
| 3325 |
|
|---|
| 3326 | /*
|
|---|
| 3327 | *@@category: Helpers\PM helpers\Help (IPF)
|
|---|
| 3328 | */
|
|---|
| 3329 |
|
|---|
| 3330 | /* ******************************************************************
|
|---|
| 3331 | *
|
|---|
| 3332 | * Help instance helpers
|
|---|
| 3333 | *
|
|---|
| 3334 | ********************************************************************/
|
|---|
| 3335 |
|
|---|
| 3336 | /*
|
|---|
| 3337 | *@@ winhCreateHelp:
|
|---|
| 3338 | * creates a help instance and connects it with the
|
|---|
| 3339 | * given frame window.
|
|---|
| 3340 | *
|
|---|
| 3341 | * If (pszFileName == NULL), we'll retrieve the
|
|---|
| 3342 | * executable's fully qualified file name and
|
|---|
| 3343 | * replace the extension with .HLP simply. This
|
|---|
| 3344 | * avoids the typical "Help not found" errors if
|
|---|
| 3345 | * the program isn't started in its own directory.
|
|---|
| 3346 | *
|
|---|
| 3347 | * If you have created a help table in memory, specify it
|
|---|
| 3348 | * with pHelpTable. To load a help table from the resources,
|
|---|
| 3349 | * specify hmod (or NULLHANDLE) and set pHelpTable to the
|
|---|
| 3350 | * following:
|
|---|
| 3351 | +
|
|---|
| 3352 | + (PHELPTABLE)MAKELONG(usTableID, 0xffff)
|
|---|
| 3353 | *
|
|---|
| 3354 | * Returns the help window handle or NULLHANDLE on errors.
|
|---|
| 3355 | *
|
|---|
| 3356 | * Based on an EDM/2 code snippet.
|
|---|
| 3357 | *
|
|---|
| 3358 | *@@added V0.9.4 (2000-07-03) [umoeller]
|
|---|
| 3359 | */
|
|---|
| 3360 |
|
|---|
| 3361 | HWND winhCreateHelp(HWND hwndFrame, // in: app's frame window handle; can be NULLHANDLE
|
|---|
| 3362 | const char *pcszFileName, // in: help file name or NULL
|
|---|
| 3363 | HMODULE hmod, // in: module with help table or NULLHANDLE (current)
|
|---|
| 3364 | PHELPTABLE pHelpTable, // in: help table or resource ID
|
|---|
| 3365 | const char *pcszWindowTitle) // in: help window title or NULL
|
|---|
| 3366 | {
|
|---|
| 3367 | HELPINIT hi;
|
|---|
| 3368 | PSZ pszExt;
|
|---|
| 3369 | CHAR szName[CCHMAXPATH];
|
|---|
| 3370 | HWND hwndHelp;
|
|---|
| 3371 |
|
|---|
| 3372 | if (pcszFileName == NULL)
|
|---|
| 3373 | {
|
|---|
| 3374 | PPIB ppib;
|
|---|
| 3375 | PTIB ptib;
|
|---|
| 3376 | DosGetInfoBlocks(&ptib, &ppib);
|
|---|
| 3377 | DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName);
|
|---|
| 3378 |
|
|---|
| 3379 | pszExt = strrchr(szName, '.');
|
|---|
| 3380 | if (pszExt)
|
|---|
| 3381 | strcpy(pszExt, ".hlp");
|
|---|
| 3382 | else
|
|---|
| 3383 | strcat(szName, ".hlp");
|
|---|
| 3384 |
|
|---|
| 3385 | pcszFileName = szName;
|
|---|
| 3386 | }
|
|---|
| 3387 |
|
|---|
| 3388 | hi.cb = sizeof(HELPINIT);
|
|---|
| 3389 | hi.ulReturnCode = 0;
|
|---|
| 3390 | hi.pszTutorialName = NULL;
|
|---|
| 3391 | hi.phtHelpTable = pHelpTable;
|
|---|
| 3392 | hi.hmodHelpTableModule = hmod;
|
|---|
| 3393 | hi.hmodAccelActionBarModule = NULLHANDLE;
|
|---|
| 3394 | hi.idAccelTable = 0;
|
|---|
| 3395 | hi.idActionBar = 0;
|
|---|
| 3396 | hi.pszHelpWindowTitle = (PSZ)pcszWindowTitle;
|
|---|
| 3397 | hi.fShowPanelId = CMIC_HIDE_PANEL_ID;
|
|---|
| 3398 | hi.pszHelpLibraryName = (PSZ)pcszFileName;
|
|---|
| 3399 |
|
|---|
| 3400 | hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame),
|
|---|
| 3401 | &hi);
|
|---|
| 3402 | if ((hwndFrame) && (hwndHelp))
|
|---|
| 3403 | {
|
|---|
| 3404 | WinAssociateHelpInstance(hwndHelp, hwndFrame);
|
|---|
| 3405 | }
|
|---|
| 3406 |
|
|---|
| 3407 | return hwndHelp;
|
|---|
| 3408 | }
|
|---|
| 3409 |
|
|---|
| 3410 | /*
|
|---|
| 3411 | *@@ winhDisplayHelpPanel:
|
|---|
| 3412 | * displays the specified help panel ID.
|
|---|
| 3413 | *
|
|---|
| 3414 | * If (ulHelpPanel == 0), this displays the
|
|---|
| 3415 | * standard OS/2 "Using help" panel.
|
|---|
| 3416 | *
|
|---|
| 3417 | * Returns zero on success or one of the
|
|---|
| 3418 | * help manager error codes on failure.
|
|---|
| 3419 | * See HM_ERROR for those.
|
|---|
| 3420 | *
|
|---|
| 3421 | *@@added V0.9.7 (2001-01-21) [umoeller]
|
|---|
| 3422 | */
|
|---|
| 3423 |
|
|---|
| 3424 | ULONG winhDisplayHelpPanel(HWND hwndHelpInstance, // in: from winhCreateHelp
|
|---|
| 3425 | ULONG ulHelpPanel) // in: help panel ID
|
|---|
| 3426 | {
|
|---|
| 3427 | return (ULONG)WinSendMsg(hwndHelpInstance,
|
|---|
| 3428 | HM_DISPLAY_HELP,
|
|---|
| 3429 | (MPARAM)ulHelpPanel,
|
|---|
| 3430 | (MPARAM)( (ulHelpPanel != 0)
|
|---|
| 3431 | ? HM_RESOURCEID
|
|---|
| 3432 | : 0));
|
|---|
| 3433 | }
|
|---|
| 3434 |
|
|---|
| 3435 | /*
|
|---|
| 3436 | *@@ winhDestroyHelp:
|
|---|
| 3437 | * destroys the help instance created by winhCreateHelp.
|
|---|
| 3438 | *
|
|---|
| 3439 | * Based on an EDM/2 code snippet.
|
|---|
| 3440 | *
|
|---|
| 3441 | *@@added V0.9.4 (2000-07-03) [umoeller]
|
|---|
| 3442 | */
|
|---|
| 3443 |
|
|---|
| 3444 | void winhDestroyHelp(HWND hwndHelp,
|
|---|
| 3445 | HWND hwndFrame) // can be NULLHANDLE if not used with winhCreateHelp
|
|---|
| 3446 | {
|
|---|
| 3447 | if (hwndHelp)
|
|---|
| 3448 | {
|
|---|
| 3449 | if (hwndFrame)
|
|---|
| 3450 | WinAssociateHelpInstance(NULLHANDLE, hwndFrame);
|
|---|
| 3451 | WinDestroyHelpInstance(hwndHelp);
|
|---|
| 3452 | }
|
|---|
| 3453 | }
|
|---|
| 3454 |
|
|---|
| 3455 | /*
|
|---|
| 3456 | *@@category: Helpers\PM helpers\Application control
|
|---|
| 3457 | */
|
|---|
| 3458 |
|
|---|
| 3459 | /* ******************************************************************
|
|---|
| 3460 | *
|
|---|
| 3461 | * Application control
|
|---|
| 3462 | *
|
|---|
| 3463 | ********************************************************************/
|
|---|
| 3464 |
|
|---|
| 3465 | /*
|
|---|
| 3466 | *@@ winhAnotherInstance:
|
|---|
| 3467 | * this tests whether another instance of the same
|
|---|
| 3468 | * application is already running.
|
|---|
| 3469 | *
|
|---|
| 3470 | * To identify instances of the same application, the
|
|---|
| 3471 | * application must call this function during startup
|
|---|
| 3472 | * with the unique name of an OS/2 semaphore. As with
|
|---|
| 3473 | * all OS/2 semaphores, the semaphore name must begin
|
|---|
| 3474 | * with "\\SEM32\\". The semaphore isn't really used
|
|---|
| 3475 | * except for testing for its existence, since that
|
|---|
| 3476 | * name is unique among all processes.
|
|---|
| 3477 | *
|
|---|
| 3478 | * If another instance is found, TRUE is returned. If
|
|---|
| 3479 | * (fSwitch == TRUE), that instance is switched to,
|
|---|
| 3480 | * using the tasklist.
|
|---|
| 3481 | *
|
|---|
| 3482 | * If no other instance is found, FALSE is returned only.
|
|---|
| 3483 | *
|
|---|
| 3484 | * Based on an EDM/2 code snippet.
|
|---|
| 3485 | *
|
|---|
| 3486 | *@@added V0.9.0 (99-10-22) [umoeller]
|
|---|
| 3487 | */
|
|---|
| 3488 |
|
|---|
| 3489 | BOOL winhAnotherInstance(const char *pcszSemName, // in: semaphore ID
|
|---|
| 3490 | BOOL fSwitch) // in: if TRUE, switch to first instance if running
|
|---|
| 3491 | {
|
|---|
| 3492 | HMTX hmtx;
|
|---|
| 3493 |
|
|---|
| 3494 | if (DosCreateMutexSem((PSZ)pcszSemName,
|
|---|
| 3495 | &hmtx,
|
|---|
| 3496 | DC_SEM_SHARED,
|
|---|
| 3497 | TRUE)
|
|---|
| 3498 | == NO_ERROR)
|
|---|
| 3499 | // semapore created: this doesn't happen if the semaphore
|
|---|
| 3500 | // exists already, so no other instance is running
|
|---|
| 3501 | return FALSE;
|
|---|
| 3502 |
|
|---|
| 3503 | // else: instance running
|
|---|
| 3504 | hmtx = NULLHANDLE;
|
|---|
| 3505 |
|
|---|
| 3506 | // switch to other instance?
|
|---|
| 3507 | if (fSwitch)
|
|---|
| 3508 | {
|
|---|
| 3509 | // yes: query mutex creator
|
|---|
| 3510 | if (DosOpenMutexSem((PSZ)pcszSemName,
|
|---|
| 3511 | &hmtx)
|
|---|
| 3512 | == NO_ERROR)
|
|---|
| 3513 | {
|
|---|
| 3514 | PID pid = 0;
|
|---|
| 3515 | TID tid = 0; // unused
|
|---|
| 3516 | ULONG ulCount; // unused
|
|---|
| 3517 |
|
|---|
| 3518 | if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
|
|---|
| 3519 | {
|
|---|
| 3520 | HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
|
|---|
| 3521 | if (hswitch != NULLHANDLE)
|
|---|
| 3522 | WinSwitchToProgram(hswitch);
|
|---|
| 3523 | }
|
|---|
| 3524 |
|
|---|
| 3525 | DosCloseMutexSem(hmtx);
|
|---|
| 3526 | }
|
|---|
| 3527 | }
|
|---|
| 3528 |
|
|---|
| 3529 | return TRUE; // another instance exists
|
|---|
| 3530 | }
|
|---|
| 3531 |
|
|---|
| 3532 | /*
|
|---|
| 3533 | *@@ winhAddToTasklist:
|
|---|
| 3534 | * this adds the specified window to the tasklist
|
|---|
| 3535 | * with hIcon as its program icon (which is also
|
|---|
| 3536 | * set for the main window). This is useful for
|
|---|
| 3537 | * the old "dialog as main window" trick.
|
|---|
| 3538 | *
|
|---|
| 3539 | * Returns the HSWITCH of the added entry.
|
|---|
| 3540 | */
|
|---|
| 3541 |
|
|---|
| 3542 | HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
|
|---|
| 3543 | HPOINTER hIcon) // in: icon for main window
|
|---|
| 3544 | {
|
|---|
| 3545 | SWCNTRL swctl;
|
|---|
| 3546 | HSWITCH hswitch = 0;
|
|---|
| 3547 | swctl.hwnd = hwnd; // window handle
|
|---|
| 3548 | swctl.hwndIcon = hIcon; // icon handle
|
|---|
| 3549 | swctl.hprog = NULLHANDLE; // program handle (use default)
|
|---|
| 3550 | WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
|
|---|
| 3551 | // process identifier
|
|---|
| 3552 | swctl.idSession = 0; // session identifier ?
|
|---|
| 3553 | swctl.uchVisibility = SWL_VISIBLE; // visibility
|
|---|
| 3554 | swctl.fbJump = SWL_JUMPABLE; // jump indicator
|
|---|
| 3555 | // get window title from window titlebar
|
|---|
| 3556 | if (hwnd)
|
|---|
| 3557 | WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
|
|---|
| 3558 | swctl.bProgType = PROG_DEFAULT; // program type
|
|---|
| 3559 | hswitch = WinAddSwitchEntry(&swctl);
|
|---|
| 3560 |
|
|---|
| 3561 | // give the main window the icon
|
|---|
| 3562 | if ((hwnd) && (hIcon))
|
|---|
| 3563 | WinSendMsg(hwnd,
|
|---|
| 3564 | WM_SETICON,
|
|---|
| 3565 | (MPARAM)hIcon,
|
|---|
| 3566 | NULL);
|
|---|
| 3567 |
|
|---|
| 3568 | return hswitch;
|
|---|
| 3569 | }
|
|---|
| 3570 |
|
|---|
| 3571 | /*
|
|---|
| 3572 | *@@category: Helpers\PM helpers\Miscellaneous
|
|---|
| 3573 | */
|
|---|
| 3574 |
|
|---|
| 3575 | /* ******************************************************************
|
|---|
| 3576 | *
|
|---|
| 3577 | * Miscellaneous
|
|---|
| 3578 | *
|
|---|
| 3579 | ********************************************************************/
|
|---|
| 3580 |
|
|---|
| 3581 | /*
|
|---|
| 3582 | *@@ winhMyAnchorBlock:
|
|---|
| 3583 | * returns the proper anchor block (HAB)
|
|---|
| 3584 | * for the calling thread.
|
|---|
| 3585 | *
|
|---|
| 3586 | * Many Win* functions require an HAB to be
|
|---|
| 3587 | * passed in. While many of them will work
|
|---|
| 3588 | * when passing in NULLHANDLE, some (such as
|
|---|
| 3589 | * WinGetMsg) won't. If you don't know the
|
|---|
| 3590 | * anchor block of the calling thread, use
|
|---|
| 3591 | * this function.
|
|---|
| 3592 | *
|
|---|
| 3593 | * This creates a temporary object window to
|
|---|
| 3594 | * find out the anchor block. This is quite
|
|---|
| 3595 | * expensive so only use this if there's no
|
|---|
| 3596 | * other way to find out.
|
|---|
| 3597 | *
|
|---|
| 3598 | *@@added V0.9.11 (2001-04-20) [umoeller]
|
|---|
| 3599 | */
|
|---|
| 3600 |
|
|---|
| 3601 | HAB winhMyAnchorBlock(VOID)
|
|---|
| 3602 | {
|
|---|
| 3603 | HAB hab = NULLHANDLE;
|
|---|
| 3604 | HWND hwnd;
|
|---|
| 3605 | if (hwnd = winhCreateObjectWindow(WC_BUTTON, NULL))
|
|---|
| 3606 | {
|
|---|
| 3607 | hab = WinQueryAnchorBlock(hwnd);
|
|---|
| 3608 | WinDestroyWindow(hwnd);
|
|---|
| 3609 | }
|
|---|
| 3610 |
|
|---|
| 3611 | return hab;
|
|---|
| 3612 | }
|
|---|
| 3613 |
|
|---|
| 3614 | /*
|
|---|
| 3615 | *@@ winhFree:
|
|---|
| 3616 | * frees a block of memory allocated by the
|
|---|
| 3617 | * winh* functions.
|
|---|
| 3618 | *
|
|---|
| 3619 | * Since the winh* functions use malloc(),
|
|---|
| 3620 | * you can also use free() directly on such
|
|---|
| 3621 | * blocks. However, you must use winhFree
|
|---|
| 3622 | * if the winh* functions are in a module
|
|---|
| 3623 | * with a different C runtime.
|
|---|
| 3624 | *
|
|---|
| 3625 | *@@added V0.9.7 (2000-12-06) [umoeller]
|
|---|
| 3626 | */
|
|---|
| 3627 |
|
|---|
| 3628 | VOID winhFree(PVOID p)
|
|---|
| 3629 | {
|
|---|
| 3630 | if (p)
|
|---|
| 3631 | free(p);
|
|---|
| 3632 | }
|
|---|
| 3633 |
|
|---|
| 3634 | /*
|
|---|
| 3635 | *@@ winhSleep:
|
|---|
| 3636 | * sleeps at least the specified amount of time,
|
|---|
| 3637 | * without blocking the message queue.
|
|---|
| 3638 | *
|
|---|
| 3639 | * NOTE: This function is a bit expensive because
|
|---|
| 3640 | * it creates a temporary object window. If you
|
|---|
| 3641 | * need to sleep several times, you should rather
|
|---|
| 3642 | * use a private timer.
|
|---|
| 3643 | *
|
|---|
| 3644 | *@@added V0.9.4 (2000-07-11) [umoeller]
|
|---|
| 3645 | *@@changed V0.9.9 (2001-03-11) [umoeller]: rewritten
|
|---|
| 3646 | */
|
|---|
| 3647 |
|
|---|
| 3648 | VOID winhSleep(ULONG ulSleep) // in: sleep time in milliseconds
|
|---|
| 3649 | {
|
|---|
| 3650 | HWND hwnd;
|
|---|
| 3651 |
|
|---|
| 3652 | if (hwnd = winhCreateObjectWindow(WC_STATIC, NULL))
|
|---|
| 3653 | {
|
|---|
| 3654 | QMSG qmsg;
|
|---|
| 3655 | HAB hab;
|
|---|
| 3656 |
|
|---|
| 3657 | if ( (hab = WinQueryAnchorBlock(hwnd))
|
|---|
| 3658 | && (WinStartTimer(hab,
|
|---|
| 3659 | hwnd,
|
|---|
| 3660 | 1,
|
|---|
| 3661 | ulSleep))
|
|---|
| 3662 | )
|
|---|
| 3663 | {
|
|---|
| 3664 | while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
|
|---|
| 3665 | {
|
|---|
| 3666 | if ( (qmsg.hwnd == hwnd)
|
|---|
| 3667 | && (qmsg.msg == WM_TIMER)
|
|---|
| 3668 | && (qmsg.mp1 == (MPARAM)1) // timer ID
|
|---|
| 3669 | )
|
|---|
| 3670 | break;
|
|---|
| 3671 |
|
|---|
| 3672 | WinDispatchMsg(hab, &qmsg);
|
|---|
| 3673 | }
|
|---|
| 3674 | WinStopTimer(hab,
|
|---|
| 3675 | hwnd,
|
|---|
| 3676 | 1);
|
|---|
| 3677 | }
|
|---|
| 3678 | else
|
|---|
| 3679 | // timer creation failed:
|
|---|
| 3680 | DosSleep(ulSleep);
|
|---|
| 3681 |
|
|---|
| 3682 | WinDestroyWindow(hwnd);
|
|---|
| 3683 | }
|
|---|
| 3684 | else
|
|---|
| 3685 | DosSleep(ulSleep);
|
|---|
| 3686 | }
|
|---|
| 3687 |
|
|---|
| 3688 | /*
|
|---|
| 3689 | *@@ winhFileDlg:
|
|---|
| 3690 | * one-short function for opening an "Open" file
|
|---|
| 3691 | * dialog.
|
|---|
| 3692 | *
|
|---|
| 3693 | * On input, pszFile specifies the directory and
|
|---|
| 3694 | * file specification (e.g. "F:\*.txt").
|
|---|
| 3695 | *
|
|---|
| 3696 | * Returns TRUE if the user pressed OK. In that
|
|---|
| 3697 | * case, the fully qualified filename is written
|
|---|
| 3698 | * into pszFile again.
|
|---|
| 3699 | *
|
|---|
| 3700 | * Returns FALSE if the user pressed Cancel.
|
|---|
| 3701 | *
|
|---|
| 3702 | * Notes about flFlags:
|
|---|
| 3703 | *
|
|---|
| 3704 | * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
|
|---|
| 3705 | * Otherwise an "Open" dialog is displayed.
|
|---|
| 3706 | *
|
|---|
| 3707 | * -- WINH_FOD_INILOADDIR: load a directory from the
|
|---|
| 3708 | * specified INI key and switch the dlg to it.
|
|---|
| 3709 | * In that case, on input, pszFile must only
|
|---|
| 3710 | * contain the file filter without any path
|
|---|
| 3711 | * specification, because that is loaded from
|
|---|
| 3712 | * the INI key. If the INI key does not exist,
|
|---|
| 3713 | * the current process directory will be used.
|
|---|
| 3714 | *
|
|---|
| 3715 | * -- WINH_FOD_INISAVEDIR: if the user presses OK,
|
|---|
| 3716 | * the directory of the selected file is written
|
|---|
| 3717 | * to the specified INI key so that it can be
|
|---|
| 3718 | * reused later. This flag is independent of
|
|---|
| 3719 | * WINH_FOD_INISAVEDIR: you can specify none,
|
|---|
| 3720 | * one, or both of them.
|
|---|
| 3721 | *
|
|---|
| 3722 | *@@added V0.9.3 (2000-04-29) [umoeller]
|
|---|
| 3723 | *@@changed V0.9.12 (2001-05-21) [umoeller]: this failed if INI data had root dir, fixed
|
|---|
| 3724 | */
|
|---|
| 3725 |
|
|---|
| 3726 | BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
|
|---|
| 3727 | PSZ pszFile, // in: file mask; out: fully q'd filename
|
|---|
| 3728 | // (should be CCHMAXPATH in size)
|
|---|
| 3729 | ULONG flFlags, // in: any combination of the following:
|
|---|
| 3730 | // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
|
|---|
| 3731 | // -- WINH_FOD_INILOADDIR: load FOD path from INI
|
|---|
| 3732 | // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
|
|---|
| 3733 | HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
|
|---|
| 3734 | const char *pcszApplication, // in: INI application to load/store last path from
|
|---|
| 3735 | const char *pcszKey) // in: INI key to load/store last path from
|
|---|
| 3736 | {
|
|---|
| 3737 | FILEDLG fd;
|
|---|
| 3738 | FILESTATUS3 fs3;
|
|---|
| 3739 |
|
|---|
| 3740 | memset(&fd, 0, sizeof(FILEDLG));
|
|---|
| 3741 | fd.cbSize = sizeof(FILEDLG);
|
|---|
| 3742 | fd.fl = FDS_CENTER;
|
|---|
| 3743 |
|
|---|
| 3744 | if (flFlags & WINH_FOD_SAVEDLG)
|
|---|
| 3745 | fd.fl |= FDS_SAVEAS_DIALOG;
|
|---|
| 3746 | else
|
|---|
| 3747 | fd.fl |= FDS_OPEN_DIALOG;
|
|---|
| 3748 |
|
|---|
| 3749 | if ( (hini)
|
|---|
| 3750 | && (flFlags & WINH_FOD_INILOADDIR)
|
|---|
| 3751 | && (PrfQueryProfileString(hini,
|
|---|
| 3752 | (PSZ)pcszApplication,
|
|---|
| 3753 | (PSZ)pcszKey,
|
|---|
| 3754 | "", // default string V0.9.9 (2001-02-10) [umoeller]
|
|---|
| 3755 | fd.szFullFile,
|
|---|
| 3756 | sizeof(fd.szFullFile)-10)
|
|---|
| 3757 | > 2)
|
|---|
| 3758 | // added these checks V0.9.12 (2001-05-21) [umoeller]
|
|---|
| 3759 | && (!DosQueryPathInfo(fd.szFullFile,
|
|---|
| 3760 | FIL_STANDARD,
|
|---|
| 3761 | &fs3,
|
|---|
| 3762 | sizeof(fs3)))
|
|---|
| 3763 | && (fs3.attrFile & FILE_DIRECTORY)
|
|---|
| 3764 | )
|
|---|
| 3765 | {
|
|---|
| 3766 | // found: append "\*"
|
|---|
| 3767 | strcat(fd.szFullFile, "\\");
|
|---|
| 3768 | strcat(fd.szFullFile, pszFile);
|
|---|
| 3769 | }
|
|---|
| 3770 | else
|
|---|
| 3771 | // default: copy pszFile
|
|---|
| 3772 | strcpy(fd.szFullFile, pszFile);
|
|---|
| 3773 | // fixed V0.9.12 (2001-05-21) [umoeller]
|
|---|
| 3774 |
|
|---|
| 3775 | if ( WinFileDlg(HWND_DESKTOP, // parent
|
|---|
| 3776 | hwndOwner, // owner
|
|---|
| 3777 | &fd)
|
|---|
| 3778 | && (fd.lReturn == DID_OK)
|
|---|
| 3779 | )
|
|---|
| 3780 | {
|
|---|
| 3781 | // save path back?
|
|---|
| 3782 | if ( (hini)
|
|---|
| 3783 | && (flFlags & WINH_FOD_INISAVEDIR)
|
|---|
| 3784 | )
|
|---|
| 3785 | {
|
|---|
| 3786 | // get the directory that was used
|
|---|
| 3787 | PSZ p = strrchr(fd.szFullFile, '\\');
|
|---|
| 3788 | if (p)
|
|---|
| 3789 | {
|
|---|
| 3790 | // contains directory:
|
|---|
| 3791 | // copy to OS2.INI
|
|---|
| 3792 | PSZ pszDir = strhSubstr(fd.szFullFile, p);
|
|---|
| 3793 | if (pszDir)
|
|---|
| 3794 | {
|
|---|
| 3795 | PrfWriteProfileString(hini,
|
|---|
| 3796 | (PSZ)pcszApplication,
|
|---|
| 3797 | (PSZ)pcszKey,
|
|---|
| 3798 | pszDir);
|
|---|
| 3799 | free(pszDir);
|
|---|
| 3800 | }
|
|---|
| 3801 | }
|
|---|
| 3802 | }
|
|---|
| 3803 |
|
|---|
| 3804 | strcpy(pszFile, fd.szFullFile);
|
|---|
| 3805 |
|
|---|
| 3806 | return TRUE;
|
|---|
| 3807 | }
|
|---|
| 3808 |
|
|---|
| 3809 | return FALSE;
|
|---|
| 3810 | }
|
|---|
| 3811 |
|
|---|
| 3812 | /*
|
|---|
| 3813 | *@@ winhSetWaitPointer:
|
|---|
| 3814 | * this sets the mouse pointer to "Wait".
|
|---|
| 3815 | * Returns the previous pointer (HPOINTER),
|
|---|
| 3816 | * which should be stored somewhere to be
|
|---|
| 3817 | * restored later. Example:
|
|---|
| 3818 | + HPOINTER hptrOld = winhSetWaitPointer();
|
|---|
| 3819 | + ...
|
|---|
| 3820 | + WinSetPointer(HWND_DESKTOP, hptrOld);
|
|---|
| 3821 | */
|
|---|
| 3822 |
|
|---|
| 3823 | HPOINTER winhSetWaitPointer(VOID)
|
|---|
| 3824 | {
|
|---|
| 3825 | HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
|
|---|
| 3826 | WinSetPointer(HWND_DESKTOP,
|
|---|
| 3827 | WinQuerySysPointer(HWND_DESKTOP,
|
|---|
| 3828 | SPTR_WAIT,
|
|---|
| 3829 | FALSE)); // no copy
|
|---|
| 3830 | return hptr;
|
|---|
| 3831 | }
|
|---|
| 3832 |
|
|---|
| 3833 | /*
|
|---|
| 3834 | *@@ winhQueryWindowText:
|
|---|
| 3835 | * this returns the window text of the specified
|
|---|
| 3836 | * HWND in a newly allocated buffer.
|
|---|
| 3837 | *
|
|---|
| 3838 | * Returns NULL on error. Use free()
|
|---|
| 3839 | * to free the return value.
|
|---|
| 3840 | */
|
|---|
| 3841 |
|
|---|
| 3842 | PSZ winhQueryWindowText(HWND hwnd)
|
|---|
| 3843 | {
|
|---|
| 3844 | PSZ pszText = NULL;
|
|---|
| 3845 | ULONG cbText = WinQueryWindowTextLength(hwnd);
|
|---|
| 3846 | // additional null character
|
|---|
| 3847 | if (cbText)
|
|---|
| 3848 | {
|
|---|
| 3849 | if (pszText = (PSZ)malloc(cbText + 1))
|
|---|
| 3850 | WinQueryWindowText(hwnd,
|
|---|
| 3851 | cbText + 1,
|
|---|
| 3852 | pszText);
|
|---|
| 3853 | }
|
|---|
| 3854 | return pszText;
|
|---|
| 3855 | }
|
|---|
| 3856 |
|
|---|
| 3857 | /*
|
|---|
| 3858 | *@@ winhSetWindowText:
|
|---|
| 3859 | * like WinSetWindowText, but this one accepts
|
|---|
| 3860 | * printf-like arguments.
|
|---|
| 3861 | *
|
|---|
| 3862 | * Note that the total string is limited to
|
|---|
| 3863 | * 1000 characters.
|
|---|
| 3864 | *
|
|---|
| 3865 | *@@added V0.9.16 (2001-10-08) [umoeller]
|
|---|
| 3866 | */
|
|---|
| 3867 |
|
|---|
| 3868 | BOOL winhSetWindowText(HWND hwnd,
|
|---|
| 3869 | const char *pcszFormat,
|
|---|
| 3870 | ...)
|
|---|
| 3871 | {
|
|---|
| 3872 | CHAR szBuf[1000];
|
|---|
| 3873 | va_list args;
|
|---|
| 3874 | int i;
|
|---|
| 3875 | va_start(args, pcszFormat);
|
|---|
| 3876 | i = vsprintf(szBuf, pcszFormat, args);
|
|---|
| 3877 | va_end(args);
|
|---|
| 3878 |
|
|---|
| 3879 | return WinSetWindowText(hwnd,
|
|---|
| 3880 | szBuf);
|
|---|
| 3881 | }
|
|---|
| 3882 |
|
|---|
| 3883 | /*
|
|---|
| 3884 | *@@ winhReplaceWindowText:
|
|---|
| 3885 | * this is a combination of winhQueryWindowText
|
|---|
| 3886 | * and strhFindReplace to replace substrings in a window.
|
|---|
| 3887 | *
|
|---|
| 3888 | * This is useful for filling in placeholders
|
|---|
| 3889 | * a la "%1" in control windows, e.g. static
|
|---|
| 3890 | * texts.
|
|---|
| 3891 | *
|
|---|
| 3892 | * This replaces only the first occurence of
|
|---|
| 3893 | * pszSearch.
|
|---|
| 3894 | *
|
|---|
| 3895 | * Returns TRUE only if the window exists and
|
|---|
| 3896 | * the search string was replaced.
|
|---|
| 3897 | *
|
|---|
| 3898 | *@@added V0.9.0 [umoeller]
|
|---|
| 3899 | */
|
|---|
| 3900 |
|
|---|
| 3901 | BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
|
|---|
| 3902 | const char *pcszSearch, // in: search string (e.g. "%1")
|
|---|
| 3903 | const char *pcszReplaceWith) // in: replacement string for pszSearch
|
|---|
| 3904 | {
|
|---|
| 3905 | BOOL brc = FALSE;
|
|---|
| 3906 | PSZ pszText = winhQueryWindowText(hwnd);
|
|---|
| 3907 | if (pszText)
|
|---|
| 3908 | {
|
|---|
| 3909 | ULONG ulOfs = 0;
|
|---|
| 3910 | if (strhFindReplace(&pszText, &ulOfs, pcszSearch, pcszReplaceWith) > 0)
|
|---|
| 3911 | {
|
|---|
| 3912 | WinSetWindowText(hwnd, pszText);
|
|---|
| 3913 | brc = TRUE;
|
|---|
| 3914 | }
|
|---|
| 3915 | free(pszText);
|
|---|
| 3916 | }
|
|---|
| 3917 | return brc;
|
|---|
| 3918 | }
|
|---|
| 3919 |
|
|---|
| 3920 | /*
|
|---|
| 3921 | *@@ winhEnableDlgItems:
|
|---|
| 3922 | * this enables/disables a whole range of controls
|
|---|
| 3923 | * in a window by enumerating the child windows
|
|---|
| 3924 | * until usIDFirst is found. If so, that subwindow
|
|---|
| 3925 | * is enabled/disabled and all the following windows
|
|---|
| 3926 | * in the enumeration also, until usIDLast is found.
|
|---|
| 3927 | *
|
|---|
| 3928 | * Note that this affects _all_ controls following
|
|---|
| 3929 | * the usIDFirst window, no matter what ID they have
|
|---|
| 3930 | * (even if "-1"), until usIDLast is found.
|
|---|
| 3931 | *
|
|---|
| 3932 | * Returns the no. of controls which were enabled/disabled
|
|---|
| 3933 | * (null if none).
|
|---|
| 3934 | *
|
|---|
| 3935 | *@@added V0.9.0 [umoeller]
|
|---|
| 3936 | *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
|
|---|
| 3937 | */
|
|---|
| 3938 |
|
|---|
| 3939 | ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
|
|---|
| 3940 | USHORT usIDFirst, // in: first affected control ID
|
|---|
| 3941 | USHORT usIDLast, // in: last affected control ID (inclusive)
|
|---|
| 3942 | BOOL fEnable) // in: enable or disable?
|
|---|
| 3943 | {
|
|---|
| 3944 | HENUM henum1 = NULLHANDLE;
|
|---|
| 3945 | HWND hwndThis = NULLHANDLE;
|
|---|
| 3946 | ULONG ulCount = 0;
|
|---|
| 3947 |
|
|---|
| 3948 | henum1 = WinBeginEnumWindows(hwndDlg);
|
|---|
| 3949 | while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
|
|---|
| 3950 | {
|
|---|
| 3951 | USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
|
|---|
| 3952 | usIDCheckLast;
|
|---|
| 3953 | if (usIDCheckFirst == usIDFirst)
|
|---|
| 3954 | {
|
|---|
| 3955 | WinEnableWindow(hwndThis, fEnable);
|
|---|
| 3956 | ulCount++;
|
|---|
| 3957 |
|
|---|
| 3958 | while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
|
|---|
| 3959 | {
|
|---|
| 3960 | WinEnableWindow(hwndThis, fEnable);
|
|---|
| 3961 | ulCount++;
|
|---|
| 3962 | usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
|
|---|
| 3963 | if (usIDCheckLast == usIDLast)
|
|---|
| 3964 | break;
|
|---|
| 3965 | }
|
|---|
| 3966 |
|
|---|
| 3967 | break; // outer loop
|
|---|
| 3968 | }
|
|---|
| 3969 | }
|
|---|
| 3970 | WinEndEnumWindows(henum1);
|
|---|
| 3971 |
|
|---|
| 3972 | return ulCount;
|
|---|
| 3973 | }
|
|---|
| 3974 |
|
|---|
| 3975 | /*
|
|---|
| 3976 | *@@ winhEnableControls2:
|
|---|
| 3977 | * like winhEnableControls, but instead this
|
|---|
| 3978 | * takes an array of ULONGs as input, which
|
|---|
| 3979 | * is assumed to contain the dialog IDs of
|
|---|
| 3980 | * the controls to be enabled/disabled.
|
|---|
| 3981 | *
|
|---|
| 3982 | *@@added V0.9.19 (2002-05-28) [umoeller]
|
|---|
| 3983 | */
|
|---|
| 3984 |
|
|---|
| 3985 | ULONG winhEnableControls2(HWND hwndDlg, // in: dialog window
|
|---|
| 3986 | const ULONG *paulIDs, // in: array of dialog IDs
|
|---|
| 3987 | ULONG cIDs, // in: array item count (NOT array size)
|
|---|
| 3988 | BOOL fEnable) // in: enable or disable?
|
|---|
| 3989 | {
|
|---|
| 3990 | ULONG ul,
|
|---|
| 3991 | ulrc = 0;
|
|---|
| 3992 | for (ul = 0;
|
|---|
| 3993 | ul < cIDs;
|
|---|
| 3994 | ++ul)
|
|---|
| 3995 | {
|
|---|
| 3996 | if (WinEnableControl(hwndDlg, paulIDs[ul], fEnable))
|
|---|
| 3997 | ++ulrc;
|
|---|
| 3998 | }
|
|---|
| 3999 |
|
|---|
| 4000 | return ulrc;
|
|---|
| 4001 | }
|
|---|
| 4002 |
|
|---|
| 4003 | /*
|
|---|
| 4004 | *@@ winhCreateStdWindow:
|
|---|
| 4005 | * much like WinCreateStdWindow, but this one
|
|---|
| 4006 | * allows you to have the standard window
|
|---|
| 4007 | * positioned automatically, using a given
|
|---|
| 4008 | * SWP structure (*pswpFrame).
|
|---|
| 4009 | *
|
|---|
| 4010 | * The frame is created with the specified parent
|
|---|
| 4011 | * (usually HWND_DESKTOP), but no owner.
|
|---|
| 4012 | *
|
|---|
| 4013 | * The client window is created with the frame as
|
|---|
| 4014 | * its parent and owner and gets an ID of FID_CLIENT.
|
|---|
| 4015 | *
|
|---|
| 4016 | * Alternatively, you can set pswpFrame to NULL
|
|---|
| 4017 | * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
|
|---|
| 4018 | * If you want the window to be shown, specify
|
|---|
| 4019 | * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
|
|---|
| 4020 | *
|
|---|
| 4021 | *@@added V0.9.0 [umoeller]
|
|---|
| 4022 | *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
|
|---|
| 4023 | *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
|
|---|
| 4024 | */
|
|---|
| 4025 |
|
|---|
| 4026 | HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
|
|---|
| 4027 | PSWP pswpFrame, // in: frame wnd pos (ptr can be NULL)
|
|---|
| 4028 | ULONG flFrameCreateFlags, // in: FCF_* flags
|
|---|
| 4029 | ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
|
|---|
| 4030 | const char *pcszFrameTitle, // in: frame title (title bar)
|
|---|
| 4031 | ULONG ulResourcesID, // in: according to FCF_* flags
|
|---|
| 4032 | const char *pcszClassClient, // in: client class name
|
|---|
| 4033 | ULONG flStyleClient, // in: client style
|
|---|
| 4034 | ULONG ulID, // in: frame window ID
|
|---|
| 4035 | PVOID pClientCtlData, // in: pCtlData structure pointer for client
|
|---|
| 4036 | PHWND phwndClient) // out: created client wnd
|
|---|
| 4037 | {
|
|---|
| 4038 | FRAMECDATA fcdata;
|
|---|
| 4039 | HWND hwndFrame;
|
|---|
| 4040 | RECTL rclClient;
|
|---|
| 4041 |
|
|---|
| 4042 | fcdata.cb = sizeof(FRAMECDATA);
|
|---|
| 4043 | fcdata.flCreateFlags = flFrameCreateFlags;
|
|---|
| 4044 | fcdata.hmodResources = (HMODULE)NULL;
|
|---|
| 4045 | fcdata.idResources = ulResourcesID;
|
|---|
| 4046 |
|
|---|
| 4047 | /* Create the frame and client windows. */
|
|---|
| 4048 | hwndFrame = WinCreateWindow(hwndFrameParent,
|
|---|
| 4049 | WC_FRAME,
|
|---|
| 4050 | (PSZ)pcszFrameTitle,
|
|---|
| 4051 | ulFrameStyle,
|
|---|
| 4052 | 0,0,0,0, // size and position = 0
|
|---|
| 4053 | NULLHANDLE, // no owner
|
|---|
| 4054 | HWND_TOP, // z-order
|
|---|
| 4055 | ulID, // frame window ID
|
|---|
| 4056 | &fcdata, // frame class data
|
|---|
| 4057 | NULL); // no presparams
|
|---|
| 4058 |
|
|---|
| 4059 | if (hwndFrame)
|
|---|
| 4060 | {
|
|---|
| 4061 | if (*phwndClient = WinCreateWindow(hwndFrame, // parent
|
|---|
| 4062 | (PSZ)pcszClassClient, // class
|
|---|
| 4063 | NULL, // no title
|
|---|
| 4064 | flStyleClient, // style
|
|---|
| 4065 | 0,0,0,0, // size and position = 0
|
|---|
| 4066 | hwndFrame, // owner
|
|---|
| 4067 | HWND_BOTTOM, // bottom z-order
|
|---|
| 4068 | FID_CLIENT, // frame window ID
|
|---|
| 4069 | pClientCtlData, // class data
|
|---|
| 4070 | NULL)) // no presparams
|
|---|
| 4071 | {
|
|---|
| 4072 | if (pswpFrame)
|
|---|
| 4073 | {
|
|---|
| 4074 | // position frame
|
|---|
| 4075 | WinSetWindowPos(hwndFrame,
|
|---|
| 4076 | pswpFrame->hwndInsertBehind,
|
|---|
| 4077 | pswpFrame->x,
|
|---|
| 4078 | pswpFrame->y,
|
|---|
| 4079 | pswpFrame->cx,
|
|---|
| 4080 | pswpFrame->cy,
|
|---|
| 4081 | pswpFrame->fl);
|
|---|
| 4082 |
|
|---|
| 4083 | // position client
|
|---|
| 4084 | // WinQueryWindowRect(hwndFrame, &rclClient);
|
|---|
| 4085 | // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
|
|---|
| 4086 | rclClient.xLeft = 0;
|
|---|
| 4087 | rclClient.yBottom = 0;
|
|---|
| 4088 | rclClient.xRight = pswpFrame->cx;
|
|---|
| 4089 | rclClient.yTop = pswpFrame->cy;
|
|---|
| 4090 | WinCalcFrameRect(hwndFrame,
|
|---|
| 4091 | &rclClient,
|
|---|
| 4092 | TRUE); // calc client from frame
|
|---|
| 4093 | WinSetWindowPos(*phwndClient,
|
|---|
| 4094 | HWND_TOP,
|
|---|
| 4095 | rclClient.xLeft,
|
|---|
| 4096 | rclClient.yBottom,
|
|---|
| 4097 | rclClient.xRight - rclClient.xLeft,
|
|---|
| 4098 | rclClient.yTop - rclClient.yBottom,
|
|---|
| 4099 | SWP_MOVE | SWP_SIZE | SWP_SHOW);
|
|---|
| 4100 | }
|
|---|
| 4101 | }
|
|---|
| 4102 | }
|
|---|
| 4103 |
|
|---|
| 4104 | return hwndFrame;
|
|---|
| 4105 | }
|
|---|
| 4106 |
|
|---|
| 4107 | /*
|
|---|
| 4108 | *@@ winhCreateObjectWindow:
|
|---|
| 4109 | * creates an object window of the specified
|
|---|
| 4110 | * window class, which you should have registered
|
|---|
| 4111 | * before calling this. pvCreateParam will be
|
|---|
| 4112 | * given to the window on WM_CREATE.
|
|---|
| 4113 | *
|
|---|
| 4114 | * Returns the HWND of the object window or
|
|---|
| 4115 | * NULLHANDLE on errors.
|
|---|
| 4116 | *
|
|---|
| 4117 | *@@added V0.9.3 (2000-04-17) [umoeller]
|
|---|
| 4118 | *@@changed V0.9.7 (2001-01-17) [umoeller]: made this a function from a macro
|
|---|
| 4119 | */
|
|---|
| 4120 |
|
|---|
| 4121 | HWND winhCreateObjectWindow(const char *pcszWindowClass, // in: PM window class name
|
|---|
| 4122 | PVOID pvCreateParam) // in: create param
|
|---|
| 4123 | {
|
|---|
| 4124 | return WinCreateWindow(HWND_OBJECT,
|
|---|
| 4125 | (PSZ)pcszWindowClass,
|
|---|
| 4126 | (PSZ)"",
|
|---|
| 4127 | 0,
|
|---|
| 4128 | 0,0,0,0,
|
|---|
| 4129 | 0,
|
|---|
| 4130 | HWND_BOTTOM,
|
|---|
| 4131 | 0,
|
|---|
| 4132 | pvCreateParam,
|
|---|
| 4133 | NULL);
|
|---|
| 4134 | }
|
|---|
| 4135 |
|
|---|
| 4136 | /*
|
|---|
| 4137 | *@@ winhCreateControl:
|
|---|
| 4138 | * creates a control with a size and position of 0.
|
|---|
| 4139 | *
|
|---|
| 4140 | *@@added V0.9.9 (2001-03-13) [umoeller]
|
|---|
| 4141 | *@@changed V1.0.0 (2002-08-26) [umoeller]: added separate hwndOwner
|
|---|
| 4142 | */
|
|---|
| 4143 |
|
|---|
| 4144 | HWND winhCreateControl(HWND hwndParent, // in: parent window
|
|---|
| 4145 | HWND hwndOwner, // in: owner window
|
|---|
| 4146 | const char *pcszClass, // in: window class (e.g. WC_BUTTON)
|
|---|
| 4147 | const char *pcszText, // in: window title
|
|---|
| 4148 | ULONG ulStyle, // in: control style
|
|---|
| 4149 | ULONG ulID) // in: control ID
|
|---|
| 4150 | {
|
|---|
| 4151 | return WinCreateWindow(hwndParent,
|
|---|
| 4152 | (PSZ)pcszClass,
|
|---|
| 4153 | (PSZ)pcszText,
|
|---|
| 4154 | ulStyle,
|
|---|
| 4155 | 0, 0, 0, 0,
|
|---|
| 4156 | hwndOwner,
|
|---|
| 4157 | HWND_TOP,
|
|---|
| 4158 | ulID,
|
|---|
| 4159 | NULL,
|
|---|
| 4160 | NULL);
|
|---|
| 4161 | }
|
|---|
| 4162 |
|
|---|
| 4163 | /*
|
|---|
| 4164 | *@@ winhRepaintWindows:
|
|---|
| 4165 | * this repaints all children of hwndParent.
|
|---|
| 4166 | * If this is passed as HWND_DESKTOP, the
|
|---|
| 4167 | * whole screen is repainted.
|
|---|
| 4168 | *
|
|---|
| 4169 | *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed
|
|---|
| 4170 | */
|
|---|
| 4171 |
|
|---|
| 4172 | VOID winhRepaintWindows(HWND hwndParent)
|
|---|
| 4173 | {
|
|---|
| 4174 | HWND hwndTop;
|
|---|
| 4175 | HENUM henum = WinBeginEnumWindows(hwndParent);
|
|---|
| 4176 | while ((hwndTop = WinGetNextWindow(henum)))
|
|---|
| 4177 | if (WinIsWindowShowing(hwndTop))
|
|---|
| 4178 | WinInvalidateRect(hwndTop, NULL, TRUE);
|
|---|
| 4179 | WinEndEnumWindows(henum);
|
|---|
| 4180 | }
|
|---|
| 4181 |
|
|---|
| 4182 | /*
|
|---|
| 4183 | *@@ winhFindMsgQueue:
|
|---|
| 4184 | * returns the message queue which matches
|
|---|
| 4185 | * the given process and thread IDs. Since,
|
|---|
| 4186 | * per IBM definition, every thread may only
|
|---|
| 4187 | * have one MQ, this should be unique.
|
|---|
| 4188 | *
|
|---|
| 4189 | *@@added V0.9.2 (2000-03-08) [umoeller]
|
|---|
| 4190 | */
|
|---|
| 4191 |
|
|---|
| 4192 | HMQ winhFindMsgQueue(PID pid, // in: process ID
|
|---|
| 4193 | TID tid, // in: thread ID
|
|---|
| 4194 | HAB* phab) // out: anchor block
|
|---|
| 4195 | {
|
|---|
| 4196 | HWND hwndThis = 0,
|
|---|
| 4197 | rc = 0;
|
|---|
| 4198 | HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
|
|---|
| 4199 | while ((hwndThis = WinGetNextWindow(henum)))
|
|---|
| 4200 | {
|
|---|
| 4201 | CHAR szClass[200];
|
|---|
| 4202 | if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
|
|---|
| 4203 | {
|
|---|
| 4204 | if (strcmp(szClass, "#32767") == 0)
|
|---|
| 4205 | {
|
|---|
| 4206 | // message queue window:
|
|---|
| 4207 | PID pidWin = 0;
|
|---|
| 4208 | TID tidWin = 0;
|
|---|
| 4209 | WinQueryWindowProcess(hwndThis,
|
|---|
| 4210 | &pidWin,
|
|---|
| 4211 | &tidWin);
|
|---|
| 4212 | if ( (pidWin == pid)
|
|---|
| 4213 | && (tidWin == tid)
|
|---|
| 4214 | )
|
|---|
| 4215 | {
|
|---|
| 4216 | // get HMQ from window words
|
|---|
| 4217 | rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
|
|---|
| 4218 | if (rc)
|
|---|
| 4219 | if (phab)
|
|---|
| 4220 | *phab = WinQueryAnchorBlock(hwndThis);
|
|---|
| 4221 | break;
|
|---|
| 4222 | }
|
|---|
| 4223 | }
|
|---|
| 4224 | }
|
|---|
| 4225 | }
|
|---|
| 4226 | WinEndEnumWindows(henum);
|
|---|
| 4227 |
|
|---|
| 4228 | return rc;
|
|---|
| 4229 | }
|
|---|
| 4230 |
|
|---|
| 4231 | /*
|
|---|
| 4232 | *@@ winhFindHardErrorWindow:
|
|---|
| 4233 | * this searches all children of HWND_OBJECT
|
|---|
| 4234 | * for the PM hard error windows, which are
|
|---|
| 4235 | * invisible most of the time. When a hard
|
|---|
| 4236 | * error occurs, that window is made a child
|
|---|
| 4237 | * of HWND_DESKTOP instead.
|
|---|
| 4238 | *
|
|---|
| 4239 | * Stolen from ProgramCommander/2 (C) Roman Stangl.
|
|---|
| 4240 | *
|
|---|
| 4241 | *@@added V0.9.3 (2000-04-27) [umoeller]
|
|---|
| 4242 | */
|
|---|
| 4243 |
|
|---|
| 4244 | VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
|
|---|
| 4245 | HWND *phwndSysError) // out: system error window
|
|---|
| 4246 | {
|
|---|
| 4247 | PID pidObject; // HWND_OBJECT's process and thread id
|
|---|
| 4248 | TID tidObject;
|
|---|
| 4249 | PID pidObjectChild; // HWND_OBJECT's child window process and thread id
|
|---|
| 4250 | TID tidObjectChild;
|
|---|
| 4251 | HENUM henumObject; // HWND_OBJECT enumeration handle
|
|---|
| 4252 | HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
|
|---|
| 4253 | UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
|
|---|
| 4254 | CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
|
|---|
| 4255 |
|
|---|
| 4256 | *phwndHardError = NULLHANDLE;
|
|---|
| 4257 | *phwndSysError = NULLHANDLE;
|
|---|
| 4258 |
|
|---|
| 4259 | // query HWND_OBJECT's window process
|
|---|
| 4260 | WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
|
|---|
| 4261 | // enumerate all child windows of HWND_OBJECT
|
|---|
| 4262 | henumObject = WinBeginEnumWindows(HWND_OBJECT);
|
|---|
| 4263 | while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
|
|---|
| 4264 | {
|
|---|
| 4265 | // see if the current HWND_OBJECT child window runs in the
|
|---|
| 4266 | // process of HWND_OBJECT (PM)
|
|---|
| 4267 | WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
|
|---|
| 4268 | if (pidObject == pidObjectChild)
|
|---|
| 4269 | {
|
|---|
| 4270 | // get the child window's data
|
|---|
| 4271 | WinQueryClassName(hwndObjectChild,
|
|---|
| 4272 | sizeof(ucClassName),
|
|---|
| 4273 | (PCH)ucClassName);
|
|---|
| 4274 | WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
|
|---|
| 4275 | (PSZ)ucClassName,
|
|---|
| 4276 | &classinfoWindow);
|
|---|
| 4277 | if ( (!strcmp((PSZ)ucClassName, "#1")
|
|---|
| 4278 | || (classinfoWindow.flClassStyle & CS_FRAME))
|
|---|
| 4279 | )
|
|---|
| 4280 | {
|
|---|
| 4281 | // if the child window is a frame window and running in
|
|---|
| 4282 | // HWND_OBJECT's (PM's) window process, it must be the
|
|---|
| 4283 | // PM Hard Error or System Error window
|
|---|
| 4284 | WinQueryClassName(WinWindowFromID(hwndObjectChild,
|
|---|
| 4285 | FID_CLIENT),
|
|---|
| 4286 | sizeof(ucClassName),
|
|---|
| 4287 | (PSZ)ucClassName);
|
|---|
| 4288 | if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
|
|---|
| 4289 | {
|
|---|
| 4290 | *phwndHardError = hwndObjectChild;
|
|---|
| 4291 | if (*phwndSysError)
|
|---|
| 4292 | // we found the other one already:
|
|---|
| 4293 | // stop searching, we got both
|
|---|
| 4294 | break;
|
|---|
| 4295 | }
|
|---|
| 4296 | else
|
|---|
| 4297 | {
|
|---|
| 4298 | printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
|
|---|
| 4299 | *phwndSysError = hwndObjectChild;
|
|---|
| 4300 | if (*phwndHardError)
|
|---|
| 4301 | // we found the other one already:
|
|---|
| 4302 | // stop searching, we got both
|
|---|
| 4303 | break;
|
|---|
| 4304 | }
|
|---|
| 4305 | }
|
|---|
| 4306 | } // end if (pidObject == pidObjectChild)
|
|---|
| 4307 | } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
|
|---|
| 4308 | WinEndEnumWindows(henumObject);
|
|---|
| 4309 | }
|
|---|
| 4310 |
|
|---|
| 4311 | /*
|
|---|
| 4312 | *@@ winhCreateFakeDesktop:
|
|---|
| 4313 | * this routine creates and displays a frameless window over
|
|---|
| 4314 | * the whole screen in the color of PM's Desktop to fool the
|
|---|
| 4315 | * user that all windows have been closed (which in fact might
|
|---|
| 4316 | * not be the case).
|
|---|
| 4317 | *
|
|---|
| 4318 | * This window's background color is set to the Desktop's
|
|---|
| 4319 | * (PM's one, not the WPS's one).
|
|---|
| 4320 | *
|
|---|
| 4321 | * Returns the HWND of this window.
|
|---|
| 4322 | */
|
|---|
| 4323 |
|
|---|
| 4324 | HWND winhCreateFakeDesktop(HWND hwndSibling)
|
|---|
| 4325 | {
|
|---|
| 4326 | // presparam for background
|
|---|
| 4327 | typedef struct _BACKGROUND
|
|---|
| 4328 | {
|
|---|
| 4329 | ULONG cb; // length of the aparam parameter, in bytes
|
|---|
| 4330 | ULONG id; // attribute type identity
|
|---|
| 4331 | ULONG cb2; // byte count of the ab parameter
|
|---|
| 4332 | RGB rgb; // attribute value
|
|---|
| 4333 | } BACKGROUND;
|
|---|
| 4334 |
|
|---|
| 4335 | BACKGROUND background;
|
|---|
| 4336 | LONG lDesktopColor;
|
|---|
| 4337 |
|
|---|
| 4338 | // create fake desktop window = empty window with
|
|---|
| 4339 | // the size of full screen
|
|---|
| 4340 | lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
|
|---|
| 4341 | SYSCLR_BACKGROUND,
|
|---|
| 4342 | 0);
|
|---|
| 4343 | background.cb = sizeof(background.id)
|
|---|
| 4344 | + sizeof(background.cb)
|
|---|
| 4345 | + sizeof(background.rgb);
|
|---|
| 4346 | background.id = PP_BACKGROUNDCOLOR;
|
|---|
| 4347 | background.cb2 = sizeof(RGB);
|
|---|
| 4348 | background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
|
|---|
| 4349 | background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
|
|---|
| 4350 | background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
|
|---|
| 4351 |
|
|---|
| 4352 | return WinCreateWindow(HWND_DESKTOP, // parent window
|
|---|
| 4353 | WC_FRAME, // class name
|
|---|
| 4354 | "", // window text
|
|---|
| 4355 | WS_VISIBLE, // window style
|
|---|
| 4356 | 0, 0, // position and size
|
|---|
| 4357 | WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
|
|---|
| 4358 | WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
|
|---|
| 4359 | NULLHANDLE, // owner window
|
|---|
| 4360 | hwndSibling, // sibling window
|
|---|
| 4361 | 1, // window id
|
|---|
| 4362 | NULL, // control data
|
|---|
| 4363 | &background); // presentation parms
|
|---|
| 4364 | }
|
|---|
| 4365 |
|
|---|
| 4366 | /*
|
|---|
| 4367 | *@@ winhAssertWarp4Notebook:
|
|---|
| 4368 | * this takes hwndDlg as a notebook dialog page and
|
|---|
| 4369 | * goes thru all its controls. If a control with an
|
|---|
| 4370 | * ID <= udIdThreshold is found, this is assumed to
|
|---|
| 4371 | * be a button which is to be given the BS_NOTEBOOKBUTTON
|
|---|
| 4372 | * style. You should therefore give all your button
|
|---|
| 4373 | * controls which should be moved such an ID.
|
|---|
| 4374 | *
|
|---|
| 4375 | * Note that this function will now automatically
|
|---|
| 4376 | * find out the lowest y coordinate that was used
|
|---|
| 4377 | * for a non-notebook button and move all controls
|
|---|
| 4378 | * down accordingly. As a result, ulDownUnit must
|
|---|
| 4379 | * no longer be specified (V0.9.19).
|
|---|
| 4380 | *
|
|---|
| 4381 | * This function is useful if you wish to create
|
|---|
| 4382 | * notebook pages using dlgedit.exe which are compatible
|
|---|
| 4383 | * with both Warp 3 and Warp 4. This should be executed
|
|---|
| 4384 | * in WM_INITDLG of the notebook dlg function if the app
|
|---|
| 4385 | * has determined that it is running on Warp 4.
|
|---|
| 4386 | *
|
|---|
| 4387 | *@@changed V0.9.16 (2002-02-02) [umoeller]: fixed entry fields
|
|---|
| 4388 | *@@changed V0.9.19 (2002-04-24) [umoeller]: removed ulDownUnits
|
|---|
| 4389 | *@@changed V0.9.19 (2002-05-02) [umoeller]: fix for combobox
|
|---|
| 4390 | */
|
|---|
| 4391 |
|
|---|
| 4392 | BOOL winhAssertWarp4Notebook(HWND hwndDlg,
|
|---|
| 4393 | USHORT usIdThreshold) // in: ID threshold
|
|---|
| 4394 | {
|
|---|
| 4395 | BOOL brc = FALSE;
|
|---|
| 4396 |
|
|---|
| 4397 | if (doshIsWarp4())
|
|---|
| 4398 | {
|
|---|
| 4399 | LONG yLowest = 10000;
|
|---|
| 4400 | HWND hwndItem;
|
|---|
| 4401 | HENUM henum = 0;
|
|---|
| 4402 | PSWP paswp,
|
|---|
| 4403 | pswpThis;
|
|---|
| 4404 | ULONG cWindows = 0,
|
|---|
| 4405 | ul;
|
|---|
| 4406 |
|
|---|
| 4407 | BOOL fIsVisible;
|
|---|
| 4408 |
|
|---|
| 4409 | if (fIsVisible = WinIsWindowVisible(hwndDlg))
|
|---|
| 4410 | // avoid flicker
|
|---|
| 4411 | WinEnableWindowUpdate(hwndDlg, FALSE);
|
|---|
| 4412 |
|
|---|
| 4413 | if (paswp = (PSWP)malloc(sizeof(SWP) * 100))
|
|---|
| 4414 | {
|
|---|
| 4415 | pswpThis = paswp;
|
|---|
| 4416 |
|
|---|
| 4417 | // loop 1: set notebook buttons, find lowest y used
|
|---|
| 4418 | henum = WinBeginEnumWindows(hwndDlg);
|
|---|
| 4419 | while ((hwndItem = WinGetNextWindow(henum)))
|
|---|
| 4420 | {
|
|---|
| 4421 | USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
|
|---|
| 4422 | // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
|
|---|
| 4423 | if (usId <= usIdThreshold)
|
|---|
| 4424 | {
|
|---|
| 4425 | // pushbutton to change:
|
|---|
| 4426 | WinSetWindowBits(hwndItem,
|
|---|
| 4427 | QWL_STYLE,
|
|---|
| 4428 | BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
|
|---|
| 4429 | brc = TRUE;
|
|---|
| 4430 | }
|
|---|
| 4431 | else
|
|---|
| 4432 | {
|
|---|
| 4433 | // no pushbutton to change:
|
|---|
| 4434 | CHAR szClass[10];
|
|---|
| 4435 |
|
|---|
| 4436 | WinQueryWindowPos(hwndItem, pswpThis);
|
|---|
| 4437 |
|
|---|
| 4438 | // special handling for entry fields
|
|---|
| 4439 | // V0.9.16 (2002-02-02) [umoeller]
|
|---|
| 4440 | WinQueryClassName(hwndItem, sizeof(szClass), szClass);
|
|---|
| 4441 | if (!strcmp(szClass, "#6"))
|
|---|
| 4442 | {
|
|---|
| 4443 | pswpThis->x += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CXBORDER);
|
|---|
| 4444 | pswpThis->y += 3 * WinQuerySysValue(HWND_DESKTOP, SV_CYBORDER);
|
|---|
| 4445 | }
|
|---|
| 4446 |
|
|---|
| 4447 | // check lowest y
|
|---|
| 4448 | if ( (pswpThis->y < yLowest)
|
|---|
| 4449 | // ignore combobox, this will distort everything
|
|---|
| 4450 | // AGAIN ... sigh V0.9.19 (2002-05-02) [umoeller]
|
|---|
| 4451 | && (strcmp(szClass, "#2"))
|
|---|
| 4452 | )
|
|---|
| 4453 | yLowest = pswpThis->y ;
|
|---|
| 4454 |
|
|---|
| 4455 | ++pswpThis;
|
|---|
| 4456 | if (++cWindows == 100)
|
|---|
| 4457 | break;
|
|---|
| 4458 | }
|
|---|
| 4459 | } // end while ((hwndItem = WinGetNextWindow(henum)))
|
|---|
| 4460 | WinEndEnumWindows(henum);
|
|---|
| 4461 |
|
|---|
| 4462 | // now adjust window positions
|
|---|
| 4463 | pswpThis = paswp;
|
|---|
| 4464 | for (ul = 0;
|
|---|
| 4465 | ul < cWindows;
|
|---|
| 4466 | ++ul, ++pswpThis)
|
|---|
| 4467 | {
|
|---|
| 4468 | pswpThis->y -= (yLowest - 8);
|
|---|
| 4469 | // 8 is magic to match the lower border of the
|
|---|
| 4470 | // standard WPS notebook pages V0.9.19 (2002-04-24) [umoeller]
|
|---|
| 4471 | pswpThis->fl = SWP_MOVE;
|
|---|
| 4472 | }
|
|---|
| 4473 |
|
|---|
| 4474 | WinSetMultWindowPos(WinQueryAnchorBlock(hwndDlg),
|
|---|
| 4475 | paswp,
|
|---|
| 4476 | cWindows);
|
|---|
| 4477 |
|
|---|
| 4478 | free(paswp);
|
|---|
| 4479 | }
|
|---|
| 4480 |
|
|---|
| 4481 | if (fIsVisible)
|
|---|
| 4482 | WinShowWindow(hwndDlg, TRUE);
|
|---|
| 4483 | }
|
|---|
| 4484 |
|
|---|
| 4485 | return brc;
|
|---|
| 4486 | }
|
|---|
| 4487 |
|
|---|
| 4488 | /*
|
|---|
| 4489 | *@@ winhDrawFormattedText:
|
|---|
| 4490 | * this func takes a rectangle and draws pszText into
|
|---|
| 4491 | * it, breaking the words as neccessary. The line spacing
|
|---|
| 4492 | * is determined from the font currently selected in hps.
|
|---|
| 4493 | *
|
|---|
| 4494 | * As opposed to WinDrawText, this can draw several lines
|
|---|
| 4495 | * at once, and format the _complete_ text according to the
|
|---|
| 4496 | * flCmd parameter, which is like with WinDrawText.
|
|---|
| 4497 | *
|
|---|
| 4498 | * After this function returns, *prcl is modified like this:
|
|---|
| 4499 | *
|
|---|
| 4500 | * -- yTop and yBottom contain the upper and lower boundaries
|
|---|
| 4501 | * which were needed to draw the text. This depends on
|
|---|
| 4502 | * whether DT_TOP etc. were specified.
|
|---|
| 4503 | * To get the height of the rectangle used, calculate the
|
|---|
| 4504 | * delta between yTop and yBottom.
|
|---|
| 4505 | *
|
|---|
| 4506 | * -- xLeft and xRight are modified to contain the outmost
|
|---|
| 4507 | * left and right coordinates which were needed to draw
|
|---|
| 4508 | * the text. This will be set to the longest line which
|
|---|
| 4509 | * was encountered.
|
|---|
| 4510 | *
|
|---|
| 4511 | * You can specify DT_QUERYEXTENT with flDraw to only have
|
|---|
| 4512 | * these text boundaries calculated without actually drawing.
|
|---|
| 4513 | *
|
|---|
| 4514 | * This returns the number of lines drawn.
|
|---|
| 4515 | *
|
|---|
| 4516 | * Note that this calls WinDrawText with DT_TEXTATTRS set,
|
|---|
| 4517 | * that is, the current text primitive attributes will be
|
|---|
| 4518 | * used (fonts and colors).
|
|---|
| 4519 | *
|
|---|
| 4520 | *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
|
|---|
| 4521 | */
|
|---|
| 4522 |
|
|---|
| 4523 | ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
|
|---|
| 4524 | // are used, but not altered
|
|---|
| 4525 | PRECTL prcl, // in/out: rectangle to use for drawing
|
|---|
| 4526 | // (modified)
|
|---|
| 4527 | const char *pcszText, // in: text to draw (zero-terminated)
|
|---|
| 4528 | ULONG flCmd) // in: flags like in WinDrawText; I have
|
|---|
| 4529 | // only tested DT_TOP and DT_LEFT though.
|
|---|
| 4530 | // DT_WORDBREAK | DT_TEXTATTRS are always
|
|---|
| 4531 | // set.
|
|---|
| 4532 | // You can specify DT_QUERYEXTENT to only
|
|---|
| 4533 | // have prcl calculated without drawing.
|
|---|
| 4534 | {
|
|---|
| 4535 | PSZ p = (PSZ)pcszText;
|
|---|
| 4536 | LONG lDrawn = 1,
|
|---|
| 4537 | lTotalDrawn = 0,
|
|---|
| 4538 | lLineCount = 0,
|
|---|
| 4539 | lOrigYTop = prcl->yTop;
|
|---|
| 4540 | ULONG ulTextLen = strlen(pcszText),
|
|---|
| 4541 | ulCharHeight,
|
|---|
| 4542 | flCmd2,
|
|---|
| 4543 | xLeftmost = prcl->xRight,
|
|---|
| 4544 | xRightmost = prcl->xLeft;
|
|---|
| 4545 | RECTL rcl2;
|
|---|
| 4546 |
|
|---|
| 4547 | flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
|
|---|
| 4548 |
|
|---|
| 4549 | ulCharHeight = gpihQueryLineSpacing(hps);
|
|---|
| 4550 |
|
|---|
| 4551 | while ( (lDrawn)
|
|---|
| 4552 | && (lTotalDrawn < ulTextLen)
|
|---|
| 4553 | )
|
|---|
| 4554 | {
|
|---|
| 4555 | memcpy(&rcl2, prcl, sizeof(rcl2));
|
|---|
| 4556 | lDrawn = WinDrawText(hps,
|
|---|
| 4557 | ulTextLen-lTotalDrawn,
|
|---|
| 4558 | p,
|
|---|
| 4559 | &rcl2,
|
|---|
| 4560 | 0, 0, // colors
|
|---|
| 4561 | flCmd2);
|
|---|
| 4562 |
|
|---|
| 4563 | // update char counters
|
|---|
| 4564 | p += lDrawn;
|
|---|
| 4565 | lTotalDrawn += lDrawn;
|
|---|
| 4566 |
|
|---|
| 4567 | // update x extents
|
|---|
| 4568 | if (rcl2.xLeft < xLeftmost)
|
|---|
| 4569 | xLeftmost = rcl2.xLeft;
|
|---|
| 4570 | if (rcl2.xRight > xRightmost)
|
|---|
| 4571 | xRightmost = rcl2.xRight;
|
|---|
| 4572 |
|
|---|
| 4573 | // update y for next line
|
|---|
| 4574 | prcl->yTop -= ulCharHeight;
|
|---|
| 4575 |
|
|---|
| 4576 | // increase line count
|
|---|
| 4577 | lLineCount++;
|
|---|
| 4578 | }
|
|---|
| 4579 | prcl->xLeft = xLeftmost;
|
|---|
| 4580 | prcl->xRight = xRightmost;
|
|---|
| 4581 | prcl->yBottom = prcl->yTop;
|
|---|
| 4582 | prcl->yTop = lOrigYTop;
|
|---|
| 4583 |
|
|---|
| 4584 | return lLineCount;
|
|---|
| 4585 | }
|
|---|
| 4586 |
|
|---|
| 4587 | /*
|
|---|
| 4588 | *@@ winhQuerySwitchList:
|
|---|
| 4589 | * returns the switch list in a newly
|
|---|
| 4590 | * allocated buffer. This does the
|
|---|
| 4591 | * regular double WinQuerySwitchList
|
|---|
| 4592 | * call to first get the no. of items
|
|---|
| 4593 | * and then get the items.
|
|---|
| 4594 | *
|
|---|
| 4595 | * The no. of items can be found in
|
|---|
| 4596 | * the returned SWBLOCK.cwsentry.
|
|---|
| 4597 | *
|
|---|
| 4598 | * Returns NULL on errors. Use
|
|---|
| 4599 | * free() to free the return value.
|
|---|
| 4600 | *
|
|---|
| 4601 | *@@added V0.9.7 (2000-12-06) [umoeller]
|
|---|
| 4602 | */
|
|---|
| 4603 |
|
|---|
| 4604 | PSWBLOCK winhQuerySwitchList(HAB hab)
|
|---|
| 4605 | {
|
|---|
| 4606 | ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
|
|---|
| 4607 | ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
|
|---|
| 4608 | PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
|
|---|
| 4609 | if (pSwBlock)
|
|---|
| 4610 | {
|
|---|
| 4611 | cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
|
|---|
| 4612 | if (!cItems)
|
|---|
| 4613 | {
|
|---|
| 4614 | free(pSwBlock);
|
|---|
| 4615 | pSwBlock = NULL;
|
|---|
| 4616 | }
|
|---|
| 4617 | }
|
|---|
| 4618 |
|
|---|
| 4619 | return pSwBlock;
|
|---|
| 4620 | }
|
|---|
| 4621 |
|
|---|
| 4622 | typedef HSWITCH APIENTRY WINHSWITCHFROMHAPP(HAPP happ);
|
|---|
| 4623 |
|
|---|
| 4624 | /*
|
|---|
| 4625 | *@@ winhHSWITCHfromHAPP:
|
|---|
| 4626 | * resolves and calls the undocumented
|
|---|
| 4627 | * WinHSWITCHfromHAPP API.
|
|---|
| 4628 | *
|
|---|
| 4629 | *@@added V0.9.19 (2002-04-17) [umoeller]
|
|---|
| 4630 | */
|
|---|
| 4631 |
|
|---|
| 4632 | HSWITCH winhHSWITCHfromHAPP(HAPP happ)
|
|---|
| 4633 | {
|
|---|
| 4634 | static WINHSWITCHFROMHAPP *pWinHSWITCHfromHAPP = NULL;
|
|---|
| 4635 |
|
|---|
| 4636 | if (!pWinHSWITCHfromHAPP)
|
|---|
| 4637 | // first call: import WinHSWITCHfromHAPP
|
|---|
| 4638 | // WinHSWITCHfromHAPP PMMERGE.5199
|
|---|
| 4639 | doshQueryProcAddr("PMMERGE",
|
|---|
| 4640 | 5199,
|
|---|
| 4641 | (PFN*)&pWinHSWITCHfromHAPP);
|
|---|
| 4642 |
|
|---|
| 4643 | if (pWinHSWITCHfromHAPP)
|
|---|
| 4644 | return pWinHSWITCHfromHAPP(happ);
|
|---|
| 4645 |
|
|---|
| 4646 | return NULLHANDLE;
|
|---|
| 4647 | }
|
|---|
| 4648 |
|
|---|
| 4649 | /*
|
|---|
| 4650 | *@@ winhQueryTasklistWindow:
|
|---|
| 4651 | * returns the window handle of the PM task list.
|
|---|
| 4652 | *
|
|---|
| 4653 | *@@added V0.9.7 (2000-12-07) [umoeller]
|
|---|
| 4654 | */
|
|---|
| 4655 |
|
|---|
| 4656 | HWND winhQueryTasklistWindow(VOID)
|
|---|
| 4657 | {
|
|---|
| 4658 | SWBLOCK swblock;
|
|---|
| 4659 |
|
|---|
| 4660 | // the tasklist has entry #0 in the SWBLOCK
|
|---|
| 4661 | WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
|
|---|
| 4662 |
|
|---|
| 4663 | return swblock.aswentry[0].swctl.hwnd;
|
|---|
| 4664 | }
|
|---|
| 4665 |
|
|---|
| 4666 | /*
|
|---|
| 4667 | *@@ winhKillTasklist:
|
|---|
| 4668 | * this will destroy the Tasklist (window list) window.
|
|---|
| 4669 | * Note: you will only be able to get it back after a
|
|---|
| 4670 | * reboot, not a WPS restart. Only for use at shutdown and such.
|
|---|
| 4671 | * This trick by Uri J. Stern at
|
|---|
| 4672 | * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
|
|---|
| 4673 | */
|
|---|
| 4674 |
|
|---|
| 4675 | VOID winhKillTasklist(VOID)
|
|---|
| 4676 | {
|
|---|
| 4677 | HWND hwndTasklist = winhQueryTasklistWindow();
|
|---|
| 4678 | WinPostMsg(hwndTasklist,
|
|---|
| 4679 | 0x0454, // undocumented msg for killing tasklist
|
|---|
| 4680 | NULL, NULL);
|
|---|
| 4681 | }
|
|---|
| 4682 |
|
|---|
| 4683 | // the following must be added for EMX (99-10-22) [umoeller]
|
|---|
| 4684 | #ifndef NERR_BufTooSmall
|
|---|
| 4685 | #define NERR_BASE 2100
|
|---|
| 4686 | #define NERR_BufTooSmall (NERR_BASE+23)
|
|---|
| 4687 | // the API return buffer is too small
|
|---|
| 4688 | #endif
|
|---|
| 4689 |
|
|---|
| 4690 | /*
|
|---|
| 4691 | *@@ winhQueryPendingSpoolJobs:
|
|---|
| 4692 | * returns the number of pending print jobs in the spooler
|
|---|
| 4693 | * or 0 if none. Useful for testing before shutdown.
|
|---|
| 4694 | */
|
|---|
| 4695 |
|
|---|
| 4696 | ULONG winhQueryPendingSpoolJobs(VOID)
|
|---|
| 4697 | {
|
|---|
| 4698 | // BOOL rcPending = FALSE;
|
|---|
| 4699 | ULONG ulTotalJobCount = 0;
|
|---|
| 4700 |
|
|---|
| 4701 | SPLERR splerr;
|
|---|
| 4702 | USHORT jobCount;
|
|---|
| 4703 | ULONG cbBuf;
|
|---|
| 4704 | ULONG cTotal;
|
|---|
| 4705 | ULONG cReturned;
|
|---|
| 4706 | ULONG cbNeeded;
|
|---|
| 4707 | ULONG ulLevel;
|
|---|
| 4708 | ULONG i,j;
|
|---|
| 4709 | PSZ pszComputerName;
|
|---|
| 4710 | PBYTE pBuf = NULL;
|
|---|
| 4711 | PPRQINFO3 prq;
|
|---|
| 4712 | PPRJINFO2 prj2;
|
|---|
| 4713 |
|
|---|
| 4714 | ulLevel = 4L;
|
|---|
| 4715 | pszComputerName = (PSZ)NULL;
|
|---|
| 4716 | splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
|
|---|
| 4717 | &cReturned, &cTotal,
|
|---|
| 4718 | &cbNeeded, NULL);
|
|---|
| 4719 | if ( (splerr == ERROR_MORE_DATA)
|
|---|
| 4720 | || (splerr == NERR_BufTooSmall)
|
|---|
| 4721 | )
|
|---|
| 4722 | {
|
|---|
| 4723 | if (!DosAllocMem((PPVOID)&pBuf,
|
|---|
| 4724 | cbNeeded,
|
|---|
| 4725 | PAG_READ | PAG_WRITE | PAG_COMMIT))
|
|---|
| 4726 | {
|
|---|
| 4727 | cbBuf = cbNeeded;
|
|---|
| 4728 | splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
|
|---|
| 4729 | &cReturned, &cTotal,
|
|---|
| 4730 | &cbNeeded, NULL);
|
|---|
| 4731 | if (splerr == NO_ERROR)
|
|---|
| 4732 | {
|
|---|
| 4733 | // set pointer to point to the beginning of the buffer
|
|---|
| 4734 | prq = (PPRQINFO3)pBuf;
|
|---|
| 4735 |
|
|---|
| 4736 | // cReturned has the count of the number of PRQINFO3 structures
|
|---|
| 4737 | for (i = 0;
|
|---|
| 4738 | i < cReturned;
|
|---|
| 4739 | i++)
|
|---|
| 4740 | {
|
|---|
| 4741 | // save the count of jobs; there are this many PRJINFO2
|
|---|
| 4742 | // structures following the PRQINFO3 structure
|
|---|
| 4743 | jobCount = prq->cJobs;
|
|---|
| 4744 | // _Pmpf(( "Job count in this queue is %d",jobCount ));
|
|---|
| 4745 |
|
|---|
| 4746 | // increment the pointer past the PRQINFO3 structure
|
|---|
| 4747 | prq++;
|
|---|
| 4748 |
|
|---|
| 4749 | // set a pointer to point to the first PRJINFO2 structure
|
|---|
| 4750 | prj2=(PPRJINFO2)prq;
|
|---|
| 4751 | for (j = 0;
|
|---|
| 4752 | j < jobCount;
|
|---|
| 4753 | j++)
|
|---|
| 4754 | {
|
|---|
| 4755 | // increment the pointer to point to the next structure
|
|---|
| 4756 | prj2++;
|
|---|
| 4757 | // increase the job count, which we'll return
|
|---|
| 4758 | ulTotalJobCount++;
|
|---|
| 4759 |
|
|---|
| 4760 | } // endfor jobCount
|
|---|
| 4761 |
|
|---|
| 4762 | // after doing all the job structures, prj2 points to the next
|
|---|
| 4763 | // queue structure; set the pointer for a PRQINFO3 structure
|
|---|
| 4764 | prq = (PPRQINFO3)prj2;
|
|---|
| 4765 | } //endfor cReturned
|
|---|
| 4766 | } // endif NO_ERROR
|
|---|
| 4767 | DosFreeMem(pBuf);
|
|---|
| 4768 | }
|
|---|
| 4769 | } // end if Q level given
|
|---|
| 4770 |
|
|---|
| 4771 | return ulTotalJobCount;
|
|---|
| 4772 | }
|
|---|
| 4773 |
|
|---|
| 4774 | /*
|
|---|
| 4775 | *@@ winhSetNumLock:
|
|---|
| 4776 | * this sets the NumLock key on or off, depending
|
|---|
| 4777 | * on fState.
|
|---|
| 4778 | *
|
|---|
| 4779 | * Based on code from WarpEnhancer, (C) Achim Hasenmller.
|
|---|
| 4780 | *
|
|---|
| 4781 | *@@added V0.9.1 (99-12-18) [umoeller]
|
|---|
| 4782 | *@@changed V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
|
|---|
| 4783 | */
|
|---|
| 4784 |
|
|---|
| 4785 | VOID winhSetNumLock(BOOL fState)
|
|---|
| 4786 | {
|
|---|
| 4787 | // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
|
|---|
| 4788 | BYTE KeyStateTable[256];
|
|---|
| 4789 | ULONG ulActionTaken; // Used by DosOpen
|
|---|
| 4790 | HFILE hKbd;
|
|---|
| 4791 |
|
|---|
| 4792 | // read keyboard state table
|
|---|
| 4793 | if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
|
|---|
| 4794 | FALSE))
|
|---|
| 4795 | {
|
|---|
| 4796 | // first set the PM state
|
|---|
| 4797 | if (fState)
|
|---|
| 4798 | KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
|
|---|
| 4799 | else
|
|---|
| 4800 | KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
|
|---|
| 4801 |
|
|---|
| 4802 | // set keyboard state table with new state values
|
|---|
| 4803 | WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
|
|---|
| 4804 | }
|
|---|
| 4805 |
|
|---|
| 4806 | // now set the OS/2 keyboard state
|
|---|
| 4807 |
|
|---|
| 4808 | // try to open OS/2 keyboard driver
|
|---|
| 4809 | if (!DosOpen("KBD$",
|
|---|
| 4810 | &hKbd, &ulActionTaken,
|
|---|
| 4811 | 0, // cbFile
|
|---|
| 4812 | FILE_NORMAL,
|
|---|
| 4813 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
|---|
| 4814 | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
|
|---|
| 4815 | NULL))
|
|---|
| 4816 | {
|
|---|
| 4817 | SHIFTSTATE ShiftState;
|
|---|
| 4818 | USHORT usLEDState;
|
|---|
| 4819 | ULONG DataLen = sizeof(SHIFTSTATE);
|
|---|
| 4820 |
|
|---|
| 4821 | memset(&ShiftState, '\0', DataLen);
|
|---|
| 4822 | DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
|
|---|
| 4823 | NULL, 0L, NULL,
|
|---|
| 4824 | &ShiftState, DataLen, &DataLen);
|
|---|
| 4825 |
|
|---|
| 4826 | if (fState)
|
|---|
| 4827 | ShiftState.fsState |= 0x0020; // turn NumLock on
|
|---|
| 4828 | else
|
|---|
| 4829 | ShiftState.fsState &= 0xFFDF; // turn NumLock off
|
|---|
| 4830 |
|
|---|
| 4831 | DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
|
|---|
| 4832 | &ShiftState, DataLen, &DataLen,
|
|---|
| 4833 | NULL, 0L, NULL);
|
|---|
| 4834 |
|
|---|
| 4835 | // XWP V1.0.6 (2006-09-30) [pr]: Set Keyboard LEDs to match @@fixes 831
|
|---|
| 4836 | usLEDState = (ShiftState.fsState & (SCROLLLOCK_ON | NUMLOCK_ON | CAPSLOCK_ON)) >> 4;
|
|---|
| 4837 | DataLen = sizeof(usLEDState);
|
|---|
| 4838 | DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_ALTERKBDLED,
|
|---|
| 4839 | &usLEDState, DataLen, &DataLen,
|
|---|
| 4840 | NULL, 0L, NULL);
|
|---|
| 4841 |
|
|---|
| 4842 | // now close OS/2 keyboard driver
|
|---|
| 4843 | DosClose(hKbd);
|
|---|
| 4844 | }
|
|---|
| 4845 | }
|
|---|
| 4846 |
|
|---|
| 4847 | /*
|
|---|
| 4848 | *@@ winhSetClipboardText:
|
|---|
| 4849 | * sets the clipboard data to the given text,
|
|---|
| 4850 | * replacing the current clipboard contents.
|
|---|
| 4851 | *
|
|---|
| 4852 | *@@added V1.0.0 (2002-08-28) [umoeller]
|
|---|
| 4853 | */
|
|---|
| 4854 |
|
|---|
| 4855 | BOOL winhSetClipboardText(HAB hab,
|
|---|
| 4856 | PCSZ pcsz,
|
|---|
| 4857 | ULONG cbSize) // in: size of buffer INCLUDING null byte
|
|---|
| 4858 | {
|
|---|
| 4859 | BOOL fSuccess = FALSE;
|
|---|
| 4860 |
|
|---|
| 4861 | if (WinOpenClipbrd(hab))
|
|---|
| 4862 | {
|
|---|
| 4863 | PSZ pszDest;
|
|---|
| 4864 | if (!DosAllocSharedMem((PVOID*)&pszDest,
|
|---|
| 4865 | NULL,
|
|---|
| 4866 | cbSize,
|
|---|
| 4867 | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE))
|
|---|
| 4868 | {
|
|---|
| 4869 | memcpy(pszDest,
|
|---|
| 4870 | pcsz,
|
|---|
| 4871 | cbSize);
|
|---|
| 4872 |
|
|---|
| 4873 | WinEmptyClipbrd(hab);
|
|---|
| 4874 |
|
|---|
| 4875 | fSuccess = WinSetClipbrdData(hab, // anchor-block handle
|
|---|
| 4876 | (ULONG)pszDest, // pointer to text data
|
|---|
| 4877 | CF_TEXT, // data is in text format
|
|---|
| 4878 | CFI_POINTER); // passing a pointer
|
|---|
| 4879 |
|
|---|
| 4880 | // PMREF says (implicitly) it is not necessary to call
|
|---|
| 4881 | // DosFreeMem. I hope that is correct.
|
|---|
| 4882 | // V0.9.19 (2002-06-02) [umoeller]
|
|---|
| 4883 | }
|
|---|
| 4884 |
|
|---|
| 4885 | WinCloseClipbrd(hab);
|
|---|
| 4886 | }
|
|---|
| 4887 |
|
|---|
| 4888 | return fSuccess;
|
|---|
| 4889 | }
|
|---|
| 4890 |
|
|---|
| 4891 | /*
|
|---|
| 4892 | *@@category: Helpers\PM helpers\Extended frame windows
|
|---|
| 4893 | */
|
|---|
| 4894 |
|
|---|
| 4895 | /* ******************************************************************
|
|---|
| 4896 | *
|
|---|
| 4897 | * Extended frame
|
|---|
| 4898 | *
|
|---|
| 4899 | ********************************************************************/
|
|---|
| 4900 |
|
|---|
| 4901 | /*
|
|---|
| 4902 | *@@ winhCalcExtFrameRect:
|
|---|
| 4903 | * implementation for WM_CALCFRAMERECT in fnwpSubclExtFrame.
|
|---|
| 4904 | * This is exported so it can be used independently
|
|---|
| 4905 | * (XWorkplace status bars).
|
|---|
| 4906 | *
|
|---|
| 4907 | *@@added V1.0.0 (2002-08-28) [umoeller]
|
|---|
| 4908 | */
|
|---|
| 4909 |
|
|---|
| 4910 | VOID winhCalcExtFrameRect(MPARAM mp1,
|
|---|
| 4911 | MPARAM mp2,
|
|---|
| 4912 | LONG lStatusBarHeight)
|
|---|
| 4913 | {
|
|---|
| 4914 | PRECTL prclPassed = (PRECTL)mp1;
|
|---|
| 4915 |
|
|---|
| 4916 | // mp2 == TRUE: Frame rectangle provided, calculate client
|
|---|
| 4917 | // mp2 == FALSE: Client area rectangle provided, calculate frame
|
|---|
| 4918 | if (mp2)
|
|---|
| 4919 | {
|
|---|
| 4920 | // TRUE: calculate the rectl of the client;
|
|---|
| 4921 | // call default window procedure to subtract child frame
|
|---|
| 4922 | // controls from the rectangle's height
|
|---|
| 4923 | LONG lClientHeight;
|
|---|
| 4924 |
|
|---|
| 4925 | // position the static text frame extension below the client
|
|---|
| 4926 | lClientHeight = prclPassed->yTop - prclPassed->yBottom;
|
|---|
| 4927 | if (lStatusBarHeight > lClientHeight)
|
|---|
| 4928 | // extension is taller than client, so set client height to 0
|
|---|
| 4929 | prclPassed->yTop = prclPassed->yBottom;
|
|---|
| 4930 | else
|
|---|
| 4931 | {
|
|---|
| 4932 | // set the origin of the client and shrink it based upon the
|
|---|
| 4933 | // static text control's height
|
|---|
| 4934 | prclPassed->yBottom += lStatusBarHeight;
|
|---|
| 4935 | prclPassed->yTop -= lStatusBarHeight;
|
|---|
| 4936 | }
|
|---|
| 4937 | }
|
|---|
| 4938 | else
|
|---|
| 4939 | {
|
|---|
| 4940 | // FALSE: calculate the rectl of the frame;
|
|---|
| 4941 | // call default window procedure to subtract child frame
|
|---|
| 4942 | // controls from the rectangle's height;
|
|---|
| 4943 | // set the origin of the frame and increase it based upon the
|
|---|
| 4944 | // static text control's height
|
|---|
| 4945 | prclPassed->yBottom -= lStatusBarHeight;
|
|---|
| 4946 | prclPassed->yTop += lStatusBarHeight;
|
|---|
| 4947 | }
|
|---|
| 4948 | }
|
|---|
| 4949 |
|
|---|
| 4950 | #define STATUS_BAR_HEIGHT 20
|
|---|
| 4951 |
|
|---|
| 4952 | /*
|
|---|
| 4953 | *@@ fnwpSubclExtFrame:
|
|---|
| 4954 | * subclassed frame window proc.
|
|---|
| 4955 | *
|
|---|
| 4956 | *@@added V0.9.16 (2001-09-29) [umoeller]
|
|---|
| 4957 | */
|
|---|
| 4958 |
|
|---|
| 4959 | MRESULT EXPENTRY fnwpSubclExtFrame(HWND hwndFrame, ULONG msg, MPARAM mp1, MPARAM mp2)
|
|---|
| 4960 | {
|
|---|
| 4961 | MRESULT mrc = 0;
|
|---|
| 4962 |
|
|---|
| 4963 | PEXTFRAMEDATA pData = (PEXTFRAMEDATA)WinQueryWindowPtr(hwndFrame, QWL_USER);
|
|---|
| 4964 |
|
|---|
| 4965 | switch (msg)
|
|---|
| 4966 | {
|
|---|
| 4967 | case WM_QUERYFRAMECTLCOUNT:
|
|---|
| 4968 | {
|
|---|
| 4969 | // query the standard frame controls count
|
|---|
| 4970 | ULONG ulrc = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
|
|---|
| 4971 |
|
|---|
| 4972 | // if we have a status bar, increment the count
|
|---|
| 4973 | ulrc++;
|
|---|
| 4974 |
|
|---|
| 4975 | mrc = (MPARAM)ulrc;
|
|---|
| 4976 | }
|
|---|
| 4977 | break;
|
|---|
| 4978 |
|
|---|
| 4979 | case WM_FORMATFRAME:
|
|---|
| 4980 | {
|
|---|
| 4981 | // query the number of standard frame controls
|
|---|
| 4982 | ULONG ulCount = (ULONG)pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
|
|---|
| 4983 |
|
|---|
| 4984 | // we have a status bar:
|
|---|
| 4985 | // format the frame
|
|---|
| 4986 | ULONG ul;
|
|---|
| 4987 | PSWP swpArr = (PSWP)mp1;
|
|---|
| 4988 |
|
|---|
| 4989 | for (ul = 0; ul < ulCount; ul++)
|
|---|
| 4990 | {
|
|---|
| 4991 | if (WinQueryWindowUShort(swpArr[ul].hwnd, QWS_ID) == 0x8008)
|
|---|
| 4992 | // FID_CLIENT
|
|---|
| 4993 | {
|
|---|
| 4994 | POINTL ptlBorderSizes;
|
|---|
| 4995 | WinSendMsg(hwndFrame,
|
|---|
| 4996 | WM_QUERYBORDERSIZE,
|
|---|
| 4997 | (MPARAM)&ptlBorderSizes,
|
|---|
| 4998 | 0);
|
|---|
| 4999 |
|
|---|
| 5000 | // first initialize the _new_ SWP for the status bar.
|
|---|
| 5001 | // Since the SWP array for the std frame controls is
|
|---|
| 5002 | // zero-based, and the standard frame controls occupy
|
|---|
| 5003 | // indices 0 thru ulCount-1 (where ulCount is the total
|
|---|
| 5004 | // count), we use ulCount for our static text control.
|
|---|
| 5005 | swpArr[ulCount].fl = SWP_MOVE | SWP_SIZE | SWP_NOADJUST | SWP_ZORDER;
|
|---|
| 5006 | swpArr[ulCount].x = ptlBorderSizes.x;
|
|---|
| 5007 | swpArr[ulCount].y = ptlBorderSizes.y;
|
|---|
| 5008 | swpArr[ulCount].cx = swpArr[ul].cx; // same as cnr's width
|
|---|
| 5009 | swpArr[ulCount].cy = STATUS_BAR_HEIGHT;
|
|---|
| 5010 | swpArr[ulCount].hwndInsertBehind = HWND_BOTTOM; // HWND_TOP;
|
|---|
| 5011 | swpArr[ulCount].hwnd = WinWindowFromID(hwndFrame, FID_STATUSBAR);
|
|---|
| 5012 |
|
|---|
| 5013 | // adjust the origin and height of the container to
|
|---|
| 5014 | // accomodate our static text control
|
|---|
| 5015 | swpArr[ul].y += swpArr[ulCount].cy;
|
|---|
| 5016 | swpArr[ul].cy -= swpArr[ulCount].cy;
|
|---|
| 5017 | }
|
|---|
| 5018 | }
|
|---|
| 5019 |
|
|---|
| 5020 | // increment the number of frame controls
|
|---|
| 5021 | // to include our status bar
|
|---|
| 5022 | mrc = (MRESULT)(ulCount + 1);
|
|---|
| 5023 | }
|
|---|
| 5024 | break;
|
|---|
| 5025 |
|
|---|
| 5026 | case WM_CALCFRAMERECT:
|
|---|
| 5027 | mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
|
|---|
| 5028 |
|
|---|
| 5029 | // we have a status bar: calculate its rectangle
|
|---|
| 5030 | winhCalcExtFrameRect(mp1,
|
|---|
| 5031 | mp2,
|
|---|
| 5032 | STATUS_BAR_HEIGHT);
|
|---|
| 5033 | break;
|
|---|
| 5034 |
|
|---|
| 5035 | case WM_DESTROY:
|
|---|
| 5036 | WinSubclassWindow(hwndFrame, pData->pfnwpOrig);
|
|---|
| 5037 | free(pData);
|
|---|
| 5038 | WinSetWindowPtr(hwndFrame, QWL_USER, NULL);
|
|---|
| 5039 | break;
|
|---|
| 5040 |
|
|---|
| 5041 | default:
|
|---|
| 5042 | mrc = pData->pfnwpOrig(hwndFrame, msg, mp1, mp2);
|
|---|
| 5043 | }
|
|---|
| 5044 |
|
|---|
| 5045 | return mrc;
|
|---|
| 5046 | }
|
|---|
| 5047 |
|
|---|
| 5048 | /*
|
|---|
| 5049 | *@@ winhCreateStatusBar:
|
|---|
| 5050 | * creates a status bar for a frame window.
|
|---|
| 5051 | *
|
|---|
| 5052 | * Normally there's no need to call this manually,
|
|---|
| 5053 | * this gets called by winhCreateExtStdWindow
|
|---|
| 5054 | * automatically.
|
|---|
| 5055 | *
|
|---|
| 5056 | *@@added V0.9.16 (2001-09-29) [umoeller]
|
|---|
| 5057 | */
|
|---|
| 5058 |
|
|---|
| 5059 | HWND winhCreateStatusBar(HWND hwndFrame,
|
|---|
| 5060 | HWND hwndOwner,
|
|---|
| 5061 | const char *pcszText, // in: initial status bar text
|
|---|
| 5062 | const char *pcszFont, // in: font to use for status bar
|
|---|
| 5063 | LONG lColor) // in: foreground color for status bar
|
|---|
| 5064 | {
|
|---|
| 5065 | // create status bar
|
|---|
| 5066 | HWND hwndReturn = NULLHANDLE;
|
|---|
| 5067 | PPRESPARAMS ppp = NULL;
|
|---|
| 5068 |
|
|---|
| 5069 | winhStorePresParam(&ppp,
|
|---|
| 5070 | PP_FONTNAMESIZE,
|
|---|
| 5071 | strlen(pcszFont) + 1,
|
|---|
| 5072 | (PVOID)pcszFont);
|
|---|
| 5073 |
|
|---|
| 5074 | lColor = WinQuerySysColor(HWND_DESKTOP,
|
|---|
| 5075 | SYSCLR_DIALOGBACKGROUND,
|
|---|
| 5076 | 0);
|
|---|
| 5077 | winhStorePresParam(&ppp,
|
|---|
| 5078 | PP_BACKGROUNDCOLOR,
|
|---|
| 5079 | sizeof(lColor),
|
|---|
| 5080 | &lColor);
|
|---|
| 5081 |
|
|---|
| 5082 | lColor = CLR_BLACK;
|
|---|
| 5083 | winhStorePresParam(&ppp,
|
|---|
| 5084 | PP_FOREGROUNDCOLOR,
|
|---|
| 5085 | sizeof(lColor),
|
|---|
| 5086 | &lColor);
|
|---|
| 5087 |
|
|---|
| 5088 | hwndReturn = WinCreateWindow(hwndFrame,
|
|---|
| 5089 | WC_STATIC,
|
|---|
| 5090 | (PSZ)pcszText,
|
|---|
| 5091 | SS_TEXT | DT_VCENTER | WS_VISIBLE,
|
|---|
| 5092 | 0, 0, 0, 0,
|
|---|
| 5093 | hwndOwner,
|
|---|
| 5094 | HWND_TOP,
|
|---|
| 5095 | FID_STATUSBAR,
|
|---|
| 5096 | NULL,
|
|---|
| 5097 | ppp);
|
|---|
| 5098 | free(ppp);
|
|---|
| 5099 |
|
|---|
| 5100 | return hwndReturn;
|
|---|
| 5101 | }
|
|---|
| 5102 |
|
|---|
| 5103 | /*
|
|---|
| 5104 | *@@ winhCreateExtStdWindow:
|
|---|
| 5105 | * creates an extended frame window.
|
|---|
| 5106 | *
|
|---|
| 5107 | * pData must point to an EXTFRAMECDATA structure
|
|---|
| 5108 | * which contains a copy of the parameters to be
|
|---|
| 5109 | * passed to winhCreateStdWindow. In addition,
|
|---|
| 5110 | * this contains the flExtFlags field, which allows
|
|---|
| 5111 | * you to automatically create a status bar for
|
|---|
| 5112 | * the window.
|
|---|
| 5113 | *
|
|---|
| 5114 | * Note that we subclass the frame here and require
|
|---|
| 5115 | * QWL_USER for that. The frame's QWL_USER points
|
|---|
| 5116 | * to an EXTFRAMEDATA structure whose pUser parameter
|
|---|
| 5117 | * you may use for additional data, if you want to
|
|---|
| 5118 | * do further subclassing.
|
|---|
| 5119 | *
|
|---|
| 5120 | *@@added V0.9.16 (2001-09-29) [umoeller]
|
|---|
| 5121 | */
|
|---|
| 5122 |
|
|---|
| 5123 | HWND winhCreateExtStdWindow(PEXTFRAMECDATA pData, // in: extended frame data
|
|---|
| 5124 | PHWND phwndClient) // out: created client wnd
|
|---|
| 5125 | {
|
|---|
| 5126 | HWND hwndFrame;
|
|---|
| 5127 |
|
|---|
| 5128 | if (hwndFrame = winhCreateStdWindow(HWND_DESKTOP,
|
|---|
| 5129 | pData->pswpFrame,
|
|---|
| 5130 | pData->flFrameCreateFlags,
|
|---|
| 5131 | pData->ulFrameStyle,
|
|---|
| 5132 | pData->pcszFrameTitle,
|
|---|
| 5133 | pData->ulResourcesID,
|
|---|
| 5134 | pData->pcszClassClient,
|
|---|
| 5135 | pData->flStyleClient,
|
|---|
| 5136 | pData->ulID,
|
|---|
| 5137 | pData->pClientCtlData,
|
|---|
| 5138 | phwndClient))
|
|---|
| 5139 | {
|
|---|
| 5140 | if (pData->flExtFlags & XFCF_STATUSBAR)
|
|---|
| 5141 | {
|
|---|
| 5142 | // create status bar as child of the frame
|
|---|
| 5143 | HWND hwndStatusBar = winhCreateStatusBar(hwndFrame,
|
|---|
| 5144 | hwndFrame,
|
|---|
| 5145 | "",
|
|---|
| 5146 | "9.WarpSans",
|
|---|
| 5147 | CLR_BLACK);
|
|---|
| 5148 |
|
|---|
| 5149 | // subclass frame for supporting status bar and msgs
|
|---|
| 5150 | PEXTFRAMEDATA pFrameData;
|
|---|
| 5151 | if (pFrameData = NEW(EXTFRAMEDATA))
|
|---|
| 5152 | {
|
|---|
| 5153 | ZERO(pFrameData),
|
|---|
| 5154 | memcpy(&pFrameData->CData, pData, sizeof(pFrameData->CData));
|
|---|
| 5155 | if (pFrameData->pfnwpOrig = WinSubclassWindow(hwndFrame,
|
|---|
| 5156 | fnwpSubclExtFrame))
|
|---|
| 5157 | {
|
|---|
| 5158 | WinSetWindowPtr(hwndFrame, QWL_USER, pFrameData);
|
|---|
| 5159 | }
|
|---|
| 5160 | else
|
|---|
| 5161 | free(pFrameData);
|
|---|
| 5162 | }
|
|---|
| 5163 | }
|
|---|
| 5164 | }
|
|---|
| 5165 |
|
|---|
| 5166 | return hwndFrame;
|
|---|
| 5167 | }
|
|---|
| 5168 |
|
|---|
| 5169 | /*
|
|---|
| 5170 | *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
|
|---|
| 5171 | */
|
|---|
| 5172 |
|
|---|
| 5173 | /* ******************************************************************
|
|---|
| 5174 | *
|
|---|
| 5175 | * WPS Class List helpers
|
|---|
| 5176 | *
|
|---|
| 5177 | ********************************************************************/
|
|---|
| 5178 |
|
|---|
| 5179 | /*
|
|---|
| 5180 | *@@ winhQueryWPSClassList:
|
|---|
| 5181 | * this returns the WPS class list in a newly
|
|---|
| 5182 | * allocated buffer. This is just a shortcut to
|
|---|
| 5183 | * the usual double WinEnumObjectClasses call.
|
|---|
| 5184 | *
|
|---|
| 5185 | * The return value is actually of the POBJCLASS type,
|
|---|
| 5186 | * so you better cast this manually. We declare this
|
|---|
| 5187 | * this as PBYTE though because POBJCLASS requires
|
|---|
| 5188 | * INCL_WINWORKPLACE.
|
|---|
| 5189 | * See WinEnumObjectClasses() for details.
|
|---|
| 5190 | *
|
|---|
| 5191 | * Returns NULL on error. Use free()
|
|---|
| 5192 | * to free the return value.
|
|---|
| 5193 | *
|
|---|
| 5194 | *@@added V0.9.0 [umoeller]
|
|---|
| 5195 | */
|
|---|
| 5196 |
|
|---|
| 5197 | PBYTE winhQueryWPSClassList(VOID)
|
|---|
| 5198 | {
|
|---|
| 5199 | ULONG ulSize;
|
|---|
| 5200 | POBJCLASS pObjClass = 0;
|
|---|
| 5201 |
|
|---|
| 5202 | // get WPS class list size
|
|---|
| 5203 | if (WinEnumObjectClasses(NULL, &ulSize))
|
|---|
| 5204 | {
|
|---|
| 5205 | // allocate buffer
|
|---|
| 5206 | pObjClass = (POBJCLASS)malloc(ulSize + 1);
|
|---|
| 5207 | // and load the classes into it
|
|---|
| 5208 | WinEnumObjectClasses(pObjClass, &ulSize);
|
|---|
| 5209 | }
|
|---|
| 5210 |
|
|---|
| 5211 | return (PBYTE)pObjClass;
|
|---|
| 5212 | }
|
|---|
| 5213 |
|
|---|
| 5214 | /*
|
|---|
| 5215 | *@@ winhQueryWPSClass:
|
|---|
| 5216 | * this returns the POBJCLASS item if pszClass is registered
|
|---|
| 5217 | * with the WPS or NULL if the class could not be found.
|
|---|
| 5218 | *
|
|---|
| 5219 | * The return value is actually of the POBJCLASS type,
|
|---|
| 5220 | * so you better cast this manually. We declare this
|
|---|
| 5221 | * this as PBYTE though because POBJCLASS requires
|
|---|
| 5222 | * INCL_WINWORKPLACE.
|
|---|
| 5223 | *
|
|---|
| 5224 | * This takes as input the return value of winhQueryWPSClassList,
|
|---|
| 5225 | * which you must call first.
|
|---|
| 5226 | *
|
|---|
| 5227 | * <B>Usage:</B>
|
|---|
| 5228 | + PBYTE pClassList = winhQueryWPSClassList(),
|
|---|
| 5229 | + pWPFolder;
|
|---|
| 5230 | + if (pClassList)
|
|---|
| 5231 | + {
|
|---|
| 5232 | + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
|
|---|
| 5233 | + ...
|
|---|
| 5234 | + free(pClassList);
|
|---|
| 5235 | + }
|
|---|
| 5236 | *
|
|---|
| 5237 | *@@added V0.9.0 [umoeller]
|
|---|
| 5238 | */
|
|---|
| 5239 |
|
|---|
| 5240 | PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
|
|---|
| 5241 | // winhQueryWPSClassList
|
|---|
| 5242 | const char *pszClass) // in: class name to query
|
|---|
| 5243 | {
|
|---|
| 5244 | PBYTE pbReturn = 0;
|
|---|
| 5245 |
|
|---|
| 5246 | POBJCLASS pocThis = (POBJCLASS)pObjClass;
|
|---|
| 5247 | // now go thru the WPS class list
|
|---|
| 5248 | while (pocThis)
|
|---|
| 5249 | {
|
|---|
| 5250 | if (strcmp(pocThis->pszClassName, pszClass) == 0)
|
|---|
| 5251 | {
|
|---|
| 5252 | pbReturn = (PBYTE)pocThis;
|
|---|
| 5253 | break;
|
|---|
| 5254 | }
|
|---|
| 5255 | // next class
|
|---|
| 5256 | pocThis = pocThis->pNext;
|
|---|
| 5257 | } // end while (pocThis)
|
|---|
| 5258 |
|
|---|
| 5259 | return pbReturn;
|
|---|
| 5260 | }
|
|---|
| 5261 |
|
|---|
| 5262 | /*
|
|---|
| 5263 | *@@ winhRegisterClass:
|
|---|
| 5264 | * this works just like WinRegisterObjectClass,
|
|---|
| 5265 | * except that it returns a more meaningful
|
|---|
| 5266 | * error code than just FALSE in case registering
|
|---|
| 5267 | * fails.
|
|---|
| 5268 | *
|
|---|
| 5269 | * This returns NO_ERROR if the class was successfully
|
|---|
| 5270 | * registered (WinRegisterObjectClass returned TRUE).
|
|---|
| 5271 | *
|
|---|
| 5272 | * Otherwise, we do a DosLoadModule if maybe the DLL
|
|---|
| 5273 | * couldn't be loaded in the first place. If DosLoadModule
|
|---|
| 5274 | * did not return NO_ERROR, this function returns that
|
|---|
| 5275 | * return code, which can be:
|
|---|
| 5276 | *
|
|---|
| 5277 | * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
|
|---|
| 5278 | * -- 2 ERROR_FILE_NOT_FOUND
|
|---|
| 5279 | * -- 3 ERROR_PATH_NOT_FOUND
|
|---|
| 5280 | * -- 4 ERROR_TOO_MANY_OPEN_FILES
|
|---|
| 5281 | * -- 5 ERROR_ACCESS_DENIED
|
|---|
| 5282 | * -- 8 ERROR_NOT_ENOUGH_MEMORY
|
|---|
| 5283 | * -- 11 ERROR_BAD_FORMAT
|
|---|
| 5284 | * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
|
|---|
| 5285 | * -- 32 ERROR_SHARING_VIOLATION
|
|---|
| 5286 | * -- 33 ERROR_LOCK_VIOLATION
|
|---|
| 5287 | * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
|
|---|
| 5288 | * -- 95 ERROR_INTERRUPT (interrupted system call)
|
|---|
| 5289 | * -- 108 ERROR_DRIVE_LOCKED (by another process)
|
|---|
| 5290 | * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
|
|---|
| 5291 | * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
|
|---|
| 5292 | * -- 180 ERROR_INVALID_SEGMENT_NUMBER
|
|---|
| 5293 | * -- 182 ERROR_INVALID_ORDINAL
|
|---|
| 5294 | * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
|
|---|
| 5295 | * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
|
|---|
| 5296 | * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
|
|---|
| 5297 | * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
|
|---|
| 5298 | * -- 195 ERROR_INVALID_MINALLOCSIZE
|
|---|
| 5299 | * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
|
|---|
| 5300 | * -- 198 ERROR_INVALID_SEGDPL
|
|---|
| 5301 | * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
|
|---|
| 5302 | * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
|
|---|
| 5303 | * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
|
|---|
| 5304 | * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
|
|---|
| 5305 | *
|
|---|
| 5306 | * In all these cases, pszBuf may contain a meaningful
|
|---|
| 5307 | * error message from DosLoadModule, especially if an import
|
|---|
| 5308 | * could not be resolved.
|
|---|
| 5309 | *
|
|---|
| 5310 | * Still worse, if DosLoadModule returned NO_ERROR, we
|
|---|
| 5311 | * probably have some SOM internal error. A probable
|
|---|
| 5312 | * reason is that the parent class of pcszClassName
|
|---|
| 5313 | * is not installed, but that's WPS/SOM internal
|
|---|
| 5314 | * and cannot be queried from outside the WPS context.
|
|---|
| 5315 | *
|
|---|
| 5316 | * In that case, ERROR_OPEN_FAILED (110) is returned.
|
|---|
| 5317 | * That one sounded good to me. ;-)
|
|---|
| 5318 | */
|
|---|
| 5319 |
|
|---|
| 5320 | APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
|
|---|
| 5321 | const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
|
|---|
| 5322 | PSZ pszBuf, // out: error message from DosLoadModule
|
|---|
| 5323 | ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
|
|---|
| 5324 | {
|
|---|
| 5325 | APIRET arc = NO_ERROR;
|
|---|
| 5326 |
|
|---|
| 5327 | if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
|
|---|
| 5328 | {
|
|---|
| 5329 | // failed: do more error checking then, try DosLoadModule
|
|---|
| 5330 | HMODULE hmod = NULLHANDLE;
|
|---|
| 5331 | arc = DosLoadModule(pszBuf, cbBuf,
|
|---|
| 5332 | (PSZ)pcszModule,
|
|---|
| 5333 | &hmod);
|
|---|
| 5334 | if (arc == NO_ERROR)
|
|---|
| 5335 | {
|
|---|
| 5336 | // DosLoadModule succeeded:
|
|---|
| 5337 | // some SOM error then
|
|---|
| 5338 | DosFreeModule(hmod);
|
|---|
| 5339 | arc = ERROR_OPEN_FAILED;
|
|---|
| 5340 | }
|
|---|
| 5341 | }
|
|---|
| 5342 | // else: ulrc still 0 (== no error)
|
|---|
| 5343 |
|
|---|
| 5344 | return arc;
|
|---|
| 5345 | }
|
|---|
| 5346 |
|
|---|
| 5347 | /*
|
|---|
| 5348 | *@@ winhIsClassRegistered:
|
|---|
| 5349 | * quick one-shot function which checks if
|
|---|
| 5350 | * a class is currently registered. Calls
|
|---|
| 5351 | * winhQueryWPSClassList and winhQueryWPSClass
|
|---|
| 5352 | * in turn.
|
|---|
| 5353 | *
|
|---|
| 5354 | *@@added V0.9.2 (2000-02-26) [umoeller]
|
|---|
| 5355 | */
|
|---|
| 5356 |
|
|---|
| 5357 | BOOL winhIsClassRegistered(const char *pcszClass)
|
|---|
| 5358 | {
|
|---|
| 5359 | BOOL brc = FALSE;
|
|---|
| 5360 | PBYTE pClassList = winhQueryWPSClassList();
|
|---|
| 5361 | if (pClassList)
|
|---|
| 5362 | {
|
|---|
| 5363 | if (winhQueryWPSClass(pClassList, pcszClass))
|
|---|
| 5364 | brc = TRUE;
|
|---|
| 5365 | free(pClassList);
|
|---|
| 5366 | }
|
|---|
| 5367 |
|
|---|
| 5368 | return brc;
|
|---|
| 5369 | }
|
|---|
| 5370 |
|
|---|
| 5371 | /*
|
|---|
| 5372 | *@@category: Helpers\PM helpers\Workplace Shell
|
|---|
| 5373 | */
|
|---|
| 5374 |
|
|---|
| 5375 | /*
|
|---|
| 5376 | *@@ winhResetWPS:
|
|---|
| 5377 | * restarts the WPS using PrfReset. Returns
|
|---|
| 5378 | * one of the following:
|
|---|
| 5379 | *
|
|---|
| 5380 | * -- 0: no error.
|
|---|
| 5381 | * -- 1: PrfReset failed.
|
|---|
| 5382 | * -- 2 or 4: PrfQueryProfile failed.
|
|---|
| 5383 | * -- 3: malloc() failed.
|
|---|
| 5384 | *
|
|---|
| 5385 | *@@added V0.9.4 (2000-07-01) [umoeller]
|
|---|
| 5386 | *@@changed V1.0.5 (2005-02-17) [pr]: replaced this with something less brutal
|
|---|
| 5387 | */
|
|---|
| 5388 |
|
|---|
| 5389 | ULONG winhResetWPS(HAB hab)
|
|---|
| 5390 | {
|
|---|
| 5391 | ULONG ulrc = 0;
|
|---|
| 5392 |
|
|---|
| 5393 | #if 1
|
|---|
| 5394 | WinRestartWorkplace();
|
|---|
| 5395 | #else
|
|---|
| 5396 | // find out current profile names
|
|---|
| 5397 | PRFPROFILE Profiles;
|
|---|
| 5398 | Profiles.cchUserName = Profiles.cchSysName = 0;
|
|---|
| 5399 | // first query their file name lengths
|
|---|
| 5400 | if (PrfQueryProfile(hab, &Profiles))
|
|---|
| 5401 | {
|
|---|
| 5402 | // allocate memory for filenames
|
|---|
| 5403 | Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
|
|---|
| 5404 | Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
|
|---|
| 5405 |
|
|---|
| 5406 | if (Profiles.pszSysName)
|
|---|
| 5407 | {
|
|---|
| 5408 | // get filenames
|
|---|
| 5409 | if (PrfQueryProfile(hab, &Profiles))
|
|---|
| 5410 | {
|
|---|
| 5411 |
|
|---|
| 5412 | // "change" INIs to these filenames:
|
|---|
| 5413 | // THIS WILL RESET THE WPS
|
|---|
| 5414 | if (PrfReset(hab, &Profiles) == FALSE)
|
|---|
| 5415 | ulrc = 1;
|
|---|
| 5416 | free(Profiles.pszSysName);
|
|---|
| 5417 | free(Profiles.pszUserName);
|
|---|
| 5418 | }
|
|---|
| 5419 | else
|
|---|
| 5420 | ulrc = 2;
|
|---|
| 5421 | }
|
|---|
| 5422 | else
|
|---|
| 5423 | ulrc = 3;
|
|---|
| 5424 | }
|
|---|
| 5425 | else
|
|---|
| 5426 | ulrc = 4;
|
|---|
| 5427 | #endif
|
|---|
| 5428 |
|
|---|
| 5429 | return ulrc;
|
|---|
| 5430 | }
|
|---|