source: trunk/src/helpers/winh.c@ 17

Last change on this file since 17 was 17, checked in by umoeller, 25 years ago

Miscellanous updates.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 145.9 KB
Line 
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-2000 Ulrich M”ller.
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_DOSERRORS
44
45#define INCL_WINWINDOWMGR
46#define INCL_WINMESSAGEMGR
47#define INCL_WINFRAMEMGR
48#define INCL_WININPUT
49#define INCL_WINDIALOGS
50#define INCL_WINPOINTERS
51#define INCL_WINRECTANGLES
52#define INCL_WINSHELLDATA
53#define INCL_WINSYS
54#define INCL_WINHELP
55#define INCL_WINPROGRAMLIST
56#define INCL_WINSWITCHLIST
57#define INCL_WINMENUS
58#define INCL_WINSCROLLBARS
59#define INCL_WINLISTBOXES
60#define INCL_WINSTDSPIN
61#define INCL_WINSTDSLIDER
62#define INCL_WINCIRCULARSLIDER
63#define INCL_WINSTDFILE
64
65#define INCL_SPL
66#define INCL_SPLDOSPRINT
67#define INCL_SPLERRORS
68
69#define INCL_GPIBITMAPS
70#define INCL_GPIPRIMITIVES
71#include <os2.h>
72
73#include <stdlib.h>
74#include <string.h>
75#include <stdio.h>
76
77#include "setup.h" // code generation and debugging options
78
79#include "helpers\dosh.h"
80#include "helpers\winh.h"
81#include "helpers\prfh.h"
82#include "helpers\gpih.h"
83#include "helpers\stringh.h"
84#include "helpers\undoc.h"
85#include "helpers\xstring.h" // extended string helpers
86
87/*
88 *@@category: Helpers\PM helpers\Menu helpers
89 */
90
91/* ******************************************************************
92 *
93 * Menu helpers
94 *
95 ********************************************************************/
96
97/*
98 *@@ winhInsertMenuItem:
99 * this inserts one one menu item into a given menu.
100 *
101 * Returns the return value of the MM_INSERTITEM msg:
102 * -- MIT_MEMERROR: space allocation for menu item failed
103 * -- MIT_ERROR: other error
104 * -- other: zero-based index of new item in menu.
105 */
106
107SHORT winhInsertMenuItem(HWND hwndMenu, // in: menu to insert item into
108 SHORT iPosition, // in: zero-based index of where to
109 // insert or MIT_END
110 SHORT sItemId, // in: ID of new menu item
111 PSZ pszItemTitle, // in: title of new menu item
112 SHORT afStyle,
113 // in: MIS_* style flags.
114 // Valid menu item styles are:
115 // -- MIS_SUBMENU
116 // -- MIS_SEPARATOR
117 // -- MIS_BITMAP: the display object is a bit map.
118 // -- MIS_TEXT: the display object is a text string.
119 // -- MIS_BUTTONSEPARATOR:
120 // The item is a menu button. Any menu can have zero,
121 // one, or two items of this type. These are the last
122 // items in a menu and are automatically displayed after
123 // a separator bar. The user cannot move the cursor to
124 // these items, but can select them with the pointing
125 // device or with the appropriate key.
126 // -- MIS_BREAK: the item begins a new row or column.
127 // -- MIS_BREAKSEPARATOR:
128 // Same as MIS_BREAK, except that it draws a separator
129 // between rows or columns of a pull-down menu.
130 // This style can only be used within a submenu.
131 // -- MIS_SYSCOMMAND:
132 // menu posts a WM_SYSCOMMAND message rather than a
133 // WM_COMMAND message.
134 // -- MIS_OWNERDRAW:
135 // WM_DRAWITEM and WM_MEASUREITEM notification messages
136 // are sent to the owner to draw the item or determine its size.
137 // -- MIS_HELP:
138 // menu posts a WM_HELP message rather than a
139 // WM_COMMAND message.
140 // -- MIS_STATIC
141 // This type of item exists for information purposes only.
142 // It cannot be selected with the pointing device or
143 // keyboard.
144 SHORT afAttr)
145 // in: MIA_* attribute flags
146 // Valid menu item attributes (afAttr) are:
147 // -- MIA_HILITED: if and only if, the item is selected.
148 // -- MIA_CHECKED: a check mark appears next to the item (submenu only).
149 // -- MIA_DISABLED: item is disabled and cannot be selected.
150 // The item is drawn in a disabled state (gray).
151 // -- MIA_FRAMED: a frame is drawn around the item (top-level menu only).
152 // -- MIA_NODISMISS:
153 // if the item is selected, the submenu remains down. A menu
154 // with this attribute is not hidden until the application
155 // or user explicitly does so, for example by selecting either
156 // another menu on the action bar or by pressing the escape key.
157{
158 MENUITEM mi;
159 SHORT src = MIT_ERROR;
160
161 mi.iPosition = iPosition;
162 mi.afStyle = afStyle;
163 mi.afAttribute = afAttr;
164 mi.id = sItemId;
165 mi.hwndSubMenu = 0;
166 mi.hItem = 0;
167 src = SHORT1FROMMR(WinSendMsg(hwndMenu,
168 MM_INSERTITEM,
169 (MPARAM)&mi,
170 (MPARAM)pszItemTitle));
171 return (src);
172}
173
174/*
175 *@@ winhInsertSubmenu:
176 * this inserts a submenu into a given menu and, if
177 * sItemId != 0, inserts one item into this new submenu also.
178 *
179 * See winhInsertMenuItem for valid menu item styles and
180 * attributes.
181 *
182 * Returns the HWND of the new submenu.
183 */
184
185HWND winhInsertSubmenu(HWND hwndMenu, // in: menu to add submenu to
186 ULONG iPosition, // in: index where to add submenu or MIT_END
187 SHORT sMenuId, // in: menu ID of new submenu
188 PSZ pszSubmenuTitle, // in: title of new submenu
189 USHORT afMenuStyle, // in: MIS* style flags for submenu;
190 // MIS_SUBMENU will always be added
191 SHORT sItemId, // in: ID of first item to add to submenu;
192 // if 0, no first item is inserted
193 PSZ pszItemTitle, // in: title of this item
194 // (if sItemID != 0)
195 USHORT afItemStyle, // in: style flags for this item, e.g. MIS_TEXT
196 // (this is ignored if sItemID == 0)
197 USHORT afAttribute) // in: attributes for this item, e.g. MIA_DISABLED
198 // (this is ignored if sItemID == 0)
199{
200 MENUITEM mi;
201 SHORT src = MIT_ERROR;
202 HWND hwndNewMenu;
203
204 // create new, empty menu
205 hwndNewMenu = WinCreateMenu(hwndMenu,
206 NULL); // no menu template
207 if (hwndNewMenu)
208 {
209 // add "submenu item" to this empty menu;
210 // for some reason, PM always needs submenus
211 // to be a menu item
212 mi.iPosition = iPosition;
213 mi.afStyle = afMenuStyle | MIS_SUBMENU;
214 mi.afAttribute = 0;
215 mi.id = sMenuId;
216 mi.hwndSubMenu = hwndNewMenu;
217 mi.hItem = 0;
218 src = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, (MPARAM)pszSubmenuTitle));
219 if ( (src != MIT_MEMERROR)
220 && (src != MIT_ERROR)
221 )
222 {
223 // set the new menu's ID to the same as the
224 // submenu item
225 WinSetWindowUShort(hwndNewMenu, QWS_ID, sMenuId);
226
227 if (sItemId)
228 {
229 // item id given: insert first menu item also
230 mi.iPosition = 0;
231 mi.afStyle = afItemStyle;
232 mi.afAttribute = afAttribute;
233 mi.id = sItemId;
234 mi.hwndSubMenu = 0;
235 mi.hItem = 0;
236 WinSendMsg(hwndNewMenu,
237 MM_INSERTITEM,
238 (MPARAM)&mi,
239 (MPARAM)pszItemTitle);
240 }
241 }
242 }
243 return (hwndNewMenu);
244}
245
246/*
247 *@@ winhInsertMenuSeparator:
248 * this inserts a separator into a given menu at
249 * the given position (which may be MIT_END);
250 * returns the position at which the item was
251 * inserted.
252 */
253
254SHORT winhInsertMenuSeparator(HWND hMenu, // in: menu to add separator to
255 SHORT iPosition, // in: index where to add separator or MIT_END
256 SHORT sId) // in: separator menu ID (doesn't really matter)
257{
258 MENUITEM mi;
259 mi.iPosition = iPosition;
260 mi.afStyle = MIS_SEPARATOR; // append separator
261 mi.afAttribute = 0;
262 mi.id = sId;
263 mi.hwndSubMenu = 0;
264 mi.hItem = 0;
265
266 return (SHORT1FROMMR(WinSendMsg(hMenu,
267 MM_INSERTITEM,
268 (MPARAM)&mi,
269 (MPARAM)"")));
270}
271
272/*
273 *@@ winhQueryMenuItemText:
274 * this returns a menu item text as a PSZ
275 * to a newly allocated buffer or NULL if
276 * not found.
277 *
278 * Returns NULL on error. Use winhFree()
279 * to free the return value.
280 *
281 * Use the WinSetMenuItemText macro to
282 * set the menu item text.
283 */
284
285PSZ winhQueryMenuItemText(HWND hwndMenu,
286 USHORT usItemID) // in: menu item ID (not index)
287{
288 PSZ prc = NULL;
289
290 SHORT sLength = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_QUERYITEMTEXTLENGTH,
291 (MPARAM)(ULONG)usItemID,
292 (MPARAM)NULL));
293 if (sLength)
294 {
295 prc = (PSZ)malloc(sLength + 1);
296 WinSendMsg(hwndMenu,
297 MM_QUERYITEMTEXT,
298 MPFROM2SHORT(usItemID, sLength + 1),
299 (MPARAM)prc);
300 }
301
302 return (prc);
303}
304
305/*
306 *@@ winhAppend2MenuItemText:
307 *
308 *@@added V0.9.2 (2000-03-08) [umoeller]
309 */
310
311BOOL winhAppend2MenuItemText(HWND hwndMenu,
312 USHORT usItemID, // in: menu item ID (not index)
313 const char *pcszAppend, // in: text to append
314 BOOL fTab) // in: if TRUE, add \t before pcszAppend
315{
316 BOOL brc = FALSE;
317 CHAR szItemText[400];
318 if (WinSendMsg(hwndMenu,
319 MM_QUERYITEMTEXT,
320 MPFROM2SHORT(usItemID,
321 sizeof(szItemText)),
322 (MPARAM)szItemText))
323 {
324 // text copied:
325 if (fTab)
326 {
327 if (strchr(szItemText, '\t'))
328 // we already have a tab:
329 strcat(szItemText, " ");
330 else
331 strcat(szItemText, "\t");
332 }
333 strcat(szItemText, pcszAppend);
334
335 brc = (BOOL)WinSendMsg(hwndMenu,
336 MM_SETITEMTEXT,
337 MPFROMSHORT(usItemID),
338 (MPARAM)szItemText);
339 }
340
341 return (brc);
342}
343
344/*
345 *@@ winhMenuRemoveEllipse:
346 * removes a "..." substring from a menu item
347 * title, if found. This is useful if confirmations
348 * have been turned off for a certain menu item, which
349 * should be reflected in the menu.
350 */
351
352VOID winhMenuRemoveEllipse(HWND hwndMenu,
353 USHORT usItemId) // in: item to remove "..." from
354{
355 CHAR szBuf[255];
356 CHAR *p;
357 WinSendMsg(hwndMenu,
358 MM_QUERYITEMTEXT,
359 MPFROM2SHORT(usItemId, sizeof(szBuf)-1),
360 (MPARAM)&szBuf);
361 if ((p = strstr(szBuf, "...")))
362 strcpy(p, p+3);
363 WinSendMsg(hwndMenu,
364 MM_SETITEMTEXT,
365 MPFROMSHORT(usItemId),
366 (MPARAM)&szBuf);
367}
368
369/*
370 *@@ winhQueryItemUnderMouse:
371 * this queries the menu item which corresponds
372 * to the given mouse coordinates.
373 * Returns the ID of the menu item and stores its
374 * rectangle in *prtlItem; returns (-1) upon errors.
375 */
376
377SHORT winhQueryItemUnderMouse(HWND hwndMenu, // in: menu handle
378 POINTL *pptlMouse, // in: mouse coordinates
379 RECTL *prtlItem) // out: rectangle of menu item
380{
381 SHORT s, sItemId, sItemCount;
382 HAB habDesktop = WinQueryAnchorBlock(HWND_DESKTOP);
383
384 sItemCount = SHORT1FROMMR(WinSendMsg(hwndMenu, MM_QUERYITEMCOUNT, MPNULL, MPNULL));
385
386 for (s = 0;
387 s <= sItemCount;
388 s++)
389 {
390 sItemId = SHORT1FROMMR(WinSendMsg(hwndMenu,
391 MM_ITEMIDFROMPOSITION,
392 (MPARAM)(ULONG)s, MPNULL));
393 WinSendMsg(hwndMenu,
394 MM_QUERYITEMRECT,
395 MPFROM2SHORT(sItemId, FALSE),
396 (MPARAM)prtlItem);
397 if (WinPtInRect(habDesktop, prtlItem, pptlMouse))
398 return (sItemId);
399 }
400 /* sItemId = (SHORT)WinSendMsg(hwndMenu, MM_ITEMIDFROMPOSITION, (MPARAM)(sItemCount-1), MPNULL);
401 return (sItemId); */
402 return (-1); // error: no valid menu item
403}
404
405/*
406 *@@category: Helpers\PM helpers\Slider helpers
407 */
408
409/* ******************************************************************
410 *
411 * Slider helpers
412 *
413 ********************************************************************/
414
415/*
416 *@@ winhReplaceWithLinearSlider:
417 * this destroys the control with the ID ulID in hwndDlg
418 * and creates a linear slider at the same position with the
419 * same ID (effectively replacing it).
420 *
421 * This is needed because the IBM dialog editor (DLGEDIT.EXE)
422 * keeps crashing when creating sliders. So the way to do
423 * this easily is to create some other control with DLGEDIT
424 * where the slider should be later and call this function
425 * on that control when the dialog is initialized.
426 *
427 * You need to specify _one_ of the following with ulSliderStyle:
428 * -- SLS_HORIZONTAL: horizontal slider (default)
429 * -- SLS_VERTICAL: vertical slider
430 *
431 * plus _one_ additional common slider style for positioning:
432 * -- for horizontal sliders: SLS_BOTTOM, SLS_CENTER, or SLS_TOP
433 * -- for vertical sliders: SLS_LEFT, SLS_CENTER, or SLS_RIGHT
434 *
435 * Additional common slider styles are:
436 * -- SLS_PRIMARYSCALE1: determines the location of the scale
437 * on the slider shaft by using increment
438 * and spacing specified for scale 1 as
439 * the incremental value for positioning
440 * the slider arm. Scale 1 is displayed
441 * above the slider shaft of a horizontal
442 * slider and to the right of the slider
443 * shaft of a vertical slider. This is
444 * the default for a slider.
445 * -- SLS_PRIMARYSCALE2: not supported by this function
446 * -- SLS_READONLY: creates a read-only slider, which
447 * presents information to the user but
448 * allows no interaction with the user.
449 * -- SLS_RIBBONSTRIP: fills, as the slider arm moves, the
450 * slider shaft between the home position
451 * and the slider arm with a color value
452 * different from slider shaft color,
453 * similar to mercury in a thermometer.
454 * -- SLS_OWNERDRAW: notifies the application whenever the
455 * slider shaft, the ribbon strip, the
456 * slider arm, and the slider background
457 * are to be drawn.
458 * -- SLS_SNAPTOINCREMENT: causes the slider arm, when positioned
459 * between two values, to be positioned
460 * to the nearest value and redrawn at
461 * that position.
462 *
463 * Additionally, for horizontal sliders:
464 * -- SLS_BUTTONSLEFT: specifies that the optional slider
465 * buttons are to be used and places them
466 * to the left of the slider shaft. The
467 * buttons move the slider arm by one
468 * position, left or right, in the
469 * direction selected.
470 * -- SLS_BUTTONSRIGHT: specifies that the optional slider
471 * buttons are to be used and places them
472 * to the right of the slider shaft. The
473 * buttons move the slider arm by one
474 * position, left or right, in the
475 * direction selected.
476 * -- SLS_HOMELEFT: specifies the slider arm's home
477 * position. The left edge is used as the
478 * base value for incrementing (default).
479 * -- SLS_HOMERIGHT: specifies the slider arm's home
480 * position. The right edge is used as
481 * the base value for incrementing.
482 *
483 * Instead, for vertical sliders:
484 * -- SLS_BUTTONSBOTTOM: specifies that the optional slider
485 * buttons are to be used and places them
486 * at the bottom of the slider shaft. The
487 * buttons move the slider arm by one
488 * position, up or down, in the direction
489 * selected.
490 * -- SLS_BUTTONSTOP: specifies that the optional slider
491 * buttons are to be used and places them
492 * at the top of the slider shaft. The
493 * buttons move the slider arm by one
494 * position, up or down, in the direction
495 * selected.
496 * -- SLS_HOMEBOTTOM: specifies the slider arm's home
497 * position. The bottom of the slider is
498 * used as the base value for
499 * incrementing.
500 * -- SLS_HOMETOP: specifies the slider arm's home
501 * position. The top of the slider is
502 * used as the base value for
503 * incrementing.
504 *
505 * Notes: This function automatically adds WS_PARENTCLIP,
506 * WS_TABSTOP, and WS_SYNCPAINT to the specified styles.
507 * For the WS_TABSTOP style, hwndInsertAfter is important.
508 * If you specify HWND_TOP, your window will be the first
509 * in the tab stop list.
510 *
511 * It also shows the slider after having done all the
512 * processing in here by calling WinShowWindow.
513 *
514 * Also, we only provide support for scale 1 here, so
515 * do not specify SLS_PRIMARYSCALE2 with ulSliderStyle,
516 * and we have the slider calculate all the spacings.
517 *
518 * This returns the HWND of the slider or NULLHANDLE upon
519 * errors.
520 *
521 *@@added V0.9.0 [umoeller]
522 */
523
524HWND winhReplaceWithLinearSlider(HWND hwndParent, // in: parent of old control and slider
525 HWND hwndOwner, // in: owner of old control and slider
526 HWND hwndInsertAfter, // in: the control after which the slider should
527 // come up, or HWND_TOP, or HWND_BOTTOM
528 ULONG ulID, // in: ID of old control and slider
529 ULONG ulSliderStyle, // in: SLS_* styles
530 ULONG ulTickCount) // in: number of ticks (scale 1)
531{
532 HWND hwndSlider = NULLHANDLE;
533 HWND hwndKill = WinWindowFromID(hwndParent, ulID);
534 if (hwndKill)
535 {
536 SWP swpControl;
537 if (WinQueryWindowPos(hwndKill, &swpControl))
538 {
539 SLDCDATA slcd;
540
541 // destroy the old control
542 WinDestroyWindow(hwndKill);
543
544 // initialize slider control data
545 slcd.cbSize = sizeof(SLDCDATA);
546 slcd.usScale1Increments = ulTickCount;
547 slcd.usScale1Spacing = 0; // have slider calculate it
548 slcd.usScale2Increments = 0;
549 slcd.usScale2Spacing = 0;
550
551 // create a slider with the same ID at the same
552 // position
553 hwndSlider = WinCreateWindow(hwndParent,
554 WC_SLIDER,
555 NULL, // no window text
556 ulSliderStyle
557 | WS_PARENTCLIP
558 | WS_SYNCPAINT
559 | WS_TABSTOP,
560 swpControl.x,
561 swpControl.y,
562 swpControl.cx,
563 swpControl.cy,
564 hwndOwner,
565 hwndInsertAfter,
566 ulID, // same ID as destroyed control
567 &slcd, // slider control data
568 NULL); // presparams
569
570 WinSendMsg(hwndSlider,
571 SLM_SETTICKSIZE,
572 MPFROM2SHORT(SMA_SETALLTICKS,
573 6), // 15 pixels high
574 NULL);
575
576 WinShowWindow(hwndSlider, TRUE);
577 }
578 }
579
580 return (hwndSlider);
581}
582
583/*
584 *@@ winhSetSliderTicks:
585 * this adds ticks to the given linear slider,
586 * which are ulPixels pixels high. A useful
587 * value for this is 4.
588 *
589 * This queries the slider for the primary
590 * scale values. Only the primary scale is
591 * supported.
592 *
593 * If mpEveryOther is 0, this sets all ticks
594 * on the primary slider scale.
595 *
596 * If mpEveryOther is != 0, SHORT1FROMMP
597 * specifies the first tick to set, and
598 * SHORT2FROMMP specifies every other tick
599 * to set from there. For example:
600 + MPFROM2SHORT(9, 10)
601 * would set tick 9, 19, 29, and so forth.
602 *
603 * Returns FALSE upon errors.
604 *
605 *@@added V0.9.1 (99-12-04) [umoeller]
606 */
607
608BOOL winhSetSliderTicks(HWND hwndSlider,
609 MPARAM mpEveryOther,
610 ULONG ulPixels)
611{
612 BOOL brc = FALSE;
613
614 if (mpEveryOther == 0)
615 {
616 // set all ticks:
617 brc = (BOOL)WinSendMsg(hwndSlider,
618 SLM_SETTICKSIZE,
619 MPFROM2SHORT(SMA_SETALLTICKS,
620 ulPixels),
621 NULL);
622 }
623 else
624 {
625 SLDCDATA slcd;
626 WNDPARAMS wp;
627 memset(&wp, 0, sizeof(WNDPARAMS));
628 wp.fsStatus = WPM_CTLDATA;
629 wp.cbCtlData = sizeof(slcd);
630 wp.pCtlData = &slcd;
631 // get primary scale data from the slider
632 if (WinSendMsg(hwndSlider,
633 WM_QUERYWINDOWPARAMS,
634 (MPARAM)&wp,
635 0))
636 {
637 USHORT usStart = SHORT1FROMMP(mpEveryOther),
638 usEveryOther = SHORT2FROMMP(mpEveryOther);
639
640 USHORT usScale1Max = slcd.usScale1Increments,
641 us;
642
643 brc = TRUE;
644
645 for (us = usStart; us < usScale1Max; us += usEveryOther)
646 {
647 if (!(BOOL)WinSendMsg(hwndSlider,
648 SLM_SETTICKSIZE,
649 MPFROM2SHORT(us,
650 ulPixels),
651 NULL))
652 {
653 brc = FALSE;
654 break;
655 }
656 }
657 }
658 }
659
660 return (brc);
661}
662
663/*
664 *@@ winhReplaceWithCircularSlider:
665 * this destroys the control with the ID ulID in hwndDlg
666 * and creates a linear slider at the same position with the
667 * same ID (effectively replacing it).
668 *
669 * This is needed because the IBM dialog editor (DLGEDIT.EXE)
670 * cannot create circular sliders. So the way to do this
671 * easily is to create some other control with DLGEDIT
672 * where the slider should be later and call this function
673 * on that control when the dialog is initialized.
674 *
675 * You need to specify the following with ulSliderStyle:
676 * -- CSS_CIRCULARVALUE: draws a circular thumb, rather than a line,
677 * for the value indicator.
678 * -- CSS_MIDPOINT: makes the mid-point tick mark larger.
679 * -- CSS_NOBUTTON: does not display value buttons. Per default, the
680 * slider displays "-" and "+" buttons to the bottom left
681 * and bottom right of the knob. (BTW, these bitmaps can be
682 * changed using CSM_SETBITMAPDATA.)
683 * -- CSS_NONUMBER: does not display the value on the dial.
684 * -- CSS_NOTEXT: does not display title text under the dial.
685 * Otherwise, the text in the pszTitle parameter
686 * will be used.
687 * -- CSS_NOTICKS (only listed in pmstddlg.h, not in PMREF):
688 * obviously, this prevents tick marks from being drawn.
689 * -- CSS_POINTSELECT: permits the values on the circular slider
690 * to change immediately when dragged.
691 * Direct manipulation is performed by using a mouse to
692 * click on and drag the circular slider. There are two
693 * modes of direct manipulation for the circular slider:
694 * <BR><B>1)</B> The default direct manipulation mode is to scroll to
695 * the value indicated by the position of the mouse.
696 * This could be important if you used a circular slider
697 * for a volume control, for example. Increasing the volume
698 * from 0% to 100% too quickly could result in damage to
699 * both the user's ears and the equipment.
700 * <BR><B>2)</B>The other mode of direct manipulation permits
701 * the value on the circular slider to change immediately when dragged.
702 * This mode is enabled using the CSS_POINTSELECT style bit. When this
703 * style is used, the value of the dial can be changed by tracking
704 * the value with the mouse, which changes values quickly.
705 * -- CSS_PROPORTIONALTICKS: allow the length of the tick marks to be calculated
706 * as a percentage of the radius (for small sliders).
707 * -- CSS_360: permits the scroll range to extend 360 degrees.
708 * CSS_360 forces the CSS_NONUMBER style on. This is necessary
709 * to keep the value indicator from corrupting the number value.
710 *
711 * FYI: The most commonly known circular slider in OS/2, the one in the
712 * default "Sound" object, has a style of 0x9002018a, meaning
713 * CSS_NOTEXT | CSS_POINTSELECT | CSS_NOTICKS.
714 *
715 * Notes: This function automatically adds WS_PARENTCLIP,
716 * WS_TABSTOP, and WS_SYNCPAINT to the specified styles.
717 * For the WS_TABSTOP style, hwndInsertAfter is important.
718 * If you specify HWND_TOP, your window will be the first
719 * in the tab stop list.
720 *
721 * It also shows the slider after having done all the
722 * processing in here by calling WinShowWindow.
723 *
724 * This returns the HWND of the slider or NULLHANDLE upon
725 * errors.
726 *
727 *@@added V0.9.0 [umoeller]
728 */
729
730HWND winhReplaceWithCircularSlider(HWND hwndParent, // in: parent of old control and slider
731 HWND hwndOwner, // in: owner of old control and slider
732 HWND hwndInsertAfter, // in: the control after which the slider should
733 // come up, or HWND_TOP, or HWND_BOTTOM
734 ULONG ulID, // in: ID of old control and slider
735 ULONG ulSliderStyle, // in: SLS_* styles
736 SHORT sMin, // in: minimum value (e.g. 0)
737 SHORT sMax, // in: maximum value (e.g. 100)
738 USHORT usIncrement, // in: minimum increment (e.g. 1)
739 USHORT usTicksEvery) // in: ticks ever x values (e.g. 20)
740{
741 HWND hwndSlider = NULLHANDLE;
742 HWND hwndKill = WinWindowFromID(hwndParent, ulID);
743 if (hwndKill)
744 {
745 SWP swpControl;
746 if (WinQueryWindowPos(hwndKill, &swpControl))
747 {
748 // destroy the old control
749 WinDestroyWindow(hwndKill);
750
751 // WinRegisterCircularSlider();
752
753 // create a slider with the same ID at the same
754 // position
755 hwndSlider = WinCreateWindow(hwndParent,
756 WC_CIRCULARSLIDER,
757 "dummy", // no window text
758 ulSliderStyle
759 // | WS_PARENTCLIP
760 // | WS_SYNCPAINT
761 | WS_TABSTOP,
762 swpControl.x,
763 swpControl.y,
764 swpControl.cx,
765 swpControl.cy,
766 hwndOwner,
767 hwndInsertAfter,
768 ulID, // same ID as destroyed control
769 NULL, // control data
770 NULL); // presparams
771
772 if (hwndSlider)
773 {
774 // set slider range
775 WinSendMsg(hwndSlider,
776 CSM_SETRANGE,
777 (MPARAM)(ULONG)sMin,
778 (MPARAM)(ULONG)sMax);
779
780 // set slider increments
781 WinSendMsg(hwndSlider,
782 CSM_SETINCREMENT,
783 (MPARAM)(ULONG)usIncrement,
784 (MPARAM)(ULONG)usTicksEvery);
785
786 // set slider value
787 WinSendMsg(hwndSlider,
788 CSM_SETVALUE,
789 (MPARAM)0,
790 (MPARAM)0);
791
792 // for some reason, the slider always has
793 // WS_CLIPSIBLINGS set, even though we don't
794 // set this; we must unset this now, or
795 // the slider won't draw itself (%&$&%"$&%!!!)
796 WinSetWindowBits(hwndSlider,
797 QWL_STYLE,
798 0, // unset bit
799 WS_CLIPSIBLINGS);
800
801 WinShowWindow(hwndSlider, TRUE);
802 }
803 }
804 }
805
806 return (hwndSlider);
807}
808
809/*
810 *@@category: Helpers\PM helpers\Spin button helpers
811 */
812
813/* ******************************************************************
814 *
815 * Spin button helpers
816 *
817 ********************************************************************/
818
819/*
820 *@@ winhSetDlgItemSpinData:
821 * sets a spin button's limits and data within a dialog window.
822 * This only works for decimal spin buttons.
823 */
824
825VOID winhSetDlgItemSpinData(HWND hwndDlg, // in: dlg window
826 ULONG idSpinButton, // in: item ID of spin button
827 ULONG min, // in: minimum allowed value
828 ULONG max, // in: maximum allowed value
829 ULONG current) // in: new current value
830{
831 HWND hwndSpinButton = WinWindowFromID(hwndDlg, idSpinButton);
832 if (hwndSpinButton)
833 {
834 WinSendMsg(hwndSpinButton,
835 SPBM_SETLIMITS, // Set limits message
836 (MPARAM)max, // Spin Button maximum setting
837 (MPARAM)min); // Spin Button minimum setting
838
839 WinSendMsg(hwndSpinButton,
840 SPBM_SETCURRENTVALUE, // Set current value message
841 (MPARAM)current,
842 (MPARAM)NULL);
843 }
844}
845
846/*
847 *@@ winhAdjustDlgItemSpinData:
848 * this can be called on a spin button control to
849 * have its current data snap to a grid. This only
850 * works for LONG integer values.
851 *
852 * For example, if you specify 100 for the grid and call
853 * this func after you have received SPBN_UP/DOWNARROW,
854 * the spin button's value will always in/decrease
855 * in steps of 100.
856 *
857 * This returns the "snapped" value to which the spin
858 * button was set.
859 *
860 * If you specify lGrid == 0, this returns the spin
861 * button's value only (V0.9.0).
862 *
863 *@@changed V0.9.0 [umoeller]: added check for lGrid == 0 (caused division by zero previously)
864 */
865
866LONG winhAdjustDlgItemSpinData(HWND hwndDlg, // in: dlg window
867 USHORT usItemID, // in: item ID of spin button
868 LONG lGrid, // in: grid
869 USHORT usNotifyCode) // in: SPBN_UP* or *DOWNARROW of WM_CONTROL message
870{
871 HWND hwndSpin = WinWindowFromID(hwndDlg, usItemID);
872 LONG lBottom, lTop, lValue;
873 // get value, which has already increased /
874 // decreased by 1
875 WinSendMsg(hwndSpin,
876 SPBM_QUERYVALUE,
877 (MPARAM)&lValue,
878 MPFROM2SHORT(0, SPBQ_ALWAYSUPDATE));
879
880 if ((lGrid)
881 && ( (usNotifyCode == SPBN_UPARROW)
882 || (usNotifyCode == SPBN_DOWNARROW)
883 )
884 )
885 {
886 // only if the up/down buttons were pressed,
887 // snap to the nearest grid; if the user
888 // manually enters something (SPBN_CHANGE),
889 // we'll accept that value
890 lValue = (lValue / lGrid) * lGrid;
891 // add /subtract grid
892 if (usNotifyCode == SPBN_UPARROW)
893 lValue += lGrid;
894 // else we'll have -= lGrid already
895
896 // balance with spin button limits
897 WinSendMsg(hwndSpin,
898 SPBM_QUERYLIMITS,
899 (MPARAM)&lTop,
900 (MPARAM)&lBottom);
901 if (lValue < lBottom)
902 lValue = lTop;
903 else if (lValue > lTop)
904 lValue = lBottom;
905
906 WinSendMsg(hwndSpin,
907 SPBM_SETCURRENTVALUE,
908 (MPARAM)(lValue),
909 MPNULL);
910 }
911 return (lValue);
912}
913
914/*
915 *@@category: Helpers\PM helpers\List box helpers
916 */
917
918/* ******************************************************************
919 *
920 * List box helpers
921 *
922 ********************************************************************/
923
924/*
925 *@@ winhQueryLboxItemText:
926 * returns the text of the specified
927 * list box item in a newly allocated
928 * buffer.
929 *
930 * Returns NULL on error. Use winhFree()
931 * to free the return value.
932 *
933 *@@added V0.9.1 (99-12-14) [umoeller]
934 */
935
936PSZ winhQueryLboxItemText(HWND hwndListbox,
937 SHORT sIndex)
938{
939 PSZ pszReturn = 0;
940 SHORT cbText = SHORT1FROMMR(WinSendMsg(hwndListbox,
941 LM_QUERYITEMTEXTLENGTH,
942 (MPARAM)(ULONG)sIndex,
943 0));
944 if ((cbText) && (cbText != LIT_ERROR))
945 {
946 pszReturn = (PSZ)malloc(cbText + 1); // add zero terminator
947 WinSendMsg(hwndListbox,
948 LM_QUERYITEMTEXT,
949 MPFROM2SHORT(sIndex,
950 cbText + 1),
951 (MPARAM)pszReturn);
952 }
953
954 return (pszReturn);
955}
956
957/*
958 *@@ winhMoveLboxItem:
959 * this moves one list box item from one
960 * list box to another, including the
961 * item text and the item "handle"
962 * (see LM_QUERYITEMHANDLE).
963 *
964 * sTargetIndex can either be a regular
965 * item index or one of the following
966 * (as in LM_INSERTITEM):
967 * -- LIT_END
968 * -- LIT_SORTASCENDING
969 * -- LIT_SORTDESCENDING
970 *
971 * If (fSelectTarget == TRUE), the new
972 * item is also selected in the target
973 * list box.
974 *
975 * Returns FALSE if moving failed. In
976 * that case, the list boxes are unchanged.
977 *
978 *@@added V0.9.1 (99-12-14) [umoeller]
979 */
980
981BOOL winhMoveLboxItem(HWND hwndSource,
982 SHORT sSourceIndex,
983 HWND hwndTarget,
984 SHORT sTargetIndex,
985 BOOL fSelectTarget)
986{
987 BOOL brc = FALSE;
988
989 PSZ pszItemText = winhQueryLboxItemText(hwndSource, sSourceIndex);
990 if (pszItemText)
991 {
992 ULONG ulItemHandle = winhQueryLboxItemHandle(hwndSource,
993 sSourceIndex);
994 // probably 0, if not used
995 LONG lTargetIndex = WinInsertLboxItem(hwndTarget,
996 sTargetIndex,
997 pszItemText);
998 if ( (lTargetIndex != LIT_ERROR)
999 && (lTargetIndex != LIT_MEMERROR)
1000 )
1001 {
1002 // successfully inserted:
1003 winhSetLboxItemHandle(hwndTarget, lTargetIndex, ulItemHandle);
1004 if (fSelectTarget)
1005 winhSetLboxSelectedItem(hwndTarget, lTargetIndex, TRUE);
1006
1007 // remove source
1008 WinDeleteLboxItem(hwndSource,
1009 sSourceIndex);
1010
1011 brc = TRUE;
1012 }
1013
1014 free(pszItemText);
1015 }
1016
1017 return (brc);
1018}
1019
1020/*
1021 *@@ winhLboxSelectAll:
1022 * this selects or deselects all items in the
1023 * given list box, depending on fSelect.
1024 *
1025 * Returns the number of items in the list box.
1026 */
1027
1028ULONG winhLboxSelectAll(HWND hwndListBox, // in: list box
1029 BOOL fSelect) // in: TRUE = select, FALSE = deselect
1030{
1031 LONG lItemCount = WinQueryLboxCount(hwndListBox);
1032 ULONG ul;
1033
1034 for (ul = 0; ul < lItemCount; ul++)
1035 {
1036 WinSendMsg(hwndListBox,
1037 LM_SELECTITEM,
1038 (MPARAM)ul, // index
1039 (MPARAM)fSelect);
1040 }
1041
1042 return (lItemCount);
1043}
1044
1045/*
1046 *@@category: Helpers\PM helpers\Scroll bar helpers
1047 */
1048
1049/* ******************************************************************
1050 *
1051 * Scroll bar helpers
1052 *
1053 ********************************************************************/
1054
1055/*
1056 *@@ winhUpdateScrollBar:
1057 * updates the given scroll bar according to the given
1058 * values. This updates the scroll bar's thumb size,
1059 * extension, and position, all in one shot.
1060 *
1061 * This simplifies the typical functionality of a scroll
1062 * bar in a client window which is to be scrolled. I am
1063 * wondering why IBM never included such a function, since
1064 * it is so damn basic and still writing it cost me a whole
1065 * day.
1066 *
1067 * Terminology:
1068 *
1069 * -- "window": the actual window with scroll bars which displays
1070 * a subrectangle of the available data.
1071 * The width or height of this must be passed in ulWinPels.
1072 *
1073 * -- "viewport": the entire data to be displayed, of which the
1074 * "window" can only display a subrectangle, if the viewport
1075 * is larger than the window. The width or height of this must be
1076 * passed in ulViewportPels. This can be smaller than ulWinPels (if the
1077 * window is larger than the data), the same or larger than ulWinPels
1078 * (if the window is too small to show all the data).
1079 *
1080 * -- "window offset": the offset of the current window within
1081 * the viewport. For horizontal scroll bars, this is
1082 * the X coordinate, counting from the left of the window
1083 * (0 means leftmost).
1084 * For vertical scroll bars, this is counted from the _top_
1085 * of the viewport (0 means topmost, as opposed to OS/2
1086 * window coordinates!).
1087 * This is because for vertical scroll bars controls, higher
1088 * values move the thumb _down_.
1089 *
1090 * The scroll bar is disabled if the entire viewport is visible,
1091 * that is, if ulViewportPels <= ulWinPels. In that case
1092 * FALSE is returned. If (fAutoHide == TRUE), the scroll
1093 * bar is not only disabled, but also hidden from the display.
1094 * In that case, you will need to reformat your output because
1095 * your viewport becomes larger without the scroll bar.
1096 *
1097 * This function will set the range of the scroll bar to 0 up
1098 * to a value depending on the viewport size. For vertical scroll
1099 * bars, 0 means topmost (which is kinda sick with the OS/2
1100 * coordinate system), for horizontal scroll bars, 0 means leftmost.
1101 * The maximum value of the scroll bar will be:
1102 + (ulViewportPels - ulWinPels) / usScrollUnitPels
1103 *
1104 * The thumb size of the scroll bar will also be adjusted
1105 * based on the viewport and window size, as it should be.
1106 *
1107 *@@added V0.9.1 (2000-02-14) [umoeller]
1108 *@@changed V0.9.3 (2000-04-30) [umoeller]: fixed pels/unit confusion
1109 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
1110 */
1111
1112BOOL winhUpdateScrollBar(HWND hwndScrollBar, // in: scroll bar (vertical or horizontal)
1113 ULONG ulWinPels, // in: vertical or horizontal dimension of
1114 // visible window part (in pixels),
1115 // excluding the scroll bar!
1116 ULONG ulViewportPels, // in: dimension of total data part, of
1117 // which ulWinPels is a sub-dimension
1118 // (in pixels);
1119 // if <= ulWinPels, the scrollbar will be
1120 // disabled
1121 ULONG ulCurPelsOfs, // in: current offset of visible part
1122 // (in pixels)
1123 BOOL fAutoHide) // in: hide scroll bar if disabled
1124{
1125 BOOL brc = FALSE;
1126
1127 // _Pmpf(("Entering winhUpdateScrollBar"));
1128
1129 // for large viewports, adjust scroll bar units
1130 USHORT usScrollUnitPels = 1;
1131 if (ulViewportPels > 10000)
1132 usScrollUnitPels = 100;
1133
1134 if (ulViewportPels > ulWinPels)
1135 {
1136 // scrollbar needed:
1137 USHORT usThumbDivisorUnits = usScrollUnitPels;
1138 USHORT lMaxAllowedUnitOfs;
1139 // _Pmpf(("winhUpdateScrollBar: ulViewportPels > ulWinPels, enabling scroller"));
1140 // divisor for thumb size (below)
1141 if (ulViewportPels > 10000)
1142 // for very large viewports, we need to
1143 // raise the divisor, because we only
1144 // have a USHORT
1145 usThumbDivisorUnits = usScrollUnitPels * 100;
1146
1147 // viewport is larger than window:
1148 WinEnableWindow(hwndScrollBar, TRUE);
1149 if (fAutoHide)
1150 WinShowWindow(hwndScrollBar, TRUE);
1151
1152 // calculate limit
1153 lMaxAllowedUnitOfs = ((ulViewportPels - ulWinPels + usScrollUnitPels)
1154 // scroll unit is 10
1155 / usScrollUnitPels);
1156
1157 // _Pmpf((" usCurUnitOfs: %d", ulCurUnitOfs));
1158 // _Pmpf((" usMaxUnits: %d", lMaxAllowedUnitOfs));
1159
1160 // set thumb position and limit
1161 WinSendMsg(hwndScrollBar,
1162 SBM_SETSCROLLBAR,
1163 (MPARAM)(ulCurPelsOfs), // / usThumbDivisorUnits), // position: 0 means top
1164 MPFROM2SHORT(0, // minimum
1165 lMaxAllowedUnitOfs)); // maximum
1166
1167 // set thumb size based on ulWinPels and
1168 // ulViewportPels
1169 WinSendMsg(hwndScrollBar,
1170 SBM_SETTHUMBSIZE,
1171 MPFROM2SHORT( ulWinPels / usThumbDivisorUnits, // visible
1172 ulViewportPels / usThumbDivisorUnits), // total
1173 0);
1174 brc = TRUE;
1175 }
1176 else
1177 {
1178 // _Pmpf(("winhUpdateScrollBar: ulViewportPels <= ulWinPels"));
1179 // entire viewport is visible:
1180 WinEnableWindow(hwndScrollBar, FALSE);
1181 if (fAutoHide)
1182 WinShowWindow(hwndScrollBar, FALSE);
1183 }
1184
1185 // _Pmpf(("End of winhUpdateScrollBar"));
1186
1187 return (brc);
1188}
1189
1190/*
1191 *@@ winhHandleScrollMsg:
1192 * this helper handles a WM_VSCROLL or WM_HSCROLL
1193 * message posted to a client window when the user
1194 * has worked on a client scroll bar. Calling this
1195 * function is ALL you need to do to handle those
1196 * two messages.
1197 *
1198 * This is most useful in conjunction with winhUpdateScrollBar.
1199 * See that function for the terminology also.
1200 *
1201 * This function calculates the new scrollbar position
1202 * (from the mp2 value, which can be line up/down,
1203 * page up/down, or slider track) and calls WinScrollWindow
1204 * accordingly. The window part which became invalid
1205 * because of the scrolling is automatically invalidated
1206 * (using WinInvalidateRect), so expect a WM_PAINT after
1207 * calling this function.
1208 *
1209 * This function assumes that the scrollbar operates
1210 * on values starting from zero. The maximum value
1211 * of the scroll bar is:
1212 + ulViewportPels - (prcl2Scroll->yTop - prcl2Scroll->yBottom)
1213 *
1214 * This function also automatically changes the scroll bar
1215 * units, should you have a viewport size which doesn't fit
1216 * into the SHORT's that the scroll bar uses internally. As
1217 * a result, this function handles a the complete range of
1218 * a ULONG for the viewport.
1219 *
1220 * Replace "bottom" and "top" with "right" and "left" for
1221 * horizontal scrollbars in the above formula.
1222 *
1223 *@@added V0.9.1 (2000-02-13) [umoeller]
1224 *@@changed V0.9.3 (2000-04-30) [umoeller]: changed prototype, fixed pels/unit confusion
1225 *@@changed V0.9.3 (2000-05-08) [umoeller]: now handling scroll units automatically
1226 */
1227
1228BOOL winhHandleScrollMsg(HWND hwnd2Scroll, // in: client window to scroll
1229 HWND hwndScrollBar, // in: vertical or horizontal scroll bar window
1230 PLONG plCurPelsOfs, // in/out: current viewport offset;
1231 // this is updated with the proper scroll units
1232 PRECTL prcl2Scroll, // in: hwnd2Scroll rectangle to scroll
1233 // (in window coordinates);
1234 // this is passed to WinScrollWindow,
1235 // which considers this inclusive!
1236 LONG ulViewportPels, // in: total viewport dimension,
1237 // into which *plCurPelsOfs is an offset
1238 USHORT usLineStepPels, // in: pixels to scroll line-wise
1239 // (scroll bar buttons pressed)
1240 ULONG msg, // in: either WM_VSCROLL or WM_HSCROLL
1241 MPARAM mp2) // in: complete mp2 of WM_VSCROLL/WM_HSCROLL;
1242 // this has two SHORT's (usPos and usCmd),
1243 // see PMREF for details
1244{
1245 LONG lOldPelsOfs = *plCurPelsOfs;
1246 USHORT usPosUnits = SHORT1FROMMP(mp2), // in scroll units
1247 usCmd = SHORT2FROMMP(mp2);
1248 LONG lMaxAllowedUnitOfs;
1249 ULONG ulWinPels;
1250
1251 // for large viewports, adjust scroll bar units
1252 USHORT usScrollUnitPels = 1;
1253 if (ulViewportPels > 10000)
1254 usScrollUnitPels = 100;
1255
1256 // calculate window size (vertical or horizontal)
1257 if (msg == WM_VSCROLL)
1258 ulWinPels = (prcl2Scroll->yTop - prcl2Scroll->yBottom);
1259 else
1260 ulWinPels = (prcl2Scroll->xRight - prcl2Scroll->xLeft);
1261
1262 lMaxAllowedUnitOfs = ((LONG)ulViewportPels - ulWinPels) / usScrollUnitPels;
1263
1264 // _Pmpf(("Entering winhHandleScrollMsg"));
1265
1266 switch (usCmd)
1267 {
1268 case SB_LINEUP:
1269 // _Pmpf(("SB_LINEUP"));
1270 *plCurPelsOfs -= usLineStepPels; // * usScrollUnitPels);
1271 break;
1272
1273 case SB_LINEDOWN:
1274 // _Pmpf(("SB_LINEDOWN"));
1275 *plCurPelsOfs += usLineStepPels; // * usScrollUnitPels);
1276 break;
1277
1278 case SB_PAGEUP:
1279 *plCurPelsOfs -= ulWinPels; // convert to units
1280 break;
1281
1282 case SB_PAGEDOWN:
1283 *plCurPelsOfs += ulWinPels; // convert to units
1284 break;
1285
1286 case SB_SLIDERTRACK:
1287 *plCurPelsOfs = (usPosUnits * usScrollUnitPels);
1288 // _Pmpf((" SB_SLIDERTRACK: usUnits = %d", usPosUnits));
1289 break;
1290
1291 case SB_SLIDERPOSITION:
1292 *plCurPelsOfs = (usPosUnits * usScrollUnitPels);
1293 break;
1294 }
1295
1296 // are we close to the lower limit?
1297 /* if (*plCurUnitOfs < usLineStepUnits) // usScrollUnit)
1298 *plCurUnitOfs = 0;
1299 // are we close to the upper limit?
1300 else if (*plCurUnitOfs + usLineStepUnits > lMaxUnitOfs)
1301 {
1302 _Pmpf((" !!! limiting: %d to %d", *plCurUnitOfs, lMaxUnitOfs));
1303 *plCurUnitOfs = lMaxUnitOfs;
1304 } */
1305
1306 if (*plCurPelsOfs < 0)
1307 *plCurPelsOfs = 0;
1308 if (*plCurPelsOfs > (lMaxAllowedUnitOfs * usScrollUnitPels))
1309 {
1310 // _Pmpf((" !!! limiting 2: %d to %d", *plCurUnitOfs, lMaxAllowedUnitOfs));
1311 *plCurPelsOfs = (lMaxAllowedUnitOfs * usScrollUnitPels);
1312 }
1313 if ( (*plCurPelsOfs != lOldPelsOfs)
1314 || (*plCurPelsOfs == 0)
1315 || (*plCurPelsOfs == (lMaxAllowedUnitOfs * usScrollUnitPels))
1316 )
1317 {
1318 RECTL rcl2Scroll,
1319 rcl2Update;
1320
1321 // changed:
1322 WinSendMsg(hwndScrollBar,
1323 SBM_SETPOS,
1324 (MPARAM)(*plCurPelsOfs / usScrollUnitPels), // / usScrollUnit),
1325 0);
1326 // scroll window rectangle:
1327 rcl2Scroll.xLeft = prcl2Scroll->xLeft;
1328 rcl2Scroll.xRight = prcl2Scroll->xRight;
1329 rcl2Scroll.yBottom = prcl2Scroll->yBottom;
1330 rcl2Scroll.yTop = prcl2Scroll->yTop;
1331
1332 if (msg == WM_VSCROLL)
1333 WinScrollWindow(hwnd2Scroll,
1334 0,
1335 (*plCurPelsOfs - lOldPelsOfs) // scroll units changed
1336 , // * usScrollUnitPels, // convert to pels
1337 &rcl2Scroll, // rcl to scroll
1338 prcl2Scroll, // clipping rect
1339 NULLHANDLE, // no region
1340 &rcl2Update,
1341 0);
1342 else
1343 WinScrollWindow(hwnd2Scroll,
1344 -(*plCurPelsOfs - lOldPelsOfs) // scroll units changed
1345 , // * usScrollUnitPels,
1346 0,
1347 &rcl2Scroll, // rcl to scroll
1348 prcl2Scroll, // clipping rect
1349 NULLHANDLE, // no region
1350 &rcl2Update,
1351 0);
1352
1353 // WinScrollWindow has stored the invalid window
1354 // rectangle which needs to be repainted in rcl2Update:
1355 WinInvalidateRect(hwnd2Scroll, &rcl2Update, FALSE);
1356 }
1357
1358 // _Pmpf(("End of winhHandleScrollMsg"));
1359
1360 return (TRUE);
1361}
1362
1363/*
1364 *@@ winhProcessScrollChars:
1365 * helper for processing WM_CHAR messages for
1366 * client windows with scroll bars.
1367 *
1368 * If your window has scroll bars, you normally
1369 * need to process a number of keystrokes to be
1370 * able to scroll the window contents. This is
1371 * tiresome to code, so here is a helper.
1372 *
1373 * When receiving WM_CHAR, call this function.
1374 * If this returns TRUE, the keystroke has been
1375 * a scroll keystroke, and the window has been
1376 * updated (by sending WM_VSCROLL or WM_HSCROLL
1377 * to hwndClient). Otherwise, you should process
1378 * the keystroke as usual because it's not a
1379 * scroll keystroke.
1380 *
1381 * The following keystrokes are processed here:
1382 *
1383 * -- "cursor up, down, right, left": scroll one
1384 * line in the proper direction.
1385 * -- "page up, down": scroll one page up or down.
1386 * -- "Home": scroll leftmost.
1387 * -- "Ctrl+ Home": scroll topmost.
1388 * -- "End": scroll rightmost.
1389 * -- "Ctrl+ End": scroll bottommost.
1390 * -- "Ctrl + page up, down": scroll topmost or bottommost.
1391 *
1392 * This is roughly CUA behavior.
1393 *
1394 * Returns TRUE if the message has been
1395 * processed.
1396 *
1397 *@@added V0.9.3 (2000-04-29) [umoeller]
1398 */
1399
1400BOOL winhProcessScrollChars(HWND hwndClient, // in: client window
1401 HWND hwndVScroll, // in: vertical scroll bar
1402 HWND hwndHScroll, // in: horizontal scroll bar
1403 MPARAM mp1, // in: WM_CHAR mp1
1404 MPARAM mp2, // in: WM_CHAR mp2
1405 ULONG ulVertMax, // in: maximum viewport cy
1406 ULONG ulHorzMax) // in: maximum viewport cx
1407{
1408 BOOL fProcessed = FALSE;
1409 USHORT usFlags = SHORT1FROMMP(mp1);
1410 // USHORT usch = SHORT1FROMMP(mp2);
1411 USHORT usvk = SHORT2FROMMP(mp2);
1412
1413 // _Pmpf(("Entering winhProcessScrollChars"));
1414
1415 if (usFlags & KC_VIRTUALKEY)
1416 {
1417 ULONG ulMsg = 0;
1418 SHORT sPos = 0;
1419 SHORT usCmd = 0;
1420 fProcessed = TRUE;
1421
1422 switch (usvk)
1423 {
1424 case VK_UP:
1425 ulMsg = WM_VSCROLL;
1426 usCmd = SB_LINEUP;
1427 break;
1428
1429 case VK_DOWN:
1430 ulMsg = WM_VSCROLL;
1431 usCmd = SB_LINEDOWN;
1432 break;
1433
1434 case VK_RIGHT:
1435 ulMsg = WM_HSCROLL;
1436 usCmd = SB_LINERIGHT;
1437 break;
1438
1439 case VK_LEFT:
1440 ulMsg = WM_HSCROLL;
1441 usCmd = SB_LINELEFT;
1442 break;
1443
1444 case VK_PAGEUP:
1445 ulMsg = WM_VSCROLL;
1446 if (usFlags & KC_CTRL)
1447 {
1448 sPos = 0;
1449 usCmd = SB_SLIDERPOSITION;
1450 }
1451 else
1452 usCmd = SB_PAGEUP;
1453 break;
1454
1455 case VK_PAGEDOWN:
1456 ulMsg = WM_VSCROLL;
1457 if (usFlags & KC_CTRL)
1458 {
1459 sPos = ulVertMax;
1460 usCmd = SB_SLIDERPOSITION;
1461 }
1462 else
1463 usCmd = SB_PAGEDOWN;
1464 break;
1465
1466 case VK_HOME:
1467 if (usFlags & KC_CTRL)
1468 // vertical:
1469 ulMsg = WM_VSCROLL;
1470 else
1471 ulMsg = WM_HSCROLL;
1472
1473 sPos = 0;
1474 usCmd = SB_SLIDERPOSITION;
1475 break;
1476
1477 case VK_END:
1478 if (usFlags & KC_CTRL)
1479 {
1480 // vertical:
1481 ulMsg = WM_VSCROLL;
1482 sPos = ulVertMax;
1483 }
1484 else
1485 {
1486 ulMsg = WM_HSCROLL;
1487 sPos = ulHorzMax;
1488 }
1489
1490 usCmd = SB_SLIDERPOSITION;
1491 break;
1492
1493 default:
1494 // other:
1495 fProcessed = FALSE;
1496 }
1497
1498 if ( ((usFlags & KC_KEYUP) == 0)
1499 && (ulMsg)
1500 )
1501 {
1502 HWND hwndScrollBar = ((ulMsg == WM_VSCROLL)
1503 ? hwndVScroll
1504 : hwndHScroll);
1505 if (WinIsWindowEnabled(hwndScrollBar))
1506 {
1507 USHORT usID = WinQueryWindowUShort(hwndScrollBar,
1508 QWS_ID);
1509 WinSendMsg(hwndClient,
1510 ulMsg,
1511 MPFROMSHORT(usID),
1512 MPFROM2SHORT(sPos,
1513 usCmd));
1514 }
1515 }
1516 }
1517
1518 // _Pmpf(("End of winhProcessScrollChars"));
1519
1520 return (fProcessed);
1521}
1522
1523/*
1524 *@@category: Helpers\PM helpers\Window positioning
1525 */
1526
1527/* ******************************************************************
1528 *
1529 * Window positioning helpers
1530 *
1531 ********************************************************************/
1532
1533/*
1534 *@@ winhSaveWindowPos:
1535 * saves the position of a certain window. As opposed
1536 * to the barely documented WinStoreWindowPos API, this
1537 * one only saves one regular SWP structure for the given
1538 * window, as returned by WinQueryWindowPos for hwnd.
1539 *
1540 * If the window is currently maximized or minimized,
1541 * we won't store the current window size and position
1542 * (which wouldn't make much sense), but retrieve the
1543 * "restored" window position from the window words
1544 * instead.
1545 *
1546 * The window should still be visible on the screen
1547 * when calling this function. Do not call it in WM_DESTROY,
1548 * because then the SWP data is no longer valid.
1549 *
1550 * This returns TRUE if saving was successful.
1551 *
1552 *@@changed V0.9.1 (99-12-19) [umoeller]: added minimize/maximize support
1553 */
1554
1555BOOL winhSaveWindowPos(HWND hwnd, // in: window to save
1556 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
1557 PSZ pszApp, // in: INI application name
1558 PSZ pszKey) // in: INI key name
1559{
1560 BOOL brc = FALSE;
1561 SWP swp;
1562 if (WinQueryWindowPos(hwnd, &swp))
1563 {
1564 if (swp.fl & (SWP_MAXIMIZE | SWP_MINIMIZE))
1565 {
1566 // window currently maximized or minimized:
1567 // retrieve "restore" position from window words
1568 swp.x = WinQueryWindowUShort(hwnd, QWS_XRESTORE);
1569 swp.y = WinQueryWindowUShort(hwnd, QWS_YRESTORE);
1570 swp.cx = WinQueryWindowUShort(hwnd, QWS_CXRESTORE);
1571 swp.cy = WinQueryWindowUShort(hwnd, QWS_CYRESTORE);
1572 }
1573
1574 brc = PrfWriteProfileData(hIni, pszApp, pszKey, &swp, sizeof(swp));
1575 }
1576 return (brc);
1577}
1578
1579/*
1580 *@@ winhRestoreWindowPos:
1581 * this will retrieve a window position which was
1582 * previously stored using winhSaveWindowPos.
1583 *
1584 * The window should not be visible to avoid flickering.
1585 * "fl" must contain the SWP_flags as in WinSetWindowPos.
1586 *
1587 * Note that only the following may be used:
1588 * -- SWP_MOVE reposition the window
1589 * -- SWP_SIZE also resize the window to
1590 * the stored position; this might
1591 * lead to problems with different
1592 * video resolutions, so be careful.
1593 * -- SWP_SHOW make window visible too
1594 * -- SWP_NOREDRAW changes are not redrawn
1595 * -- SWP_NOADJUST do not send a WM_ADJUSTWINDOWPOS message
1596 * before moving or sizing
1597 * -- SWP_ACTIVATE activate window (make topmost)
1598 * -- SWP_DEACTIVATE deactivate window (make bottommost)
1599 *
1600 * Do not specify any other SWP_* flags.
1601 *
1602 * If SWP_SIZE is not set, the window will be moved only.
1603 *
1604 * This returns TRUE if INI data was found.
1605 *
1606 * This function automatically checks for whether the
1607 * window would be positioned outside the visible screen
1608 * area and will adjust coordinates accordingly. This can
1609 * happen when changing video resolutions.
1610 */
1611
1612BOOL winhRestoreWindowPos(HWND hwnd, // in: window to restore
1613 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
1614 PSZ pszApp, // in: INI application name
1615 PSZ pszKey, // in: INI key name
1616 ULONG fl) // in: "fl" parameter for WinSetWindowPos
1617{
1618 BOOL brc = FALSE;
1619 SWP swp, swpNow;
1620 ULONG cbswp = sizeof(swp);
1621 ULONG fl2 = fl;
1622
1623 if (PrfQueryProfileData(hIni, pszApp, pszKey, &swp, &cbswp))
1624 {
1625 ULONG ulScreenCX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
1626 ULONG ulScreenCY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
1627
1628 brc = TRUE;
1629
1630 if ((fl & SWP_SIZE) == 0)
1631 {
1632 // if no resize, we need to get the current position
1633 brc = WinQueryWindowPos(hwnd, &swpNow);
1634 swp.cx = swpNow.cx;
1635 swp.cy = swpNow.cy;
1636 }
1637
1638 if (brc)
1639 {
1640 // check for full visibility
1641 if ( (swp.x + swp.cx) > ulScreenCX)
1642 swp.x = ulScreenCX - swp.cx;
1643 if ( (swp.y + swp.cy) > ulScreenCY)
1644 swp.y = ulScreenCY - swp.cy;
1645 }
1646
1647 brc = TRUE;
1648
1649 }
1650 else
1651 // window pos not found in INI: unset SWP_MOVE etc.
1652 fl2 &= ~(SWP_MOVE | SWP_SIZE);
1653
1654 WinSetWindowPos(hwnd,
1655 NULLHANDLE, // insert-behind window
1656 swp.x,
1657 swp.y,
1658 swp.cx,
1659 swp.cy,
1660 fl2); // SWP_* flags
1661
1662 return (brc);
1663}
1664
1665/*
1666 *@@ winhAdjustControls:
1667 * helper function for dynamically adjusting a window's
1668 * controls when the window is resized.
1669 *
1670 * This is most useful with dialogs loaded from resources
1671 * which should be sizeable. Normally, when the dialog
1672 * frame is resized, the controls stick to their positions,
1673 * and for dialogs with many controls, programming the
1674 * changes can be tiresome.
1675 *
1676 * Enter this function. ;-) Basically, this takes a
1677 * static array of MPARAM's as input (plus one dynamic
1678 * storage area for the window positions).
1679 *
1680 * This function must get called in three contexts:
1681 * during WM_INITDLG, during WM_WINDOWPOSCHANGED, and
1682 * during WM_DESTROY, with varying parameters.
1683 *
1684 * In detail, there are four things you need to do to make
1685 * this work:
1686 *
1687 * 1) Set up a static array (as a global variable) of
1688 * MPARAM's, one for each control in your array.
1689 * Each MPARAM will have the control's ID and the
1690 * XAF* flags (winh.h) how the control shall be moved.
1691 * Use MPFROM2SHORT to easily create this. Example:
1692 *
1693 + MPARAM ampControlFlags[] =
1694 + { MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX),
1695 + MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY),
1696 + ...
1697 + }
1698 *
1699 * This can safely be declared as a global variable
1700 * because this data will only be read and never
1701 * changed by this function.
1702 *
1703 * 2) In WM_INITDLG of your dialog function, set up
1704 * an XADJUSTCTRLS structure, preferrably in your
1705 * window words (QWL_USER).
1706 *
1707 * ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS),
1708 * or this func will not work.
1709 *
1710 * Call this function with pswpNew == NULL and
1711 * pxac pointing to that new structure. This will
1712 * query the positions of all the controls listed
1713 * in the MPARAMs array and store them in the
1714 * XADJUSTCTRLS area.
1715 *
1716 * 3) Intercept WM_WINDOWPOSCHANGED:
1717 *
1718 + case WM_WINDOWPOSCHANGED:
1719 + {
1720 + // this msg is passed two SWP structs:
1721 + // one for the old, one for the new data
1722 + // (from PM docs)
1723 + PSWP pswpNew = PVOIDFROMMP(mp1);
1724 + PSWP pswpOld = pswpNew + 1;
1725 +
1726 + // resizing?
1727 + if (pswpNew->fl & SWP_SIZE)
1728 + {
1729 + PXADJUSTCTRLS pxac = ... // get it from your window words
1730 +
1731 + winhAdjustControls(hwndDlg, // dialog
1732 + ampControlFlags, // MPARAMs array
1733 + sizeof(ampControlFlags) / sizeof(MPARAM),
1734 + // items count
1735 + pswpNew, // mp1
1736 + pxac); // storage area
1737 + }
1738 + mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ...
1739 *
1740 * 4) In WM_DESTROY, call this function again with pmpFlags,
1741 * pswpNew, and pswpNew set to NULL. This will clean up the
1742 * data which has been allocated internally (pointed to from
1743 * the XADJUSTCTRLS structure).
1744 * Don't forget to free your storage for XADJUSTCTLRS
1745 * _itself_, that's the job of the caller.
1746 *
1747 * This might sound complicated, but it's a lot easier than
1748 * having to write dozens of WinSetWindowPos calls oneself.
1749 *
1750 *@@added V0.9.0 [umoeller]
1751 */
1752
1753BOOL winhAdjustControls(HWND hwndDlg, // in: dialog (req.)
1754 MPARAM *pmpFlags, // in: init flags or NULL for cleanup
1755 ULONG ulCount, // in: item count (req.)
1756 PSWP pswpNew, // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
1757 PXADJUSTCTRLS pxac) // in: adjust-controls storage area (req.)
1758{
1759 BOOL brc = FALSE;
1760 ULONG ul = 0;
1761
1762 /* if (!WinIsWindowVisible(hwndDlg))
1763 return (FALSE); */
1764
1765 if ((pmpFlags) && (pxac))
1766 {
1767 PSWP pswpThis;
1768 MPARAM *pmpThis;
1769 LONG ldcx, ldcy;
1770 ULONG cWindows = 0;
1771
1772 // setup mode:
1773 if (pxac->fInitialized == FALSE)
1774 {
1775 // first call: get all the SWP's
1776 WinQueryWindowPos(hwndDlg, &pxac->swpMain);
1777 // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d",
1778 // pxac->swpMain.cx, pxac->swpMain.cy));
1779
1780 pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount);
1781
1782 pswpThis = pxac->paswp;
1783 pmpThis = pmpFlags;
1784
1785 for (ul = 0;
1786 ul < ulCount;
1787 ul++)
1788 {
1789 HWND hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis));
1790 if (hwndThis)
1791 {
1792 WinQueryWindowPos(hwndThis, pswpThis);
1793 cWindows++;
1794 }
1795
1796 pswpThis++;
1797 pmpThis++;
1798 }
1799
1800 pxac->fInitialized = TRUE;
1801 // _Pmpf(("winhAdjustControls: queried %d controls", cWindows));
1802 }
1803
1804 if (pswpNew)
1805 {
1806 // compute width and height delta
1807 ldcx = (pswpNew->cx - pxac->swpMain.cx);
1808 ldcy = (pswpNew->cy - pxac->swpMain.cy);
1809
1810 // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d",
1811 // pswpNew->cx, pswpNew->cy));
1812
1813 // now adjust the controls
1814 cWindows = 0;
1815 pswpThis = pxac->paswp;
1816 pmpThis = pmpFlags;
1817 for (ul = 0;
1818 ul < ulCount;
1819 ul++)
1820 {
1821 HWND hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis));
1822 if (hwndThis)
1823 {
1824 LONG x = pswpThis->x,
1825 y = pswpThis->y,
1826 cx = pswpThis->cx,
1827 cy = pswpThis->cy;
1828
1829 ULONG ulSwpFlags = 0;
1830 // get flags for this control
1831 USHORT usFlags = SHORT2FROMMP(*pmpThis);
1832
1833 if (usFlags & XAC_MOVEX)
1834 {
1835 x += ldcx;
1836 ulSwpFlags |= SWP_MOVE;
1837 }
1838 if (usFlags & XAC_MOVEY)
1839 {
1840 y += ldcy;
1841 ulSwpFlags |= SWP_MOVE;
1842 }
1843 if (usFlags & XAC_SIZEX)
1844 {
1845 cx += ldcx;
1846 ulSwpFlags |= SWP_SIZE;
1847 }
1848 if (usFlags & XAC_SIZEY)
1849 {
1850 cy += ldcy;
1851 ulSwpFlags |= SWP_SIZE;
1852 }
1853
1854 if (ulSwpFlags)
1855 {
1856 WinSetWindowPos(hwndThis,
1857 NULLHANDLE, // hwndInsertBehind
1858 x, y, cx, cy,
1859 ulSwpFlags);
1860 cWindows++;
1861 brc = TRUE;
1862 }
1863 }
1864
1865 pswpThis++;
1866 pmpThis++;
1867 }
1868
1869 // _Pmpf(("winhAdjustControls: set %d windows", cWindows));
1870 }
1871 }
1872 else
1873 {
1874 // pxac == NULL:
1875 // cleanup mode
1876 if (pxac->paswp)
1877 free(pxac->paswp);
1878 }
1879
1880 return (brc);
1881}
1882
1883/*
1884 *@@ winhCenterWindow:
1885 * centers a window within its parent window. If that's
1886 * the PM desktop, it will be centered according to the
1887 * whole screen.
1888 * For dialog boxes, use WinCenteredDlgBox as a one-shot
1889 * function.
1890 *
1891 * Note: When calling this function, the window should
1892 * not be visible to avoid flickering.
1893 * This func does not show the window either, so call
1894 * WinShowWindow afterwards.
1895 */
1896
1897void winhCenterWindow(HWND hwnd)
1898{
1899 RECTL rclParent;
1900 RECTL rclWindow;
1901
1902 WinQueryWindowRect(hwnd, &rclWindow);
1903 WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent);
1904
1905 rclWindow.xLeft = (rclParent.xRight - rclWindow.xRight) / 2;
1906 rclWindow.yBottom = (rclParent.yTop - rclWindow.yTop ) / 2;
1907
1908 WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom,
1909 0, 0, SWP_MOVE);
1910}
1911
1912/*
1913 *@@ winhCenteredDlgBox:
1914 * just like WinDlgBox, but the dlg box is centered on the screen;
1915 * you should mark the dlg template as not visible in the dlg
1916 * editor, or display will flicker.
1917 * As opposed to winhCenterWindow, this _does_ show the window.
1918 */
1919
1920ULONG winhCenteredDlgBox(HWND hwndParent,
1921 HWND hwndOwner,
1922 PFNWP pfnDlgProc,
1923 HMODULE hmod,
1924 ULONG idDlg,
1925 PVOID pCreateParams)
1926{
1927 ULONG ulReply;
1928 HWND hwndDlg = WinLoadDlg(hwndParent,
1929 hwndOwner,
1930 pfnDlgProc,
1931 hmod,
1932 idDlg,
1933 pCreateParams);
1934 winhCenterWindow(hwndDlg);
1935 ulReply = WinProcessDlg(hwndDlg);
1936 WinDestroyWindow(hwndDlg);
1937 return (ulReply);
1938}
1939
1940/*
1941 *@@ winhFindWindowBelow:
1942 * finds the window with the same parent
1943 * which sits right below hwndFind in the
1944 * window Z-order.
1945 *
1946 *@@added V0.9.7 (2000-12-04) [umoeller]
1947 */
1948
1949HWND winhFindWindowBelow(HWND hwndFind)
1950{
1951 HWND hwnd = NULLHANDLE,
1952 hwndParent = WinQueryWindow(hwndFind, QW_PARENT);
1953
1954 if (hwndParent)
1955 {
1956 HENUM henum = WinBeginEnumWindows(hwndParent);
1957 HWND hwndThis;
1958 while (hwndThis = WinGetNextWindow(henum))
1959 {
1960 SWP swp;
1961 WinQueryWindowPos(hwndThis, &swp);
1962 if (swp.hwndInsertBehind == hwndFind)
1963 {
1964 hwnd = hwndThis;
1965 break;
1966 }
1967 }
1968 WinEndEnumWindows(henum);
1969 }
1970
1971 return (hwnd);
1972}
1973
1974/*
1975 *@@category: Helpers\PM helpers\Presentation parameters
1976 */
1977
1978/* ******************************************************************
1979 *
1980 * Presparams helpers
1981 *
1982 ********************************************************************/
1983
1984/*
1985 *@@ winhQueryWindowFont:
1986 * returns the window font presentation parameter
1987 * in a newly allocated buffer.
1988 *
1989 * Returns NULL on error. Use winhFree()
1990 * to free the return value.
1991 *
1992 *@@added V0.9.1 (2000-02-14) [umoeller]
1993 */
1994
1995PSZ winhQueryWindowFont(HWND hwnd)
1996{
1997 CHAR szNewFont[100] = "";
1998 WinQueryPresParam(hwnd,
1999 PP_FONTNAMESIZE,
2000 0,
2001 NULL,
2002 (ULONG)sizeof(szNewFont),
2003 (PVOID)&szNewFont,
2004 QPF_NOINHERIT);
2005 if (szNewFont[0] != 0)
2006 return (strdup(szNewFont));
2007
2008 return (NULL);
2009}
2010
2011/*
2012 *@@ winhSetWindowFont:
2013 * this sets a window's font by invoking
2014 * WinSetPresParam on it.
2015 *
2016 * If (pszFont == NULL), a default font will be set
2017 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2018 *
2019 * winh.h also defines the winhSetDlgItemFont macro.
2020 *
2021 * Returns TRUE if successful or FALSE otherwise.
2022 *
2023 *@@added V0.9.0 [umoeller]
2024 */
2025
2026BOOL winhSetWindowFont(HWND hwnd,
2027 const char *pcszFont)
2028{
2029 CHAR szFont[256];
2030
2031 if (pcszFont == NULL)
2032 {
2033 if (doshIsWarp4())
2034 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
2035 else
2036 strhncpy0(szFont, "8.Helv", sizeof(szFont));
2037 }
2038 else
2039 strhncpy0(szFont, pcszFont, sizeof(szFont));
2040
2041 return (WinSetPresParam(hwnd,
2042 PP_FONTNAMESIZE,
2043 strlen(szFont)+1,
2044 szFont));
2045}
2046
2047/*
2048 *@@ winhSetControlsFont:
2049 * this sets the font for all the controls of hwndDlg
2050 * which have a control ID in the range of usIDMin to
2051 * usIDMax. "Unused" IDs (i.e. -1) will also be set.
2052 *
2053 * If (pszFont == NULL), a default font will be set
2054 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2055 *
2056 * Returns the no. of controls set.
2057 *
2058 *@@added V0.9.0 [umoeller]
2059 */
2060
2061ULONG winhSetControlsFont(HWND hwndDlg, // in: dlg to set
2062 SHORT usIDMin, // in: minimum control ID to be set (inclusive)
2063 SHORT usIDMax, // in: maximum control ID to be set (inclusive)
2064 const char *pcszFont) // in: font to use (e.g. "9.WarpSans") or NULL
2065{
2066 ULONG ulrc = 0;
2067 HENUM henum;
2068 HWND hwndItem;
2069 CHAR szFont[256];
2070 ULONG cbFont;
2071
2072 if (pcszFont == NULL)
2073 {
2074 if (doshIsWarp4())
2075 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
2076 else
2077 strhncpy0(szFont, "8.Helv", sizeof(szFont));
2078 }
2079 else
2080 strhncpy0(szFont, pcszFont, sizeof(szFont));
2081 cbFont = strlen(szFont)+1;
2082
2083 // set font for all the dialog controls
2084 henum = WinBeginEnumWindows(hwndDlg);
2085 while ((hwndItem = WinGetNextWindow(henum)))
2086 {
2087 SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID);
2088 if ( (sID == -1)
2089 || ((sID >= usIDMin) && (sID <= usIDMax))
2090 )
2091 if (WinSetPresParam(hwndItem,
2092 PP_FONTNAMESIZE,
2093 cbFont,
2094 szFont))
2095 // successful:
2096 ulrc++;
2097 }
2098 WinEndEnumWindows(henum);
2099 return (ulrc);
2100}
2101
2102/*
2103 *@@ winhStorePresParam:
2104 * this appends a new presentation parameter to an
2105 * array of presentation parameters which can be
2106 * passed to WinCreateWindow. This is preferred
2107 * over setting the presparams using WinSetPresParams,
2108 * because that call will cause a lot of messages.
2109 *
2110 * On the first call, pppp _must_ be NULL. This
2111 * will allocate memory for storing the given
2112 * data as necessary and modify *pppp to point
2113 * to the new array.
2114 *
2115 * On subsequent calls with the same pppp, memory
2116 * will be reallocated, the old data will be copied,
2117 * and the new given data will be appended.
2118 *
2119 * Use free() on your PPRESPARAMS pointer (whose
2120 * address was passed) after WinCreateWindow.
2121 *
2122 * See winhQueryPresColor for typical presparams
2123 * used in OS/2.
2124 *
2125 * Example:
2126 + PPRESPARAMS ppp = NULL;
2127 + CHAR szFont[] = "9.WarpSans";
2128 + LONG lColor = CLR_WHITE;
2129 + winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont);
2130 + winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor);
2131 + WinCreateWindow(...., ppp);
2132 + free(ppp);
2133 *
2134 *@@added V0.9.0 [umoeller]
2135 */
2136
2137BOOL winhStorePresParam(PPRESPARAMS *pppp, // in: data pointer (modified)
2138 ULONG ulAttrType, // in: PP_* index
2139 ULONG cbData, // in: sizeof(*pData), e.g. sizeof(LONG)
2140 PVOID pData) // in: presparam data (e.g. a PLONG to a color)
2141{
2142 BOOL brc = FALSE;
2143 if (pppp)
2144 {
2145 ULONG cbOld = 0,
2146 cbNew;
2147 PBYTE pbTemp = 0;
2148 PPRESPARAMS pppTemp = 0;
2149 PPARAM pppCopyTo = 0;
2150
2151 if (*pppp != NULL)
2152 // subsequent calls:
2153 cbOld = (**pppp).cb;
2154
2155 cbNew = sizeof(ULONG) // PRESPARAMS.cb
2156 + cbOld // old count, which does not include PRESPARAMS.cb
2157 + sizeof(ULONG) // PRESPARAMS.aparam[0].id
2158 + sizeof(ULONG) // PRESPARAMS.aparam[0].cb
2159 + cbData; // PRESPARAMS.aparam[0].ab[]
2160
2161 pbTemp = (PBYTE)malloc(cbNew);
2162 if (pbTemp)
2163 {
2164 pppTemp = (PPRESPARAMS)pbTemp;
2165
2166 if (*pppp != NULL)
2167 {
2168 // copy old data
2169 memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb
2170 pppCopyTo = (PPARAM)(pbTemp // new buffer
2171 + sizeof(ULONG) // skipping PRESPARAMS.cb
2172 + cbOld); // old PARAM array
2173 }
2174 else
2175 // first call:
2176 pppCopyTo = pppTemp->aparam;
2177
2178 pppTemp->cb = cbNew - sizeof(ULONG); // excluding PRESPARAMS.cb
2179 pppCopyTo->id = ulAttrType;
2180 pppCopyTo->cb = cbData; // byte count of PARAM.ab[]
2181 memcpy(pppCopyTo->ab, pData, cbData);
2182
2183 free(*pppp);
2184 *pppp = pppTemp;
2185
2186 brc = TRUE;
2187 }
2188 }
2189 return (brc);
2190}
2191
2192/*
2193 *@@ winhQueryPresColor:
2194 * returns the specified color. This is queried in the
2195 * following order:
2196 *
2197 * 1) hwnd's pres params are searched for ulPP
2198 * (which should be a PP_* index);
2199 * 2) if (fInherit == TRUE), the parent windows
2200 * are searched also;
2201 * 3) if this fails or (fInherit == FALSE), WinQuerySysColor
2202 * is called to get lSysColor (which should be a SYSCLR_*
2203 * index), if lSysColor != -1;
2204 * 4) if (lSysColor == -1), -1 is returned.
2205 *
2206 * The return value is always an RGB LONG, _not_ a color index.
2207 * This is even true for the returned system colors, which are
2208 * converted to RGB.
2209 *
2210 * If you do any painting with this value, you should switch
2211 * the HPS you're using to RGB mode (use gpihSwitchToRGB for that).
2212 *
2213 * Some useful ulPP / lSysColor pairs
2214 * (default values as in PMREF):
2215 *
2216 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT (for most controls also)
2217 + SYSCLR_WINDOWSTATICTEXT (for static controls)
2218 + Foreground color (default: black)
2219 + -- PP_BACKGROUNDCOLOR SYSCLR_BACKGROUND
2220 + SYSCLR_DIALOGBACKGROUND
2221 + SYSCLR_FIELDBACKGROUND (for disabled scrollbars)
2222 + SYSCLR_WINDOW (application surface -- empty clients)
2223 + Background color (default: light gray)
2224 + -- PP_ACTIVETEXTFGNDCOLOR
2225 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
2226 + Highlighted foreground color, for example for selected menu
2227 + (def.: white)
2228 + -- PP_ACTIVETEXTBGNDCOLOR
2229 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
2230 + Highlighted background color (def.: dark gray)
2231 + -- PP_INACTIVETEXTFGNDCOLOR
2232 + -- PP_DISABLEDFOREGROUNDCOLOR SYSCLR_MENUDISABLEDTEXT
2233 + Disabled foreground color (dark gray)
2234 + -- PP_INACTIVETEXTBGNDCOLOR
2235 + -- PP_DISABLEDBACKGROUNDCOLOR
2236 + Disabled background color
2237 + -- PP_BORDERCOLOR SYSCLR_WINDOWFRAME
2238 + SYSCLR_INACTIVEBORDER
2239 + Border color (around pushbuttons, in addition to
2240 + the 3D colors)
2241 + -- PP_ACTIVECOLOR SYSCLR_ACTIVETITLE
2242 + Active color
2243 + -- PP_INACTIVECOLOR SYSCLR_INACTIVETITLE
2244 + Inactive color
2245 *
2246 * For menus:
2247 + -- PP_MENUBACKGROUNDCOLOR SYSCLR_MENU
2248 + -- PP_MENUFOREGROUNDCOLOR SYSCLR_MENUTEXT
2249 + -- PP_MENUHILITEBGNDCOLOR SYSCLR_MENUHILITEBGND
2250 + -- PP_MENUHILITEFGNDCOLOR SYSCLR_MENUHILITE
2251 + -- ?? SYSCLR_MENUDISABLEDTEXT
2252 +
2253 * For containers (according to the API ref. at EDM/2):
2254 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT
2255 + -- PP_BACKGROUNDCOLOR SYSCLR_WINDOW
2256 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
2257 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
2258 + -- PP_BORDERCOLOR
2259 + (used for separator lines, eg. in Details view)
2260 + -- PP_ICONTEXTBACKGROUNDCOLOR
2261 + (column titles in Details view?!?)
2262 +
2263 * For listboxes / entryfields / MLE's:
2264 + -- PP_BACKGROUNDCOLOR SYSCLR_ENTRYFIELD
2265 *
2266 * PMREF has more of these.
2267 *
2268 *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed
2269 *@@changed V0.9.0 [umoeller]: added fInherit parameter
2270 *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support
2271 */
2272
2273LONG winhQueryPresColor(HWND hwnd, // in: window to query
2274 ULONG ulPP, // in: PP_* index
2275 BOOL fInherit, // in: search parent windows too?
2276 LONG lSysColor) // in: SYSCLR_* index
2277{
2278 ULONG ul,
2279 attrFound,
2280 abValue[32];
2281
2282 if (ulPP != (ULONG)-1)
2283 if ((ul = WinQueryPresParam(hwnd,
2284 ulPP,
2285 0,
2286 &attrFound,
2287 (ULONG)sizeof(abValue),
2288 (PVOID)&abValue,
2289 (fInherit)
2290 ? 0
2291 : QPF_NOINHERIT)))
2292 return (abValue[0]);
2293
2294 // not found: get system color
2295 if (lSysColor != -1)
2296 return (WinQuerySysColor(HWND_DESKTOP, lSysColor, 0));
2297
2298 return -1;
2299}
2300
2301/*
2302 *@@category: Helpers\PM helpers\Help (IPF)
2303 */
2304
2305/* ******************************************************************
2306 *
2307 * Help instance helpers
2308 *
2309 ********************************************************************/
2310
2311/*
2312 *@@ winhCreateHelp:
2313 * creates a help instance and connects it with the
2314 * given frame window.
2315 *
2316 * If (pszFileName == NULL), we'll retrieve the
2317 * executable's fully qualified file name and
2318 * replace the extension with .HLP simply. This
2319 * avoids the typical "Help not found" errors if
2320 * the program isn't started in its own directory.
2321 *
2322 * If you have created a help table in memory, specify it
2323 * with pHelpTable. To load a help table from the resources,
2324 * specify hmod (or NULLHANDLE) and set pHelpTable to the
2325 * following:
2326 +
2327 + (PHELPTABLE)MAKELONG(usTableID, 0xffff)
2328 *
2329 * Returns the help window handle or NULLHANDLE on errors.
2330 *
2331 * Based on an EDM/2 code snippet.
2332 *
2333 *@@added V0.9.4 (2000-07-03) [umoeller]
2334 */
2335
2336HWND winhCreateHelp(HWND hwndFrame, // in: app's frame window handle; can be NULLHANDLE
2337 PSZ pszFileName, // in: help file name or NULL
2338 HMODULE hmod, // in: module with help table or NULLHANDLE (current)
2339 PHELPTABLE pHelpTable, // in: help table or resource ID
2340 PSZ pszWindowTitle) // in: help window title or NULL
2341{
2342 PPIB ppib;
2343 PTIB ptib;
2344 HELPINIT hi;
2345 PSZ pszExt;
2346 CHAR szName[ CCHMAXPATH ];
2347 HWND hwndHelp;
2348
2349 if ( (pszFileName == NULL)
2350 // || (*pszFileName)
2351 )
2352 {
2353 DosGetInfoBlocks(&ptib, &ppib);
2354
2355 DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName);
2356
2357 pszExt = strrchr(szName, '.');
2358 if (pszExt)
2359 strcpy(pszExt, ".hlp");
2360 else
2361 strcat(szName, ".hlp");
2362
2363 pszFileName = szName;
2364 }
2365
2366 hi.cb = sizeof(HELPINIT);
2367 hi.ulReturnCode = 0;
2368 hi.pszTutorialName = NULL;
2369 hi.phtHelpTable = pHelpTable;
2370 hi.hmodHelpTableModule = hmod;
2371 hi.hmodAccelActionBarModule = NULLHANDLE;
2372 hi.idAccelTable = 0;
2373 hi.idActionBar = 0;
2374 hi.pszHelpWindowTitle = pszWindowTitle;
2375 hi.fShowPanelId = CMIC_HIDE_PANEL_ID;
2376 hi.pszHelpLibraryName = pszFileName;
2377
2378 hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame),
2379 &hi);
2380 if ((hwndFrame) && (hwndHelp))
2381 {
2382 WinAssociateHelpInstance(hwndHelp, hwndFrame);
2383 }
2384
2385 return (hwndHelp);
2386}
2387
2388/*
2389 *@@ winhDestroyHelp:
2390 * destroys the help instance created by winhCreateHelp.
2391 *
2392 * Based on an EDM/2 code snippet.
2393 *
2394 *@@added V0.9.4 (2000-07-03) [umoeller]
2395 */
2396
2397void winhDestroyHelp(HWND hwndHelp,
2398 HWND hwndFrame) // can be NULLHANDLE if not used with winhCreateHelp
2399{
2400 if (hwndHelp)
2401 {
2402 if (hwndFrame)
2403 WinAssociateHelpInstance(NULLHANDLE, hwndFrame);
2404 WinDestroyHelpInstance(hwndHelp);
2405 }
2406}
2407
2408/*
2409 *@@category: Helpers\PM helpers\Application control
2410 */
2411
2412/* ******************************************************************
2413 *
2414 * Application control
2415 *
2416 ********************************************************************/
2417
2418/*
2419 *@@ CallBatchCorrectly:
2420 * fixes the specified PROGDETAILS for
2421 * command files in the executable part
2422 * by inserting /C XXX into the parameters
2423 * and setting the executable according
2424 * to an environment variable.
2425 *
2426 *@@added V0.9.6 (2000-10-16) [umoeller]
2427 */
2428
2429VOID CallBatchCorrectly(PPROGDETAILS pProgDetails,
2430 PSZ *ppszParams, // in/out: modified parameters (reallocated)
2431 const char *pcszEnvVar, // in: env var spec'g command proc
2432 // (e.g. "OS2_SHELL"); can be NULL
2433 const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
2434{
2435 // XXX.CMD file as executable:
2436 // fix args to /C XXX.CMD
2437 XSTRING strNewParams;
2438 xstrInit(&strNewParams, 200);
2439 xstrcpy(&strNewParams, "/C ");
2440 xstrcat(&strNewParams, pProgDetails->pszExecutable);
2441 if (*ppszParams)
2442 {
2443 // append old params
2444 xstrcat(&strNewParams, " ");
2445 xstrcat(&strNewParams, *ppszParams);
2446 free(*ppszParams);
2447 }
2448 *ppszParams = strNewParams.psz;
2449 // freed by caller
2450
2451 // set executable to $(OS2_SHELL)
2452 pProgDetails->pszExecutable = NULL;
2453 if (pcszEnvVar)
2454 pProgDetails->pszExecutable = getenv(pcszEnvVar);
2455 if (!pProgDetails->pszExecutable)
2456 pProgDetails->pszExecutable = (PSZ)pcszDefProc;
2457 // should be on PATH
2458}
2459
2460/*
2461 *@@ winhStartApp:
2462 * wrapper around WinStartApp which fixes the
2463 * specified PROGDETAILS to (hopefully) work
2464 * work with all executable types:
2465 *
2466 * 1. This fixes the executable info to support:
2467 *
2468 * -- starting "*" executables (command prompts
2469 * for OS/2, DOS, Win-OS/2);
2470 *
2471 * -- starting ".CMD" and ".BAT" files as
2472 * PROGDETAILS.pszExecutable.
2473 *
2474 * 2. Handles and merges special and default
2475 * environments for the app to be started.
2476 * If PROGDETAILS.pszEnvironment is empty
2477 * and the application is a Win-OS/2 app,
2478 * this uses the default Win-OS/2 settings
2479 * as specified in the "Win-OS/2" WPS settings
2480 * object.
2481 *
2482 * Even though this isn't clearly said in PMREF,
2483 * PROGDETAILS.swpInitial is important:
2484 *
2485 * -- To start a session minimized, set SWP_MINIMIZE.
2486 *
2487 * -- To start a VIO session without auto-close, set
2488 * the half-documented SWP_NOAUTOCLOSE flag (0x8000)
2489 * This flag is now in the newer toolkit headers.
2490 *
2491 * Since this calls WinStartApp in turn, this
2492 * requires a message queue on the calling thread.
2493 *
2494 *@@added V0.9.6 (2000-10-16) [umoeller]
2495 *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
2496 */
2497
2498HAPP winhStartApp(HWND hwndNotify, // in: notify window (as with WinStartApp)
2499 const PROGDETAILS *pcProgDetails) // in: program data
2500{
2501 HAPP happ = NULLHANDLE;
2502 PSZ pszParamsPatched = NULL;
2503 BOOL fIsWindowsApp = FALSE,
2504 fIsWindowsEnhApp = FALSE;
2505 PROGDETAILS ProgDetails;
2506 PSZ pszWinOS2Env = 0;
2507
2508 memcpy(&ProgDetails, pcProgDetails, sizeof(PROGDETAILS));
2509 // pointers still point into old prog details buffer
2510 ProgDetails.Length = sizeof(PROGDETAILS);
2511 ProgDetails.progt.fbVisible = SHE_VISIBLE;
2512 ProgDetails.pszEnvironment = 0;
2513
2514 // memset(&ProgDetails.swpInitial, 0, sizeof(SWP));
2515 // this wasn't a good idea... WPProgram stores stuff
2516 // in here, such as the "minimize on startup" -> SWP_MINIMIZE
2517
2518 // duplicate parameters...
2519 // we need this for string manipulations below...
2520 if (ProgDetails.pszParameters)
2521 pszParamsPatched = strdup(ProgDetails.pszParameters);
2522
2523 // _Pmpf((__FUNCTION__ ": old progc: 0x%lX", pcProgDetails->progt.progc));
2524 // _Pmpf((" pszTitle: %s", (ProgDetails.pszTitle) ? ProgDetails.pszTitle : NULL));
2525 // _Pmpf((" pszIcon: %s", (ProgDetails.pszIcon) ? ProgDetails.pszIcon : NULL));
2526
2527 // program type fixups
2528 switch (ProgDetails.progt.progc) // that's a ULONG
2529 {
2530 case ((ULONG)-1): // we get that sometimes...
2531 case PROG_DEFAULT:
2532 // ###
2533 break;
2534 }
2535
2536 // now try again...
2537 switch (ProgDetails.progt.progc)
2538 {
2539 case PROG_31_ENHSEAMLESSVDM: // 17
2540 case PROG_31_ENHSEAMLESSCOMMON: // 18
2541 case PROG_31_ENH: // 19
2542 fIsWindowsApp = TRUE;
2543 fIsWindowsEnhApp = TRUE;
2544 break;
2545
2546#ifndef PROG_30_STD
2547 #define PROG_30_STD (PROGCATEGORY)11
2548#endif
2549
2550#ifndef PROG_30_STDSEAMLESSVDM
2551 #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
2552#endif
2553
2554 case PROG_WINDOW_REAL: // 10
2555 case PROG_30_STD: // 11
2556 case PROG_WINDOW_AUTO: // 12
2557 case PROG_30_STDSEAMLESSVDM: // 13
2558 case PROG_30_STDSEAMLESSCOMMON: // 14
2559 case PROG_31_STDSEAMLESSVDM: // 15
2560 case PROG_31_STDSEAMLESSCOMMON: // 16
2561 case PROG_31_STD: // 20
2562 fIsWindowsApp = TRUE;
2563 break;
2564 }
2565
2566 /*
2567 * command lines fixups:
2568 *
2569 */
2570
2571 if (strcmp(ProgDetails.pszExecutable, "*") == 0)
2572 {
2573 /*
2574 * "*" for command sessions:
2575 *
2576 */
2577
2578 if (fIsWindowsEnhApp)
2579 {
2580 // enhanced Win-OS/2 session:
2581 XSTRING str2;
2582 xstrInit(&str2, 200);
2583 xstrcpy(&str2, "/3 ");
2584 if (pszParamsPatched)
2585 {
2586 // append existing params
2587 xstrcat(&str2, pszParamsPatched);
2588 free(pszParamsPatched);
2589 }
2590
2591 pszParamsPatched = str2.psz;
2592 }
2593
2594 if (fIsWindowsApp)
2595 {
2596 // cheat: WinStartApp doesn't support NULL
2597 // for Win-OS2 sessions, so manually start winos2.com
2598 ProgDetails.pszExecutable = "WINOS2.COM";
2599 // this is a DOS app, so fix this to DOS fullscreen
2600 ProgDetails.progt.progc = PROG_VDM;
2601 }
2602 else
2603 // for all other executable types
2604 // (including OS/2 and DOS sessions),
2605 // set pszExecutable to NULL; this will
2606 // have WinStartApp start a cmd shell
2607 ProgDetails.pszExecutable = NULL;
2608
2609 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
2610 else
2611 switch (ProgDetails.progt.progc)
2612 {
2613 /*
2614 * .CMD files fixups
2615 *
2616 */
2617
2618 case PROG_FULLSCREEN: // OS/2 fullscreen
2619 case PROG_WINDOWABLEVIO: // OS/2 window
2620 {
2621 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2622 if (pszExtension)
2623 {
2624 if (stricmp(pszExtension, "CMD") == 0)
2625 {
2626 CallBatchCorrectly(&ProgDetails,
2627 &pszParamsPatched,
2628 "OS2_SHELL",
2629 "CMD.EXE");
2630 }
2631 }
2632 break; }
2633
2634 case PROG_VDM: // DOS fullscreen
2635 case PROG_WINDOWEDVDM: // DOS window
2636 {
2637 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2638 if (pszExtension)
2639 {
2640 if (stricmp(pszExtension, "BAT") == 0)
2641 {
2642 CallBatchCorrectly(&ProgDetails,
2643 &pszParamsPatched,
2644 NULL,
2645 "COMMAND.COM");
2646 }
2647 }
2648 break; }
2649 } // end switch (ProgDetails.progt.progc)
2650
2651 /*
2652 * Fix environment for Win-OS/2
2653 *
2654 */
2655
2656 if ( !(xstrIsString(ProgDetails.pszEnvironment)) // env empty
2657 && (fIsWindowsApp) // and win-os2 app
2658 )
2659 {
2660 ULONG ulSize = 0;
2661 // get default environment (from Win-OS/2 settings object)
2662 // from OS2.INI
2663 PSZ pszDefEnv = prfhQueryProfileData(HINI_USER,
2664 "WINOS2",
2665 "PM_GlobalWindows31Settings",
2666 &ulSize);
2667 if (pszDefEnv)
2668 {
2669 PSZ pszDefEnv2 = (PSZ)malloc(ulSize + 2);
2670 if (pszDefEnv2)
2671 {
2672 PSZ p = pszDefEnv2;
2673 memset(pszDefEnv2, 0, ulSize + 2);
2674 memcpy(pszDefEnv2, pszDefEnv, ulSize);
2675
2676 for (p = pszDefEnv2;
2677 p < pszDefEnv2 + ulSize;
2678 p++)
2679 if (*p == ';')
2680 *p = 0;
2681
2682 // okay.... now we got an OS/2-style environment
2683 // with 0, 0, 00 strings
2684
2685 pszWinOS2Env = pszDefEnv2; // freed below
2686
2687 // use this
2688 ProgDetails.pszEnvironment = pszWinOS2Env;
2689 }
2690
2691 free(pszDefEnv);
2692 }
2693 }
2694
2695 // _Pmpf((__FUNCTION__ ": calling WinStartApp"));
2696 // _Pmpf((" exec: %s",
2697 // (ProgDetails.pszExecutable)
2698 // ? ProgDetails.pszExecutable
2699 // : "NULL"));
2700 // _Pmpf((" startupDir: %s",
2701 // (ProgDetails.pszStartupDir)
2702 // ? ProgDetails.pszStartupDir
2703 // : "NULL"));
2704 // _Pmpf((" params: %s",
2705 // (pszParamsPatched)
2706 // ? pszParamsPatched
2707 // : "NULL"));
2708 // _Pmpf((" new progc: 0x%lX", ProgDetails.progt.progc));
2709
2710 ProgDetails.pszParameters = pszParamsPatched;
2711
2712 happ = WinStartApp(hwndNotify,
2713 // receives WM_APPTERMINATENOTIFY
2714 &ProgDetails,
2715 pszParamsPatched,
2716 NULL, // "reserved", PMREF says...
2717 SAF_INSTALLEDCMDLINE);
2718 // we MUST use SAF_INSTALLEDCMDLINE
2719 // or no Win-OS/2 session will start...
2720 // whatever is going on here... Warp 4 FP11
2721
2722 // do not use SAF_STARTCHILDAPP, or the
2723 // app will be terminated automatically
2724 // when the WPS terminates!
2725
2726 // _Pmpf((__FUNCTION__ ": got happ 0x%lX", happ));
2727
2728 if (pszParamsPatched)
2729 free(pszParamsPatched);
2730 if (pszWinOS2Env)
2731 free(pszWinOS2Env);
2732
2733 return (happ);
2734}
2735
2736/*
2737 *@@ winhAnotherInstance:
2738 * this tests whether another instance of the same
2739 * application is already running.
2740 *
2741 * To identify instances of the same application, the
2742 * application must call this function during startup
2743 * with the unique name of an OS/2 semaphore. As with
2744 * all OS/2 semaphores, the semaphore name must begin
2745 * with "\\SEM32\\". The semaphore isn't really used
2746 * except for testing for its existence, since that
2747 * name is unique among all processes.
2748 *
2749 * If another instance is found, TRUE is returned. If
2750 * (fSwitch == TRUE), that instance is switched to,
2751 * using the tasklist.
2752 *
2753 * If no other instance is found, FALSE is returned only.
2754 *
2755 * Based on an EDM/2 code snippet.
2756 *
2757 *@@added V0.9.0 (99-10-22) [umoeller]
2758 */
2759
2760BOOL winhAnotherInstance(PSZ pszSemName, // in: semaphore ID
2761 BOOL fSwitch) // in: if TRUE, switch to first instance if running
2762{
2763 HMTX hmtx;
2764
2765 if (DosCreateMutexSem(pszSemName,
2766 &hmtx,
2767 DC_SEM_SHARED,
2768 TRUE)
2769 == NO_ERROR)
2770 // semapore created: this doesn't happen if the semaphore
2771 // exists already, so no other instance is running
2772 return (FALSE);
2773
2774 // else: instance running
2775 hmtx = NULLHANDLE;
2776
2777 // switch to other instance?
2778 if (fSwitch)
2779 {
2780 // yes: query mutex creator
2781 if (DosOpenMutexSem(pszSemName,
2782 &hmtx)
2783 == NO_ERROR)
2784 {
2785 PID pid = 0;
2786 TID tid = 0; // unused
2787 ULONG ulCount; // unused
2788
2789 if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
2790 {
2791 HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
2792 if (hswitch != NULLHANDLE)
2793 WinSwitchToProgram(hswitch);
2794 }
2795
2796 DosCloseMutexSem(hmtx);
2797 }
2798 }
2799
2800 return (TRUE); // another instance exists
2801}
2802
2803/*
2804 *@@ winhAddToTasklist:
2805 * this adds the specified window to the tasklist
2806 * with hIcon as its program icon (which is also
2807 * set for the main window). This is useful for
2808 * the old "dialog as main window" trick.
2809 *
2810 * Returns the HSWITCH of the added entry.
2811 */
2812
2813HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
2814 HPOINTER hIcon) // in: icon for main window
2815{
2816 SWCNTRL swctl;
2817 HSWITCH hswitch = 0;
2818 swctl.hwnd = hwnd; // window handle
2819 swctl.hwndIcon = hIcon; // icon handle
2820 swctl.hprog = NULLHANDLE; // program handle (use default)
2821 WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
2822 // process identifier
2823 swctl.idSession = 0; // session identifier ?
2824 swctl.uchVisibility = SWL_VISIBLE; // visibility
2825 swctl.fbJump = SWL_JUMPABLE; // jump indicator
2826 // get window title from window titlebar
2827 if (hwnd)
2828 WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
2829 swctl.bProgType = PROG_DEFAULT; // program type
2830 hswitch = WinAddSwitchEntry(&swctl);
2831
2832 // give the main window the icon
2833 if ((hwnd) && (hIcon))
2834 WinSendMsg(hwnd,
2835 WM_SETICON,
2836 (MPARAM)hIcon,
2837 NULL);
2838
2839 return (hswitch);
2840}
2841
2842/*
2843 *@@category: Helpers\PM helpers\Miscellaneous
2844 */
2845
2846/* ******************************************************************
2847 *
2848 * Miscellaneous
2849 *
2850 ********************************************************************/
2851
2852/*
2853 *@@ winhFree:
2854 * frees a block of memory allocated by the
2855 * winh* functions.
2856 *
2857 * Since the winh* functions use malloc(),
2858 * you can also use free() directly on such
2859 * blocks. However, you must use winhFree
2860 * if the winh* functions are in a module
2861 * with a different C runtime.
2862 *
2863 *@@added V0.9.7 (2000-12-06) [umoeller]
2864 */
2865
2866VOID winhFree(PVOID p)
2867{
2868 if (p)
2869 free(p);
2870}
2871
2872/*
2873 *@@ winhSleep:
2874 * sleeps at least the specified amount of time,
2875 * without blocking the message queue.
2876 *
2877 *@@added V0.9.4 (2000-07-11) [umoeller]
2878 */
2879
2880VOID winhSleep(HAB hab,
2881 ULONG ulSleep) // in: sleep time in milliseconds
2882{
2883 ULONG ul = 0;
2884 QMSG qmsg;
2885 for (ul = 0;
2886 ul < (ulSleep / 50);
2887 ul++)
2888 {
2889 DosSleep(50);
2890 while (WinPeekMsg(hab,
2891 &qmsg, 0, 0, 0,
2892 PM_REMOVE))
2893 WinDispatchMsg(hab, &qmsg);
2894
2895 }
2896}
2897
2898/*
2899 *@@ winhFileDlg:
2900 * one-short function for opening an "Open" file
2901 * dialog.
2902 *
2903 * On input, pszFile specifies the directory and
2904 * file specification (e.g. "F:\*.txt").
2905 *
2906 * Returns TRUE if the user pressed OK. In that
2907 * case, the fully qualified filename is written
2908 * into pszFile again.
2909 *
2910 * Returns FALSE if the user pressed Cancel.
2911 *
2912 * Notes about flFlags:
2913 *
2914 * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
2915 * Otherwise an "Open" dialog is displayed.
2916 *
2917 * -- WINH_FOD_INILOADDIR: load a directory from the
2918 * specified INI key and switch the dlg to it.
2919 * In that case, on input, pszFile must only
2920 * contain the file filter without any path
2921 * specification, because that is loaded from
2922 * the INI key. If the INI key does not exist,
2923 * the current process directory will be used.
2924 *
2925 * -- WINH_FOD_INISAVEDIR: if the user presses OK,
2926 * the directory of the selected file is written
2927 * to the specified INI key so that it can be
2928 * reused later. This flag is independent of
2929 * WINH_FOD_INISAVEDIR: you can specify none,
2930 * one, or both of them.
2931 *
2932 *@@added V0.9.3 (2000-04-29) [umoeller]
2933 */
2934
2935BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
2936 PSZ pszFile, // in: file mask; out: fully q'd filename
2937 // (should be CCHMAXPATH in size)
2938 ULONG flFlags, // in: any combination of the following:
2939 // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
2940 // -- WINH_FOD_INILOADDIR: load FOD path from INI
2941 // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
2942 HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
2943 PSZ pszApplication, // in: INI application to load/store last path from
2944 PSZ pszKey) // in: INI key to load/store last path from
2945{
2946 FILEDLG fd;
2947 memset(&fd, 0, sizeof(FILEDLG));
2948 fd.cbSize = sizeof(FILEDLG);
2949 fd.fl = FDS_CENTER;
2950
2951 if (flFlags & WINH_FOD_SAVEDLG)
2952 fd.fl |= FDS_SAVEAS_DIALOG;
2953 else
2954 fd.fl |= FDS_OPEN_DIALOG;
2955
2956 // default: copy pszFile
2957 strcpy(fd.szFullFile, pszFile);
2958
2959 if ( (hini) && (flFlags & WINH_FOD_INILOADDIR) )
2960 {
2961 // overwrite with initial directory for FOD from OS2.INI
2962 if (PrfQueryProfileString(hini,
2963 pszApplication,
2964 pszKey,
2965 "", // default string
2966 fd.szFullFile,
2967 sizeof(fd.szFullFile)-10)
2968 >= 2)
2969 {
2970 // found: append "\*"
2971 strcat(fd.szFullFile, "\\");
2972 strcat(fd.szFullFile, pszFile);
2973 }
2974 }
2975
2976 if ( WinFileDlg(HWND_DESKTOP, // parent
2977 hwndOwner, // owner
2978 &fd)
2979 && (fd.lReturn == DID_OK)
2980 )
2981 {
2982 // save path back?
2983 if ( (hini)
2984 && (flFlags & WINH_FOD_INISAVEDIR)
2985 )
2986 {
2987 // get the directory that was used
2988 PSZ p = strrchr(fd.szFullFile, '\\');
2989 if (p)
2990 {
2991 // contains directory:
2992 // copy to OS2.INI
2993 PSZ pszDir = strhSubstr(fd.szFullFile, p);
2994 if (pszDir)
2995 {
2996 PrfWriteProfileString(hini,
2997 pszApplication,
2998 pszKey, // "XWPSound:LastDir"
2999 pszDir);
3000 free(pszDir);
3001 }
3002 }
3003 }
3004
3005 strcpy(pszFile, fd.szFullFile);
3006
3007 return (TRUE);
3008 }
3009
3010 return (FALSE);
3011}
3012
3013/*
3014 *@@ winhSetWaitPointer:
3015 * this sets the mouse pointer to "Wait".
3016 * Returns the previous pointer (HPOINTER),
3017 * which should be stored somewhere to be
3018 * restored later. Example:
3019 + HPOINTER hptrOld = winhSetWaitPointer();
3020 + ...
3021 + WinSetPointer(HWND_DESKTOP, hptrOld);
3022 */
3023
3024HPOINTER winhSetWaitPointer(VOID)
3025{
3026 HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
3027 WinSetPointer(HWND_DESKTOP,
3028 WinQuerySysPointer(HWND_DESKTOP,
3029 SPTR_WAIT,
3030 FALSE)); // no copy
3031 return (hptr);
3032}
3033
3034/*
3035 *@@ winhQueryWindowText:
3036 * this returns the window text of the specified
3037 * HWND in a newly allocated buffer.
3038 *
3039 * Returns NULL on error. Use winhFree()
3040 * to free the return value.
3041 */
3042
3043PSZ winhQueryWindowText(HWND hwnd)
3044{
3045 PSZ pszText = NULL;
3046 ULONG cbText = WinQueryWindowTextLength(hwnd);
3047 // additional null character
3048 if (cbText)
3049 {
3050 pszText = (PSZ)malloc(cbText + 1);
3051 if (pszText)
3052 WinQueryWindowText(hwnd,
3053 cbText + 1,
3054 pszText);
3055 }
3056 return (pszText);
3057}
3058
3059/*
3060 *@@ winhReplaceWindowText:
3061 * this is a combination of winhQueryWindowText
3062 * and xstrrpl (stringh.c) to replace substrings
3063 * in a window.
3064 *
3065 * This is useful for filling in placeholders
3066 * a la "%1" in control windows, e.g. static
3067 * texts.
3068 *
3069 * This replaces only the first occurence of
3070 * pszSearch.
3071 *
3072 * Returns TRUE only if the window exists and
3073 * the search string was replaced.
3074 *
3075 *@@added V0.9.0 [umoeller]
3076 */
3077
3078BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
3079 PSZ pszSearch, // in: search string (e.g. "%1")
3080 PSZ pszReplaceWith) // in: replacement string for pszSearch
3081{
3082 BOOL brc = FALSE;
3083 PSZ pszText = winhQueryWindowText(hwnd);
3084 if (pszText)
3085 {
3086 ULONG ulOfs = 0;
3087 if (strhrpl(&pszText, &ulOfs, pszSearch, pszReplaceWith) > 0)
3088 {
3089 WinSetWindowText(hwnd, pszText);
3090 brc = TRUE;
3091 }
3092 free(pszText);
3093 }
3094 return (brc);
3095}
3096
3097/*
3098 *@@ winhEnableDlgItems:
3099 * this enables/disables a whole range of controls
3100 * in a window by enumerating the child windows
3101 * until usIDFirst is found. If so, that subwindow
3102 * is enabled/disabled and all the following windows
3103 * in the enumeration also, until usIDLast is found.
3104 *
3105 * Note that this affects _all_ controls following
3106 * the usIDFirst window, no matter what ID they have
3107 * (even if "-1"), until usIDLast is found.
3108 *
3109 * Returns the no. of controls which were enabled/disabled
3110 * (null if none).
3111 *
3112 *@@added V0.9.0 [umoeller]
3113 *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
3114 */
3115
3116ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
3117 USHORT usIDFirst, // in: first affected control ID
3118 USHORT usIDLast, // in: last affected control ID (inclusive)
3119 BOOL fEnable)
3120{
3121 HENUM henum1 = NULLHANDLE;
3122 HWND hwndThis = NULLHANDLE;
3123 ULONG ulCount = 0;
3124
3125 henum1 = WinBeginEnumWindows(hwndDlg);
3126 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3127 {
3128 USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
3129 usIDCheckLast;
3130 if (usIDCheckFirst == usIDFirst)
3131 {
3132 WinEnableWindow(hwndThis, fEnable);
3133 ulCount++;
3134
3135 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3136 {
3137 WinEnableWindow(hwndThis, fEnable);
3138 ulCount++;
3139 usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
3140 if (usIDCheckLast == usIDLast)
3141 break;
3142 }
3143
3144 break; // outer loop
3145 }
3146 }
3147 WinEndEnumWindows(henum1);
3148 return (ulCount);
3149}
3150
3151/*
3152 *@@ winhCreateStdWindow:
3153 * much like WinCreateStdWindow, but this one
3154 * allows you to have the standard window
3155 * positioned automatically, using a given
3156 * SWP structure (*pswpFrame).
3157 *
3158 * Alternatively, you can set pswpFrame to NULL
3159 * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
3160 * If you want the window to be shown, specify
3161 * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
3162 *
3163 *@@added V0.9.0 [umoeller]
3164 *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
3165 *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
3166 */
3167
3168HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
3169 PSWP pswpFrame, // in: frame wnd pos
3170 ULONG flFrameCreateFlags, // in: FCF_* flags
3171 ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
3172 PSZ pszFrameTitle,
3173 ULONG ulResourcesID, // in: according to FCF_* flags
3174 PSZ pszClassClient,
3175 ULONG flStyleClient,
3176 ULONG ulID, // in: frame window ID
3177 PVOID pClientCtlData, // in: pCtlData structure pointer for client
3178 PHWND phwndClient) // out: created client wnd
3179{
3180 FRAMECDATA fcdata;
3181 HWND hwndFrame;
3182 RECTL rclClient;
3183
3184 fcdata.cb = sizeof(FRAMECDATA);
3185 fcdata.flCreateFlags = flFrameCreateFlags;
3186 fcdata.hmodResources = (HMODULE)NULL;
3187 fcdata.idResources = ulResourcesID;
3188
3189 /* Create the frame and client windows. */
3190 hwndFrame = WinCreateWindow(hwndFrameParent,
3191 WC_FRAME,
3192 pszFrameTitle,
3193 ulFrameStyle,
3194 0,0,0,0, // size and position = 0
3195 NULLHANDLE, // no owner
3196 HWND_TOP, // z-order
3197 ulID, // frame window ID
3198 &fcdata, // frame class data
3199 NULL); // no presparams
3200
3201 if (hwndFrame)
3202 {
3203 *phwndClient = WinCreateWindow(hwndFrame, // parent
3204 pszClassClient, // class
3205 NULL, // no title
3206 flStyleClient, // style
3207 0,0,0,0, // size and position = 0
3208 hwndFrame, // owner
3209 HWND_BOTTOM, // bottom z-order
3210 FID_CLIENT, // frame window ID
3211 pClientCtlData, // class data
3212 NULL); // no presparams
3213
3214 if (*phwndClient)
3215 {
3216 if (pswpFrame)
3217 // position frame
3218 WinSetWindowPos(hwndFrame,
3219 pswpFrame->hwndInsertBehind,
3220 pswpFrame->x,
3221 pswpFrame->y,
3222 pswpFrame->cx,
3223 pswpFrame->cy,
3224 pswpFrame->fl);
3225
3226 // position client
3227 // WinQueryWindowRect(hwndFrame, &rclClient);
3228 // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
3229 rclClient.xLeft = 0;
3230 rclClient.yBottom = 0;
3231 rclClient.xRight = pswpFrame->cx;
3232 rclClient.yTop = pswpFrame->cy;
3233 WinCalcFrameRect(hwndFrame,
3234 &rclClient,
3235 TRUE); // calc client from frame
3236 WinSetWindowPos(*phwndClient,
3237 HWND_TOP,
3238 rclClient.xLeft,
3239 rclClient.yBottom,
3240 rclClient.xRight - rclClient.xLeft,
3241 rclClient.yTop - rclClient.yBottom,
3242 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3243 }
3244 }
3245 return (hwndFrame);
3246}
3247
3248/*
3249 *@@ winhRepaintWindows:
3250 * this repaints all children of hwndParent.
3251 * If this is passed as HWND_DESKTOP, the
3252 * whole screen is repainted.
3253 *
3254 *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed
3255 */
3256
3257VOID winhRepaintWindows(HWND hwndParent)
3258{
3259 HWND hwndTop;
3260 HENUM henum = WinBeginEnumWindows(hwndParent);
3261 while ((hwndTop = WinGetNextWindow(henum)))
3262 if (WinIsWindowShowing(hwndTop))
3263 WinInvalidateRect(hwndTop, NULL, TRUE);
3264 WinEndEnumWindows(henum);
3265}
3266
3267/*
3268 *@@ winhFindMsgQueue:
3269 * returns the message queue which matches
3270 * the given process and thread IDs. Since,
3271 * per IBM definition, every thread may only
3272 * have one MQ, this should be unique.
3273 *
3274 *@@added V0.9.2 (2000-03-08) [umoeller]
3275 */
3276
3277HMQ winhFindMsgQueue(PID pid, // in: process ID
3278 TID tid, // in: thread ID
3279 HAB* phab) // out: anchor block
3280{
3281 HWND hwndThis = 0,
3282 rc = 0;
3283 HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
3284 while ((hwndThis = WinGetNextWindow(henum)))
3285 {
3286 CHAR szClass[200];
3287 if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
3288 {
3289 if (strcmp(szClass, "#32767") == 0)
3290 {
3291 // message queue window:
3292 PID pidWin = 0;
3293 TID tidWin = 0;
3294 WinQueryWindowProcess(hwndThis,
3295 &pidWin,
3296 &tidWin);
3297 if ( (pidWin == pid)
3298 && (tidWin == tid)
3299 )
3300 {
3301 // get HMQ from window words
3302 rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
3303 if (rc)
3304 if (phab)
3305 *phab = WinQueryAnchorBlock(hwndThis);
3306 break;
3307 }
3308 }
3309 }
3310 }
3311 WinEndEnumWindows(henum);
3312
3313 return (rc);
3314}
3315
3316/*
3317 *@@ winhFindHardErrorWindow:
3318 * this searches all children of HWND_OBJECT
3319 * for the PM hard error windows, which are
3320 * invisible most of the time. When a hard
3321 * error occurs, that window is made a child
3322 * of HWND_DESKTOP instead.
3323 *
3324 * Stolen from ProgramCommander/2 (C) Roman Stangl.
3325 *
3326 *@@added V0.9.3 (2000-04-27) [umoeller]
3327 */
3328
3329VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
3330 HWND *phwndSysError) // out: system error window
3331{
3332 PID pidObject; // HWND_OBJECT's process and thread id
3333 TID tidObject;
3334 PID pidObjectChild; // HWND_OBJECT's child window process and thread id
3335 TID tidObjectChild;
3336 HENUM henumObject; // HWND_OBJECT enumeration handle
3337 HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
3338 UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
3339 CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
3340
3341 *phwndHardError = NULLHANDLE;
3342 *phwndSysError = NULLHANDLE;
3343
3344 // query HWND_OBJECT's window process
3345 WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
3346 // enumerate all child windows of HWND_OBJECT
3347 henumObject = WinBeginEnumWindows(HWND_OBJECT);
3348 while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3349 {
3350 // see if the current HWND_OBJECT child window runs in the
3351 // process of HWND_OBJECT (PM)
3352 WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
3353 if (pidObject == pidObjectChild)
3354 {
3355 // get the child window's data
3356 WinQueryClassName(hwndObjectChild,
3357 sizeof(ucClassName),
3358 (PCH)ucClassName);
3359 WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
3360 (PSZ)ucClassName,
3361 &classinfoWindow);
3362 if ( (!strcmp((PSZ)ucClassName, "#1")
3363 || (classinfoWindow.flClassStyle & CS_FRAME))
3364 )
3365 {
3366 // if the child window is a frame window and running in
3367 // HWND_OBJECT's (PM's) window process, it must be the
3368 // PM Hard Error or System Error window
3369 WinQueryClassName(WinWindowFromID(hwndObjectChild,
3370 FID_CLIENT),
3371 sizeof(ucClassName),
3372 (PSZ)ucClassName);
3373 if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
3374 {
3375 *phwndHardError = hwndObjectChild;
3376 if (*phwndSysError)
3377 // we found the other one already:
3378 // stop searching, we got both
3379 break;
3380 }
3381 else
3382 {
3383 printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
3384 *phwndSysError = hwndObjectChild;
3385 if (*phwndHardError)
3386 // we found the other one already:
3387 // stop searching, we got both
3388 break;
3389 }
3390 }
3391 } // end if (pidObject == pidObjectChild)
3392 } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3393 WinEndEnumWindows(henumObject);
3394}
3395
3396/*
3397 *@@ winhCreateFakeDesktop:
3398 * this routine creates and displays a frameless window over
3399 * the whole screen in the color of PM's Desktop to fool the
3400 * user that all windows have been closed (which in fact might
3401 * not be the case).
3402 * This window's background color is set to the Desktop's
3403 * (PM's one, not the WPS's one).
3404 * Returns the HWND of this window.
3405 */
3406
3407HWND winhCreateFakeDesktop(HWND hwndSibling)
3408{
3409 // presparam for background
3410 typedef struct _BACKGROUND
3411 {
3412 ULONG cb; // length of the aparam parameter, in bytes
3413 ULONG id; // attribute type identity
3414 ULONG cb2; // byte count of the ab parameter
3415 RGB rgb; // attribute value
3416 } BACKGROUND;
3417
3418 BACKGROUND background;
3419 LONG lDesktopColor;
3420
3421 // create fake desktop window = empty window with
3422 // the size of full screen
3423 lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
3424 SYSCLR_BACKGROUND,
3425 0);
3426 background.cb = sizeof(background.id)
3427 + sizeof(background.cb)
3428 + sizeof(background.rgb);
3429 background.id = PP_BACKGROUNDCOLOR;
3430 background.cb2 = sizeof(RGB);
3431 background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
3432 background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
3433 background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
3434
3435 return (WinCreateWindow(HWND_DESKTOP, // parent window
3436 WC_FRAME, // class name
3437 "", // window text
3438 WS_VISIBLE, // window style
3439 0, 0, // position and size
3440 WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
3441 WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
3442 NULLHANDLE, // owner window
3443 hwndSibling, // sibling window
3444 1, // window id
3445 NULL, // control data
3446 &background)); // presentation parms
3447}
3448
3449/*
3450 *@@ winhAssertWarp4Notebook:
3451 * this takes hwndDlg as a notebook dialog page and
3452 * goes thru all its controls. If a control with an
3453 * ID <= udIdThreshold is found, this is assumed to
3454 * be a button which is to be given the BS_NOTEBOOKBUTTON
3455 * style. You should therefore give all your button
3456 * controls which should be moved such an ID.
3457 *
3458 * You can also specify how many dialog units
3459 * all the other controls will be moved downward in
3460 * ulDownUnits; this is useful to fill up the space
3461 * which was used by the buttons before moving them.
3462 * Returns TRUE if anything was changed.
3463 *
3464 * This function is useful if you wish to create
3465 * notebook pages using dlgedit.exe which are compatible
3466 * with both Warp 3 and Warp 4. This should be executed
3467 * in WM_INITDLG of the notebook dlg function if the app
3468 * has determined that it is running on Warp 4.
3469 */
3470
3471BOOL winhAssertWarp4Notebook(HWND hwndDlg,
3472 USHORT usIdThreshold, // in: ID threshold
3473 ULONG ulDownUnits) // in: dialog units or 0
3474{
3475 BOOL brc = FALSE;
3476
3477 if (doshIsWarp4())
3478 {
3479 POINTL ptl;
3480 HWND hwndItem;
3481 HENUM henum = 0;
3482
3483 BOOL fIsVisible = WinIsWindowVisible(hwndDlg);
3484 if (ulDownUnits)
3485 {
3486 ptl.x = 0;
3487 ptl.y = ulDownUnits;
3488 WinMapDlgPoints(hwndDlg, &ptl, 1, TRUE);
3489 }
3490
3491 if (fIsVisible)
3492 WinEnableWindowUpdate(hwndDlg, FALSE);
3493
3494 henum = WinBeginEnumWindows(hwndDlg);
3495 while ((hwndItem = WinGetNextWindow(henum)))
3496 {
3497 USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
3498 // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
3499 if (usId <= usIdThreshold)
3500 {
3501 // pushbutton to change:
3502 // _Pmpf((" Setting bit"));
3503 WinSetWindowBits(hwndItem,
3504 QWL_STYLE,
3505 BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
3506 brc = TRUE;
3507 }
3508 else
3509 // no pushbutton to change: move downwards
3510 // if desired
3511 if (ulDownUnits)
3512 {
3513 SWP swp;
3514 // _Pmpf(("Moving downwards %d pixels", ptl.y));
3515 WinQueryWindowPos(hwndItem, &swp);
3516 WinSetWindowPos(hwndItem, 0,
3517 swp.x,
3518 swp.y - ptl.y,
3519 0, 0,
3520 SWP_MOVE);
3521 }
3522 }
3523 WinEndEnumWindows(henum);
3524
3525 if (fIsVisible)
3526 WinShowWindow(hwndDlg, TRUE);
3527 }
3528
3529 return (brc);
3530}
3531
3532/*
3533 *@@ winhDrawFormattedText:
3534 * this func takes a rectangle and draws pszText into
3535 * it, breaking the words as neccessary. The line spacing
3536 * is determined from the font currently selected in hps.
3537 *
3538 * As opposed to WinDrawText, this can draw several lines
3539 * at once, and format the _complete_ text according to the
3540 * flCmd parameter, which is like with WinDrawText.
3541 *
3542 * After this function returns, *prcl is modified like this:
3543 * -- yTop and yBottom contain the upper and lower boundaries
3544 * which were needed to draw the text. This depends on
3545 * whether DT_TOP etc. were specified.
3546 * To get the height of the rectangle used, calculate the
3547 * delta between yTop and yBottom.
3548 *
3549 * -- xLeft and xRight are modified to contain the outmost
3550 * left and right coordinates which were needed to draw
3551 * the text. This will be set to the longest line which
3552 * was encountered.
3553 *
3554 * You can specify DT_QUERYEXTENT with flDraw to only have
3555 * these text boundaries calculated without actually drawing.
3556 *
3557 * This returns the number of lines drawn.
3558 *
3559 * Note that this calls WinDrawText with DT_TEXTATTRS set,
3560 * that is, the current text primitive attributes will be
3561 * used (fonts and colors).
3562 *
3563 *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
3564 */
3565
3566ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
3567 // are used, but not altered
3568 PRECTL prcl, // in/out: rectangle to use for drawing
3569 // (modified)
3570 PSZ pszText, // in: text to draw (zero-terminated)
3571 ULONG flCmd) // in: flags like in WinDrawText; I have
3572 // only tested DT_TOP and DT_LEFT though.
3573 // DT_WORDBREAK | DT_TEXTATTRS are always
3574 // set.
3575 // You can specify DT_QUERYEXTENT to only
3576 // have prcl calculated without drawing.
3577{
3578 PSZ p = pszText;
3579 LONG lDrawn = 1,
3580 lTotalDrawn = 0,
3581 lLineCount = 0,
3582 lOrigYTop = prcl->yTop;
3583 ULONG ulTextLen = strlen(pszText),
3584 ulCharHeight,
3585 flCmd2,
3586 xLeftmost = prcl->xRight,
3587 xRightmost = prcl->xLeft;
3588 RECTL rcl2;
3589
3590 flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
3591
3592 ulCharHeight = gpihQueryLineSpacing(hps, pszText);
3593
3594 while ( (lDrawn)
3595 && (lTotalDrawn < ulTextLen)
3596 )
3597 {
3598 memcpy(&rcl2, prcl, sizeof(rcl2));
3599 lDrawn = WinDrawText(hps,
3600 ulTextLen-lTotalDrawn,
3601 p,
3602 &rcl2,
3603 0, 0, // colors
3604 flCmd2);
3605
3606 // update char counters
3607 p += lDrawn;
3608 lTotalDrawn += lDrawn;
3609
3610 // update x extents
3611 if (rcl2.xLeft < xLeftmost)
3612 xLeftmost = rcl2.xLeft;
3613 if (rcl2.xRight > xRightmost)
3614 xRightmost = rcl2.xRight;
3615
3616 // update y for next line
3617 prcl->yTop -= ulCharHeight;
3618
3619 // increase line count
3620 lLineCount++;
3621 }
3622 prcl->xLeft = xLeftmost;
3623 prcl->xRight = xRightmost;
3624 prcl->yBottom = prcl->yTop;
3625 prcl->yTop = lOrigYTop;
3626
3627 return (lLineCount);
3628}
3629
3630/*
3631 *@@ winhQuerySwitchList:
3632 * returns the switch list in a newly
3633 * allocated buffer. This does the
3634 * regular double WinQuerySwitchList
3635 * call to first get the no. of items
3636 * and then get the items.
3637 *
3638 * The no. of items can be found in
3639 * the returned SWBLOCK.cwsentry.
3640 *
3641 * Returns NULL on errors. Use
3642 * winhFree to free the return value.
3643 *
3644 *@@added V0.9.7 (2000-12-06) [umoeller]
3645 */
3646
3647PSWBLOCK winhQuerySwitchList(HAB hab)
3648{
3649 ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
3650 ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
3651 PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
3652 if (pSwBlock)
3653 {
3654 cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
3655 if (!cItems)
3656 {
3657 free(pSwBlock);
3658 pSwBlock = NULL;
3659 }
3660 }
3661
3662 return (pSwBlock);
3663}
3664
3665/*
3666 *@@ winhQueryTasklistWindow:
3667 * returns the window handle of the PM task list.
3668 *
3669 *@@added V0.9.7 (2000-12-07) [umoeller]
3670 */
3671
3672HWND winhQueryTasklistWindow(VOID)
3673{
3674 SWBLOCK swblock;
3675 HWND hwndTasklist = winhQueryTasklistWindow();
3676 // the tasklist has entry #0 in the SWBLOCK
3677 WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
3678 return (swblock.aswentry[0].swctl.hwnd);
3679}
3680
3681/*
3682 *@@ winhKillTasklist:
3683 * this will destroy the Tasklist (window list) window.
3684 * Note: you will only be able to get it back after a
3685 * reboot, not a WPS restart. Only for use at shutdown and such.
3686 * This trick by Uri J. Stern at
3687 * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
3688 */
3689
3690VOID winhKillTasklist(VOID)
3691{
3692 HWND hwndTasklist = winhQueryTasklistWindow();
3693 WinPostMsg(hwndTasklist,
3694 0x0454, // undocumented msg for killing tasklist
3695 NULL, NULL);
3696}
3697
3698// the following must be added for EMX (99-10-22) [umoeller]
3699#ifndef NERR_BufTooSmall
3700 #define NERR_BASE 2100
3701 #define NERR_BufTooSmall (NERR_BASE+23)
3702 // the API return buffer is too small
3703#endif
3704
3705/*
3706 *@@ winhQueryPendingSpoolJobs:
3707 * returns the number of pending print jobs in the spooler
3708 * or 0 if none. Useful for testing before shutdown.
3709 */
3710
3711ULONG winhQueryPendingSpoolJobs(VOID)
3712{
3713 // BOOL rcPending = FALSE;
3714 ULONG ulTotalJobCount = 0;
3715
3716 SPLERR splerr;
3717 USHORT jobCount;
3718 ULONG cbBuf;
3719 ULONG cTotal;
3720 ULONG cReturned;
3721 ULONG cbNeeded;
3722 ULONG ulLevel;
3723 ULONG i,j;
3724 PSZ pszComputerName;
3725 PBYTE pBuf = NULL;
3726 PPRQINFO3 prq;
3727 PPRJINFO2 prj2;
3728
3729 ulLevel = 4L;
3730 pszComputerName = (PSZ)NULL;
3731 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
3732 &cReturned, &cTotal,
3733 &cbNeeded, NULL);
3734 if ( (splerr == ERROR_MORE_DATA)
3735 || (splerr == NERR_BufTooSmall)
3736 )
3737 {
3738 if (!DosAllocMem((PPVOID)&pBuf,
3739 cbNeeded,
3740 PAG_READ | PAG_WRITE | PAG_COMMIT))
3741 {
3742 cbBuf = cbNeeded;
3743 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
3744 &cReturned, &cTotal,
3745 &cbNeeded, NULL);
3746 if (splerr == NO_ERROR)
3747 {
3748 // set pointer to point to the beginning of the buffer
3749 prq = (PPRQINFO3)pBuf;
3750
3751 // cReturned has the count of the number of PRQINFO3 structures
3752 for (i = 0;
3753 i < cReturned;
3754 i++)
3755 {
3756 // save the count of jobs; there are this many PRJINFO2
3757 // structures following the PRQINFO3 structure
3758 jobCount = prq->cJobs;
3759 // _Pmpf(( "Job count in this queue is %d",jobCount ));
3760
3761 // increment the pointer past the PRQINFO3 structure
3762 prq++;
3763
3764 // set a pointer to point to the first PRJINFO2 structure
3765 prj2=(PPRJINFO2)prq;
3766 for (j = 0;
3767 j < jobCount;
3768 j++)
3769 {
3770 // increment the pointer to point to the next structure
3771 prj2++;
3772 // increase the job count, which we'll return
3773 ulTotalJobCount++;
3774
3775 } // endfor jobCount
3776
3777 // after doing all the job structures, prj2 points to the next
3778 // queue structure; set the pointer for a PRQINFO3 structure
3779 prq = (PPRQINFO3)prj2;
3780 } //endfor cReturned
3781 } // endif NO_ERROR
3782 DosFreeMem(pBuf);
3783 }
3784 } // end if Q level given
3785
3786 return (ulTotalJobCount);
3787}
3788
3789/*
3790 *@@ winhSetNumLock:
3791 * this sets the NumLock key on or off, depending
3792 * on fState.
3793 *
3794 * Based on code from WarpEnhancer, (C) Achim Hasenmller.
3795 *
3796 *@@added V0.9.1 (99-12-18) [umoeller]
3797 */
3798
3799VOID winhSetNumLock(BOOL fState)
3800{
3801 // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
3802 BYTE KeyStateTable[256];
3803 ULONG ulActionTaken; // Used by DosOpen
3804 HFILE hKbd;
3805
3806 // read keyboard state table
3807 if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
3808 FALSE))
3809 {
3810 // first set the PM state
3811 if (fState)
3812 KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
3813 else
3814 KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
3815
3816 // set keyboard state table with new state values
3817 WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
3818 }
3819
3820 // now set the OS/2 keyboard state
3821
3822 // try to open OS/2 keyboard driver
3823 if (!DosOpen("KBD$",
3824 &hKbd, &ulActionTaken,
3825 0, // cbFile
3826 FILE_NORMAL,
3827 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
3828 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
3829 NULL))
3830 {
3831 SHIFTSTATE ShiftState;
3832 ULONG DataLen = sizeof(SHIFTSTATE);
3833
3834 memset(&ShiftState, '\0', DataLen);
3835 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
3836 NULL, 0L, NULL,
3837 &ShiftState, DataLen, &DataLen);
3838
3839 if (fState)
3840 ShiftState.fsState |= 0x0020; // turn NumLock on
3841 else
3842 ShiftState.fsState &= 0xFFDF; // turn NumLock off
3843
3844 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
3845 &ShiftState, DataLen, &DataLen,
3846 NULL, 0L, NULL);
3847 // now close OS/2 keyboard driver
3848 DosClose(hKbd);
3849 }
3850 return;
3851}
3852
3853/*
3854 *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
3855 */
3856
3857/* ******************************************************************
3858 *
3859 * WPS Class List helpers
3860 *
3861 ********************************************************************/
3862
3863/*
3864 *@@ winhQueryWPSClassList:
3865 * this returns the WPS class list in a newly
3866 * allocated buffer. This is just a shortcut to
3867 * the usual double WinEnumObjectClasses call.
3868 *
3869 * The return value is actually of the POBJCLASS type,
3870 * so you better cast this manually. We declare this
3871 * this as PBYTE though because POBJCLASS requires
3872 * INCL_WINWORKPLACE.
3873 * See WinEnumObjectClasses() for details.
3874 *
3875 * Returns NULL on error. Use winhFree()
3876 * to free the return value.
3877 *
3878 *@@added V0.9.0 [umoeller]
3879 */
3880
3881PBYTE winhQueryWPSClassList(VOID)
3882{
3883 ULONG ulSize;
3884 POBJCLASS pObjClass = 0;
3885
3886 // get WPS class list size
3887 if (WinEnumObjectClasses(NULL, &ulSize))
3888 {
3889 // allocate buffer
3890 pObjClass = (POBJCLASS)malloc(ulSize+1);
3891 // and load the classes into it
3892 WinEnumObjectClasses(pObjClass, &ulSize);
3893 }
3894
3895 return ((PBYTE)pObjClass);
3896}
3897
3898/*
3899 *@@ winhQueryWPSClass:
3900 * this returns the POBJCLASS item if pszClass is registered
3901 * with the WPS or NULL if the class could not be found.
3902 *
3903 * The return value is actually of the POBJCLASS type,
3904 * so you better cast this manually. We declare this
3905 * this as PBYTE though because POBJCLASS requires
3906 * INCL_WINWORKPLACE.
3907 *
3908 * This takes as input the return value of winhQueryWPSClassList,
3909 * which you must call first.
3910 *
3911 * <B>Usage:</B>
3912 + PBYTE pClassList = winhQueryWPSClassList(),
3913 + pWPFolder;
3914 + if (pClassList)
3915 + {
3916 + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
3917 + ...
3918 + free(pClassList);
3919 + }
3920 *
3921 *@@added V0.9.0 [umoeller]
3922 */
3923
3924PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
3925 // winhQueryWPSClassList
3926 const char *pszClass) // in: class name to query
3927{
3928 PBYTE pbReturn = 0;
3929
3930 POBJCLASS pocThis = (POBJCLASS)pObjClass;
3931 // now go thru the WPS class list
3932 while (pocThis)
3933 {
3934 if (strcmp(pocThis->pszClassName, pszClass) == 0)
3935 {
3936 pbReturn = (PBYTE)pocThis;
3937 break;
3938 }
3939 // next class
3940 pocThis = pocThis->pNext;
3941 } // end while (pocThis)
3942
3943 return (pbReturn);
3944}
3945
3946/*
3947 *@@ winhRegisterClass:
3948 * this works just like WinRegisterObjectClass,
3949 * except that it returns a more meaningful
3950 * error code than just FALSE in case registering
3951 * fails.
3952 *
3953 * This returns NO_ERROR if the class was successfully
3954 * registered (WinRegisterObjectClass returned TRUE).
3955 *
3956 * Otherwise, we do a DosLoadModule if maybe the DLL
3957 * couldn't be loaded in the first place. If DosLoadModule
3958 * did not return NO_ERROR, this function returns that
3959 * return code, which can be:
3960 *
3961 * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
3962 * -- 2 ERROR_FILE_NOT_FOUND
3963 * -- 3 ERROR_PATH_NOT_FOUND
3964 * -- 4 ERROR_TOO_MANY_OPEN_FILES
3965 * -- 5 ERROR_ACCESS_DENIED
3966 * -- 8 ERROR_NOT_ENOUGH_MEMORY
3967 * -- 11 ERROR_BAD_FORMAT
3968 * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
3969 * -- 32 ERROR_SHARING_VIOLATION
3970 * -- 33 ERROR_LOCK_VIOLATION
3971 * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
3972 * -- 95 ERROR_INTERRUPT (interrupted system call)
3973 * -- 108 ERROR_DRIVE_LOCKED (by another process)
3974 * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
3975 * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
3976 * -- 180 ERROR_INVALID_SEGMENT_NUMBER
3977 * -- 182 ERROR_INVALID_ORDINAL
3978 * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
3979 * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
3980 * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
3981 * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
3982 * -- 195 ERROR_INVALID_MINALLOCSIZE
3983 * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
3984 * -- 198 ERROR_INVALID_SEGDPL
3985 * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
3986 * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
3987 * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
3988 * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
3989 *
3990 * In all these cases, pszBuf may contain a meaningful
3991 * error message from DosLoadModule, especially if an import
3992 * could not be resolved.
3993 *
3994 * Still worse, if DosLoadModule returned NO_ERROR, we
3995 * probably have some SOM internal error. A probable
3996 * reason is that the parent class of pcszClassName
3997 * is not installed, but that's WPS/SOM internal
3998 * and cannot be queried from outside the WPS context.
3999 *
4000 * In that case, ERROR_OPEN_FAILED (110) is returned.
4001 * That one sounded good to me. ;-)
4002 */
4003
4004APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
4005 const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
4006 PSZ pszBuf, // out: error message from DosLoadModule
4007 ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
4008{
4009 APIRET arc = NO_ERROR;
4010
4011 if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
4012 {
4013 // failed: do more error checking then, try DosLoadModule
4014 HMODULE hmod = NULLHANDLE;
4015 arc = DosLoadModule(pszBuf, cbBuf,
4016 (PSZ)pcszModule,
4017 &hmod);
4018 if (arc == NO_ERROR)
4019 {
4020 // DosLoadModule succeeded:
4021 // some SOM error then
4022 DosFreeModule(hmod);
4023 arc = ERROR_OPEN_FAILED;
4024 }
4025 }
4026 // else: ulrc still 0 (== no error)
4027
4028 return (arc);
4029}
4030
4031/*
4032 *@@ winhIsClassRegistered:
4033 * quick one-shot function which checks if
4034 * a class is currently registered. Calls
4035 * winhQueryWPSClassList and winhQueryWPSClass
4036 * in turn.
4037 *
4038 *@@added V0.9.2 (2000-02-26) [umoeller]
4039 */
4040
4041BOOL winhIsClassRegistered(const char *pcszClass)
4042{
4043 BOOL brc = FALSE;
4044 PBYTE pClassList = winhQueryWPSClassList();
4045 if (pClassList)
4046 {
4047 if (winhQueryWPSClass(pClassList, pcszClass))
4048 brc = TRUE;
4049 free(pClassList);
4050 }
4051
4052 return (brc);
4053}
4054
4055/*
4056 *@@category: Helpers\PM helpers\Workplace Shell
4057 */
4058
4059/*
4060 *@@ winhResetWPS:
4061 * restarts the WPS using PrfReset. Returns
4062 * one of the following:
4063 *
4064 * -- 0: no error.
4065 * -- 1: PrfReset failed.
4066 * -- 2 or 4: PrfQueryProfile failed.
4067 * -- 3: malloc() failed.
4068 *
4069 *@@added V0.9.4 (2000-07-01) [umoeller]
4070 */
4071
4072ULONG winhResetWPS(HAB hab)
4073{
4074 ULONG ulrc = 0;
4075 // find out current profile names
4076 PRFPROFILE Profiles;
4077 Profiles.cchUserName = Profiles.cchSysName = 0;
4078 // first query their file name lengths
4079 if (PrfQueryProfile(hab, &Profiles))
4080 {
4081 // allocate memory for filenames
4082 Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
4083 Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
4084
4085 if (Profiles.pszSysName)
4086 {
4087 // get filenames
4088 if (PrfQueryProfile(hab, &Profiles))
4089 {
4090
4091 // "change" INIs to these filenames:
4092 // THIS WILL RESET THE WPS
4093 if (PrfReset(hab, &Profiles) == FALSE)
4094 ulrc = 1;
4095 free(Profiles.pszSysName);
4096 free(Profiles.pszUserName);
4097 }
4098 else
4099 ulrc = 2;
4100 }
4101 else
4102 ulrc = 3;
4103 }
4104 else
4105 ulrc = 4;
4106
4107 return (ulrc);
4108}
Note: See TracBrowser for help on using the repository browser.