4 * Copyright 1993, 1994 Alexandre Julliard
6 static char Copyright[] = "Copyright Alexandre Julliard, 1993, 1994";
19 /* #define DEBUG_DIALOG */
22 /* Dialog base units */
23 static WORD xBaseUnit
= 0, yBaseUnit
= 0;
26 /***********************************************************************
29 * Initialisation of the dialog manager.
36 /* Calculate the dialog base units */
38 if (!(hdc
= GetDC( 0 ))) return FALSE
;
39 GetTextMetrics( hdc
, &tm
);
41 xBaseUnit
= tm
.tmAveCharWidth
;
42 yBaseUnit
= tm
.tmHeight
;
44 /* Dialog units are based on a proportional system font */
45 /* so we adjust them a bit for a fixed font. */
46 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
) xBaseUnit
= xBaseUnit
* 5 / 4;
48 dprintf_dialog( stddeb
, "DIALOG_Init: base units = %d,%d\n",
49 xBaseUnit
, yBaseUnit
);
54 /***********************************************************************
55 * DIALOG_GetFirstTabItem
57 * Return the first item of the dialog that has the WS_TABSTOP style.
59 HWND
DIALOG_GetFirstTabItem( HWND hwndDlg
)
62 WND
*wndPtr
= WIN_FindWndPtr( hwndDlg
);
63 hwnd
= wndPtr
->hwndChild
;
66 wndPtr
= WIN_FindWndPtr( hwnd
);
67 if (wndPtr
->dwStyle
& WS_TABSTOP
) break;
68 hwnd
= wndPtr
->hwndNext
;
74 /***********************************************************************
77 * Return the class and text of the control pointed to by ptr,
78 * and return a pointer to the next control.
80 static DLGCONTROLHEADER
* DIALOG_GetControl( DLGCONTROLHEADER
* ptr
,
81 char ** class, char ** text
)
83 unsigned char * p
= (unsigned char *)ptr
;
84 p
+= 14; /* size of control header */
90 case 0x80: *class = "BUTTON"; break;
91 case 0x81: *class = "EDIT"; break;
92 case 0x82: *class = "STATIC"; break;
93 case 0x83: *class = "LISTBOX"; break;
94 case 0x84: *class = "SCROLLBAR"; break;
95 case 0x85: *class = "COMBOBOX"; break;
96 default: *class = ""; break;
106 /* Integer id, not documented (?). Only works for SS_ICON controls */
107 *text
= (char *)MAKEINTRESOURCE( p
[1] + 256*p
[2] );
115 return (DLGCONTROLHEADER
*)p
;
119 /***********************************************************************
120 * DIALOG_ParseTemplate
122 * Fill a DLGTEMPLATE structure from the dialog template, and return
123 * a pointer to the first control.
125 static DLGCONTROLHEADER
* DIALOG_ParseTemplate( LPCSTR
template,
126 DLGTEMPLATE
* result
)
128 unsigned char * p
= (unsigned char *)template;
130 result
->header
= (DLGTEMPLATEHEADER
*)p
;
133 result
->menuName
= p
;
134 if (*p
== 0xff) p
+= 3;
135 else p
+= strlen(p
) + 1;
137 if (*p
) result
->className
= p
;
138 else result
->className
= DIALOG_CLASS_NAME
;
144 if (result
->header
->style
& DS_SETFONT
)
146 result
->pointSize
= *(WORD
*)p
; p
+= sizeof(WORD
);
147 result
->faceName
= p
; p
+= strlen(p
) + 1;
150 return (DLGCONTROLHEADER
*)p
;
154 /***********************************************************************
155 * DIALOG_DisplayTemplate
157 static void DIALOG_DisplayTemplate( DLGTEMPLATE
* result
)
159 dprintf_dialog(stddeb
, "DIALOG %d, %d, %d, %d\n", result
->header
->x
, result
->header
->y
,
160 result
->header
->cx
, result
->header
->cy
);
161 dprintf_dialog(stddeb
, " STYLE %08lx\n", result
->header
->style
);
162 dprintf_dialog(stddeb
, " CAPTION '%s'\n", result
->caption
);
163 dprintf_dialog(stddeb
, " CLASS '%s'\n", result
->className
);
164 if (result
->menuName
[0] == 0xff)
165 dprintf_dialog(stddeb
, " MENU %d\n", result
->menuName
[1] + 256*result
->menuName
[2] );
167 dprintf_dialog(stddeb
, " MENU '%s'\n", result
->menuName
);
168 if (result
->header
->style
& DS_SETFONT
)
169 dprintf_dialog(stddeb
, " FONT %d,'%s'\n", result
->pointSize
, result
->faceName
);
173 /***********************************************************************
174 * CreateDialog (USER.89)
176 HWND
CreateDialog( HINSTANCE hInst
, SEGPTR dlgTemplate
,
177 HWND owner
, WNDPROC dlgProc
)
179 return CreateDialogParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
183 /***********************************************************************
184 * CreateDialogParam (USER.241)
186 HWND
CreateDialogParam( HINSTANCE hInst
, SEGPTR dlgTemplate
,
187 HWND owner
, WNDPROC dlgProc
, LPARAM param
)
193 dprintf_dialog(stddeb
, "CreateDialogParam: %d,%08lx,%d,%p,%ld\n",
194 hInst
, dlgTemplate
, owner
, dlgProc
, param
);
196 /* FIXME: MAKEINTRESOURCE should be replaced by RT_DIALOG */
197 if (!(hres
= FindResource( hInst
, dlgTemplate
, MAKEINTRESOURCE(0x8005) )))
199 if (!(hmem
= LoadResource( hInst
, hres
))) return 0;
200 if (!(data
= LockResource( hmem
))) hwnd
= 0;
201 else hwnd
= CreateDialogIndirectParam(hInst
, data
, owner
, dlgProc
, param
);
202 FreeResource( hmem
);
207 /***********************************************************************
208 * CreateDialogIndirect (USER.219)
210 HWND
CreateDialogIndirect( HINSTANCE hInst
, LPCSTR dlgTemplate
,
211 HWND owner
, WNDPROC dlgProc
)
213 return CreateDialogIndirectParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
217 /***********************************************************************
218 * CreateDialogIndirectParam (USER.242)
220 HWND
CreateDialogIndirectParam( HINSTANCE hInst
, LPCSTR dlgTemplate
,
221 HWND owner
, WNDPROC dlgProc
, LPARAM param
)
229 DLGTEMPLATE
template;
230 DLGCONTROLHEADER
* header
;
231 DIALOGINFO
* dlgInfo
;
233 WORD xUnit
= xBaseUnit
;
234 WORD yUnit
= yBaseUnit
;
236 /* Parse dialog template */
238 if (!dlgTemplate
) return 0;
239 header
= DIALOG_ParseTemplate( dlgTemplate
, &template );
240 if(debugging_dialog
)DIALOG_DisplayTemplate( &template );
244 switch (template.menuName
[0])
250 hMenu
= LoadMenu( hInst
, MAKEINTRESOURCE( template.menuName
[1] +
251 256*template.menuName
[2] ));
255 /* Need to copy the menu name to a 16-bit area */
256 HANDLE handle
= USER_HEAP_ALLOC( strlen(template.menuName
)+1 );
257 strcpy( USER_HEAP_LIN_ADDR( handle
), template.menuName
);
258 hMenu
= LoadMenu( hInst
, USER_HEAP_SEG_ADDR( handle
) );
259 USER_HEAP_FREE( handle
);
264 /* Create custom font if needed */
266 if (template.header
->style
& DS_SETFONT
)
268 /* The font height must be negative as it is a point size */
269 /* (see CreateFont() documentation in the Windows SDK). */
270 hFont
= CreateFont( -template.pointSize
, 0, 0, 0, FW_DONTCARE
,
271 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
272 DEFAULT_QUALITY
, FF_DONTCARE
, template.faceName
);
280 oldFont
= SelectObject( hdc
, hFont
);
281 GetTextMetrics( hdc
, &tm
);
282 SelectObject( hdc
, oldFont
);
284 xUnit
= tm
.tmAveCharWidth
;
286 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
287 xBaseUnit
= xBaseUnit
* 5 / 4; /* See DIALOG_Init() */
291 /* Create dialog main window */
293 rect
.left
= rect
.top
= 0;
294 if (!(template.header
->style
& DS_ABSALIGN
))
295 ClientToScreen( owner
, (POINT
*)&rect
);
296 rect
.right
= rect
.left
+ template.header
->cx
* xUnit
/ 4;
297 rect
.bottom
= rect
.top
+ template.header
->cy
* yUnit
/ 8;
298 if (template.header
->style
& DS_MODALFRAME
) exStyle
|= WS_EX_DLGMODALFRAME
;
299 AdjustWindowRectEx( &rect
, template.header
->style
, hMenu
, exStyle
);
301 hwnd
= CreateWindowEx( exStyle
, template.className
, template.caption
,
302 template.header
->style
,
303 rect
.left
+ template.header
->x
* xUnit
/ 4,
304 rect
.top
+ template.header
->y
* yUnit
/ 8,
305 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
306 owner
, hMenu
, hInst
, (SEGPTR
)0 );
309 if (hFont
) DeleteObject( hFont
);
310 if (hMenu
) DestroyMenu( hMenu
);
314 /* Create control windows */
316 dprintf_dialog(stddeb
, " BEGIN\n" );
318 wndPtr
= WIN_FindWndPtr( hwnd
);
319 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
320 dlgInfo
->msgResult
= 0; /* This is used to store the default button id */
321 dlgInfo
->hDialogHeap
= 0;
323 for (i
= 0; i
< template.header
->nbItems
; i
++)
325 DLGCONTROLHEADER
* next_header
;
327 HWND hwndDefButton
= 0;
328 next_header
= DIALOG_GetControl( header
, &class, &text
);
330 dprintf_dialog(stddeb
, " %s ", class);
331 if ((int)text
& 0xffff0000)
332 dprintf_dialog(stddeb
,"'%s'", text
);
334 dprintf_dialog(stddeb
,"%4X", (int)text
& 0xffff);
335 dprintf_dialog(stddeb
," %d, %d, %d, %d, %d, %08lx\n",
336 header
->id
, header
->x
, header
->y
,
337 header
->cx
, header
->cy
, header
->style
);
339 if ((strcmp(class, "EDIT") == 0) &&
340 ((header
->style
& DS_LOCALEDIT
) != DS_LOCALEDIT
)) {
341 if (!dlgInfo
->hDialogHeap
) {
342 dlgInfo
->hDialogHeap
= GlobalAlloc(GMEM_FIXED
, 0x10000);
343 if (!dlgInfo
->hDialogHeap
) {
344 fprintf(stderr
,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
347 LocalInit(dlgInfo
->hDialogHeap
, 0, 0xffff);
349 header
->style
|= WS_CHILD
;
350 hwndCtrl
= CreateWindowEx( WS_EX_NOPARENTNOTIFY
,
351 class, text
, header
->style
,
352 header
->x
* xUnit
/ 4, header
->y
* yUnit
/ 8,
353 header
->cx
* xUnit
/ 4, header
->cy
* yUnit
/ 8,
354 hwnd
, header
->id
, dlgInfo
->hDialogHeap
, (SEGPTR
)0 );
358 header
->style
|= WS_CHILD
;
359 hwndCtrl
= CreateWindowEx( WS_EX_NOPARENTNOTIFY
,
360 class, text
, header
->style
,
361 header
->x
* xUnit
/ 4, header
->y
* yUnit
/ 8,
362 header
->cx
* xUnit
/ 4, header
->cy
* yUnit
/ 8,
363 hwnd
, header
->id
, hInst
, (SEGPTR
)0 );
365 /* Make the control last one in Z-order, so that controls remain
366 in the order in which they were created */
367 SetWindowPos( hwndCtrl
, HWND_BOTTOM
, 0, 0, 0, 0,
368 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
370 /* Send initialisation messages to the control */
371 if (hFont
) SendMessage( hwndCtrl
, WM_SETFONT
, hFont
, 0 );
372 if (SendMessage( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
374 /* If there's already a default push-button, set it back */
375 /* to normal and use this one instead. */
377 SendMessage( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
378 hwndDefButton
= hwndCtrl
;
379 dlgInfo
->msgResult
= header
->id
;
381 header
= next_header
;
384 dprintf_dialog(stddeb
, " END\n" );
386 /* Initialise dialog extra data */
388 dlgInfo
->dlgProc
= dlgProc
;
389 dlgInfo
->hUserFont
= hFont
;
390 dlgInfo
->hMenu
= hMenu
;
391 dlgInfo
->xBaseUnit
= xUnit
;
392 dlgInfo
->yBaseUnit
= yUnit
;
393 dlgInfo
->hwndFocus
= DIALOG_GetFirstTabItem( hwnd
);
395 /* Send initialisation messages and set focus */
397 if (dlgInfo
->hUserFont
)
398 SendMessage( hwnd
, WM_SETFONT
, dlgInfo
->hUserFont
, 0 );
399 if (SendMessage( hwnd
, WM_INITDIALOG
, dlgInfo
->hwndFocus
, param
))
400 SetFocus( dlgInfo
->hwndFocus
);
406 /***********************************************************************
409 static int DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
412 DIALOGINFO
* dlgInfo
;
417 /* Owner must be a top-level window */
418 while (owner
&& GetParent(owner
)) owner
= GetParent(owner
);
419 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return -1;
420 if (!(msgHandle
= USER_HEAP_ALLOC( sizeof(MSG
) ))) return -1;
421 lpmsg
= (MSG
*) USER_HEAP_LIN_ADDR( msgHandle
);
422 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
423 EnableWindow( owner
, FALSE
);
424 ShowWindow( hwnd
, SW_SHOW
);
426 while (MSG_InternalGetMessage( USER_HEAP_SEG_ADDR(msgHandle
), hwnd
, owner
,
427 MSGF_DIALOGBOX
, PM_REMOVE
,
428 !(wndPtr
->dwStyle
& DS_NOIDLEMSG
) ))
430 if (!IsDialogMessage( hwnd
, lpmsg
))
432 TranslateMessage( lpmsg
);
433 DispatchMessage( lpmsg
);
435 if (dlgInfo
->fEnd
) break;
437 retval
= dlgInfo
->msgResult
;
438 DestroyWindow( hwnd
);
439 USER_HEAP_FREE( msgHandle
);
440 EnableWindow( owner
, TRUE
);
445 /***********************************************************************
446 * DialogBox (USER.87)
448 int DialogBox( HINSTANCE hInst
, SEGPTR dlgTemplate
,
449 HWND owner
, WNDPROC dlgProc
)
451 return DialogBoxParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
455 /***********************************************************************
456 * DialogBoxParam (USER.239)
458 int DialogBoxParam( HINSTANCE hInst
, SEGPTR dlgTemplate
,
459 HWND owner
, WNDPROC dlgProc
, LPARAM param
)
463 dprintf_dialog(stddeb
, "DialogBoxParam: %d,%08lx,%d,%p,%ld\n",
464 hInst
, dlgTemplate
, owner
, dlgProc
, param
);
465 hwnd
= CreateDialogParam( hInst
, dlgTemplate
, owner
, dlgProc
, param
);
466 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
471 /***********************************************************************
472 * DialogBoxIndirect (USER.218)
474 int DialogBoxIndirect( HINSTANCE hInst
, HANDLE dlgTemplate
,
475 HWND owner
, WNDPROC dlgProc
)
477 return DialogBoxIndirectParam( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
481 /***********************************************************************
482 * DialogBoxIndirectParam (USER.240)
484 int DialogBoxIndirectParam( HINSTANCE hInst
, HANDLE dlgTemplate
,
485 HWND owner
, WNDPROC dlgProc
, LPARAM param
)
490 if (!(ptr
= GlobalLock( dlgTemplate
))) return -1;
491 hwnd
= CreateDialogIndirectParam( hInst
, ptr
, owner
, dlgProc
, param
);
492 GlobalUnlock( dlgTemplate
);
493 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
498 /***********************************************************************
499 * DialogBoxIndirectParamPtr
500 * like DialogBoxIndirectParam, but expects pointer to template
502 int DialogBoxIndirectParamPtr(HINSTANCE hInst
,LPCSTR dlgTemplate
,
503 HWND owner
, WNDPROC dlgProc
, LPARAM param
)
506 hwnd
= CreateDialogIndirectParam( hInst
, dlgTemplate
, owner
, dlgProc
, param
);
507 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
511 /***********************************************************************
512 * DialogBoxIndirectPtr
513 * like DialogBoxIndirect, but expects pointer to template
515 int DialogBoxIndirectPtr( HINSTANCE hInst
, LPCSTR dlgTemplate
,
516 HWND owner
, WNDPROC dlgProc
)
518 return DialogBoxIndirectParamPtr(hInst
, dlgTemplate
, owner
, dlgProc
, 0);
521 /***********************************************************************
522 * EndDialog (USER.88)
524 void EndDialog( HWND hwnd
, short retval
)
526 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
527 DIALOGINFO
* dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
528 dlgInfo
->msgResult
= retval
;
529 dlgInfo
->fEnd
= TRUE
;
530 dprintf_dialog(stddeb
, "EndDialog: %d %d\n", hwnd
, retval
);
534 /***********************************************************************
535 * IsDialogMessage (USER.90)
537 BOOL
IsDialogMessage( HWND hwndDlg
, LPMSG msg
)
542 if (!(wndPtr
= WIN_FindWndPtr( hwndDlg
))) return FALSE
;
543 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
)) return FALSE
;
545 /* Only the key messages get special processing */
546 if ((msg
->message
!= WM_KEYDOWN
) &&
547 (msg
->message
!= WM_SYSCHAR
) &&
548 (msg
->message
!= WM_CHAR
))
551 dlgCode
= SendMessage( msg
->hwnd
, WM_GETDLGCODE
, 0, 0 );
552 if (dlgCode
& DLGC_WANTMESSAGE
)
554 DispatchMessage( msg
);
561 if (dlgCode
& DLGC_WANTALLKEYS
) break;
565 if (!(dlgCode
& DLGC_WANTTAB
))
567 SendMessage( hwndDlg
, WM_NEXTDLGCTL
,
568 (GetKeyState(VK_SHIFT
) & 0x80), 0 );
575 if (!(dlgCode
& DLGC_WANTARROWS
))
577 SetFocus(GetNextDlgGroupItem(hwndDlg
,GetFocus(),FALSE
));
584 if (!(dlgCode
& DLGC_WANTARROWS
))
586 SetFocus(GetNextDlgGroupItem(hwndDlg
,GetFocus(),TRUE
));
592 SendMessage( hwndDlg
, WM_COMMAND
, IDCANCEL
,
593 MAKELPARAM( GetDlgItem(hwndDlg
,IDCANCEL
), 0 ));
598 DWORD dw
= SendMessage( hwndDlg
, DM_GETDEFID
, 0, 0 );
599 if (HIWORD(dw
) == DC_HASDEFID
)
600 SendMessage( hwndDlg
, WM_COMMAND
, LOWORD(dw
),
601 MAKELPARAM( GetDlgItem( hwndDlg
, LOWORD(dw
) ),
604 SendMessage( hwndDlg
, WM_COMMAND
, IDOK
,
605 MAKELPARAM( GetDlgItem(hwndDlg
,IDOK
), 0 ));
609 break; /* case WM_KEYDOWN */
613 if (dlgCode
& (DLGC_WANTALLKEYS
| DLGC_WANTCHARS
)) break;
617 if (dlgCode
& DLGC_WANTALLKEYS
) break;
621 /* If we get here, the message has not been treated specially */
622 /* and can be sent to its destination window. */
623 DispatchMessage( msg
);
628 /****************************************************************
629 * GetDlgCtrlID (USER.277)
631 int GetDlgCtrlID( HWND hwnd
)
633 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
634 if (wndPtr
) return wndPtr
->wIDmenu
;
639 /***********************************************************************
640 * GetDlgItem (USER.91)
642 HWND
GetDlgItem( HWND hwndDlg
, WORD id
)
648 if (!(wndPtr
= WIN_FindWndPtr( hwndDlg
))) return 0;
649 curChild
= wndPtr
->hwndChild
;
652 childPtr
= WIN_FindWndPtr( curChild
);
653 if (childPtr
->wIDmenu
== id
) return curChild
;
654 curChild
= childPtr
->hwndNext
;
660 /*******************************************************************
661 * SendDlgItemMessage (USER.101)
663 LONG
SendDlgItemMessage(HWND hwnd
, WORD id
, UINT msg
, WORD wParam
, LONG lParam
)
665 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
666 if (hwndCtrl
) return SendMessage( hwndCtrl
, msg
, wParam
, lParam
);
671 /*******************************************************************
672 * SetDlgItemText (USER.92)
674 void SetDlgItemText( HWND hwnd
, WORD id
, SEGPTR lpString
)
676 SendDlgItemMessage( hwnd
, id
, WM_SETTEXT
, 0, (DWORD
)lpString
);
680 /***********************************************************************
681 * GetDlgItemText (USER.93)
683 int GetDlgItemText( HWND hwnd
, WORD id
, SEGPTR str
, WORD max
)
685 return (int)SendDlgItemMessage( hwnd
, id
, WM_GETTEXT
, max
, (DWORD
)str
);
689 /*******************************************************************
690 * SetDlgItemInt (USER.94)
692 void SetDlgItemInt( HWND hwnd
, WORD id
, WORD value
, BOOL fSigned
)
694 HANDLE hText
= USER_HEAP_ALLOC( 10 );
695 char * str
= (char *) USER_HEAP_LIN_ADDR( hText
);
697 if (fSigned
) sprintf( str
, "%d", value
);
698 else sprintf( str
, "%u", value
);
699 SendDlgItemMessage( hwnd
, id
, WM_SETTEXT
, 0,
700 USER_HEAP_SEG_ADDR(hText
) );
701 USER_HEAP_FREE( hText
);
705 /***********************************************************************
706 * GetDlgItemInt (USER.95)
708 WORD
GetDlgItemInt( HWND hwnd
, WORD id
, BOOL
* translated
, BOOL fSigned
)
715 if (translated
) *translated
= FALSE
;
716 if (!(len
= SendDlgItemMessage( hwnd
, id
, WM_GETTEXTLENGTH
, 0, 0 )))
718 if (!(hText
= USER_HEAP_ALLOC( len
+1 ))) return 0;
719 str
= (char *) USER_HEAP_LIN_ADDR( hText
);
720 if (SendDlgItemMessage( hwnd
, id
, WM_GETTEXT
, len
+1,
721 USER_HEAP_SEG_ADDR(hText
) ))
724 result
= strtol( str
, &endptr
, 10 );
725 if (endptr
&& (endptr
!= str
)) /* Conversion was successful */
729 if ((result
< -32767) || (result
> 32767)) result
= 0;
730 else if (translated
) *translated
= TRUE
;
734 if ((result
< 0) || (result
> 65535)) result
= 0;
735 else if (translated
) *translated
= TRUE
;
739 USER_HEAP_FREE( hText
);
744 /***********************************************************************
745 * CheckDlgButton (USER.97)
747 void CheckDlgButton( HWND hwnd
, WORD id
, WORD check
)
749 SendDlgItemMessage( hwnd
, id
, BM_SETCHECK
, check
, 0 );
753 /***********************************************************************
754 * IsDlgButtonChecked (USER.98)
756 WORD
IsDlgButtonChecked( HWND hwnd
, WORD id
)
758 return (WORD
)SendDlgItemMessage( hwnd
, id
, BM_GETCHECK
, 0, 0 );
762 /***********************************************************************
763 * CheckRadioButton (USER.96)
765 void CheckRadioButton( HWND hwndDlg
, WORD firstID
, WORD lastID
, WORD checkID
)
767 HWND button
= GetWindow( hwndDlg
, GW_CHILD
);
772 if (!(wndPtr
= WIN_FindWndPtr( button
))) return;
773 if ((wndPtr
->wIDmenu
== firstID
) || (wndPtr
->wIDmenu
== lastID
)) break;
774 button
= wndPtr
->hwndNext
;
778 if (wndPtr
->wIDmenu
== lastID
)
779 lastID
= firstID
; /* Buttons are in reverse order */
782 if (!(wndPtr
= WIN_FindWndPtr( button
))) return;
783 SendMessage( button
, BM_SETCHECK
, (wndPtr
->wIDmenu
== checkID
), 0 );
784 if (wndPtr
->wIDmenu
== lastID
) break;
785 button
= wndPtr
->hwndNext
;
790 /***********************************************************************
791 * GetDialogBaseUnits (USER.243)
793 DWORD
GetDialogBaseUnits()
795 return MAKELONG( xBaseUnit
, yBaseUnit
);
799 /***********************************************************************
800 * MapDialogRect (USER.103)
802 void MapDialogRect( HWND hwnd
, LPRECT rect
)
804 DIALOGINFO
* dlgInfo
;
805 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
807 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
808 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
809 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
810 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
811 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
815 /***********************************************************************
816 * GetNextDlgGroupItem (USER.227)
818 HWND
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
820 HWND hwnd
, hwndStart
;
821 WND
* dlgPtr
, * ctrlPtr
, * wndPtr
;
823 if (!(dlgPtr
= WIN_FindWndPtr( hwndDlg
))) return 0;
824 if (!(ctrlPtr
= WIN_FindWndPtr( hwndCtrl
))) return 0;
825 if (ctrlPtr
->hwndParent
!= hwndDlg
) return 0;
827 if (!fPrevious
&& ctrlPtr
->hwndNext
) /*Check if next control is in group*/
829 wndPtr
= WIN_FindWndPtr( ctrlPtr
->hwndNext
);
830 if (!(wndPtr
->dwStyle
& WS_GROUP
)) return ctrlPtr
->hwndNext
;
833 if (ctrlPtr
->dwStyle
& WS_GROUP
) /* Control is the first of the group */
835 if (!fPrevious
) return hwndCtrl
; /* Control is alone in his group */
836 hwnd
= ctrlPtr
->hwndNext
;
837 while(hwnd
) /* Find last control of the group */
839 wndPtr
= WIN_FindWndPtr( hwnd
);
840 if (wndPtr
->dwStyle
& WS_GROUP
) break;
842 hwnd
= wndPtr
->hwndNext
;
847 /* Now we will have to find the start of the group */
849 hwndStart
= hwnd
= dlgPtr
->hwndChild
;
852 wndPtr
= WIN_FindWndPtr( hwnd
);
853 if (wndPtr
->dwStyle
& WS_GROUP
) hwndStart
= hwnd
; /*Start of a group*/
854 if (hwnd
== hwndCtrl
)
856 /* We found the control -> hwndStart is the first of the group */
857 if (!fPrevious
) return hwndStart
;
859 while(hwndStart
) /* Find the control placed before hwndCtrl */
861 wndPtr
= WIN_FindWndPtr( hwndStart
);
862 if (wndPtr
->hwndNext
== hwndCtrl
) return hwndStart
;
863 hwndStart
= wndPtr
->hwndNext
;
867 hwnd
= wndPtr
->hwndNext
;
869 return hwndCtrl
; /* Not found -> return original control */
873 /***********************************************************************
874 * GetNextDlgTabItem (USER.228)
876 HWND
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
879 WND
* dlgPtr
, * ctrlPtr
, * wndPtr
;
881 if (!(dlgPtr
= WIN_FindWndPtr( hwndDlg
))) return 0;
882 if (!(ctrlPtr
= WIN_FindWndPtr( hwndCtrl
))) return 0;
883 if (ctrlPtr
->hwndParent
!= hwndDlg
) return 0;
886 hwnd
= ctrlPtr
->hwndNext
;
889 if (!hwnd
) hwnd
= dlgPtr
->hwndChild
;
890 if (hwnd
== hwndCtrl
) break;
891 wndPtr
= WIN_FindWndPtr( hwnd
);
892 if (wndPtr
->dwStyle
& WS_TABSTOP
)
895 if (!fPrevious
) break;
897 hwnd
= wndPtr
->hwndNext
;