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

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

Major updates; timers, LVM, miscellaneous.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 144.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 * Since this calls WinStartApp in turn, this
2483 * requires a message queue on the calling thread.
2484 *
2485 *@@added V0.9.6 (2000-10-16) [umoeller]
2486 */
2487
2488HAPP winhStartApp(HWND hwndNotify, // in: notify window (as with WinStartApp)
2489 const PROGDETAILS *pcProgDetails) // in: program data
2490{
2491 HAPP happ = NULLHANDLE;
2492 PSZ pszParamsPatched = NULL;
2493 BOOL fIsWindowsApp = FALSE,
2494 fIsWindowsEnhApp = FALSE;
2495 PROGDETAILS ProgDetails;
2496 PSZ pszWinOS2Env = 0;
2497
2498 memcpy(&ProgDetails, pcProgDetails, sizeof(PROGDETAILS));
2499 // pointers still point into old prog details buffer
2500 ProgDetails.Length = sizeof(PROGDETAILS);
2501 ProgDetails.progt.fbVisible = SHE_VISIBLE;
2502 ProgDetails.pszEnvironment = 0; // "WORKPLACE\0\0";
2503 memset(&ProgDetails.swpInitial, 0, sizeof(SWP));
2504
2505 // duplicate parameters...
2506 // we need this for string manipulations below...
2507 if (ProgDetails.pszParameters)
2508 pszParamsPatched = strdup(ProgDetails.pszParameters);
2509
2510 // _Pmpf((__FUNCTION__ ": old progc: 0x%lX", pcProgDetails->progt.progc));
2511 // _Pmpf((" pszTitle: %s", (ProgDetails.pszTitle) ? ProgDetails.pszTitle : NULL));
2512 // _Pmpf((" pszIcon: %s", (ProgDetails.pszIcon) ? ProgDetails.pszIcon : NULL));
2513
2514 // program type fixups
2515 switch (ProgDetails.progt.progc)
2516 {
2517 case ((ULONG)-1): // we get that sometimes...
2518 case PROG_DEFAULT:
2519 // ###
2520 break;
2521 }
2522
2523 // now try again...
2524 switch (ProgDetails.progt.progc)
2525 {
2526 case PROG_31_ENH:
2527 case PROG_31_ENHSEAMLESSCOMMON:
2528 case PROG_31_ENHSEAMLESSVDM:
2529 fIsWindowsApp = TRUE;
2530 fIsWindowsEnhApp = TRUE;
2531 break;
2532
2533 case PROG_WINDOW_AUTO:
2534#ifdef PROG_30_STD
2535 case PROG_30_STD:
2536#endif
2537 case PROG_31_STD:
2538 case PROG_WINDOW_REAL:
2539#ifdef PROG_30_STDSEAMLESSVDM
2540 case PROG_30_STDSEAMLESSVDM:
2541#endif
2542 case PROG_31_STDSEAMLESSVDM:
2543 case PROG_30_STDSEAMLESSCOMMON:
2544 case PROG_31_STDSEAMLESSCOMMON:
2545 fIsWindowsApp = TRUE;
2546 break;
2547 }
2548
2549 /*
2550 * command lines fixups:
2551 *
2552 */
2553
2554 if (strcmp(ProgDetails.pszExecutable, "*") == 0)
2555 {
2556 /*
2557 * "*" for command sessions:
2558 *
2559 */
2560
2561 if (fIsWindowsEnhApp)
2562 {
2563 // enhanced Win-OS/2 session:
2564 XSTRING str2;
2565 xstrInit(&str2, 200);
2566 xstrcpy(&str2, "/3 ");
2567 if (pszParamsPatched)
2568 {
2569 // append existing params
2570 xstrcat(&str2, pszParamsPatched);
2571 free(pszParamsPatched);
2572 }
2573
2574 pszParamsPatched = str2.psz;
2575 }
2576
2577 if (fIsWindowsApp)
2578 {
2579 // cheat: WinStartApp doesn't support NULL
2580 // for Win-OS2 sessions, so manually start winos2.com
2581 ProgDetails.pszExecutable = "WINOS2.COM";
2582 // this is a DOS app, so fix this to DOS fullscreen
2583 ProgDetails.progt.progc = PROG_VDM;
2584 }
2585 else
2586 // for all other executable types
2587 // (including OS/2 and DOS sessions),
2588 // set pszExecutable to NULL; this will
2589 // have WinStartApp start a cmd shell
2590 ProgDetails.pszExecutable = NULL;
2591
2592 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
2593 else
2594 switch (ProgDetails.progt.progc)
2595 {
2596 /*
2597 * .CMD files fixups
2598 *
2599 */
2600
2601 case PROG_FULLSCREEN: // OS/2 fullscreen
2602 case PROG_WINDOWABLEVIO: // OS/2 window
2603 {
2604 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2605 if (pszExtension)
2606 {
2607 if (stricmp(pszExtension, "CMD") == 0)
2608 {
2609 CallBatchCorrectly(&ProgDetails,
2610 &pszParamsPatched,
2611 "OS2_SHELL",
2612 "CMD.EXE");
2613 }
2614 }
2615 break; }
2616
2617 case PROG_VDM: // DOS fullscreen
2618 case PROG_WINDOWEDVDM: // DOS window
2619 {
2620 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2621 if (pszExtension)
2622 {
2623 if (stricmp(pszExtension, "BAT") == 0)
2624 {
2625 CallBatchCorrectly(&ProgDetails,
2626 &pszParamsPatched,
2627 NULL,
2628 "COMMAND.COM");
2629 }
2630 }
2631 break; }
2632 } // end switch (ProgDetails.progt.progc)
2633
2634 /*
2635 * Fix environment for Win-OS/2
2636 *
2637 */
2638
2639 if ( !(xstrIsString(ProgDetails.pszEnvironment)) // env empty
2640 && (fIsWindowsApp) // and win-os2 app
2641 )
2642 {
2643 ULONG ulSize = 0;
2644 // get default environment (from Win-OS/2 settings object)
2645 // from OS2.INI
2646 PSZ pszDefEnv = prfhQueryProfileData(HINI_USER,
2647 "WINOS2",
2648 "PM_GlobalWindows31Settings",
2649 &ulSize);
2650 if (pszDefEnv)
2651 {
2652 PSZ pszDefEnv2 = (PSZ)malloc(ulSize + 2);
2653 if (pszDefEnv2)
2654 {
2655 PSZ p = pszDefEnv2;
2656 memset(pszDefEnv2, 0, ulSize + 2);
2657 memcpy(pszDefEnv2, pszDefEnv, ulSize);
2658
2659 for (p = pszDefEnv2;
2660 p < pszDefEnv2 + ulSize;
2661 p++)
2662 if (*p == ';')
2663 *p = 0;
2664
2665 // okay.... now we got an OS/2-style environment
2666 // with 0, 0, 00 strings
2667
2668 pszWinOS2Env = pszDefEnv2; // freed below
2669
2670 // use this
2671 ProgDetails.pszEnvironment = pszWinOS2Env;
2672 }
2673
2674 free(pszDefEnv);
2675 }
2676 }
2677
2678 // _Pmpf((__FUNCTION__ ": calling WinStartApp"));
2679 // _Pmpf((" exec: %s",
2680 // (ProgDetails.pszExecutable)
2681 // ? ProgDetails.pszExecutable
2682 // : "NULL"));
2683 // _Pmpf((" startupDir: %s",
2684 // (ProgDetails.pszStartupDir)
2685 // ? ProgDetails.pszStartupDir
2686 // : "NULL"));
2687 // _Pmpf((" params: %s",
2688 // (pszParamsPatched)
2689 // ? pszParamsPatched
2690 // : "NULL"));
2691 // _Pmpf((" new progc: 0x%lX", ProgDetails.progt.progc));
2692
2693 ProgDetails.pszParameters = pszParamsPatched;
2694
2695 happ = WinStartApp(hwndNotify,
2696 // receives WM_APPTERMINATENOTIFY
2697 &ProgDetails,
2698 pszParamsPatched,
2699 NULL, // "reserved", PMREF says...
2700 SAF_INSTALLEDCMDLINE);
2701 // we MUST use SAF_INSTALLEDCMDLINE
2702 // or no Win-OS/2 session will start...
2703 // whatever is going on here... Warp 4 FP11
2704
2705 // do not use SAF_STARTCHILDAPP, or the
2706 // app will be terminated automatically
2707
2708 // _Pmpf((__FUNCTION__ ": got happ 0x%lX", happ));
2709
2710 if (pszParamsPatched)
2711 free(pszParamsPatched);
2712 if (pszWinOS2Env)
2713 free(pszWinOS2Env);
2714
2715 return (happ);
2716}
2717
2718/*
2719 *@@ winhAnotherInstance:
2720 * this tests whether another instance of the same
2721 * application is already running.
2722 *
2723 * To identify instances of the same application, the
2724 * application must call this function during startup
2725 * with the unique name of an OS/2 semaphore. As with
2726 * all OS/2 semaphores, the semaphore name must begin
2727 * with "\\SEM32\\". The semaphore isn't really used
2728 * except for testing for its existence, since that
2729 * name is unique among all processes.
2730 *
2731 * If another instance is found, TRUE is returned. If
2732 * (fSwitch == TRUE), that instance is switched to,
2733 * using the tasklist.
2734 *
2735 * If no other instance is found, FALSE is returned only.
2736 *
2737 * Based on an EDM/2 code snippet.
2738 *
2739 *@@added V0.9.0 (99-10-22) [umoeller]
2740 */
2741
2742BOOL winhAnotherInstance(PSZ pszSemName, // in: semaphore ID
2743 BOOL fSwitch) // in: if TRUE, switch to first instance if running
2744{
2745 HMTX hmtx;
2746
2747 if (DosCreateMutexSem(pszSemName,
2748 &hmtx,
2749 DC_SEM_SHARED,
2750 TRUE)
2751 == NO_ERROR)
2752 // semapore created: this doesn't happen if the semaphore
2753 // exists already, so no other instance is running
2754 return (FALSE);
2755
2756 // else: instance running
2757 hmtx = NULLHANDLE;
2758
2759 // switch to other instance?
2760 if (fSwitch)
2761 {
2762 // yes: query mutex creator
2763 if (DosOpenMutexSem(pszSemName,
2764 &hmtx)
2765 == NO_ERROR)
2766 {
2767 PID pid = 0;
2768 TID tid = 0; // unused
2769 ULONG ulCount; // unused
2770
2771 if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
2772 {
2773 HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
2774 if (hswitch != NULLHANDLE)
2775 WinSwitchToProgram(hswitch);
2776 }
2777
2778 DosCloseMutexSem(hmtx);
2779 }
2780 }
2781
2782 return (TRUE); // another instance exists
2783}
2784
2785/*
2786 *@@ winhAddToTasklist:
2787 * this adds the specified window to the tasklist
2788 * with hIcon as its program icon (which is also
2789 * set for the main window). This is useful for
2790 * the old "dialog as main window" trick.
2791 *
2792 * Returns the HSWITCH of the added entry.
2793 */
2794
2795HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
2796 HPOINTER hIcon) // in: icon for main window
2797{
2798 SWCNTRL swctl;
2799 HSWITCH hswitch = 0;
2800 swctl.hwnd = hwnd; // window handle
2801 swctl.hwndIcon = hIcon; // icon handle
2802 swctl.hprog = NULLHANDLE; // program handle (use default)
2803 WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
2804 // process identifier
2805 swctl.idSession = 0; // session identifier ?
2806 swctl.uchVisibility = SWL_VISIBLE; // visibility
2807 swctl.fbJump = SWL_JUMPABLE; // jump indicator
2808 // get window title from window titlebar
2809 if (hwnd)
2810 WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
2811 swctl.bProgType = PROG_DEFAULT; // program type
2812 hswitch = WinAddSwitchEntry(&swctl);
2813
2814 // give the main window the icon
2815 if ((hwnd) && (hIcon))
2816 WinSendMsg(hwnd,
2817 WM_SETICON,
2818 (MPARAM)hIcon,
2819 NULL);
2820
2821 return (hswitch);
2822}
2823
2824/*
2825 *@@category: Helpers\PM helpers\Miscellaneous
2826 */
2827
2828/* ******************************************************************
2829 *
2830 * Miscellaneous
2831 *
2832 ********************************************************************/
2833
2834/*
2835 *@@ winhFree:
2836 * frees a block of memory allocated by the
2837 * winh* functions.
2838 *
2839 * Since the winh* functions use malloc(),
2840 * you can also use free() directly on such
2841 * blocks. However, you must use winhFree
2842 * if the winh* functions are in a module
2843 * with a different C runtime.
2844 *
2845 *@@added V0.9.7 (2000-12-06) [umoeller]
2846 */
2847
2848VOID winhFree(PVOID p)
2849{
2850 if (p)
2851 free(p);
2852}
2853
2854/*
2855 *@@ winhSleep:
2856 * sleeps at least the specified amount of time,
2857 * without blocking the message queue.
2858 *
2859 *@@added V0.9.4 (2000-07-11) [umoeller]
2860 */
2861
2862VOID winhSleep(HAB hab,
2863 ULONG ulSleep) // in: sleep time in milliseconds
2864{
2865 ULONG ul = 0;
2866 QMSG qmsg;
2867 for (ul = 0;
2868 ul < (ulSleep / 50);
2869 ul++)
2870 {
2871 DosSleep(50);
2872 while (WinPeekMsg(hab,
2873 &qmsg, 0, 0, 0,
2874 PM_REMOVE))
2875 WinDispatchMsg(hab, &qmsg);
2876
2877 }
2878}
2879
2880/*
2881 *@@ winhFileDlg:
2882 * one-short function for opening an "Open" file
2883 * dialog.
2884 *
2885 * On input, pszFile specifies the directory and
2886 * file specification (e.g. "F:\*.txt").
2887 *
2888 * Returns TRUE if the user pressed OK. In that
2889 * case, the fully qualified filename is written
2890 * into pszFile again.
2891 *
2892 * Returns FALSE if the user pressed Cancel.
2893 *
2894 * Notes about flFlags:
2895 *
2896 * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
2897 * Otherwise an "Open" dialog is displayed.
2898 *
2899 * -- WINH_FOD_INILOADDIR: load a directory from the
2900 * specified INI key and switch the dlg to it.
2901 * In that case, on input, pszFile must only
2902 * contain the file filter without any path
2903 * specification, because that is loaded from
2904 * the INI key. If the INI key does not exist,
2905 * the current process directory will be used.
2906 *
2907 * -- WINH_FOD_INISAVEDIR: if the user presses OK,
2908 * the directory of the selected file is written
2909 * to the specified INI key so that it can be
2910 * reused later. This flag is independent of
2911 * WINH_FOD_INISAVEDIR: you can specify none,
2912 * one, or both of them.
2913 *
2914 *@@added V0.9.3 (2000-04-29) [umoeller]
2915 */
2916
2917BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
2918 PSZ pszFile, // in: file mask; out: fully q'd filename
2919 // (should be CCHMAXPATH in size)
2920 ULONG flFlags, // in: any combination of the following:
2921 // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
2922 // -- WINH_FOD_INILOADDIR: load FOD path from INI
2923 // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
2924 HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
2925 PSZ pszApplication, // in: INI application to load/store last path from
2926 PSZ pszKey) // in: INI key to load/store last path from
2927{
2928 FILEDLG fd;
2929 memset(&fd, 0, sizeof(FILEDLG));
2930 fd.cbSize = sizeof(FILEDLG);
2931 fd.fl = FDS_CENTER;
2932
2933 if (flFlags & WINH_FOD_SAVEDLG)
2934 fd.fl |= FDS_SAVEAS_DIALOG;
2935 else
2936 fd.fl |= FDS_OPEN_DIALOG;
2937
2938 // default: copy pszFile
2939 strcpy(fd.szFullFile, pszFile);
2940
2941 if ( (hini) && (flFlags & WINH_FOD_INILOADDIR) )
2942 {
2943 // overwrite with initial directory for FOD from OS2.INI
2944 if (PrfQueryProfileString(hini,
2945 pszApplication,
2946 pszKey,
2947 "", // default string
2948 fd.szFullFile,
2949 sizeof(fd.szFullFile)-10)
2950 >= 2)
2951 {
2952 // found: append "\*"
2953 strcat(fd.szFullFile, "\\");
2954 strcat(fd.szFullFile, pszFile);
2955 }
2956 }
2957
2958 if ( WinFileDlg(HWND_DESKTOP, // parent
2959 hwndOwner, // owner
2960 &fd)
2961 && (fd.lReturn == DID_OK)
2962 )
2963 {
2964 // save path back?
2965 if ( (hini)
2966 && (flFlags & WINH_FOD_INISAVEDIR)
2967 )
2968 {
2969 // get the directory that was used
2970 PSZ p = strrchr(fd.szFullFile, '\\');
2971 if (p)
2972 {
2973 // contains directory:
2974 // copy to OS2.INI
2975 PSZ pszDir = strhSubstr(fd.szFullFile, p);
2976 if (pszDir)
2977 {
2978 PrfWriteProfileString(hini,
2979 pszApplication,
2980 pszKey, // "XWPSound:LastDir"
2981 pszDir);
2982 free(pszDir);
2983 }
2984 }
2985 }
2986
2987 strcpy(pszFile, fd.szFullFile);
2988
2989 return (TRUE);
2990 }
2991
2992 return (FALSE);
2993}
2994
2995/*
2996 *@@ winhSetWaitPointer:
2997 * this sets the mouse pointer to "Wait".
2998 * Returns the previous pointer (HPOINTER),
2999 * which should be stored somewhere to be
3000 * restored later. Example:
3001 + HPOINTER hptrOld = winhSetWaitPointer();
3002 + ...
3003 + WinSetPointer(HWND_DESKTOP, hptrOld);
3004 */
3005
3006HPOINTER winhSetWaitPointer(VOID)
3007{
3008 HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
3009 WinSetPointer(HWND_DESKTOP,
3010 WinQuerySysPointer(HWND_DESKTOP,
3011 SPTR_WAIT,
3012 FALSE)); // no copy
3013 return (hptr);
3014}
3015
3016/*
3017 *@@ winhQueryWindowText:
3018 * this returns the window text of the specified
3019 * HWND in a newly allocated buffer.
3020 *
3021 * Returns NULL on error. Use winhFree()
3022 * to free the return value.
3023 */
3024
3025PSZ winhQueryWindowText(HWND hwnd)
3026{
3027 PSZ pszText = NULL;
3028 ULONG cbText = WinQueryWindowTextLength(hwnd);
3029 // additional null character
3030 if (cbText)
3031 {
3032 pszText = (PSZ)malloc(cbText + 1);
3033 if (pszText)
3034 WinQueryWindowText(hwnd,
3035 cbText + 1,
3036 pszText);
3037 }
3038 return (pszText);
3039}
3040
3041/*
3042 *@@ winhReplaceWindowText:
3043 * this is a combination of winhQueryWindowText
3044 * and xstrrpl (stringh.c) to replace substrings
3045 * in a window.
3046 *
3047 * This is useful for filling in placeholders
3048 * a la "%1" in control windows, e.g. static
3049 * texts.
3050 *
3051 * This replaces only the first occurence of
3052 * pszSearch.
3053 *
3054 * Returns TRUE only if the window exists and
3055 * the search string was replaced.
3056 *
3057 *@@added V0.9.0 [umoeller]
3058 */
3059
3060BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
3061 PSZ pszSearch, // in: search string (e.g. "%1")
3062 PSZ pszReplaceWith) // in: replacement string for pszSearch
3063{
3064 BOOL brc = FALSE;
3065 PSZ pszText = winhQueryWindowText(hwnd);
3066 if (pszText)
3067 {
3068 ULONG ulOfs = 0;
3069 if (strhrpl(&pszText, &ulOfs, pszSearch, pszReplaceWith) > 0)
3070 {
3071 WinSetWindowText(hwnd, pszText);
3072 brc = TRUE;
3073 }
3074 free(pszText);
3075 }
3076 return (brc);
3077}
3078
3079/*
3080 *@@ winhEnableDlgItems:
3081 * this enables/disables a whole range of controls
3082 * in a window by enumerating the child windows
3083 * until usIDFirst is found. If so, that subwindow
3084 * is enabled/disabled and all the following windows
3085 * in the enumeration also, until usIDLast is found.
3086 *
3087 * Note that this affects _all_ controls following
3088 * the usIDFirst window, no matter what ID they have
3089 * (even if "-1"), until usIDLast is found.
3090 *
3091 * Returns the no. of controls which were enabled/disabled
3092 * (null if none).
3093 *
3094 *@@added V0.9.0 [umoeller]
3095 *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
3096 */
3097
3098ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
3099 USHORT usIDFirst, // in: first affected control ID
3100 USHORT usIDLast, // in: last affected control ID (inclusive)
3101 BOOL fEnable)
3102{
3103 HENUM henum1 = NULLHANDLE;
3104 HWND hwndThis = NULLHANDLE;
3105 ULONG ulCount = 0;
3106
3107 henum1 = WinBeginEnumWindows(hwndDlg);
3108 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3109 {
3110 USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
3111 usIDCheckLast;
3112 if (usIDCheckFirst == usIDFirst)
3113 {
3114 WinEnableWindow(hwndThis, fEnable);
3115 ulCount++;
3116
3117 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3118 {
3119 WinEnableWindow(hwndThis, fEnable);
3120 ulCount++;
3121 usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
3122 if (usIDCheckLast == usIDLast)
3123 break;
3124 }
3125
3126 break; // outer loop
3127 }
3128 }
3129 WinEndEnumWindows(henum1);
3130 return (ulCount);
3131}
3132
3133/*
3134 *@@ winhCreateStdWindow:
3135 * much like WinCreateStdWindow, but this one
3136 * allows you to have the standard window
3137 * positioned automatically, using a given
3138 * SWP structure (*pswpFrame).
3139 *
3140 * Alternatively, you can set pswpFrame to NULL
3141 * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
3142 * If you want the window to be shown, specify
3143 * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
3144 *
3145 *@@added V0.9.0 [umoeller]
3146 *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
3147 *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
3148 */
3149
3150HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
3151 PSWP pswpFrame, // in: frame wnd pos
3152 ULONG flFrameCreateFlags, // in: FCF_* flags
3153 ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
3154 PSZ pszFrameTitle,
3155 ULONG ulResourcesID, // in: according to FCF_* flags
3156 PSZ pszClassClient,
3157 ULONG flStyleClient,
3158 ULONG ulID, // in: frame window ID
3159 PVOID pClientCtlData, // in: pCtlData structure pointer for client
3160 PHWND phwndClient) // out: created client wnd
3161{
3162 FRAMECDATA fcdata;
3163 HWND hwndFrame;
3164 RECTL rclClient;
3165
3166 fcdata.cb = sizeof(FRAMECDATA);
3167 fcdata.flCreateFlags = flFrameCreateFlags;
3168 fcdata.hmodResources = (HMODULE)NULL;
3169 fcdata.idResources = ulResourcesID;
3170
3171 /* Create the frame and client windows. */
3172 hwndFrame = WinCreateWindow(hwndFrameParent,
3173 WC_FRAME,
3174 pszFrameTitle,
3175 ulFrameStyle,
3176 0,0,0,0, // size and position = 0
3177 NULLHANDLE, // no owner
3178 HWND_TOP, // z-order
3179 ulID, // frame window ID
3180 &fcdata, // frame class data
3181 NULL); // no presparams
3182
3183 if (hwndFrame)
3184 {
3185 *phwndClient = WinCreateWindow(hwndFrame, // parent
3186 pszClassClient, // class
3187 NULL, // no title
3188 flStyleClient, // style
3189 0,0,0,0, // size and position = 0
3190 hwndFrame, // owner
3191 HWND_BOTTOM, // bottom z-order
3192 FID_CLIENT, // frame window ID
3193 pClientCtlData, // class data
3194 NULL); // no presparams
3195
3196 if (*phwndClient)
3197 {
3198 if (pswpFrame)
3199 // position frame
3200 WinSetWindowPos(hwndFrame,
3201 pswpFrame->hwndInsertBehind,
3202 pswpFrame->x,
3203 pswpFrame->y,
3204 pswpFrame->cx,
3205 pswpFrame->cy,
3206 pswpFrame->fl);
3207
3208 // position client
3209 // WinQueryWindowRect(hwndFrame, &rclClient);
3210 // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
3211 rclClient.xLeft = 0;
3212 rclClient.yBottom = 0;
3213 rclClient.xRight = pswpFrame->cx;
3214 rclClient.yTop = pswpFrame->cy;
3215 WinCalcFrameRect(hwndFrame,
3216 &rclClient,
3217 TRUE); // calc client from frame
3218 WinSetWindowPos(*phwndClient,
3219 HWND_TOP,
3220 rclClient.xLeft,
3221 rclClient.yBottom,
3222 rclClient.xRight - rclClient.xLeft,
3223 rclClient.yTop - rclClient.yBottom,
3224 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3225 }
3226 }
3227 return (hwndFrame);
3228}
3229
3230/*
3231 *@@ winhRepaintWindows:
3232 * this repaints all children of hwndParent.
3233 * If this is passed as HWND_DESKTOP, the
3234 * whole screen is repainted.
3235 */
3236
3237VOID winhRepaintWindows(HWND hwndParent)
3238{
3239 HWND hwndTop;
3240 HENUM henum = WinBeginEnumWindows(HWND_DESKTOP);
3241 while ((hwndTop = WinGetNextWindow(henum)))
3242 if (WinIsWindowShowing(hwndTop))
3243 WinInvalidateRect(hwndTop, NULL, TRUE);
3244 WinEndEnumWindows(henum);
3245}
3246
3247/*
3248 *@@ winhFindMsgQueue:
3249 * returns the message queue which matches
3250 * the given process and thread IDs. Since,
3251 * per IBM definition, every thread may only
3252 * have one MQ, this should be unique.
3253 *
3254 *@@added V0.9.2 (2000-03-08) [umoeller]
3255 */
3256
3257HMQ winhFindMsgQueue(PID pid, // in: process ID
3258 TID tid, // in: thread ID
3259 HAB* phab) // out: anchor block
3260{
3261 HWND hwndThis = 0,
3262 rc = 0;
3263 HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
3264 while ((hwndThis = WinGetNextWindow(henum)))
3265 {
3266 CHAR szClass[200];
3267 if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
3268 {
3269 if (strcmp(szClass, "#32767") == 0)
3270 {
3271 // message queue window:
3272 PID pidWin = 0;
3273 TID tidWin = 0;
3274 WinQueryWindowProcess(hwndThis,
3275 &pidWin,
3276 &tidWin);
3277 if ( (pidWin == pid)
3278 && (tidWin == tid)
3279 )
3280 {
3281 // get HMQ from window words
3282 rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
3283 if (rc)
3284 if (phab)
3285 *phab = WinQueryAnchorBlock(hwndThis);
3286 break;
3287 }
3288 }
3289 }
3290 }
3291 WinEndEnumWindows(henum);
3292
3293 return (rc);
3294}
3295
3296/*
3297 *@@ winhFindHardErrorWindow:
3298 * this searches all children of HWND_OBJECT
3299 * for the PM hard error windows, which are
3300 * invisible most of the time. When a hard
3301 * error occurs, that window is made a child
3302 * of HWND_DESKTOP instead.
3303 *
3304 * Stolen from ProgramCommander/2 (C) Roman Stangl.
3305 *
3306 *@@added V0.9.3 (2000-04-27) [umoeller]
3307 */
3308
3309VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
3310 HWND *phwndSysError) // out: system error window
3311{
3312 PID pidObject; // HWND_OBJECT's process and thread id
3313 TID tidObject;
3314 PID pidObjectChild; // HWND_OBJECT's child window process and thread id
3315 TID tidObjectChild;
3316 HENUM henumObject; // HWND_OBJECT enumeration handle
3317 HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
3318 UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
3319 CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
3320
3321 *phwndHardError = NULLHANDLE;
3322 *phwndSysError = NULLHANDLE;
3323
3324 // query HWND_OBJECT's window process
3325 WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
3326 // enumerate all child windows of HWND_OBJECT
3327 henumObject = WinBeginEnumWindows(HWND_OBJECT);
3328 while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3329 {
3330 // see if the current HWND_OBJECT child window runs in the
3331 // process of HWND_OBJECT (PM)
3332 WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
3333 if (pidObject == pidObjectChild)
3334 {
3335 // get the child window's data
3336 WinQueryClassName(hwndObjectChild,
3337 sizeof(ucClassName),
3338 (PCH)ucClassName);
3339 WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
3340 (PSZ)ucClassName,
3341 &classinfoWindow);
3342 if ( (!strcmp((PSZ)ucClassName, "#1")
3343 || (classinfoWindow.flClassStyle & CS_FRAME))
3344 )
3345 {
3346 // if the child window is a frame window and running in
3347 // HWND_OBJECT's (PM's) window process, it must be the
3348 // PM Hard Error or System Error window
3349 WinQueryClassName(WinWindowFromID(hwndObjectChild,
3350 FID_CLIENT),
3351 sizeof(ucClassName),
3352 (PSZ)ucClassName);
3353 if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
3354 {
3355 *phwndHardError = hwndObjectChild;
3356 if (*phwndSysError)
3357 // we found the other one already:
3358 // stop searching, we got both
3359 break;
3360 }
3361 else
3362 {
3363 printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
3364 *phwndSysError = hwndObjectChild;
3365 if (*phwndHardError)
3366 // we found the other one already:
3367 // stop searching, we got both
3368 break;
3369 }
3370 }
3371 } // end if (pidObject == pidObjectChild)
3372 } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3373 WinEndEnumWindows(henumObject);
3374}
3375
3376/*
3377 *@@ winhCreateFakeDesktop:
3378 * this routine creates and displays a frameless window over
3379 * the whole screen in the color of PM's Desktop to fool the
3380 * user that all windows have been closed (which in fact might
3381 * not be the case).
3382 * This window's background color is set to the Desktop's
3383 * (PM's one, not the WPS's one).
3384 * Returns the HWND of this window.
3385 */
3386
3387HWND winhCreateFakeDesktop(HWND hwndSibling)
3388{
3389 // presparam for background
3390 typedef struct _BACKGROUND
3391 {
3392 ULONG cb; // length of the aparam parameter, in bytes
3393 ULONG id; // attribute type identity
3394 ULONG cb2; // byte count of the ab parameter
3395 RGB rgb; // attribute value
3396 } BACKGROUND;
3397
3398 BACKGROUND background;
3399 LONG lDesktopColor;
3400
3401 // create fake desktop window = empty window with
3402 // the size of full screen
3403 lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
3404 SYSCLR_BACKGROUND,
3405 0);
3406 background.cb = sizeof(background.id)
3407 + sizeof(background.cb)
3408 + sizeof(background.rgb);
3409 background.id = PP_BACKGROUNDCOLOR;
3410 background.cb2 = sizeof(RGB);
3411 background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
3412 background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
3413 background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
3414
3415 return (WinCreateWindow(HWND_DESKTOP, // parent window
3416 WC_FRAME, // class name
3417 "", // window text
3418 WS_VISIBLE, // window style
3419 0, 0, // position and size
3420 WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
3421 WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
3422 NULLHANDLE, // owner window
3423 hwndSibling, // sibling window
3424 1, // window id
3425 NULL, // control data
3426 &background)); // presentation parms
3427}
3428
3429/*
3430 *@@ winhAssertWarp4Notebook:
3431 * this takes hwndDlg as a notebook dialog page and
3432 * goes thru all its controls. If a control with an
3433 * ID <= udIdThreshold is found, this is assumed to
3434 * be a button which is to be given the BS_NOTEBOOKBUTTON
3435 * style. You should therefore give all your button
3436 * controls which should be moved such an ID.
3437 *
3438 * You can also specify how many dialog units
3439 * all the other controls will be moved downward in
3440 * ulDownUnits; this is useful to fill up the space
3441 * which was used by the buttons before moving them.
3442 * Returns TRUE if anything was changed.
3443 *
3444 * This function is useful if you wish to create
3445 * notebook pages using dlgedit.exe which are compatible
3446 * with both Warp 3 and Warp 4. This should be executed
3447 * in WM_INITDLG of the notebook dlg function if the app
3448 * has determined that it is running on Warp 4.
3449 */
3450
3451BOOL winhAssertWarp4Notebook(HWND hwndDlg,
3452 USHORT usIdThreshold, // in: ID threshold
3453 ULONG ulDownUnits) // in: dialog units or 0
3454{
3455 BOOL brc = FALSE;
3456
3457 if (doshIsWarp4())
3458 {
3459 POINTL ptl;
3460 HWND hwndItem;
3461 HENUM henum = 0;
3462
3463 BOOL fIsVisible = WinIsWindowVisible(hwndDlg);
3464 if (ulDownUnits)
3465 {
3466 ptl.x = 0;
3467 ptl.y = ulDownUnits;
3468 WinMapDlgPoints(hwndDlg, &ptl, 1, TRUE);
3469 }
3470
3471 if (fIsVisible)
3472 WinEnableWindowUpdate(hwndDlg, FALSE);
3473
3474 henum = WinBeginEnumWindows(hwndDlg);
3475 while ((hwndItem = WinGetNextWindow(henum)))
3476 {
3477 USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
3478 // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
3479 if (usId <= usIdThreshold)
3480 {
3481 // pushbutton to change:
3482 // _Pmpf((" Setting bit"));
3483 WinSetWindowBits(hwndItem,
3484 QWL_STYLE,
3485 BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
3486 brc = TRUE;
3487 }
3488 else
3489 // no pushbutton to change: move downwards
3490 // if desired
3491 if (ulDownUnits)
3492 {
3493 SWP swp;
3494 // _Pmpf(("Moving downwards %d pixels", ptl.y));
3495 WinQueryWindowPos(hwndItem, &swp);
3496 WinSetWindowPos(hwndItem, 0,
3497 swp.x,
3498 swp.y - ptl.y,
3499 0, 0,
3500 SWP_MOVE);
3501 }
3502 }
3503 WinEndEnumWindows(henum);
3504
3505 if (fIsVisible)
3506 WinShowWindow(hwndDlg, TRUE);
3507 }
3508
3509 return (brc);
3510}
3511
3512/*
3513 *@@ winhDrawFormattedText:
3514 * this func takes a rectangle and draws pszText into
3515 * it, breaking the words as neccessary. The line spacing
3516 * is determined from the font currently selected in hps.
3517 *
3518 * As opposed to WinDrawText, this can draw several lines
3519 * at once, and format the _complete_ text according to the
3520 * flCmd parameter, which is like with WinDrawText.
3521 *
3522 * After this function returns, *prcl is modified like this:
3523 * -- yTop and yBottom contain the upper and lower boundaries
3524 * which were needed to draw the text. This depends on
3525 * whether DT_TOP etc. were specified.
3526 * To get the height of the rectangle used, calculate the
3527 * delta between yTop and yBottom.
3528 *
3529 * -- xLeft and xRight are modified to contain the outmost
3530 * left and right coordinates which were needed to draw
3531 * the text. This will be set to the longest line which
3532 * was encountered.
3533 *
3534 * You can specify DT_QUERYEXTENT with flDraw to only have
3535 * these text boundaries calculated without actually drawing.
3536 *
3537 * This returns the number of lines drawn.
3538 *
3539 * Note that this calls WinDrawText with DT_TEXTATTRS set,
3540 * that is, the current text primitive attributes will be
3541 * used (fonts and colors).
3542 *
3543 *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
3544 */
3545
3546ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
3547 // are used, but not altered
3548 PRECTL prcl, // in/out: rectangle to use for drawing
3549 // (modified)
3550 PSZ pszText, // in: text to draw (zero-terminated)
3551 ULONG flCmd) // in: flags like in WinDrawText; I have
3552 // only tested DT_TOP and DT_LEFT though.
3553 // DT_WORDBREAK | DT_TEXTATTRS are always
3554 // set.
3555 // You can specify DT_QUERYEXTENT to only
3556 // have prcl calculated without drawing.
3557{
3558 PSZ p = pszText;
3559 LONG lDrawn = 1,
3560 lTotalDrawn = 0,
3561 lLineCount = 0,
3562 lOrigYTop = prcl->yTop;
3563 ULONG ulTextLen = strlen(pszText),
3564 ulCharHeight,
3565 flCmd2,
3566 xLeftmost = prcl->xRight,
3567 xRightmost = prcl->xLeft;
3568 RECTL rcl2;
3569
3570 flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
3571
3572 ulCharHeight = gpihQueryLineSpacing(hps, pszText);
3573
3574 while ( (lDrawn)
3575 && (lTotalDrawn < ulTextLen)
3576 )
3577 {
3578 memcpy(&rcl2, prcl, sizeof(rcl2));
3579 lDrawn = WinDrawText(hps,
3580 ulTextLen-lTotalDrawn,
3581 p,
3582 &rcl2,
3583 0, 0, // colors
3584 flCmd2);
3585
3586 // update char counters
3587 p += lDrawn;
3588 lTotalDrawn += lDrawn;
3589
3590 // update x extents
3591 if (rcl2.xLeft < xLeftmost)
3592 xLeftmost = rcl2.xLeft;
3593 if (rcl2.xRight > xRightmost)
3594 xRightmost = rcl2.xRight;
3595
3596 // update y for next line
3597 prcl->yTop -= ulCharHeight;
3598
3599 // increase line count
3600 lLineCount++;
3601 }
3602 prcl->xLeft = xLeftmost;
3603 prcl->xRight = xRightmost;
3604 prcl->yBottom = prcl->yTop;
3605 prcl->yTop = lOrigYTop;
3606
3607 return (lLineCount);
3608}
3609
3610/*
3611 *@@ winhQuerySwitchList:
3612 * returns the switch list in a newly
3613 * allocated buffer. This does the
3614 * regular double WinQuerySwitchList
3615 * call to first get the no. of items
3616 * and then get the items.
3617 *
3618 * The no. of items can be found in
3619 * the returned SWBLOCK.cwsentry.
3620 *
3621 * Returns NULL on errors. Use
3622 * winhFree to free the return value.
3623 *
3624 *@@added V0.9.7 (2000-12-06) [umoeller]
3625 */
3626
3627PSWBLOCK winhQuerySwitchList(HAB hab)
3628{
3629 ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
3630 ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
3631 PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
3632 if (pSwBlock)
3633 {
3634 cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
3635 if (!cItems)
3636 {
3637 free(pSwBlock);
3638 pSwBlock = NULL;
3639 }
3640 }
3641
3642 return (pSwBlock);
3643}
3644
3645/*
3646 *@@ winhQueryTasklistWindow:
3647 * returns the window handle of the PM task list.
3648 *
3649 *@@added V0.9.7 (2000-12-07) [umoeller]
3650 */
3651
3652HWND winhQueryTasklistWindow(VOID)
3653{
3654 SWBLOCK swblock;
3655 HWND hwndTasklist = winhQueryTasklistWindow();
3656 // the tasklist has entry #0 in the SWBLOCK
3657 WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
3658 return (swblock.aswentry[0].swctl.hwnd);
3659}
3660
3661/*
3662 *@@ winhKillTasklist:
3663 * this will destroy the Tasklist (window list) window.
3664 * Note: you will only be able to get it back after a
3665 * reboot, not a WPS restart. Only for use at shutdown and such.
3666 * This trick by Uri J. Stern at
3667 * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
3668 */
3669
3670VOID winhKillTasklist(VOID)
3671{
3672 HWND hwndTasklist = winhQueryTasklistWindow();
3673 WinPostMsg(hwndTasklist,
3674 0x0454, // undocumented msg for killing tasklist
3675 NULL, NULL);
3676}
3677
3678// the following must be added for EMX (99-10-22) [umoeller]
3679#ifndef NERR_BufTooSmall
3680 #define NERR_BASE 2100
3681 #define NERR_BufTooSmall (NERR_BASE+23)
3682 // the API return buffer is too small
3683#endif
3684
3685/*
3686 *@@ winhQueryPendingSpoolJobs:
3687 * returns the number of pending print jobs in the spooler
3688 * or 0 if none. Useful for testing before shutdown.
3689 */
3690
3691ULONG winhQueryPendingSpoolJobs(VOID)
3692{
3693 // BOOL rcPending = FALSE;
3694 ULONG ulTotalJobCount = 0;
3695
3696 SPLERR splerr;
3697 USHORT jobCount;
3698 ULONG cbBuf;
3699 ULONG cTotal;
3700 ULONG cReturned;
3701 ULONG cbNeeded;
3702 ULONG ulLevel;
3703 ULONG i,j;
3704 PSZ pszComputerName;
3705 PBYTE pBuf = NULL;
3706 PPRQINFO3 prq;
3707 PPRJINFO2 prj2;
3708
3709 ulLevel = 4L;
3710 pszComputerName = (PSZ)NULL;
3711 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
3712 &cReturned, &cTotal,
3713 &cbNeeded, NULL);
3714 if ( (splerr == ERROR_MORE_DATA)
3715 || (splerr == NERR_BufTooSmall)
3716 )
3717 {
3718 if (!DosAllocMem((PPVOID)&pBuf,
3719 cbNeeded,
3720 PAG_READ | PAG_WRITE | PAG_COMMIT))
3721 {
3722 cbBuf = cbNeeded;
3723 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
3724 &cReturned, &cTotal,
3725 &cbNeeded, NULL);
3726 if (splerr == NO_ERROR)
3727 {
3728 // set pointer to point to the beginning of the buffer
3729 prq = (PPRQINFO3)pBuf;
3730
3731 // cReturned has the count of the number of PRQINFO3 structures
3732 for (i = 0;
3733 i < cReturned;
3734 i++)
3735 {
3736 // save the count of jobs; there are this many PRJINFO2
3737 // structures following the PRQINFO3 structure
3738 jobCount = prq->cJobs;
3739 // _Pmpf(( "Job count in this queue is %d",jobCount ));
3740
3741 // increment the pointer past the PRQINFO3 structure
3742 prq++;
3743
3744 // set a pointer to point to the first PRJINFO2 structure
3745 prj2=(PPRJINFO2)prq;
3746 for (j = 0;
3747 j < jobCount;
3748 j++)
3749 {
3750 // increment the pointer to point to the next structure
3751 prj2++;
3752 // increase the job count, which we'll return
3753 ulTotalJobCount++;
3754
3755 } // endfor jobCount
3756
3757 // after doing all the job structures, prj2 points to the next
3758 // queue structure; set the pointer for a PRQINFO3 structure
3759 prq = (PPRQINFO3)prj2;
3760 } //endfor cReturned
3761 } // endif NO_ERROR
3762 DosFreeMem(pBuf);
3763 }
3764 } // end if Q level given
3765
3766 return (ulTotalJobCount);
3767}
3768
3769/*
3770 *@@ winhSetNumLock:
3771 * this sets the NumLock key on or off, depending
3772 * on fState.
3773 *
3774 * Based on code from WarpEnhancer, (C) Achim Hasenmller.
3775 *
3776 *@@added V0.9.1 (99-12-18) [umoeller]
3777 */
3778
3779VOID winhSetNumLock(BOOL fState)
3780{
3781 // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
3782 BYTE KeyStateTable[256];
3783 ULONG ulActionTaken; // Used by DosOpen
3784 HFILE hKbd;
3785
3786 // read keyboard state table
3787 if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
3788 FALSE))
3789 {
3790 // first set the PM state
3791 if (fState)
3792 KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
3793 else
3794 KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
3795
3796 // set keyboard state table with new state values
3797 WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
3798 }
3799
3800 // now set the OS/2 keyboard state
3801
3802 // try to open OS/2 keyboard driver
3803 if (!DosOpen("KBD$",
3804 &hKbd, &ulActionTaken,
3805 0, // cbFile
3806 FILE_NORMAL,
3807 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
3808 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
3809 NULL))
3810 {
3811 SHIFTSTATE ShiftState;
3812 ULONG DataLen = sizeof(SHIFTSTATE);
3813
3814 memset(&ShiftState, '\0', DataLen);
3815 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
3816 NULL, 0L, NULL,
3817 &ShiftState, DataLen, &DataLen);
3818
3819 if (fState)
3820 ShiftState.fsState |= 0x0020; // turn NumLock on
3821 else
3822 ShiftState.fsState &= 0xFFDF; // turn NumLock off
3823
3824 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
3825 &ShiftState, DataLen, &DataLen,
3826 NULL, 0L, NULL);
3827 // now close OS/2 keyboard driver
3828 DosClose(hKbd);
3829 }
3830 return;
3831}
3832
3833/*
3834 *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
3835 */
3836
3837/* ******************************************************************
3838 *
3839 * WPS Class List helpers
3840 *
3841 ********************************************************************/
3842
3843/*
3844 *@@ winhQueryWPSClassList:
3845 * this returns the WPS class list in a newly
3846 * allocated buffer. This is just a shortcut to
3847 * the usual double WinEnumObjectClasses call.
3848 *
3849 * The return value is actually of the POBJCLASS type,
3850 * so you better cast this manually. We declare this
3851 * this as PBYTE though because POBJCLASS requires
3852 * INCL_WINWORKPLACE.
3853 * See WinEnumObjectClasses() for details.
3854 *
3855 * Returns NULL on error. Use winhFree()
3856 * to free the return value.
3857 *
3858 *@@added V0.9.0 [umoeller]
3859 */
3860
3861PBYTE winhQueryWPSClassList(VOID)
3862{
3863 ULONG ulSize;
3864 POBJCLASS pObjClass = 0;
3865
3866 // get WPS class list size
3867 if (WinEnumObjectClasses(NULL, &ulSize))
3868 {
3869 // allocate buffer
3870 pObjClass = (POBJCLASS)malloc(ulSize+1);
3871 // and load the classes into it
3872 WinEnumObjectClasses(pObjClass, &ulSize);
3873 }
3874
3875 return ((PBYTE)pObjClass);
3876}
3877
3878/*
3879 *@@ winhQueryWPSClass:
3880 * this returns the POBJCLASS item if pszClass is registered
3881 * with the WPS or NULL if the class could not be found.
3882 *
3883 * The return value is actually of the POBJCLASS type,
3884 * so you better cast this manually. We declare this
3885 * this as PBYTE though because POBJCLASS requires
3886 * INCL_WINWORKPLACE.
3887 *
3888 * This takes as input the return value of winhQueryWPSClassList,
3889 * which you must call first.
3890 *
3891 * <B>Usage:</B>
3892 + PBYTE pClassList = winhQueryWPSClassList(),
3893 + pWPFolder;
3894 + if (pClassList)
3895 + {
3896 + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
3897 + ...
3898 + free(pClassList);
3899 + }
3900 *
3901 *@@added V0.9.0 [umoeller]
3902 */
3903
3904PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
3905 // winhQueryWPSClassList
3906 const char *pszClass) // in: class name to query
3907{
3908 PBYTE pbReturn = 0;
3909
3910 POBJCLASS pocThis = (POBJCLASS)pObjClass;
3911 // now go thru the WPS class list
3912 while (pocThis)
3913 {
3914 if (strcmp(pocThis->pszClassName, pszClass) == 0)
3915 {
3916 pbReturn = (PBYTE)pocThis;
3917 break;
3918 }
3919 // next class
3920 pocThis = pocThis->pNext;
3921 } // end while (pocThis)
3922
3923 return (pbReturn);
3924}
3925
3926/*
3927 *@@ winhRegisterClass:
3928 * this works just like WinRegisterObjectClass,
3929 * except that it returns a more meaningful
3930 * error code than just FALSE in case registering
3931 * fails.
3932 *
3933 * This returns NO_ERROR if the class was successfully
3934 * registered (WinRegisterObjectClass returned TRUE).
3935 *
3936 * Otherwise, we do a DosLoadModule if maybe the DLL
3937 * couldn't be loaded in the first place. If DosLoadModule
3938 * did not return NO_ERROR, this function returns that
3939 * return code, which can be:
3940 *
3941 * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
3942 * -- 2 ERROR_FILE_NOT_FOUND
3943 * -- 3 ERROR_PATH_NOT_FOUND
3944 * -- 4 ERROR_TOO_MANY_OPEN_FILES
3945 * -- 5 ERROR_ACCESS_DENIED
3946 * -- 8 ERROR_NOT_ENOUGH_MEMORY
3947 * -- 11 ERROR_BAD_FORMAT
3948 * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
3949 * -- 32 ERROR_SHARING_VIOLATION
3950 * -- 33 ERROR_LOCK_VIOLATION
3951 * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
3952 * -- 95 ERROR_INTERRUPT (interrupted system call)
3953 * -- 108 ERROR_DRIVE_LOCKED (by another process)
3954 * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
3955 * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
3956 * -- 180 ERROR_INVALID_SEGMENT_NUMBER
3957 * -- 182 ERROR_INVALID_ORDINAL
3958 * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
3959 * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
3960 * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
3961 * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
3962 * -- 195 ERROR_INVALID_MINALLOCSIZE
3963 * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
3964 * -- 198 ERROR_INVALID_SEGDPL
3965 * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
3966 * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
3967 * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
3968 * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
3969 *
3970 * In all these cases, pszBuf may contain a meaningful
3971 * error message from DosLoadModule, especially if an import
3972 * could not be resolved.
3973 *
3974 * Still worse, if DosLoadModule returned NO_ERROR, we
3975 * probably have some SOM internal error. A probable
3976 * reason is that the parent class of pcszClassName
3977 * is not installed, but that's WPS/SOM internal
3978 * and cannot be queried from outside the WPS context.
3979 *
3980 * In that case, ERROR_OPEN_FAILED (110) is returned.
3981 * That one sounded good to me. ;-)
3982 */
3983
3984APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
3985 const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
3986 PSZ pszBuf, // out: error message from DosLoadModule
3987 ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
3988{
3989 APIRET arc = NO_ERROR;
3990
3991 if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
3992 {
3993 // failed: do more error checking then, try DosLoadModule
3994 HMODULE hmod = NULLHANDLE;
3995 arc = DosLoadModule(pszBuf, cbBuf,
3996 (PSZ)pcszModule,
3997 &hmod);
3998 if (arc == NO_ERROR)
3999 {
4000 // DosLoadModule succeeded:
4001 // some SOM error then
4002 DosFreeModule(hmod);
4003 arc = ERROR_OPEN_FAILED;
4004 }
4005 }
4006 // else: ulrc still 0 (== no error)
4007
4008 return (arc);
4009}
4010
4011/*
4012 *@@ winhIsClassRegistered:
4013 * quick one-shot function which checks if
4014 * a class is currently registered. Calls
4015 * winhQueryWPSClassList and winhQueryWPSClass
4016 * in turn.
4017 *
4018 *@@added V0.9.2 (2000-02-26) [umoeller]
4019 */
4020
4021BOOL winhIsClassRegistered(const char *pcszClass)
4022{
4023 BOOL brc = FALSE;
4024 PBYTE pClassList = winhQueryWPSClassList();
4025 if (pClassList)
4026 {
4027 if (winhQueryWPSClass(pClassList, pcszClass))
4028 brc = TRUE;
4029 free(pClassList);
4030 }
4031
4032 return (brc);
4033}
4034
4035/*
4036 *@@category: Helpers\PM helpers\Workplace Shell
4037 */
4038
4039/*
4040 *@@ winhResetWPS:
4041 * restarts the WPS using PrfReset. Returns
4042 * one of the following:
4043 *
4044 * -- 0: no error.
4045 * -- 1: PrfReset failed.
4046 * -- 2 or 4: PrfQueryProfile failed.
4047 * -- 3: malloc() failed.
4048 *
4049 *@@added V0.9.4 (2000-07-01) [umoeller]
4050 */
4051
4052ULONG winhResetWPS(HAB hab)
4053{
4054 ULONG ulrc = 0;
4055 // find out current profile names
4056 PRFPROFILE Profiles;
4057 Profiles.cchUserName = Profiles.cchSysName = 0;
4058 // first query their file name lengths
4059 if (PrfQueryProfile(hab, &Profiles))
4060 {
4061 // allocate memory for filenames
4062 Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
4063 Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
4064
4065 if (Profiles.pszSysName)
4066 {
4067 // get filenames
4068 if (PrfQueryProfile(hab, &Profiles))
4069 {
4070
4071 // "change" INIs to these filenames:
4072 // THIS WILL RESET THE WPS
4073 if (PrfReset(hab, &Profiles) == FALSE)
4074 ulrc = 1;
4075 free(Profiles.pszSysName);
4076 free(Profiles.pszUserName);
4077 }
4078 else
4079 ulrc = 2;
4080 }
4081 else
4082 ulrc = 3;
4083 }
4084 else
4085 ulrc = 4;
4086
4087 return (ulrc);
4088}
Note: See TracBrowser for help on using the repository browser.