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

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

Final changes for 0.9.7, i hope...

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 146.4 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 *@@changed V0.9.7 (2000-12-20) [umoeller]: fixed invalid params if INI key not found
1612 */
1613
1614BOOL winhRestoreWindowPos(HWND hwnd, // in: window to restore
1615 HINI hIni, // in: INI file (or HINI_USER/SYSTEM)
1616 PSZ pszApp, // in: INI application name
1617 PSZ pszKey, // in: INI key name
1618 ULONG fl) // in: "fl" parameter for WinSetWindowPos
1619{
1620 BOOL brc = FALSE;
1621 SWP swp;
1622 ULONG cbswp = sizeof(swp);
1623 ULONG fl2 = (fl & ~SWP_ZORDER);
1624
1625 if (PrfQueryProfileData(hIni, pszApp, pszKey, &swp, &cbswp))
1626 {
1627 ULONG ulScreenCX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
1628 ULONG ulScreenCY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
1629
1630 brc = TRUE;
1631
1632 if ((fl & SWP_SIZE) == 0)
1633 {
1634 // if no resize, we need to get the current position
1635 SWP swpNow;
1636 brc = WinQueryWindowPos(hwnd, &swpNow);
1637 swp.cx = swpNow.cx;
1638 swp.cy = swpNow.cy;
1639 }
1640
1641 if (brc)
1642 {
1643 // check for full visibility
1644 if ( (swp.x + swp.cx) > ulScreenCX)
1645 swp.x = ulScreenCX - swp.cx;
1646 if ( (swp.y + swp.cy) > ulScreenCY)
1647 swp.y = ulScreenCY - swp.cy;
1648 }
1649
1650 brc = TRUE;
1651
1652 }
1653 else
1654 {
1655 // window pos not found in INI: unset SWP_MOVE etc.
1656 WinQueryWindowPos(hwnd, &swp);
1657 fl2 &= ~(SWP_MOVE | SWP_SIZE);
1658 }
1659
1660 WinSetWindowPos(hwnd,
1661 NULLHANDLE, // insert-behind window
1662 swp.x,
1663 swp.y,
1664 swp.cx,
1665 swp.cy,
1666 fl2); // SWP_* flags
1667
1668 return (brc);
1669}
1670
1671/*
1672 *@@ winhAdjustControls:
1673 * helper function for dynamically adjusting a window's
1674 * controls when the window is resized.
1675 *
1676 * This is most useful with dialogs loaded from resources
1677 * which should be sizeable. Normally, when the dialog
1678 * frame is resized, the controls stick to their positions,
1679 * and for dialogs with many controls, programming the
1680 * changes can be tiresome.
1681 *
1682 * Enter this function. ;-) Basically, this takes a
1683 * static array of MPARAM's as input (plus one dynamic
1684 * storage area for the window positions).
1685 *
1686 * This function must get called in three contexts:
1687 * during WM_INITDLG, during WM_WINDOWPOSCHANGED, and
1688 * during WM_DESTROY, with varying parameters.
1689 *
1690 * In detail, there are four things you need to do to make
1691 * this work:
1692 *
1693 * 1) Set up a static array (as a global variable) of
1694 * MPARAM's, one for each control in your array.
1695 * Each MPARAM will have the control's ID and the
1696 * XAF* flags (winh.h) how the control shall be moved.
1697 * Use MPFROM2SHORT to easily create this. Example:
1698 *
1699 + MPARAM ampControlFlags[] =
1700 + { MPFROM2SHORT(ID_CONTROL_1, XAC_MOVEX),
1701 + MPFROM2SHORT(ID_CONTROL_2, XAC_SIZEY),
1702 + ...
1703 + }
1704 *
1705 * This can safely be declared as a global variable
1706 * because this data will only be read and never
1707 * changed by this function.
1708 *
1709 * 2) In WM_INITDLG of your dialog function, set up
1710 * an XADJUSTCTRLS structure, preferrably in your
1711 * window words (QWL_USER).
1712 *
1713 * ZERO THAT STRUCTURE (memset(&xac, 0, sizeof(XADJUSTCTRLS),
1714 * or this func will not work.
1715 *
1716 * Call this function with pswpNew == NULL and
1717 * pxac pointing to that new structure. This will
1718 * query the positions of all the controls listed
1719 * in the MPARAMs array and store them in the
1720 * XADJUSTCTRLS area.
1721 *
1722 * 3) Intercept WM_WINDOWPOSCHANGED:
1723 *
1724 + case WM_WINDOWPOSCHANGED:
1725 + {
1726 + // this msg is passed two SWP structs:
1727 + // one for the old, one for the new data
1728 + // (from PM docs)
1729 + PSWP pswpNew = PVOIDFROMMP(mp1);
1730 + PSWP pswpOld = pswpNew + 1;
1731 +
1732 + // resizing?
1733 + if (pswpNew->fl & SWP_SIZE)
1734 + {
1735 + PXADJUSTCTRLS pxac = ... // get it from your window words
1736 +
1737 + winhAdjustControls(hwndDlg, // dialog
1738 + ampControlFlags, // MPARAMs array
1739 + sizeof(ampControlFlags) / sizeof(MPARAM),
1740 + // items count
1741 + pswpNew, // mp1
1742 + pxac); // storage area
1743 + }
1744 + mrc = WinDefDlgProc(hwnd, msg, mp1, mp2); ...
1745 *
1746 * 4) In WM_DESTROY, call this function again with pmpFlags,
1747 * pswpNew, and pswpNew set to NULL. This will clean up the
1748 * data which has been allocated internally (pointed to from
1749 * the XADJUSTCTRLS structure).
1750 * Don't forget to free your storage for XADJUSTCTLRS
1751 * _itself_, that's the job of the caller.
1752 *
1753 * This might sound complicated, but it's a lot easier than
1754 * having to write dozens of WinSetWindowPos calls oneself.
1755 *
1756 *@@added V0.9.0 [umoeller]
1757 */
1758
1759BOOL winhAdjustControls(HWND hwndDlg, // in: dialog (req.)
1760 MPARAM *pmpFlags, // in: init flags or NULL for cleanup
1761 ULONG ulCount, // in: item count (req.)
1762 PSWP pswpNew, // in: pswpNew from WM_WINDOWPOSCHANGED or NULL for cleanup
1763 PXADJUSTCTRLS pxac) // in: adjust-controls storage area (req.)
1764{
1765 BOOL brc = FALSE;
1766 ULONG ul = 0;
1767
1768 /* if (!WinIsWindowVisible(hwndDlg))
1769 return (FALSE); */
1770
1771 if ((pmpFlags) && (pxac))
1772 {
1773 PSWP pswpThis;
1774 MPARAM *pmpThis;
1775 LONG ldcx, ldcy;
1776 ULONG cWindows = 0;
1777
1778 // setup mode:
1779 if (pxac->fInitialized == FALSE)
1780 {
1781 // first call: get all the SWP's
1782 WinQueryWindowPos(hwndDlg, &pxac->swpMain);
1783 // _Pmpf(("winhAdjustControls: queried main cx = %d, cy = %d",
1784 // pxac->swpMain.cx, pxac->swpMain.cy));
1785
1786 pxac->paswp = (PSWP)malloc(sizeof(SWP) * ulCount);
1787
1788 pswpThis = pxac->paswp;
1789 pmpThis = pmpFlags;
1790
1791 for (ul = 0;
1792 ul < ulCount;
1793 ul++)
1794 {
1795 HWND hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis));
1796 if (hwndThis)
1797 {
1798 WinQueryWindowPos(hwndThis, pswpThis);
1799 cWindows++;
1800 }
1801
1802 pswpThis++;
1803 pmpThis++;
1804 }
1805
1806 pxac->fInitialized = TRUE;
1807 // _Pmpf(("winhAdjustControls: queried %d controls", cWindows));
1808 }
1809
1810 if (pswpNew)
1811 {
1812 // compute width and height delta
1813 ldcx = (pswpNew->cx - pxac->swpMain.cx);
1814 ldcy = (pswpNew->cy - pxac->swpMain.cy);
1815
1816 // _Pmpf(("winhAdjustControls: new cx = %d, cy = %d",
1817 // pswpNew->cx, pswpNew->cy));
1818
1819 // now adjust the controls
1820 cWindows = 0;
1821 pswpThis = pxac->paswp;
1822 pmpThis = pmpFlags;
1823 for (ul = 0;
1824 ul < ulCount;
1825 ul++)
1826 {
1827 HWND hwndThis = WinWindowFromID(hwndDlg, SHORT1FROMMP(*pmpThis));
1828 if (hwndThis)
1829 {
1830 LONG x = pswpThis->x,
1831 y = pswpThis->y,
1832 cx = pswpThis->cx,
1833 cy = pswpThis->cy;
1834
1835 ULONG ulSwpFlags = 0;
1836 // get flags for this control
1837 USHORT usFlags = SHORT2FROMMP(*pmpThis);
1838
1839 if (usFlags & XAC_MOVEX)
1840 {
1841 x += ldcx;
1842 ulSwpFlags |= SWP_MOVE;
1843 }
1844 if (usFlags & XAC_MOVEY)
1845 {
1846 y += ldcy;
1847 ulSwpFlags |= SWP_MOVE;
1848 }
1849 if (usFlags & XAC_SIZEX)
1850 {
1851 cx += ldcx;
1852 ulSwpFlags |= SWP_SIZE;
1853 }
1854 if (usFlags & XAC_SIZEY)
1855 {
1856 cy += ldcy;
1857 ulSwpFlags |= SWP_SIZE;
1858 }
1859
1860 if (ulSwpFlags)
1861 {
1862 WinSetWindowPos(hwndThis,
1863 NULLHANDLE, // hwndInsertBehind
1864 x, y, cx, cy,
1865 ulSwpFlags);
1866 cWindows++;
1867 brc = TRUE;
1868 }
1869 }
1870
1871 pswpThis++;
1872 pmpThis++;
1873 }
1874
1875 // _Pmpf(("winhAdjustControls: set %d windows", cWindows));
1876 }
1877 }
1878 else
1879 {
1880 // pxac == NULL:
1881 // cleanup mode
1882 if (pxac->paswp)
1883 free(pxac->paswp);
1884 }
1885
1886 return (brc);
1887}
1888
1889/*
1890 *@@ winhCenterWindow:
1891 * centers a window within its parent window. If that's
1892 * the PM desktop, it will be centered according to the
1893 * whole screen.
1894 * For dialog boxes, use WinCenteredDlgBox as a one-shot
1895 * function.
1896 *
1897 * Note: When calling this function, the window should
1898 * not be visible to avoid flickering.
1899 * This func does not show the window either, so call
1900 * WinShowWindow afterwards.
1901 */
1902
1903void winhCenterWindow(HWND hwnd)
1904{
1905 RECTL rclParent;
1906 RECTL rclWindow;
1907
1908 WinQueryWindowRect(hwnd, &rclWindow);
1909 WinQueryWindowRect(WinQueryWindow(hwnd, QW_PARENT), &rclParent);
1910
1911 rclWindow.xLeft = (rclParent.xRight - rclWindow.xRight) / 2;
1912 rclWindow.yBottom = (rclParent.yTop - rclWindow.yTop ) / 2;
1913
1914 WinSetWindowPos(hwnd, NULLHANDLE, rclWindow.xLeft, rclWindow.yBottom,
1915 0, 0, SWP_MOVE);
1916}
1917
1918/*
1919 *@@ winhCenteredDlgBox:
1920 * just like WinDlgBox, but the dlg box is centered on the screen;
1921 * you should mark the dlg template as not visible in the dlg
1922 * editor, or display will flicker.
1923 * As opposed to winhCenterWindow, this _does_ show the window.
1924 */
1925
1926ULONG winhCenteredDlgBox(HWND hwndParent,
1927 HWND hwndOwner,
1928 PFNWP pfnDlgProc,
1929 HMODULE hmod,
1930 ULONG idDlg,
1931 PVOID pCreateParams)
1932{
1933 ULONG ulReply;
1934 HWND hwndDlg = WinLoadDlg(hwndParent,
1935 hwndOwner,
1936 pfnDlgProc,
1937 hmod,
1938 idDlg,
1939 pCreateParams);
1940 winhCenterWindow(hwndDlg);
1941 ulReply = WinProcessDlg(hwndDlg);
1942 WinDestroyWindow(hwndDlg);
1943 return (ulReply);
1944}
1945
1946/*
1947 *@@ winhFindWindowBelow:
1948 * finds the window with the same parent
1949 * which sits right below hwndFind in the
1950 * window Z-order.
1951 *
1952 *@@added V0.9.7 (2000-12-04) [umoeller]
1953 */
1954
1955HWND winhFindWindowBelow(HWND hwndFind)
1956{
1957 HWND hwnd = NULLHANDLE,
1958 hwndParent = WinQueryWindow(hwndFind, QW_PARENT);
1959
1960 if (hwndParent)
1961 {
1962 HENUM henum = WinBeginEnumWindows(hwndParent);
1963 HWND hwndThis;
1964 while (hwndThis = WinGetNextWindow(henum))
1965 {
1966 SWP swp;
1967 WinQueryWindowPos(hwndThis, &swp);
1968 if (swp.hwndInsertBehind == hwndFind)
1969 {
1970 hwnd = hwndThis;
1971 break;
1972 }
1973 }
1974 WinEndEnumWindows(henum);
1975 }
1976
1977 return (hwnd);
1978}
1979
1980/*
1981 *@@category: Helpers\PM helpers\Presentation parameters
1982 */
1983
1984/* ******************************************************************
1985 *
1986 * Presparams helpers
1987 *
1988 ********************************************************************/
1989
1990/*
1991 *@@ winhQueryWindowFont:
1992 * returns the window font presentation parameter
1993 * in a newly allocated buffer.
1994 *
1995 * Returns NULL on error. Use winhFree()
1996 * to free the return value.
1997 *
1998 *@@added V0.9.1 (2000-02-14) [umoeller]
1999 */
2000
2001PSZ winhQueryWindowFont(HWND hwnd)
2002{
2003 CHAR szNewFont[100] = "";
2004 WinQueryPresParam(hwnd,
2005 PP_FONTNAMESIZE,
2006 0,
2007 NULL,
2008 (ULONG)sizeof(szNewFont),
2009 (PVOID)&szNewFont,
2010 QPF_NOINHERIT);
2011 if (szNewFont[0] != 0)
2012 return (strdup(szNewFont));
2013
2014 return (NULL);
2015}
2016
2017/*
2018 *@@ winhSetWindowFont:
2019 * this sets a window's font by invoking
2020 * WinSetPresParam on it.
2021 *
2022 * If (pszFont == NULL), a default font will be set
2023 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2024 *
2025 * winh.h also defines the winhSetDlgItemFont macro.
2026 *
2027 * Returns TRUE if successful or FALSE otherwise.
2028 *
2029 *@@added V0.9.0 [umoeller]
2030 */
2031
2032BOOL winhSetWindowFont(HWND hwnd,
2033 const char *pcszFont)
2034{
2035 CHAR szFont[256];
2036
2037 if (pcszFont == NULL)
2038 {
2039 if (doshIsWarp4())
2040 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
2041 else
2042 strhncpy0(szFont, "8.Helv", sizeof(szFont));
2043 }
2044 else
2045 strhncpy0(szFont, pcszFont, sizeof(szFont));
2046
2047 return (WinSetPresParam(hwnd,
2048 PP_FONTNAMESIZE,
2049 strlen(szFont)+1,
2050 szFont));
2051}
2052
2053/*
2054 *@@ winhSetControlsFont:
2055 * this sets the font for all the controls of hwndDlg
2056 * which have a control ID in the range of usIDMin to
2057 * usIDMax. "Unused" IDs (i.e. -1) will also be set.
2058 *
2059 * If (pszFont == NULL), a default font will be set
2060 * (on Warp 4, "9.WarpSans", on Warp 3, "8.Helv").
2061 *
2062 * Returns the no. of controls set.
2063 *
2064 *@@added V0.9.0 [umoeller]
2065 */
2066
2067ULONG winhSetControlsFont(HWND hwndDlg, // in: dlg to set
2068 SHORT usIDMin, // in: minimum control ID to be set (inclusive)
2069 SHORT usIDMax, // in: maximum control ID to be set (inclusive)
2070 const char *pcszFont) // in: font to use (e.g. "9.WarpSans") or NULL
2071{
2072 ULONG ulrc = 0;
2073 HENUM henum;
2074 HWND hwndItem;
2075 CHAR szFont[256];
2076 ULONG cbFont;
2077
2078 if (pcszFont == NULL)
2079 {
2080 if (doshIsWarp4())
2081 strhncpy0(szFont, "9.WarpSans", sizeof(szFont));
2082 else
2083 strhncpy0(szFont, "8.Helv", sizeof(szFont));
2084 }
2085 else
2086 strhncpy0(szFont, pcszFont, sizeof(szFont));
2087 cbFont = strlen(szFont)+1;
2088
2089 // set font for all the dialog controls
2090 henum = WinBeginEnumWindows(hwndDlg);
2091 while ((hwndItem = WinGetNextWindow(henum)))
2092 {
2093 SHORT sID = WinQueryWindowUShort(hwndItem, QWS_ID);
2094 if ( (sID == -1)
2095 || ((sID >= usIDMin) && (sID <= usIDMax))
2096 )
2097 if (WinSetPresParam(hwndItem,
2098 PP_FONTNAMESIZE,
2099 cbFont,
2100 szFont))
2101 // successful:
2102 ulrc++;
2103 }
2104 WinEndEnumWindows(henum);
2105 return (ulrc);
2106}
2107
2108/*
2109 *@@ winhStorePresParam:
2110 * this appends a new presentation parameter to an
2111 * array of presentation parameters which can be
2112 * passed to WinCreateWindow. This is preferred
2113 * over setting the presparams using WinSetPresParams,
2114 * because that call will cause a lot of messages.
2115 *
2116 * On the first call, pppp _must_ be NULL. This
2117 * will allocate memory for storing the given
2118 * data as necessary and modify *pppp to point
2119 * to the new array.
2120 *
2121 * On subsequent calls with the same pppp, memory
2122 * will be reallocated, the old data will be copied,
2123 * and the new given data will be appended.
2124 *
2125 * Use free() on your PPRESPARAMS pointer (whose
2126 * address was passed) after WinCreateWindow.
2127 *
2128 * See winhQueryPresColor for typical presparams
2129 * used in OS/2.
2130 *
2131 * Example:
2132 *
2133 + PPRESPARAMS ppp = NULL;
2134 + CHAR szFont[] = "9.WarpSans";
2135 + LONG lColor = CLR_WHITE;
2136 + winhStorePresParam(&ppp, PP_FONTNAMESIZE, sizeof(szFont), szFont);
2137 + winhStorePresParam(&ppp, PP_BACKGROUNDCOLOR, sizeof(lColor), &lColor);
2138 + WinCreateWindow(...., ppp);
2139 + free(ppp);
2140 *
2141 *@@added V0.9.0 [umoeller]
2142 */
2143
2144BOOL winhStorePresParam(PPRESPARAMS *pppp, // in: data pointer (modified)
2145 ULONG ulAttrType, // in: PP_* index
2146 ULONG cbData, // in: sizeof(*pData), e.g. sizeof(LONG)
2147 PVOID pData) // in: presparam data (e.g. a PLONG to a color)
2148{
2149 BOOL brc = FALSE;
2150 if (pppp)
2151 {
2152 ULONG cbOld = 0,
2153 cbNew;
2154 PBYTE pbTemp = 0;
2155 PPRESPARAMS pppTemp = 0;
2156 PPARAM pppCopyTo = 0;
2157
2158 if (*pppp != NULL)
2159 // subsequent calls:
2160 cbOld = (**pppp).cb;
2161
2162 cbNew = sizeof(ULONG) // PRESPARAMS.cb
2163 + cbOld // old count, which does not include PRESPARAMS.cb
2164 + sizeof(ULONG) // PRESPARAMS.aparam[0].id
2165 + sizeof(ULONG) // PRESPARAMS.aparam[0].cb
2166 + cbData; // PRESPARAMS.aparam[0].ab[]
2167
2168 pbTemp = (PBYTE)malloc(cbNew);
2169 if (pbTemp)
2170 {
2171 pppTemp = (PPRESPARAMS)pbTemp;
2172
2173 if (*pppp != NULL)
2174 {
2175 // copy old data
2176 memcpy(pbTemp, *pppp, cbOld + sizeof(ULONG)); // including PRESPARAMS.cb
2177 pppCopyTo = (PPARAM)(pbTemp // new buffer
2178 + sizeof(ULONG) // skipping PRESPARAMS.cb
2179 + cbOld); // old PARAM array
2180 }
2181 else
2182 // first call:
2183 pppCopyTo = pppTemp->aparam;
2184
2185 pppTemp->cb = cbNew - sizeof(ULONG); // excluding PRESPARAMS.cb
2186 pppCopyTo->id = ulAttrType;
2187 pppCopyTo->cb = cbData; // byte count of PARAM.ab[]
2188 memcpy(pppCopyTo->ab, pData, cbData);
2189
2190 free(*pppp);
2191 *pppp = pppTemp;
2192
2193 brc = TRUE;
2194 }
2195 }
2196 return (brc);
2197}
2198
2199/*
2200 *@@ winhQueryPresColor:
2201 * returns the specified color. This is queried in the
2202 * following order:
2203 *
2204 * 1) hwnd's pres params are searched for ulPP
2205 * (which should be a PP_* index);
2206 * 2) if (fInherit == TRUE), the parent windows
2207 * are searched also;
2208 * 3) if this fails or (fInherit == FALSE), WinQuerySysColor
2209 * is called to get lSysColor (which should be a SYSCLR_*
2210 * index), if lSysColor != -1;
2211 * 4) if (lSysColor == -1), -1 is returned.
2212 *
2213 * The return value is always an RGB LONG, _not_ a color index.
2214 * This is even true for the returned system colors, which are
2215 * converted to RGB.
2216 *
2217 * If you do any painting with this value, you should switch
2218 * the HPS you're using to RGB mode (use gpihSwitchToRGB for that).
2219 *
2220 * Some useful ulPP / lSysColor pairs
2221 * (default values as in PMREF):
2222 *
2223 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT (for most controls also)
2224 + SYSCLR_WINDOWSTATICTEXT (for static controls)
2225 + Foreground color (default: black)
2226 + -- PP_BACKGROUNDCOLOR SYSCLR_BACKGROUND
2227 + SYSCLR_DIALOGBACKGROUND
2228 + SYSCLR_FIELDBACKGROUND (for disabled scrollbars)
2229 + SYSCLR_WINDOW (application surface -- empty clients)
2230 + Background color (default: light gray)
2231 + -- PP_ACTIVETEXTFGNDCOLOR
2232 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
2233 + Highlighted foreground color, for example for selected menu
2234 + (def.: white)
2235 + -- PP_ACTIVETEXTBGNDCOLOR
2236 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
2237 + Highlighted background color (def.: dark gray)
2238 + -- PP_INACTIVETEXTFGNDCOLOR
2239 + -- PP_DISABLEDFOREGROUNDCOLOR SYSCLR_MENUDISABLEDTEXT
2240 + Disabled foreground color (dark gray)
2241 + -- PP_INACTIVETEXTBGNDCOLOR
2242 + -- PP_DISABLEDBACKGROUNDCOLOR
2243 + Disabled background color
2244 + -- PP_BORDERCOLOR SYSCLR_WINDOWFRAME
2245 + SYSCLR_INACTIVEBORDER
2246 + Border color (around pushbuttons, in addition to
2247 + the 3D colors)
2248 + -- PP_ACTIVECOLOR SYSCLR_ACTIVETITLE
2249 + Active color
2250 + -- PP_INACTIVECOLOR SYSCLR_INACTIVETITLE
2251 + Inactive color
2252 *
2253 * For menus:
2254 + -- PP_MENUBACKGROUNDCOLOR SYSCLR_MENU
2255 + -- PP_MENUFOREGROUNDCOLOR SYSCLR_MENUTEXT
2256 + -- PP_MENUHILITEBGNDCOLOR SYSCLR_MENUHILITEBGND
2257 + -- PP_MENUHILITEFGNDCOLOR SYSCLR_MENUHILITE
2258 + -- ?? SYSCLR_MENUDISABLEDTEXT
2259 +
2260 * For containers (according to the API ref. at EDM/2):
2261 + -- PP_FOREGROUNDCOLOR SYSCLR_WINDOWTEXT
2262 + -- PP_BACKGROUNDCOLOR SYSCLR_WINDOW
2263 + -- PP_HILITEFOREGROUNDCOLOR SYSCLR_HILITEFOREGROUND
2264 + -- PP_HILITEBACKGROUNDCOLOR SYSCLR_HILITEBACKGROUND
2265 + -- PP_BORDERCOLOR
2266 + (used for separator lines, eg. in Details view)
2267 + -- PP_ICONTEXTBACKGROUNDCOLOR
2268 + (column titles in Details view?!?)
2269 +
2270 * For listboxes / entryfields / MLE's:
2271 + -- PP_BACKGROUNDCOLOR SYSCLR_ENTRYFIELD
2272 *
2273 * PMREF has more of these.
2274 *
2275 *@@changed V0.9.0 [umoeller]: removed INI key query, using SYSCLR_* instead; function prototype changed
2276 *@@changed V0.9.0 [umoeller]: added fInherit parameter
2277 *@@changed V0.9.7 (2000-12-02) [umoeller]: added lSysColor == -1 support
2278 */
2279
2280LONG winhQueryPresColor(HWND hwnd, // in: window to query
2281 ULONG ulPP, // in: PP_* index
2282 BOOL fInherit, // in: search parent windows too?
2283 LONG lSysColor) // in: SYSCLR_* index
2284{
2285 ULONG ul,
2286 attrFound,
2287 abValue[32];
2288
2289 if (ulPP != (ULONG)-1)
2290 if ((ul = WinQueryPresParam(hwnd,
2291 ulPP,
2292 0,
2293 &attrFound,
2294 (ULONG)sizeof(abValue),
2295 (PVOID)&abValue,
2296 (fInherit)
2297 ? 0
2298 : QPF_NOINHERIT)))
2299 return (abValue[0]);
2300
2301 // not found: get system color
2302 if (lSysColor != -1)
2303 return (WinQuerySysColor(HWND_DESKTOP, lSysColor, 0));
2304
2305 return -1;
2306}
2307
2308/*
2309 *@@category: Helpers\PM helpers\Help (IPF)
2310 */
2311
2312/* ******************************************************************
2313 *
2314 * Help instance helpers
2315 *
2316 ********************************************************************/
2317
2318/*
2319 *@@ winhCreateHelp:
2320 * creates a help instance and connects it with the
2321 * given frame window.
2322 *
2323 * If (pszFileName == NULL), we'll retrieve the
2324 * executable's fully qualified file name and
2325 * replace the extension with .HLP simply. This
2326 * avoids the typical "Help not found" errors if
2327 * the program isn't started in its own directory.
2328 *
2329 * If you have created a help table in memory, specify it
2330 * with pHelpTable. To load a help table from the resources,
2331 * specify hmod (or NULLHANDLE) and set pHelpTable to the
2332 * following:
2333 +
2334 + (PHELPTABLE)MAKELONG(usTableID, 0xffff)
2335 *
2336 * Returns the help window handle or NULLHANDLE on errors.
2337 *
2338 * Based on an EDM/2 code snippet.
2339 *
2340 *@@added V0.9.4 (2000-07-03) [umoeller]
2341 */
2342
2343HWND winhCreateHelp(HWND hwndFrame, // in: app's frame window handle; can be NULLHANDLE
2344 PSZ pszFileName, // in: help file name or NULL
2345 HMODULE hmod, // in: module with help table or NULLHANDLE (current)
2346 PHELPTABLE pHelpTable, // in: help table or resource ID
2347 PSZ pszWindowTitle) // in: help window title or NULL
2348{
2349 PPIB ppib;
2350 PTIB ptib;
2351 HELPINIT hi;
2352 PSZ pszExt;
2353 CHAR szName[ CCHMAXPATH ];
2354 HWND hwndHelp;
2355
2356 if ( (pszFileName == NULL)
2357 // || (*pszFileName)
2358 )
2359 {
2360 DosGetInfoBlocks(&ptib, &ppib);
2361
2362 DosQueryModuleName(ppib->pib_hmte, sizeof(szName), szName);
2363
2364 pszExt = strrchr(szName, '.');
2365 if (pszExt)
2366 strcpy(pszExt, ".hlp");
2367 else
2368 strcat(szName, ".hlp");
2369
2370 pszFileName = szName;
2371 }
2372
2373 hi.cb = sizeof(HELPINIT);
2374 hi.ulReturnCode = 0;
2375 hi.pszTutorialName = NULL;
2376 hi.phtHelpTable = pHelpTable;
2377 hi.hmodHelpTableModule = hmod;
2378 hi.hmodAccelActionBarModule = NULLHANDLE;
2379 hi.idAccelTable = 0;
2380 hi.idActionBar = 0;
2381 hi.pszHelpWindowTitle = pszWindowTitle;
2382 hi.fShowPanelId = CMIC_HIDE_PANEL_ID;
2383 hi.pszHelpLibraryName = pszFileName;
2384
2385 hwndHelp = WinCreateHelpInstance(WinQueryAnchorBlock(hwndFrame),
2386 &hi);
2387 if ((hwndFrame) && (hwndHelp))
2388 {
2389 WinAssociateHelpInstance(hwndHelp, hwndFrame);
2390 }
2391
2392 return (hwndHelp);
2393}
2394
2395/*
2396 *@@ winhDestroyHelp:
2397 * destroys the help instance created by winhCreateHelp.
2398 *
2399 * Based on an EDM/2 code snippet.
2400 *
2401 *@@added V0.9.4 (2000-07-03) [umoeller]
2402 */
2403
2404void winhDestroyHelp(HWND hwndHelp,
2405 HWND hwndFrame) // can be NULLHANDLE if not used with winhCreateHelp
2406{
2407 if (hwndHelp)
2408 {
2409 if (hwndFrame)
2410 WinAssociateHelpInstance(NULLHANDLE, hwndFrame);
2411 WinDestroyHelpInstance(hwndHelp);
2412 }
2413}
2414
2415/*
2416 *@@category: Helpers\PM helpers\Application control
2417 */
2418
2419/* ******************************************************************
2420 *
2421 * Application control
2422 *
2423 ********************************************************************/
2424
2425/*
2426 *@@ CallBatchCorrectly:
2427 * fixes the specified PROGDETAILS for
2428 * command files in the executable part
2429 * by inserting /C XXX into the parameters
2430 * and setting the executable according
2431 * to an environment variable.
2432 *
2433 *@@added V0.9.6 (2000-10-16) [umoeller]
2434 */
2435
2436VOID CallBatchCorrectly(PPROGDETAILS pProgDetails,
2437 PSZ *ppszParams, // in/out: modified parameters (reallocated)
2438 const char *pcszEnvVar, // in: env var spec'g command proc
2439 // (e.g. "OS2_SHELL"); can be NULL
2440 const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
2441{
2442 // XXX.CMD file as executable:
2443 // fix args to /C XXX.CMD
2444 XSTRING strNewParams;
2445 xstrInit(&strNewParams, 200);
2446 xstrcpy(&strNewParams, "/C ");
2447 xstrcat(&strNewParams, pProgDetails->pszExecutable);
2448 if (*ppszParams)
2449 {
2450 // append old params
2451 xstrcat(&strNewParams, " ");
2452 xstrcat(&strNewParams, *ppszParams);
2453 free(*ppszParams);
2454 }
2455 *ppszParams = strNewParams.psz;
2456 // freed by caller
2457
2458 // set executable to $(OS2_SHELL)
2459 pProgDetails->pszExecutable = NULL;
2460 if (pcszEnvVar)
2461 pProgDetails->pszExecutable = getenv(pcszEnvVar);
2462 if (!pProgDetails->pszExecutable)
2463 pProgDetails->pszExecutable = (PSZ)pcszDefProc;
2464 // should be on PATH
2465}
2466
2467/*
2468 *@@ winhStartApp:
2469 * wrapper around WinStartApp which fixes the
2470 * specified PROGDETAILS to (hopefully) work
2471 * work with all executable types.
2472 *
2473 * This fixes the executable info to support:
2474 *
2475 * -- starting "*" executables (command prompts
2476 * for OS/2, DOS, Win-OS/2);
2477 *
2478 * -- starting ".CMD" and ".BAT" files as
2479 * PROGDETAILS.pszExecutable.
2480 *
2481 * This also handles and merges special and default
2482 * environments for the app to be started.
2483 * If PROGDETAILS.pszEnvironment is empty
2484 * and the application is a Win-OS/2 app,
2485 * this uses the default Win-OS/2 settings
2486 * as specified in the "Win-OS/2" WPS settings
2487 * object.
2488 *
2489 * Even though this isn't clearly said in PMREF,
2490 * PROGDETAILS.swpInitial is important:
2491 *
2492 * -- To start a session minimized, set SWP_MINIMIZE.
2493 *
2494 * -- To start a VIO session without auto-close, set
2495 * the half-documented SWP_NOAUTOCLOSE flag (0x8000)
2496 * This flag is now in the newer toolkit headers.
2497 *
2498 * Since this calls WinStartApp in turn, this
2499 * requires a message queue on the calling thread.
2500 *
2501 *@@added V0.9.6 (2000-10-16) [umoeller]
2502 *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
2503 *@@changed V0.9.7 (2000-12-17) [umoeller]: PROGDETAILS.pszEnvironment no longer zeroed
2504 */
2505
2506HAPP winhStartApp(HWND hwndNotify, // in: notify window (as with WinStartApp)
2507 const PROGDETAILS *pcProgDetails) // in: program data
2508{
2509 HAPP happ = NULLHANDLE;
2510 PSZ pszParamsPatched = NULL;
2511 BOOL fIsWindowsApp = FALSE,
2512 fIsWindowsEnhApp = FALSE;
2513 PROGDETAILS ProgDetails;
2514 PSZ pszWinOS2Env = 0;
2515
2516 memcpy(&ProgDetails, pcProgDetails, sizeof(PROGDETAILS));
2517 // pointers still point into old prog details buffer
2518 ProgDetails.Length = sizeof(PROGDETAILS);
2519 ProgDetails.progt.fbVisible = SHE_VISIBLE;
2520 // ProgDetails.pszEnvironment = 0;
2521
2522 // memset(&ProgDetails.swpInitial, 0, sizeof(SWP));
2523 // this wasn't a good idea... WPProgram stores stuff
2524 // in here, such as the "minimize on startup" -> SWP_MINIMIZE
2525
2526 // duplicate parameters...
2527 // we need this for string manipulations below...
2528 if (ProgDetails.pszParameters)
2529 pszParamsPatched = strdup(ProgDetails.pszParameters);
2530
2531 // _Pmpf((__FUNCTION__ ": old progc: 0x%lX", pcProgDetails->progt.progc));
2532 // _Pmpf((" pszTitle: %s", (ProgDetails.pszTitle) ? ProgDetails.pszTitle : NULL));
2533 // _Pmpf((" pszIcon: %s", (ProgDetails.pszIcon) ? ProgDetails.pszIcon : NULL));
2534
2535 // program type fixups
2536 switch (ProgDetails.progt.progc) // that's a ULONG
2537 {
2538 case ((ULONG)-1): // we get that sometimes...
2539 case PROG_DEFAULT:
2540 // ###
2541 break;
2542 }
2543
2544 // now try again...
2545 switch (ProgDetails.progt.progc)
2546 {
2547 case PROG_31_ENHSEAMLESSVDM: // 17
2548 case PROG_31_ENHSEAMLESSCOMMON: // 18
2549 case PROG_31_ENH: // 19
2550 fIsWindowsApp = TRUE;
2551 fIsWindowsEnhApp = TRUE;
2552 break;
2553
2554#ifndef PROG_30_STD
2555 #define PROG_30_STD (PROGCATEGORY)11
2556#endif
2557
2558#ifndef PROG_30_STDSEAMLESSVDM
2559 #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
2560#endif
2561
2562 case PROG_WINDOW_REAL: // 10
2563 case PROG_30_STD: // 11
2564 case PROG_WINDOW_AUTO: // 12
2565 case PROG_30_STDSEAMLESSVDM: // 13
2566 case PROG_30_STDSEAMLESSCOMMON: // 14
2567 case PROG_31_STDSEAMLESSVDM: // 15
2568 case PROG_31_STDSEAMLESSCOMMON: // 16
2569 case PROG_31_STD: // 20
2570 fIsWindowsApp = TRUE;
2571 break;
2572 }
2573
2574 /*
2575 * command lines fixups:
2576 *
2577 */
2578
2579 if (strcmp(ProgDetails.pszExecutable, "*") == 0)
2580 {
2581 /*
2582 * "*" for command sessions:
2583 *
2584 */
2585
2586 if (fIsWindowsEnhApp)
2587 {
2588 // enhanced Win-OS/2 session:
2589 XSTRING str2;
2590 xstrInit(&str2, 200);
2591 xstrcpy(&str2, "/3 ");
2592 if (pszParamsPatched)
2593 {
2594 // append existing params
2595 xstrcat(&str2, pszParamsPatched);
2596 free(pszParamsPatched);
2597 }
2598
2599 pszParamsPatched = str2.psz;
2600 }
2601
2602 if (fIsWindowsApp)
2603 {
2604 // cheat: WinStartApp doesn't support NULL
2605 // for Win-OS2 sessions, so manually start winos2.com
2606 ProgDetails.pszExecutable = "WINOS2.COM";
2607 // this is a DOS app, so fix this to DOS fullscreen
2608 ProgDetails.progt.progc = PROG_VDM;
2609 }
2610 else
2611 // for all other executable types
2612 // (including OS/2 and DOS sessions),
2613 // set pszExecutable to NULL; this will
2614 // have WinStartApp start a cmd shell
2615 ProgDetails.pszExecutable = NULL;
2616
2617 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
2618 else
2619 switch (ProgDetails.progt.progc)
2620 {
2621 /*
2622 * .CMD files fixups
2623 *
2624 */
2625
2626 case PROG_FULLSCREEN: // OS/2 fullscreen
2627 case PROG_WINDOWABLEVIO: // OS/2 window
2628 {
2629 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2630 if (pszExtension)
2631 {
2632 if (stricmp(pszExtension, "CMD") == 0)
2633 {
2634 CallBatchCorrectly(&ProgDetails,
2635 &pszParamsPatched,
2636 "OS2_SHELL",
2637 "CMD.EXE");
2638 }
2639 }
2640 break; }
2641
2642 case PROG_VDM: // DOS fullscreen
2643 case PROG_WINDOWEDVDM: // DOS window
2644 {
2645 PSZ pszExtension = doshGetExtension(ProgDetails.pszExecutable);
2646 if (pszExtension)
2647 {
2648 if (stricmp(pszExtension, "BAT") == 0)
2649 {
2650 CallBatchCorrectly(&ProgDetails,
2651 &pszParamsPatched,
2652 NULL,
2653 "COMMAND.COM");
2654 }
2655 }
2656 break; }
2657 } // end switch (ProgDetails.progt.progc)
2658
2659 /*
2660 * Fix environment for Win-OS/2
2661 *
2662 */
2663
2664 if ( !(xstrIsString(ProgDetails.pszEnvironment)) // env empty
2665 && (fIsWindowsApp) // and win-os2 app
2666 )
2667 {
2668 ULONG ulSize = 0;
2669 // get default environment (from Win-OS/2 settings object)
2670 // from OS2.INI
2671 PSZ pszDefEnv = prfhQueryProfileData(HINI_USER,
2672 "WINOS2",
2673 "PM_GlobalWindows31Settings",
2674 &ulSize);
2675 if (pszDefEnv)
2676 {
2677 PSZ pszDefEnv2 = (PSZ)malloc(ulSize + 2);
2678 if (pszDefEnv2)
2679 {
2680 PSZ p = pszDefEnv2;
2681 memset(pszDefEnv2, 0, ulSize + 2);
2682 memcpy(pszDefEnv2, pszDefEnv, ulSize);
2683
2684 for (p = pszDefEnv2;
2685 p < pszDefEnv2 + ulSize;
2686 p++)
2687 if (*p == ';')
2688 *p = 0;
2689
2690 // okay.... now we got an OS/2-style environment
2691 // with 0, 0, 00 strings
2692
2693 pszWinOS2Env = pszDefEnv2; // freed below
2694
2695 // use this
2696 ProgDetails.pszEnvironment = pszWinOS2Env;
2697 }
2698
2699 free(pszDefEnv);
2700 }
2701 }
2702
2703 // _Pmpf((__FUNCTION__ ": calling WinStartApp"));
2704 // _Pmpf((" exec: %s",
2705 // (ProgDetails.pszExecutable)
2706 // ? ProgDetails.pszExecutable
2707 // : "NULL"));
2708 // _Pmpf((" startupDir: %s",
2709 // (ProgDetails.pszStartupDir)
2710 // ? ProgDetails.pszStartupDir
2711 // : "NULL"));
2712 // _Pmpf((" params: %s",
2713 // (pszParamsPatched)
2714 // ? pszParamsPatched
2715 // : "NULL"));
2716 // _Pmpf((" new progc: 0x%lX", ProgDetails.progt.progc));
2717
2718 ProgDetails.pszParameters = pszParamsPatched;
2719
2720 happ = WinStartApp(hwndNotify,
2721 // receives WM_APPTERMINATENOTIFY
2722 &ProgDetails,
2723 pszParamsPatched,
2724 NULL, // "reserved", PMREF says...
2725 SAF_INSTALLEDCMDLINE);
2726 // we MUST use SAF_INSTALLEDCMDLINE
2727 // or no Win-OS/2 session will start...
2728 // whatever is going on here... Warp 4 FP11
2729
2730 // do not use SAF_STARTCHILDAPP, or the
2731 // app will be terminated automatically
2732 // when the WPS terminates!
2733
2734 // _Pmpf((__FUNCTION__ ": got happ 0x%lX", happ));
2735
2736 if (pszParamsPatched)
2737 free(pszParamsPatched);
2738 if (pszWinOS2Env)
2739 free(pszWinOS2Env);
2740
2741 return (happ);
2742}
2743
2744/*
2745 *@@ winhAnotherInstance:
2746 * this tests whether another instance of the same
2747 * application is already running.
2748 *
2749 * To identify instances of the same application, the
2750 * application must call this function during startup
2751 * with the unique name of an OS/2 semaphore. As with
2752 * all OS/2 semaphores, the semaphore name must begin
2753 * with "\\SEM32\\". The semaphore isn't really used
2754 * except for testing for its existence, since that
2755 * name is unique among all processes.
2756 *
2757 * If another instance is found, TRUE is returned. If
2758 * (fSwitch == TRUE), that instance is switched to,
2759 * using the tasklist.
2760 *
2761 * If no other instance is found, FALSE is returned only.
2762 *
2763 * Based on an EDM/2 code snippet.
2764 *
2765 *@@added V0.9.0 (99-10-22) [umoeller]
2766 */
2767
2768BOOL winhAnotherInstance(PSZ pszSemName, // in: semaphore ID
2769 BOOL fSwitch) // in: if TRUE, switch to first instance if running
2770{
2771 HMTX hmtx;
2772
2773 if (DosCreateMutexSem(pszSemName,
2774 &hmtx,
2775 DC_SEM_SHARED,
2776 TRUE)
2777 == NO_ERROR)
2778 // semapore created: this doesn't happen if the semaphore
2779 // exists already, so no other instance is running
2780 return (FALSE);
2781
2782 // else: instance running
2783 hmtx = NULLHANDLE;
2784
2785 // switch to other instance?
2786 if (fSwitch)
2787 {
2788 // yes: query mutex creator
2789 if (DosOpenMutexSem(pszSemName,
2790 &hmtx)
2791 == NO_ERROR)
2792 {
2793 PID pid = 0;
2794 TID tid = 0; // unused
2795 ULONG ulCount; // unused
2796
2797 if (DosQueryMutexSem(hmtx, &pid, &tid, &ulCount) == NO_ERROR)
2798 {
2799 HSWITCH hswitch = WinQuerySwitchHandle(NULLHANDLE, pid);
2800 if (hswitch != NULLHANDLE)
2801 WinSwitchToProgram(hswitch);
2802 }
2803
2804 DosCloseMutexSem(hmtx);
2805 }
2806 }
2807
2808 return (TRUE); // another instance exists
2809}
2810
2811/*
2812 *@@ winhAddToTasklist:
2813 * this adds the specified window to the tasklist
2814 * with hIcon as its program icon (which is also
2815 * set for the main window). This is useful for
2816 * the old "dialog as main window" trick.
2817 *
2818 * Returns the HSWITCH of the added entry.
2819 */
2820
2821HSWITCH winhAddToTasklist(HWND hwnd, // in: window to add
2822 HPOINTER hIcon) // in: icon for main window
2823{
2824 SWCNTRL swctl;
2825 HSWITCH hswitch = 0;
2826 swctl.hwnd = hwnd; // window handle
2827 swctl.hwndIcon = hIcon; // icon handle
2828 swctl.hprog = NULLHANDLE; // program handle (use default)
2829 WinQueryWindowProcess(hwnd, &(swctl.idProcess), NULL);
2830 // process identifier
2831 swctl.idSession = 0; // session identifier ?
2832 swctl.uchVisibility = SWL_VISIBLE; // visibility
2833 swctl.fbJump = SWL_JUMPABLE; // jump indicator
2834 // get window title from window titlebar
2835 if (hwnd)
2836 WinQueryWindowText(hwnd, sizeof(swctl.szSwtitle), swctl.szSwtitle);
2837 swctl.bProgType = PROG_DEFAULT; // program type
2838 hswitch = WinAddSwitchEntry(&swctl);
2839
2840 // give the main window the icon
2841 if ((hwnd) && (hIcon))
2842 WinSendMsg(hwnd,
2843 WM_SETICON,
2844 (MPARAM)hIcon,
2845 NULL);
2846
2847 return (hswitch);
2848}
2849
2850/*
2851 *@@category: Helpers\PM helpers\Miscellaneous
2852 */
2853
2854/* ******************************************************************
2855 *
2856 * Miscellaneous
2857 *
2858 ********************************************************************/
2859
2860/*
2861 *@@ winhFree:
2862 * frees a block of memory allocated by the
2863 * winh* functions.
2864 *
2865 * Since the winh* functions use malloc(),
2866 * you can also use free() directly on such
2867 * blocks. However, you must use winhFree
2868 * if the winh* functions are in a module
2869 * with a different C runtime.
2870 *
2871 *@@added V0.9.7 (2000-12-06) [umoeller]
2872 */
2873
2874VOID winhFree(PVOID p)
2875{
2876 if (p)
2877 free(p);
2878}
2879
2880/*
2881 *@@ winhSleep:
2882 * sleeps at least the specified amount of time,
2883 * without blocking the message queue.
2884 *
2885 *@@added V0.9.4 (2000-07-11) [umoeller]
2886 */
2887
2888VOID winhSleep(HAB hab,
2889 ULONG ulSleep) // in: sleep time in milliseconds
2890{
2891 ULONG ul = 0;
2892 QMSG qmsg;
2893 for (ul = 0;
2894 ul < (ulSleep / 50);
2895 ul++)
2896 {
2897 DosSleep(50);
2898 while (WinPeekMsg(hab,
2899 &qmsg, 0, 0, 0,
2900 PM_REMOVE))
2901 WinDispatchMsg(hab, &qmsg);
2902
2903 }
2904}
2905
2906/*
2907 *@@ winhFileDlg:
2908 * one-short function for opening an "Open" file
2909 * dialog.
2910 *
2911 * On input, pszFile specifies the directory and
2912 * file specification (e.g. "F:\*.txt").
2913 *
2914 * Returns TRUE if the user pressed OK. In that
2915 * case, the fully qualified filename is written
2916 * into pszFile again.
2917 *
2918 * Returns FALSE if the user pressed Cancel.
2919 *
2920 * Notes about flFlags:
2921 *
2922 * -- WINH_FOD_SAVEDLG: display a "Save As" dialog.
2923 * Otherwise an "Open" dialog is displayed.
2924 *
2925 * -- WINH_FOD_INILOADDIR: load a directory from the
2926 * specified INI key and switch the dlg to it.
2927 * In that case, on input, pszFile must only
2928 * contain the file filter without any path
2929 * specification, because that is loaded from
2930 * the INI key. If the INI key does not exist,
2931 * the current process directory will be used.
2932 *
2933 * -- WINH_FOD_INISAVEDIR: if the user presses OK,
2934 * the directory of the selected file is written
2935 * to the specified INI key so that it can be
2936 * reused later. This flag is independent of
2937 * WINH_FOD_INISAVEDIR: you can specify none,
2938 * one, or both of them.
2939 *
2940 *@@added V0.9.3 (2000-04-29) [umoeller]
2941 */
2942
2943BOOL winhFileDlg(HWND hwndOwner, // in: owner for file dlg
2944 PSZ pszFile, // in: file mask; out: fully q'd filename
2945 // (should be CCHMAXPATH in size)
2946 ULONG flFlags, // in: any combination of the following:
2947 // -- WINH_FOD_SAVEDLG: save dlg; else open dlg
2948 // -- WINH_FOD_INILOADDIR: load FOD path from INI
2949 // -- WINH_FOD_INISAVEDIR: store FOD path to INI on OK
2950 HINI hini, // in: INI file to load/store last path from (can be HINI_USER)
2951 PSZ pszApplication, // in: INI application to load/store last path from
2952 PSZ pszKey) // in: INI key to load/store last path from
2953{
2954 FILEDLG fd;
2955 memset(&fd, 0, sizeof(FILEDLG));
2956 fd.cbSize = sizeof(FILEDLG);
2957 fd.fl = FDS_CENTER;
2958
2959 if (flFlags & WINH_FOD_SAVEDLG)
2960 fd.fl |= FDS_SAVEAS_DIALOG;
2961 else
2962 fd.fl |= FDS_OPEN_DIALOG;
2963
2964 // default: copy pszFile
2965 strcpy(fd.szFullFile, pszFile);
2966
2967 if ( (hini) && (flFlags & WINH_FOD_INILOADDIR) )
2968 {
2969 // overwrite with initial directory for FOD from OS2.INI
2970 if (PrfQueryProfileString(hini,
2971 pszApplication,
2972 pszKey,
2973 "", // default string
2974 fd.szFullFile,
2975 sizeof(fd.szFullFile)-10)
2976 >= 2)
2977 {
2978 // found: append "\*"
2979 strcat(fd.szFullFile, "\\");
2980 strcat(fd.szFullFile, pszFile);
2981 }
2982 }
2983
2984 if ( WinFileDlg(HWND_DESKTOP, // parent
2985 hwndOwner, // owner
2986 &fd)
2987 && (fd.lReturn == DID_OK)
2988 )
2989 {
2990 // save path back?
2991 if ( (hini)
2992 && (flFlags & WINH_FOD_INISAVEDIR)
2993 )
2994 {
2995 // get the directory that was used
2996 PSZ p = strrchr(fd.szFullFile, '\\');
2997 if (p)
2998 {
2999 // contains directory:
3000 // copy to OS2.INI
3001 PSZ pszDir = strhSubstr(fd.szFullFile, p);
3002 if (pszDir)
3003 {
3004 PrfWriteProfileString(hini,
3005 pszApplication,
3006 pszKey, // "XWPSound:LastDir"
3007 pszDir);
3008 free(pszDir);
3009 }
3010 }
3011 }
3012
3013 strcpy(pszFile, fd.szFullFile);
3014
3015 return (TRUE);
3016 }
3017
3018 return (FALSE);
3019}
3020
3021/*
3022 *@@ winhSetWaitPointer:
3023 * this sets the mouse pointer to "Wait".
3024 * Returns the previous pointer (HPOINTER),
3025 * which should be stored somewhere to be
3026 * restored later. Example:
3027 + HPOINTER hptrOld = winhSetWaitPointer();
3028 + ...
3029 + WinSetPointer(HWND_DESKTOP, hptrOld);
3030 */
3031
3032HPOINTER winhSetWaitPointer(VOID)
3033{
3034 HPOINTER hptr = WinQueryPointer(HWND_DESKTOP);
3035 WinSetPointer(HWND_DESKTOP,
3036 WinQuerySysPointer(HWND_DESKTOP,
3037 SPTR_WAIT,
3038 FALSE)); // no copy
3039 return (hptr);
3040}
3041
3042/*
3043 *@@ winhQueryWindowText:
3044 * this returns the window text of the specified
3045 * HWND in a newly allocated buffer.
3046 *
3047 * Returns NULL on error. Use winhFree()
3048 * to free the return value.
3049 */
3050
3051PSZ winhQueryWindowText(HWND hwnd)
3052{
3053 PSZ pszText = NULL;
3054 ULONG cbText = WinQueryWindowTextLength(hwnd);
3055 // additional null character
3056 if (cbText)
3057 {
3058 pszText = (PSZ)malloc(cbText + 1);
3059 if (pszText)
3060 WinQueryWindowText(hwnd,
3061 cbText + 1,
3062 pszText);
3063 }
3064 return (pszText);
3065}
3066
3067/*
3068 *@@ winhReplaceWindowText:
3069 * this is a combination of winhQueryWindowText
3070 * and xstrrpl (stringh.c) to replace substrings
3071 * in a window.
3072 *
3073 * This is useful for filling in placeholders
3074 * a la "%1" in control windows, e.g. static
3075 * texts.
3076 *
3077 * This replaces only the first occurence of
3078 * pszSearch.
3079 *
3080 * Returns TRUE only if the window exists and
3081 * the search string was replaced.
3082 *
3083 *@@added V0.9.0 [umoeller]
3084 */
3085
3086BOOL winhReplaceWindowText(HWND hwnd, // in: window whose text is to be modified
3087 PSZ pszSearch, // in: search string (e.g. "%1")
3088 PSZ pszReplaceWith) // in: replacement string for pszSearch
3089{
3090 BOOL brc = FALSE;
3091 PSZ pszText = winhQueryWindowText(hwnd);
3092 if (pszText)
3093 {
3094 ULONG ulOfs = 0;
3095 if (strhrpl(&pszText, &ulOfs, pszSearch, pszReplaceWith) > 0)
3096 {
3097 WinSetWindowText(hwnd, pszText);
3098 brc = TRUE;
3099 }
3100 free(pszText);
3101 }
3102 return (brc);
3103}
3104
3105/*
3106 *@@ winhEnableDlgItems:
3107 * this enables/disables a whole range of controls
3108 * in a window by enumerating the child windows
3109 * until usIDFirst is found. If so, that subwindow
3110 * is enabled/disabled and all the following windows
3111 * in the enumeration also, until usIDLast is found.
3112 *
3113 * Note that this affects _all_ controls following
3114 * the usIDFirst window, no matter what ID they have
3115 * (even if "-1"), until usIDLast is found.
3116 *
3117 * Returns the no. of controls which were enabled/disabled
3118 * (null if none).
3119 *
3120 *@@added V0.9.0 [umoeller]
3121 *@@changed V0.9.1 (99-12-20) [umoeller]: renamed from winhEnableDlgItems
3122 */
3123
3124ULONG winhEnableControls(HWND hwndDlg, // in: dialog window
3125 USHORT usIDFirst, // in: first affected control ID
3126 USHORT usIDLast, // in: last affected control ID (inclusive)
3127 BOOL fEnable)
3128{
3129 HENUM henum1 = NULLHANDLE;
3130 HWND hwndThis = NULLHANDLE;
3131 ULONG ulCount = 0;
3132
3133 henum1 = WinBeginEnumWindows(hwndDlg);
3134 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3135 {
3136 USHORT usIDCheckFirst = WinQueryWindowUShort(hwndThis, QWS_ID),
3137 usIDCheckLast;
3138 if (usIDCheckFirst == usIDFirst)
3139 {
3140 WinEnableWindow(hwndThis, fEnable);
3141 ulCount++;
3142
3143 while ((hwndThis = WinGetNextWindow(henum1)) != NULLHANDLE)
3144 {
3145 WinEnableWindow(hwndThis, fEnable);
3146 ulCount++;
3147 usIDCheckLast = WinQueryWindowUShort(hwndThis, QWS_ID);
3148 if (usIDCheckLast == usIDLast)
3149 break;
3150 }
3151
3152 break; // outer loop
3153 }
3154 }
3155 WinEndEnumWindows(henum1);
3156 return (ulCount);
3157}
3158
3159/*
3160 *@@ winhCreateStdWindow:
3161 * much like WinCreateStdWindow, but this one
3162 * allows you to have the standard window
3163 * positioned automatically, using a given
3164 * SWP structure (*pswpFrame).
3165 *
3166 * The client window is created with the frame as
3167 * its parent and owner and gets an ID of FID_CLIENT.
3168 *
3169 * Alternatively, you can set pswpFrame to NULL
3170 * and specify FCF_SHELLPOSITION with flFrameCreateFlags.
3171 * If you want the window to be shown, specify
3172 * SWP_SHOW (and maybe SWP_ACTIVATE) in *pswpFrame.
3173 *
3174 *@@added V0.9.0 [umoeller]
3175 *@@changed V0.9.5 (2000-08-13) [umoeller]: flStyleClient never worked, fixed
3176 *@@changed V0.9.7 (2000-12-08) [umoeller]: fixed client calc for invisible window
3177 */
3178
3179HWND winhCreateStdWindow(HWND hwndFrameParent, // in: normally HWND_DESKTOP
3180 PSWP pswpFrame, // in: frame wnd pos
3181 ULONG flFrameCreateFlags, // in: FCF_* flags
3182 ULONG ulFrameStyle, // in: WS_* flags (e.g. WS_VISIBLE, WS_ANIMATE)
3183 PSZ pszFrameTitle,
3184 ULONG ulResourcesID, // in: according to FCF_* flags
3185 PSZ pszClassClient,
3186 ULONG flStyleClient,
3187 ULONG ulID, // in: frame window ID
3188 PVOID pClientCtlData, // in: pCtlData structure pointer for client
3189 PHWND phwndClient) // out: created client wnd
3190{
3191 FRAMECDATA fcdata;
3192 HWND hwndFrame;
3193 RECTL rclClient;
3194
3195 fcdata.cb = sizeof(FRAMECDATA);
3196 fcdata.flCreateFlags = flFrameCreateFlags;
3197 fcdata.hmodResources = (HMODULE)NULL;
3198 fcdata.idResources = ulResourcesID;
3199
3200 /* Create the frame and client windows. */
3201 hwndFrame = WinCreateWindow(hwndFrameParent,
3202 WC_FRAME,
3203 pszFrameTitle,
3204 ulFrameStyle,
3205 0,0,0,0, // size and position = 0
3206 NULLHANDLE, // no owner
3207 HWND_TOP, // z-order
3208 ulID, // frame window ID
3209 &fcdata, // frame class data
3210 NULL); // no presparams
3211
3212 if (hwndFrame)
3213 {
3214 *phwndClient = WinCreateWindow(hwndFrame, // parent
3215 pszClassClient, // class
3216 NULL, // no title
3217 flStyleClient, // style
3218 0,0,0,0, // size and position = 0
3219 hwndFrame, // owner
3220 HWND_BOTTOM, // bottom z-order
3221 FID_CLIENT, // frame window ID
3222 pClientCtlData, // class data
3223 NULL); // no presparams
3224
3225 if (*phwndClient)
3226 {
3227 if (pswpFrame)
3228 {
3229 // position frame
3230 WinSetWindowPos(hwndFrame,
3231 pswpFrame->hwndInsertBehind,
3232 pswpFrame->x,
3233 pswpFrame->y,
3234 pswpFrame->cx,
3235 pswpFrame->cy,
3236 pswpFrame->fl);
3237
3238 // position client
3239 // WinQueryWindowRect(hwndFrame, &rclClient);
3240 // doesn't work because it might be invisible V0.9.7 (2000-12-08) [umoeller]
3241 rclClient.xLeft = 0;
3242 rclClient.yBottom = 0;
3243 rclClient.xRight = pswpFrame->cx;
3244 rclClient.yTop = pswpFrame->cy;
3245 WinCalcFrameRect(hwndFrame,
3246 &rclClient,
3247 TRUE); // calc client from frame
3248 WinSetWindowPos(*phwndClient,
3249 HWND_TOP,
3250 rclClient.xLeft,
3251 rclClient.yBottom,
3252 rclClient.xRight - rclClient.xLeft,
3253 rclClient.yTop - rclClient.yBottom,
3254 SWP_MOVE | SWP_SIZE | SWP_SHOW);
3255 }
3256 }
3257 }
3258 return (hwndFrame);
3259}
3260
3261/*
3262 *@@ winhRepaintWindows:
3263 * this repaints all children of hwndParent.
3264 * If this is passed as HWND_DESKTOP, the
3265 * whole screen is repainted.
3266 *
3267 *@@changed V0.9.7 (2000-12-13) [umoeller]: hwndParent was never respected, fixed
3268 */
3269
3270VOID winhRepaintWindows(HWND hwndParent)
3271{
3272 HWND hwndTop;
3273 HENUM henum = WinBeginEnumWindows(hwndParent);
3274 while ((hwndTop = WinGetNextWindow(henum)))
3275 if (WinIsWindowShowing(hwndTop))
3276 WinInvalidateRect(hwndTop, NULL, TRUE);
3277 WinEndEnumWindows(henum);
3278}
3279
3280/*
3281 *@@ winhFindMsgQueue:
3282 * returns the message queue which matches
3283 * the given process and thread IDs. Since,
3284 * per IBM definition, every thread may only
3285 * have one MQ, this should be unique.
3286 *
3287 *@@added V0.9.2 (2000-03-08) [umoeller]
3288 */
3289
3290HMQ winhFindMsgQueue(PID pid, // in: process ID
3291 TID tid, // in: thread ID
3292 HAB* phab) // out: anchor block
3293{
3294 HWND hwndThis = 0,
3295 rc = 0;
3296 HENUM henum = WinBeginEnumWindows(HWND_OBJECT);
3297 while ((hwndThis = WinGetNextWindow(henum)))
3298 {
3299 CHAR szClass[200];
3300 if (WinQueryClassName(hwndThis, sizeof(szClass), szClass))
3301 {
3302 if (strcmp(szClass, "#32767") == 0)
3303 {
3304 // message queue window:
3305 PID pidWin = 0;
3306 TID tidWin = 0;
3307 WinQueryWindowProcess(hwndThis,
3308 &pidWin,
3309 &tidWin);
3310 if ( (pidWin == pid)
3311 && (tidWin == tid)
3312 )
3313 {
3314 // get HMQ from window words
3315 rc = WinQueryWindowULong(hwndThis, QWL_HMQ);
3316 if (rc)
3317 if (phab)
3318 *phab = WinQueryAnchorBlock(hwndThis);
3319 break;
3320 }
3321 }
3322 }
3323 }
3324 WinEndEnumWindows(henum);
3325
3326 return (rc);
3327}
3328
3329/*
3330 *@@ winhFindHardErrorWindow:
3331 * this searches all children of HWND_OBJECT
3332 * for the PM hard error windows, which are
3333 * invisible most of the time. When a hard
3334 * error occurs, that window is made a child
3335 * of HWND_DESKTOP instead.
3336 *
3337 * Stolen from ProgramCommander/2 (C) Roman Stangl.
3338 *
3339 *@@added V0.9.3 (2000-04-27) [umoeller]
3340 */
3341
3342VOID winhFindPMErrorWindows(HWND *phwndHardError, // out: hard error window
3343 HWND *phwndSysError) // out: system error window
3344{
3345 PID pidObject; // HWND_OBJECT's process and thread id
3346 TID tidObject;
3347 PID pidObjectChild; // HWND_OBJECT's child window process and thread id
3348 TID tidObjectChild;
3349 HENUM henumObject; // HWND_OBJECT enumeration handle
3350 HWND hwndObjectChild; // Window handle of current HWND_OBJECT child
3351 UCHAR ucClassName[32]; // Window class e.g. #1 for WC_FRAME
3352 CLASSINFO classinfoWindow; // Class info of current HWND_OBJECT child
3353
3354 *phwndHardError = NULLHANDLE;
3355 *phwndSysError = NULLHANDLE;
3356
3357 // query HWND_OBJECT's window process
3358 WinQueryWindowProcess(WinQueryObjectWindow(HWND_DESKTOP), &pidObject, &tidObject);
3359 // enumerate all child windows of HWND_OBJECT
3360 henumObject = WinBeginEnumWindows(HWND_OBJECT);
3361 while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3362 {
3363 // see if the current HWND_OBJECT child window runs in the
3364 // process of HWND_OBJECT (PM)
3365 WinQueryWindowProcess(hwndObjectChild, &pidObjectChild, &tidObjectChild);
3366 if (pidObject == pidObjectChild)
3367 {
3368 // get the child window's data
3369 WinQueryClassName(hwndObjectChild,
3370 sizeof(ucClassName),
3371 (PCH)ucClassName);
3372 WinQueryClassInfo(WinQueryAnchorBlock(hwndObjectChild),
3373 (PSZ)ucClassName,
3374 &classinfoWindow);
3375 if ( (!strcmp((PSZ)ucClassName, "#1")
3376 || (classinfoWindow.flClassStyle & CS_FRAME))
3377 )
3378 {
3379 // if the child window is a frame window and running in
3380 // HWND_OBJECT's (PM's) window process, it must be the
3381 // PM Hard Error or System Error window
3382 WinQueryClassName(WinWindowFromID(hwndObjectChild,
3383 FID_CLIENT),
3384 sizeof(ucClassName),
3385 (PSZ)ucClassName);
3386 if (!strcmp((PSZ)ucClassName, "PM Hard Error"))
3387 {
3388 *phwndHardError = hwndObjectChild;
3389 if (*phwndSysError)
3390 // we found the other one already:
3391 // stop searching, we got both
3392 break;
3393 }
3394 else
3395 {
3396 printf("Utility: Found System Error %08X\n", (int)hwndObjectChild);
3397 *phwndSysError = hwndObjectChild;
3398 if (*phwndHardError)
3399 // we found the other one already:
3400 // stop searching, we got both
3401 break;
3402 }
3403 }
3404 } // end if (pidObject == pidObjectChild)
3405 } // end while ((hwndObjectChild = WinGetNextWindow(henumObject)) != NULLHANDLE)
3406 WinEndEnumWindows(henumObject);
3407}
3408
3409/*
3410 *@@ winhCreateFakeDesktop:
3411 * this routine creates and displays a frameless window over
3412 * the whole screen in the color of PM's Desktop to fool the
3413 * user that all windows have been closed (which in fact might
3414 * not be the case).
3415 * This window's background color is set to the Desktop's
3416 * (PM's one, not the WPS's one).
3417 * Returns the HWND of this window.
3418 */
3419
3420HWND winhCreateFakeDesktop(HWND hwndSibling)
3421{
3422 // presparam for background
3423 typedef struct _BACKGROUND
3424 {
3425 ULONG cb; // length of the aparam parameter, in bytes
3426 ULONG id; // attribute type identity
3427 ULONG cb2; // byte count of the ab parameter
3428 RGB rgb; // attribute value
3429 } BACKGROUND;
3430
3431 BACKGROUND background;
3432 LONG lDesktopColor;
3433
3434 // create fake desktop window = empty window with
3435 // the size of full screen
3436 lDesktopColor = WinQuerySysColor(HWND_DESKTOP,
3437 SYSCLR_BACKGROUND,
3438 0);
3439 background.cb = sizeof(background.id)
3440 + sizeof(background.cb)
3441 + sizeof(background.rgb);
3442 background.id = PP_BACKGROUNDCOLOR;
3443 background.cb2 = sizeof(RGB);
3444 background.rgb.bBlue = (CHAR1FROMMP(lDesktopColor));
3445 background.rgb.bGreen= (CHAR2FROMMP(lDesktopColor));
3446 background.rgb.bRed = (CHAR3FROMMP(lDesktopColor));
3447
3448 return (WinCreateWindow(HWND_DESKTOP, // parent window
3449 WC_FRAME, // class name
3450 "", // window text
3451 WS_VISIBLE, // window style
3452 0, 0, // position and size
3453 WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN),
3454 WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN),
3455 NULLHANDLE, // owner window
3456 hwndSibling, // sibling window
3457 1, // window id
3458 NULL, // control data
3459 &background)); // presentation parms
3460}
3461
3462/*
3463 *@@ winhAssertWarp4Notebook:
3464 * this takes hwndDlg as a notebook dialog page and
3465 * goes thru all its controls. If a control with an
3466 * ID <= udIdThreshold is found, this is assumed to
3467 * be a button which is to be given the BS_NOTEBOOKBUTTON
3468 * style. You should therefore give all your button
3469 * controls which should be moved such an ID.
3470 *
3471 * You can also specify how many dialog units
3472 * all the other controls will be moved downward in
3473 * ulDownUnits; this is useful to fill up the space
3474 * which was used by the buttons before moving them.
3475 * Returns TRUE if anything was changed.
3476 *
3477 * This function is useful if you wish to create
3478 * notebook pages using dlgedit.exe which are compatible
3479 * with both Warp 3 and Warp 4. This should be executed
3480 * in WM_INITDLG of the notebook dlg function if the app
3481 * has determined that it is running on Warp 4.
3482 */
3483
3484BOOL winhAssertWarp4Notebook(HWND hwndDlg,
3485 USHORT usIdThreshold, // in: ID threshold
3486 ULONG ulDownUnits) // in: dialog units or 0
3487{
3488 BOOL brc = FALSE;
3489
3490 if (doshIsWarp4())
3491 {
3492 POINTL ptl;
3493 HWND hwndItem;
3494 HENUM henum = 0;
3495
3496 BOOL fIsVisible = WinIsWindowVisible(hwndDlg);
3497 if (ulDownUnits)
3498 {
3499 ptl.x = 0;
3500 ptl.y = ulDownUnits;
3501 WinMapDlgPoints(hwndDlg, &ptl, 1, TRUE);
3502 }
3503
3504 if (fIsVisible)
3505 WinEnableWindowUpdate(hwndDlg, FALSE);
3506
3507 henum = WinBeginEnumWindows(hwndDlg);
3508 while ((hwndItem = WinGetNextWindow(henum)))
3509 {
3510 USHORT usId = WinQueryWindowUShort(hwndItem, QWS_ID);
3511 // _Pmpf(("hwndItem: 0x%lX, ID: 0x%lX", hwndItem, usId));
3512 if (usId <= usIdThreshold)
3513 {
3514 // pushbutton to change:
3515 // _Pmpf((" Setting bit"));
3516 WinSetWindowBits(hwndItem,
3517 QWL_STYLE,
3518 BS_NOTEBOOKBUTTON, BS_NOTEBOOKBUTTON);
3519 brc = TRUE;
3520 }
3521 else
3522 // no pushbutton to change: move downwards
3523 // if desired
3524 if (ulDownUnits)
3525 {
3526 SWP swp;
3527 // _Pmpf(("Moving downwards %d pixels", ptl.y));
3528 WinQueryWindowPos(hwndItem, &swp);
3529 WinSetWindowPos(hwndItem, 0,
3530 swp.x,
3531 swp.y - ptl.y,
3532 0, 0,
3533 SWP_MOVE);
3534 }
3535 }
3536 WinEndEnumWindows(henum);
3537
3538 if (fIsVisible)
3539 WinShowWindow(hwndDlg, TRUE);
3540 }
3541
3542 return (brc);
3543}
3544
3545/*
3546 *@@ winhDrawFormattedText:
3547 * this func takes a rectangle and draws pszText into
3548 * it, breaking the words as neccessary. The line spacing
3549 * is determined from the font currently selected in hps.
3550 *
3551 * As opposed to WinDrawText, this can draw several lines
3552 * at once, and format the _complete_ text according to the
3553 * flCmd parameter, which is like with WinDrawText.
3554 *
3555 * After this function returns, *prcl is modified like this:
3556 * -- yTop and yBottom contain the upper and lower boundaries
3557 * which were needed to draw the text. This depends on
3558 * whether DT_TOP etc. were specified.
3559 * To get the height of the rectangle used, calculate the
3560 * delta between yTop and yBottom.
3561 *
3562 * -- xLeft and xRight are modified to contain the outmost
3563 * left and right coordinates which were needed to draw
3564 * the text. This will be set to the longest line which
3565 * was encountered.
3566 *
3567 * You can specify DT_QUERYEXTENT with flDraw to only have
3568 * these text boundaries calculated without actually drawing.
3569 *
3570 * This returns the number of lines drawn.
3571 *
3572 * Note that this calls WinDrawText with DT_TEXTATTRS set,
3573 * that is, the current text primitive attributes will be
3574 * used (fonts and colors).
3575 *
3576 *@@changed V0.9.0 [umoeller]: prcl.xLeft and xRight are now updated too upon return
3577 */
3578
3579ULONG winhDrawFormattedText(HPS hps, // in: presentation space; its settings
3580 // are used, but not altered
3581 PRECTL prcl, // in/out: rectangle to use for drawing
3582 // (modified)
3583 PSZ pszText, // in: text to draw (zero-terminated)
3584 ULONG flCmd) // in: flags like in WinDrawText; I have
3585 // only tested DT_TOP and DT_LEFT though.
3586 // DT_WORDBREAK | DT_TEXTATTRS are always
3587 // set.
3588 // You can specify DT_QUERYEXTENT to only
3589 // have prcl calculated without drawing.
3590{
3591 PSZ p = pszText;
3592 LONG lDrawn = 1,
3593 lTotalDrawn = 0,
3594 lLineCount = 0,
3595 lOrigYTop = prcl->yTop;
3596 ULONG ulTextLen = strlen(pszText),
3597 ulCharHeight,
3598 flCmd2,
3599 xLeftmost = prcl->xRight,
3600 xRightmost = prcl->xLeft;
3601 RECTL rcl2;
3602
3603 flCmd2 = flCmd | DT_WORDBREAK | DT_TEXTATTRS;
3604
3605 ulCharHeight = gpihQueryLineSpacing(hps);
3606
3607 while ( (lDrawn)
3608 && (lTotalDrawn < ulTextLen)
3609 )
3610 {
3611 memcpy(&rcl2, prcl, sizeof(rcl2));
3612 lDrawn = WinDrawText(hps,
3613 ulTextLen-lTotalDrawn,
3614 p,
3615 &rcl2,
3616 0, 0, // colors
3617 flCmd2);
3618
3619 // update char counters
3620 p += lDrawn;
3621 lTotalDrawn += lDrawn;
3622
3623 // update x extents
3624 if (rcl2.xLeft < xLeftmost)
3625 xLeftmost = rcl2.xLeft;
3626 if (rcl2.xRight > xRightmost)
3627 xRightmost = rcl2.xRight;
3628
3629 // update y for next line
3630 prcl->yTop -= ulCharHeight;
3631
3632 // increase line count
3633 lLineCount++;
3634 }
3635 prcl->xLeft = xLeftmost;
3636 prcl->xRight = xRightmost;
3637 prcl->yBottom = prcl->yTop;
3638 prcl->yTop = lOrigYTop;
3639
3640 return (lLineCount);
3641}
3642
3643/*
3644 *@@ winhQuerySwitchList:
3645 * returns the switch list in a newly
3646 * allocated buffer. This does the
3647 * regular double WinQuerySwitchList
3648 * call to first get the no. of items
3649 * and then get the items.
3650 *
3651 * The no. of items can be found in
3652 * the returned SWBLOCK.cwsentry.
3653 *
3654 * Returns NULL on errors. Use
3655 * winhFree to free the return value.
3656 *
3657 *@@added V0.9.7 (2000-12-06) [umoeller]
3658 */
3659
3660PSWBLOCK winhQuerySwitchList(HAB hab)
3661{
3662 ULONG cItems = WinQuerySwitchList(hab, NULL, 0);
3663 ULONG ulBufSize = (cItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
3664 PSWBLOCK pSwBlock = (PSWBLOCK)malloc(ulBufSize);
3665 if (pSwBlock)
3666 {
3667 cItems = WinQuerySwitchList(hab, pSwBlock, ulBufSize);
3668 if (!cItems)
3669 {
3670 free(pSwBlock);
3671 pSwBlock = NULL;
3672 }
3673 }
3674
3675 return (pSwBlock);
3676}
3677
3678/*
3679 *@@ winhQueryTasklistWindow:
3680 * returns the window handle of the PM task list.
3681 *
3682 *@@added V0.9.7 (2000-12-07) [umoeller]
3683 */
3684
3685HWND winhQueryTasklistWindow(VOID)
3686{
3687 SWBLOCK swblock;
3688 HWND hwndTasklist = winhQueryTasklistWindow();
3689 // the tasklist has entry #0 in the SWBLOCK
3690 WinQuerySwitchList(NULLHANDLE, &swblock, sizeof(SWBLOCK));
3691 return (swblock.aswentry[0].swctl.hwnd);
3692}
3693
3694/*
3695 *@@ winhKillTasklist:
3696 * this will destroy the Tasklist (window list) window.
3697 * Note: you will only be able to get it back after a
3698 * reboot, not a WPS restart. Only for use at shutdown and such.
3699 * This trick by Uri J. Stern at
3700 * http://zebra.asta.fh-weingarten.de/os2/Snippets/Howt8881.HTML
3701 */
3702
3703VOID winhKillTasklist(VOID)
3704{
3705 HWND hwndTasklist = winhQueryTasklistWindow();
3706 WinPostMsg(hwndTasklist,
3707 0x0454, // undocumented msg for killing tasklist
3708 NULL, NULL);
3709}
3710
3711// the following must be added for EMX (99-10-22) [umoeller]
3712#ifndef NERR_BufTooSmall
3713 #define NERR_BASE 2100
3714 #define NERR_BufTooSmall (NERR_BASE+23)
3715 // the API return buffer is too small
3716#endif
3717
3718/*
3719 *@@ winhQueryPendingSpoolJobs:
3720 * returns the number of pending print jobs in the spooler
3721 * or 0 if none. Useful for testing before shutdown.
3722 */
3723
3724ULONG winhQueryPendingSpoolJobs(VOID)
3725{
3726 // BOOL rcPending = FALSE;
3727 ULONG ulTotalJobCount = 0;
3728
3729 SPLERR splerr;
3730 USHORT jobCount;
3731 ULONG cbBuf;
3732 ULONG cTotal;
3733 ULONG cReturned;
3734 ULONG cbNeeded;
3735 ULONG ulLevel;
3736 ULONG i,j;
3737 PSZ pszComputerName;
3738 PBYTE pBuf = NULL;
3739 PPRQINFO3 prq;
3740 PPRJINFO2 prj2;
3741
3742 ulLevel = 4L;
3743 pszComputerName = (PSZ)NULL;
3744 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, 0L, // cbBuf
3745 &cReturned, &cTotal,
3746 &cbNeeded, NULL);
3747 if ( (splerr == ERROR_MORE_DATA)
3748 || (splerr == NERR_BufTooSmall)
3749 )
3750 {
3751 if (!DosAllocMem((PPVOID)&pBuf,
3752 cbNeeded,
3753 PAG_READ | PAG_WRITE | PAG_COMMIT))
3754 {
3755 cbBuf = cbNeeded;
3756 splerr = SplEnumQueue(pszComputerName, ulLevel, pBuf, cbBuf,
3757 &cReturned, &cTotal,
3758 &cbNeeded, NULL);
3759 if (splerr == NO_ERROR)
3760 {
3761 // set pointer to point to the beginning of the buffer
3762 prq = (PPRQINFO3)pBuf;
3763
3764 // cReturned has the count of the number of PRQINFO3 structures
3765 for (i = 0;
3766 i < cReturned;
3767 i++)
3768 {
3769 // save the count of jobs; there are this many PRJINFO2
3770 // structures following the PRQINFO3 structure
3771 jobCount = prq->cJobs;
3772 // _Pmpf(( "Job count in this queue is %d",jobCount ));
3773
3774 // increment the pointer past the PRQINFO3 structure
3775 prq++;
3776
3777 // set a pointer to point to the first PRJINFO2 structure
3778 prj2=(PPRJINFO2)prq;
3779 for (j = 0;
3780 j < jobCount;
3781 j++)
3782 {
3783 // increment the pointer to point to the next structure
3784 prj2++;
3785 // increase the job count, which we'll return
3786 ulTotalJobCount++;
3787
3788 } // endfor jobCount
3789
3790 // after doing all the job structures, prj2 points to the next
3791 // queue structure; set the pointer for a PRQINFO3 structure
3792 prq = (PPRQINFO3)prj2;
3793 } //endfor cReturned
3794 } // endif NO_ERROR
3795 DosFreeMem(pBuf);
3796 }
3797 } // end if Q level given
3798
3799 return (ulTotalJobCount);
3800}
3801
3802/*
3803 *@@ winhSetNumLock:
3804 * this sets the NumLock key on or off, depending
3805 * on fState.
3806 *
3807 * Based on code from WarpEnhancer, (C) Achim Hasenmller.
3808 *
3809 *@@added V0.9.1 (99-12-18) [umoeller]
3810 */
3811
3812VOID winhSetNumLock(BOOL fState)
3813{
3814 // BOOL fRestoreKBD = FALSE; // Assume we're not going to close Kbd
3815 BYTE KeyStateTable[256];
3816 ULONG ulActionTaken; // Used by DosOpen
3817 HFILE hKbd;
3818
3819 // read keyboard state table
3820 if (WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0],
3821 FALSE))
3822 {
3823 // first set the PM state
3824 if (fState)
3825 KeyStateTable[VK_NUMLOCK] |= 0x01; // Turn numlock on
3826 else
3827 KeyStateTable[VK_NUMLOCK] &= 0xFE; // Turn numlock off
3828
3829 // set keyboard state table with new state values
3830 WinSetKeyboardStateTable(HWND_DESKTOP, &KeyStateTable[0], TRUE);
3831 }
3832
3833 // now set the OS/2 keyboard state
3834
3835 // try to open OS/2 keyboard driver
3836 if (!DosOpen("KBD$",
3837 &hKbd, &ulActionTaken,
3838 0, // cbFile
3839 FILE_NORMAL,
3840 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
3841 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
3842 NULL))
3843 {
3844 SHIFTSTATE ShiftState;
3845 ULONG DataLen = sizeof(SHIFTSTATE);
3846
3847 memset(&ShiftState, '\0', DataLen);
3848 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_GETSHIFTSTATE,
3849 NULL, 0L, NULL,
3850 &ShiftState, DataLen, &DataLen);
3851
3852 if (fState)
3853 ShiftState.fsState |= 0x0020; // turn NumLock on
3854 else
3855 ShiftState.fsState &= 0xFFDF; // turn NumLock off
3856
3857 DosDevIOCtl(hKbd, IOCTL_KEYBOARD, KBD_SETSHIFTSTATE,
3858 &ShiftState, DataLen, &DataLen,
3859 NULL, 0L, NULL);
3860 // now close OS/2 keyboard driver
3861 DosClose(hKbd);
3862 }
3863 return;
3864}
3865
3866/*
3867 *@@category: Helpers\PM helpers\Workplace Shell\WPS class list
3868 */
3869
3870/* ******************************************************************
3871 *
3872 * WPS Class List helpers
3873 *
3874 ********************************************************************/
3875
3876/*
3877 *@@ winhQueryWPSClassList:
3878 * this returns the WPS class list in a newly
3879 * allocated buffer. This is just a shortcut to
3880 * the usual double WinEnumObjectClasses call.
3881 *
3882 * The return value is actually of the POBJCLASS type,
3883 * so you better cast this manually. We declare this
3884 * this as PBYTE though because POBJCLASS requires
3885 * INCL_WINWORKPLACE.
3886 * See WinEnumObjectClasses() for details.
3887 *
3888 * Returns NULL on error. Use winhFree()
3889 * to free the return value.
3890 *
3891 *@@added V0.9.0 [umoeller]
3892 */
3893
3894PBYTE winhQueryWPSClassList(VOID)
3895{
3896 ULONG ulSize;
3897 POBJCLASS pObjClass = 0;
3898
3899 // get WPS class list size
3900 if (WinEnumObjectClasses(NULL, &ulSize))
3901 {
3902 // allocate buffer
3903 pObjClass = (POBJCLASS)malloc(ulSize+1);
3904 // and load the classes into it
3905 WinEnumObjectClasses(pObjClass, &ulSize);
3906 }
3907
3908 return ((PBYTE)pObjClass);
3909}
3910
3911/*
3912 *@@ winhQueryWPSClass:
3913 * this returns the POBJCLASS item if pszClass is registered
3914 * with the WPS or NULL if the class could not be found.
3915 *
3916 * The return value is actually of the POBJCLASS type,
3917 * so you better cast this manually. We declare this
3918 * this as PBYTE though because POBJCLASS requires
3919 * INCL_WINWORKPLACE.
3920 *
3921 * This takes as input the return value of winhQueryWPSClassList,
3922 * which you must call first.
3923 *
3924 * <B>Usage:</B>
3925 + PBYTE pClassList = winhQueryWPSClassList(),
3926 + pWPFolder;
3927 + if (pClassList)
3928 + {
3929 + if (pWPFolder = winhQueryWPSClass(pClassList, "WPFolder"))
3930 + ...
3931 + free(pClassList);
3932 + }
3933 *
3934 *@@added V0.9.0 [umoeller]
3935 */
3936
3937PBYTE winhQueryWPSClass(PBYTE pObjClass, // in: buffer returned by
3938 // winhQueryWPSClassList
3939 const char *pszClass) // in: class name to query
3940{
3941 PBYTE pbReturn = 0;
3942
3943 POBJCLASS pocThis = (POBJCLASS)pObjClass;
3944 // now go thru the WPS class list
3945 while (pocThis)
3946 {
3947 if (strcmp(pocThis->pszClassName, pszClass) == 0)
3948 {
3949 pbReturn = (PBYTE)pocThis;
3950 break;
3951 }
3952 // next class
3953 pocThis = pocThis->pNext;
3954 } // end while (pocThis)
3955
3956 return (pbReturn);
3957}
3958
3959/*
3960 *@@ winhRegisterClass:
3961 * this works just like WinRegisterObjectClass,
3962 * except that it returns a more meaningful
3963 * error code than just FALSE in case registering
3964 * fails.
3965 *
3966 * This returns NO_ERROR if the class was successfully
3967 * registered (WinRegisterObjectClass returned TRUE).
3968 *
3969 * Otherwise, we do a DosLoadModule if maybe the DLL
3970 * couldn't be loaded in the first place. If DosLoadModule
3971 * did not return NO_ERROR, this function returns that
3972 * return code, which can be:
3973 *
3974 * -- 2 ERROR_FILE_NOT_FOUND: pcszModule does not exist
3975 * -- 2 ERROR_FILE_NOT_FOUND
3976 * -- 3 ERROR_PATH_NOT_FOUND
3977 * -- 4 ERROR_TOO_MANY_OPEN_FILES
3978 * -- 5 ERROR_ACCESS_DENIED
3979 * -- 8 ERROR_NOT_ENOUGH_MEMORY
3980 * -- 11 ERROR_BAD_FORMAT
3981 * -- 26 ERROR_NOT_DOS_DISK (unknown media type)
3982 * -- 32 ERROR_SHARING_VIOLATION
3983 * -- 33 ERROR_LOCK_VIOLATION
3984 * -- 36 ERROR_SHARING_BUFFER_EXCEEDED
3985 * -- 95 ERROR_INTERRUPT (interrupted system call)
3986 * -- 108 ERROR_DRIVE_LOCKED (by another process)
3987 * -- 123 ERROR_INVALID_NAME (illegal character or FS name not valid)
3988 * -- 127 ERROR_PROC_NOT_FOUND (DosQueryProcAddr error)
3989 * -- 180 ERROR_INVALID_SEGMENT_NUMBER
3990 * -- 182 ERROR_INVALID_ORDINAL
3991 * -- 190 ERROR_INVALID_MODULETYPE (probably an application)
3992 * -- 191 ERROR_INVALID_EXE_SIGNATURE (probably not LX DLL)
3993 * -- 192 ERROR_EXE_MARKED_INVALID (by linker)
3994 * -- 194 ERROR_ITERATED_DATA_EXCEEDS_64K (in a DLL segment)
3995 * -- 195 ERROR_INVALID_MINALLOCSIZE
3996 * -- 196 ERROR_DYNLINK_FROM_INVALID_RING
3997 * -- 198 ERROR_INVALID_SEGDPL
3998 * -- 199 ERROR_AUTODATASEG_EXCEEDS_64K
3999 * -- 201 ERROR_RELOCSRC_CHAIN_EXCEEDS_SEGLIMIT
4000 * -- 206 ERROR_FILENAME_EXCED_RANGE (not matching 8+3 spec)
4001 * -- 295 ERROR_INIT_ROUTINE_FAILED (DLL init routine failed)
4002 *
4003 * In all these cases, pszBuf may contain a meaningful
4004 * error message from DosLoadModule, especially if an import
4005 * could not be resolved.
4006 *
4007 * Still worse, if DosLoadModule returned NO_ERROR, we
4008 * probably have some SOM internal error. A probable
4009 * reason is that the parent class of pcszClassName
4010 * is not installed, but that's WPS/SOM internal
4011 * and cannot be queried from outside the WPS context.
4012 *
4013 * In that case, ERROR_OPEN_FAILED (110) is returned.
4014 * That one sounded good to me. ;-)
4015 */
4016
4017APIRET winhRegisterClass(const char* pcszClassName, // in: e.g. "XFolder"
4018 const char* pcszModule, // in: e.g. "C:\XFOLDER\XFLDR.DLL"
4019 PSZ pszBuf, // out: error message from DosLoadModule
4020 ULONG cbBuf) // in: sizeof(*pszBuf), passed to DosLoadModule
4021{
4022 APIRET arc = NO_ERROR;
4023
4024 if (!WinRegisterObjectClass((PSZ)pcszClassName, (PSZ)pcszModule))
4025 {
4026 // failed: do more error checking then, try DosLoadModule
4027 HMODULE hmod = NULLHANDLE;
4028 arc = DosLoadModule(pszBuf, cbBuf,
4029 (PSZ)pcszModule,
4030 &hmod);
4031 if (arc == NO_ERROR)
4032 {
4033 // DosLoadModule succeeded:
4034 // some SOM error then
4035 DosFreeModule(hmod);
4036 arc = ERROR_OPEN_FAILED;
4037 }
4038 }
4039 // else: ulrc still 0 (== no error)
4040
4041 return (arc);
4042}
4043
4044/*
4045 *@@ winhIsClassRegistered:
4046 * quick one-shot function which checks if
4047 * a class is currently registered. Calls
4048 * winhQueryWPSClassList and winhQueryWPSClass
4049 * in turn.
4050 *
4051 *@@added V0.9.2 (2000-02-26) [umoeller]
4052 */
4053
4054BOOL winhIsClassRegistered(const char *pcszClass)
4055{
4056 BOOL brc = FALSE;
4057 PBYTE pClassList = winhQueryWPSClassList();
4058 if (pClassList)
4059 {
4060 if (winhQueryWPSClass(pClassList, pcszClass))
4061 brc = TRUE;
4062 free(pClassList);
4063 }
4064
4065 return (brc);
4066}
4067
4068/*
4069 *@@category: Helpers\PM helpers\Workplace Shell
4070 */
4071
4072/*
4073 *@@ winhResetWPS:
4074 * restarts the WPS using PrfReset. Returns
4075 * one of the following:
4076 *
4077 * -- 0: no error.
4078 * -- 1: PrfReset failed.
4079 * -- 2 or 4: PrfQueryProfile failed.
4080 * -- 3: malloc() failed.
4081 *
4082 *@@added V0.9.4 (2000-07-01) [umoeller]
4083 */
4084
4085ULONG winhResetWPS(HAB hab)
4086{
4087 ULONG ulrc = 0;
4088 // find out current profile names
4089 PRFPROFILE Profiles;
4090 Profiles.cchUserName = Profiles.cchSysName = 0;
4091 // first query their file name lengths
4092 if (PrfQueryProfile(hab, &Profiles))
4093 {
4094 // allocate memory for filenames
4095 Profiles.pszUserName = (PSZ)malloc(Profiles.cchUserName);
4096 Profiles.pszSysName = (PSZ)malloc(Profiles.cchSysName);
4097
4098 if (Profiles.pszSysName)
4099 {
4100 // get filenames
4101 if (PrfQueryProfile(hab, &Profiles))
4102 {
4103
4104 // "change" INIs to these filenames:
4105 // THIS WILL RESET THE WPS
4106 if (PrfReset(hab, &Profiles) == FALSE)
4107 ulrc = 1;
4108 free(Profiles.pszSysName);
4109 free(Profiles.pszUserName);
4110 }
4111 else
4112 ulrc = 2;
4113 }
4114 else
4115 ulrc = 3;
4116 }
4117 else
4118 ulrc = 4;
4119
4120 return (ulrc);
4121}
Note: See TracBrowser for help on using the repository browser.