3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * PROJECT: ReactOS user32.dll
21 * FILE: dll/win32/user32/windows/dialog.c
23 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
24 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
25 * Steven Edwards (Steven_Ed4153@yahoo.com)
27 * 07-26-2003 Code ported from wine
28 * 09-05-2001 CSH Created
31 /* INCLUDES ******************************************************************/
35 #include <wine/debug.h>
36 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
38 /* MACROS/DEFINITIONS ********************************************************/
41 #define DF_OWNERENABLED 0x0002
42 #define DF_DIALOGACTIVE 0x4000 // ReactOS
43 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
44 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
45 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
46 #define GET_WORD(ptr) (*(WORD *)(ptr))
47 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
50 /* INTERNAL STRUCTS **********************************************************/
52 /* Dialog info structure */
55 HWND hwndFocus
; /* Current control with focus */
56 HFONT hUserFont
; /* Dialog font */
57 HMENU hMenu
; /* Dialog menu */
58 UINT xBaseUnit
; /* Dialog units (depends on the font) */
60 INT idResult
; /* EndDialog() result / default pushbutton ID */
61 UINT flags
; /* EndDialog() called for this dialog */
64 /* Dialog control information */
77 BOOL windowNameFree
; // ReactOS
102 /* CheckRadioButton structure */
111 /*********************************************************************
112 * dialog class descriptor
114 const struct builtin_class_descr DIALOG_builtin_class
=
116 WC_DIALOG
, /* name */
117 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
118 (WNDPROC
) DefDlgProcA
, /* procA */
119 (WNDPROC
) DefDlgProcW
, /* procW */
120 DLGWINDOWEXTRA
, /* extra */
121 (LPCWSTR
) IDC_ARROW
, /* cursor */
126 /* INTERNAL FUNCTIONS ********************************************************/
128 /***********************************************************************
131 * Get the DIALOGINFO structure of a window, allocating it if needed
132 * and 'create' is TRUE.
136 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
141 pWindow
= ValidateHwnd( hWnd
);
147 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
149 if (!dlgInfo
&& create
)
151 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
153 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
156 dlgInfo
->idResult
= IDOK
;
157 SETDLGINFO( hWnd
, dlgInfo
);
167 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
169 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
175 /***********************************************************************
178 * Helper function for modal dialogs to enable again the
179 * owner of the dialog box.
181 void DIALOG_EnableOwner( HWND hOwner
)
183 /* Owner must be a top-level window */
185 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
187 EnableWindow( hOwner
, TRUE
);
191 /***********************************************************************
192 * DIALOG_DisableOwner
194 * Helper function for modal dialogs to disable the
195 * owner of the dialog box. Returns TRUE if owner was enabled.
197 BOOL
DIALOG_DisableOwner( HWND hOwner
)
199 /* Owner must be a top-level window */
201 hOwner
= GetAncestor( hOwner
, GA_ROOT
);
202 if (!hOwner
) return FALSE
;
203 if (IsWindowEnabled( hOwner
))
205 EnableWindow( hOwner
, FALSE
);
212 /***********************************************************************
213 * DIALOG_GetControl32
215 * Return the class and text of the control pointed to by ptr,
216 * fill the header structure and return a pointer to the next control.
218 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
223 info
->helpId
= GET_DWORD(p
); p
+= 2;
224 info
->exStyle
= GET_DWORD(p
); p
+= 2;
225 info
->style
= GET_DWORD(p
); p
+= 2;
230 info
->style
= GET_DWORD(p
); p
+= 2;
231 info
->exStyle
= GET_DWORD(p
); p
+= 2;
233 info
->x
= GET_WORD(p
); p
++;
234 info
->y
= GET_WORD(p
); p
++;
235 info
->cx
= GET_WORD(p
); p
++;
236 info
->cy
= GET_WORD(p
); p
++;
240 /* id is a DWORD for DIALOGEX */
241 info
->id
= GET_DWORD(p
);
246 info
->id
= GET_WORD(p
);
250 if (GET_WORD(p
) == 0xffff)
252 static const WCHAR class_names
[6][10] =
254 { 'B','u','t','t','o','n', }, /* 0x80 */
255 { 'E','d','i','t', }, /* 0x81 */
256 { 'S','t','a','t','i','c', }, /* 0x82 */
257 { 'L','i','s','t','B','o','x', }, /* 0x83 */
258 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
259 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
261 WORD id
= GET_WORD(p
+1);
262 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
263 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
266 info
->className
= class_names
[id
];
270 info
->className
= NULL
;
271 /* FIXME: load other classes here? */
272 ERR("Unknown built-in class id %04x\n", id
);
278 info
->className
= (LPCWSTR
)p
;
279 p
+= strlenW( info
->className
) + 1;
282 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
284 //// ReactOS Rev 6478
285 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
286 if (info
->windowName
!= NULL
)
288 wsprintf((LPWSTR
)info
->windowName
, L
"#%u", GET_WORD(p
+ 1));
289 info
->windowNameFree
= TRUE
;
293 info
->windowNameFree
= FALSE
;
299 info
->windowName
= (LPCWSTR
)p
;
300 info
->windowNameFree
= FALSE
;
301 p
+= strlenW( info
->windowName
) + 1;
304 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
305 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
306 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
307 info
->style
, info
->exStyle
, info
->helpId
);
312 p
+= GET_WORD(p
) / sizeof(WORD
);
314 else info
->data
= NULL
;
317 /* Next control is on dword boundary */
318 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
322 /***********************************************************************
323 * DIALOG_CreateControls32
325 * Create the control windows for a dialog.
327 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
328 HINSTANCE hInst
, BOOL unicode
)
330 DIALOGINFO
* dlgInfo
;
331 DLG_CONTROL_INFO info
;
332 HWND hwndCtrl
, hwndDefButton
= 0;
333 INT items
= dlgTemplate
->nbItems
;
335 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
340 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
341 dlgTemplate
->dialogEx
);
342 info
.style
&= ~WS_POPUP
;
343 info
.style
|= WS_CHILD
;
345 if (info
.style
& WS_BORDER
)
347 info
.style
&= ~WS_BORDER
;
348 info
.exStyle
|= WS_EX_CLIENTEDGE
;
353 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
354 info
.className
, info
.windowName
,
355 info
.style
| WS_CHILD
,
356 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
357 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
358 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
359 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
360 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
361 hInst
, (LPVOID
)info
.data
);
365 LPSTR
class = (LPSTR
)info
.className
;
366 LPSTR caption
= (LPSTR
)info
.windowName
;
368 if (!IS_INTRESOURCE(class))
370 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
371 class = HeapAlloc( GetProcessHeap(), 0, len
);
373 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
375 if (!IS_INTRESOURCE(caption
))
377 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
378 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
380 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
383 if (class != NULL
&& caption
!= NULL
)
385 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
386 class, caption
, info
.style
| WS_CHILD
,
387 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
388 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
389 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
390 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
391 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
392 hInst
, (LPVOID
)info
.data
);
396 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
397 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
400 if (info
.windowNameFree
)
402 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
407 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
408 debugstr_w(info
.windowName
));
409 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
413 /* Send initialisation messages to the control */
414 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
415 (WPARAM
)dlgInfo
->hUserFont
, 0 );
416 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
418 /* If there's already a default push-button, set it back */
419 /* to normal and use this one instead. */
421 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
422 hwndDefButton
= hwndCtrl
;
423 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
431 /***********************************************************************
432 * DIALOG_IsAccelerator
434 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
436 HWND hwndControl
= hwnd
;
443 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
444 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
446 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
447 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
448 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
450 /* find the accelerator key */
451 LPWSTR p
= buffer
- 2;
455 p
= strchrW( p
+ 2, '&' );
457 while (p
!= NULL
&& p
[1] == '&');
459 /* and check if it's the one we're looking for */
460 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
462 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
464 /* set focus to the control */
465 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
466 /* and bump it on to next */
467 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
469 else if (dlgCode
& DLGC_BUTTON
)
471 /* send BM_CLICK message to the control */
472 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
477 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
481 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
483 while (!hwndNext
&& hwndControl
)
485 hwndControl
= GetParent( hwndControl
);
486 if (hwndControl
== hwndDlg
)
488 if(hwnd
==hwndDlg
) /* prevent endless loop */
493 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
496 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
498 hwndControl
= hwndNext
;
500 while (hwndControl
&& (hwndControl
!= hwnd
));
505 /***********************************************************************
506 * DIALOG_FindMsgDestination
508 * The messages that IsDialogMessage sends may not go to the dialog
509 * calling IsDialogMessage if that dialog is a child, and it has the
510 * DS_CONTROL style set.
511 * We propagate up until we hit one that does not have DS_CONTROL, or
512 * whose parent is not a dialog.
514 * This is undocumented behaviour.
516 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
518 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
521 HWND hParent
= GetParent(hwndDlg
);
524 if (!IsWindow(hParent
)) break;
526 pWnd
= ValidateHwnd(hParent
);
527 // FIXME: Use pWnd->fnid == FNID_DESKTOP
528 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
530 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
541 /***********************************************************************
544 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
546 DIALOGINFO
* dlgInfo
;
549 HWND ownerMsg
= GetAncestor( owner
, GA_ROOT
);
553 pWnd
= ValidateHwnd(hwnd
);
554 if (!pWnd
) return -1;
556 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
559 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
563 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
567 /* ShowWindow the first time the queue goes empty */
568 ShowWindow( hwnd
, SW_SHOWNORMAL
);
571 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
573 /* No message present -> send ENTERIDLE and wait */
574 if (ownerMsg
) SendMessageW( ownerMsg
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
576 GetMessageW( &msg
, 0, 0, 0 );
579 if (msg
.message
== WM_QUIT
)
581 PostQuitMessage( msg
.wParam
);
582 if (!IsWindow( hwnd
)) return 0;
587 * If the user is pressing Ctrl+C, send a WM_COPY message.
588 * Guido Pola, Bug 5281, Is there another way to check if the Dialog it's a MessageBox?
590 if( msg
.message
== WM_KEYDOWN
&&
591 pWnd
->state
& WNDS_MSGBOX
&& // Yes!
592 GetForegroundWindow() == hwnd
)
594 if( msg
.wParam
== L
'C' && GetKeyState(VK_CONTROL
) < 0 )
595 SendMessageW( hwnd
, WM_COPY
, 0, 0);
598 if (!IsWindow( hwnd
)) return 0;
599 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
601 TranslateMessage( &msg
);
602 DispatchMessageW( &msg
);
604 if (!IsWindow( hwnd
)) return 0;
605 if (dlgInfo
->flags
& DF_END
) break;
607 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
609 ShowWindow( hwnd
, SW_SHOWNORMAL
);
614 if (dlgInfo
->flags
& DF_OWNERENABLED
) DIALOG_EnableOwner( owner
);
615 retval
= dlgInfo
->idResult
;
616 DestroyWindow( hwnd
);
620 /***********************************************************************
621 * DIALOG_ParseTemplate32
623 * Fill a DLG_TEMPLATE structure from the dialog template, and return
624 * a pointer to the first control.
626 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
628 const WORD
*p
= (const WORD
*)template;
632 dlgver
= GET_WORD(p
); p
++;
633 signature
= GET_WORD(p
); p
++;
635 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
637 result
->dialogEx
= TRUE
;
638 result
->helpId
= GET_DWORD(p
); p
+= 2;
639 result
->exStyle
= GET_DWORD(p
); p
+= 2;
640 result
->style
= GET_DWORD(p
); p
+= 2;
644 result
->style
= GET_DWORD(p
- 2);
645 result
->dialogEx
= FALSE
;
647 result
->exStyle
= GET_DWORD(p
); p
+= 2;
649 result
->nbItems
= GET_WORD(p
); p
++;
650 result
->x
= GET_WORD(p
); p
++;
651 result
->y
= GET_WORD(p
); p
++;
652 result
->cx
= GET_WORD(p
); p
++;
653 result
->cy
= GET_WORD(p
); p
++;
654 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
655 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
656 result
->cx
, result
->cy
, result
->helpId
);
657 TRACE(" STYLE 0x%08x\n", result
->style
);
658 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
660 /* Get the menu name */
665 result
->menuName
= NULL
;
669 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
671 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
674 result
->menuName
= (LPCWSTR
)p
;
675 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
676 p
+= strlenW( result
->menuName
) + 1;
680 /* Get the class name */
685 result
->className
= WC_DIALOG
;
689 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
691 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
694 result
->className
= (LPCWSTR
)p
;
695 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
696 p
+= strlenW( result
->className
) + 1;
700 /* Get the window caption */
702 result
->caption
= (LPCWSTR
)p
;
703 p
+= strlenW( result
->caption
) + 1;
704 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
706 /* Get the font name */
708 result
->pointSize
= 0;
709 result
->faceName
= NULL
;
710 result
->weight
= FW_DONTCARE
;
711 result
->italic
= FALSE
;
713 if (result
->style
& DS_SETFONT
)
715 result
->pointSize
= GET_WORD(p
);
718 /* If pointSize is 0x7fff, it means that we need to use the font
719 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
720 * italic, and facename from the dialog template.
722 if (result
->pointSize
== 0x7fff)
724 /* We could call SystemParametersInfo here, but then we'd have
725 * to convert from pixel size to point size (which can be
728 TRACE(" FONT: Using message box font\n");
732 if (result
->dialogEx
)
734 result
->weight
= GET_WORD(p
); p
++;
735 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
737 result
->faceName
= (LPCWSTR
)p
;
738 p
+= strlenW( result
->faceName
) + 1;
740 TRACE(" FONT %d, %s, %d, %s\n",
741 result
->pointSize
, debugstr_w( result
->faceName
),
742 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
746 /* First control is on dword boundary */
747 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
750 /***********************************************************************
753 * Set the focus to a control of the dialog, selecting the text if
754 * the control is an edit dialog that has DLGC_HASSETSEL.
756 static void DEFDLG_SetFocus( HWND hwndCtrl
)
758 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
759 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
760 SetFocus( hwndCtrl
);
764 /***********************************************************************
767 static void DEFDLG_SaveFocus( HWND hwnd
)
770 HWND hwndFocus
= GetFocus();
772 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
773 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
774 infoPtr
->hwndFocus
= hwndFocus
;
775 /* Remove default button */
779 /***********************************************************************
780 * DEFDLG_RestoreFocus
782 static void DEFDLG_RestoreFocus( HWND hwnd
, BOOL justActivate
)
786 if (IsIconic( hwnd
)) return;
787 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
788 /* Don't set the focus back to controls if EndDialog is already called.*/
789 if (infoPtr
->flags
& DF_END
) return;
790 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
791 if (justActivate
) return;
792 /* If no saved focus control exists, set focus to the first visible,
793 non-disabled, WS_TABSTOP control in the dialog */
794 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
795 /* If there are no WS_TABSTOP controls, set focus to the first visible,
796 non-disabled control in the dialog */
797 if (!infoPtr
->hwndFocus
) infoPtr
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
798 if (!IsWindow( infoPtr
->hwndFocus
)) return;
801 SetFocus( infoPtr
->hwndFocus
);
803 DEFDLG_SetFocus( infoPtr
->hwndFocus
);
805 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
806 sometimes losing focus when receiving WM_SETFOCUS messages. */
809 /***********************************************************************
810 * DIALOG_CreateIndirect
811 * Creates a dialog box window
813 * modal = TRUE if we are called from a modal dialog box.
814 * (it's more compatible to do it here, as under Windows the owner
815 * is never disabled if the dialog fails because of an invalid template)
817 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
818 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
819 BOOL unicode
, BOOL modal
)
825 DLG_TEMPLATE
template;
826 DIALOGINFO
* dlgInfo
= NULL
;
827 DWORD units
= GetDialogBaseUnits();
828 BOOL ownerEnabled
= TRUE
;
832 UINT xBaseUnit
= LOWORD(units
);
833 UINT yBaseUnit
= HIWORD(units
);
835 /* Parse dialog template */
837 if (!dlgTemplate
) return 0;
838 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
842 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
844 /* Create custom font if needed */
846 if (template.style
& DS_SETFONT
)
850 if (template.pointSize
== 0x7fff)
852 /* We get the message font from the non-client metrics */
853 NONCLIENTMETRICSW ncMetrics
;
855 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
856 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
857 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
859 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
864 /* We convert the size to pixels and then make it -ve. This works
865 * for both +ve and -ve template.pointSize */
866 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
867 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
868 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
869 PROOF_QUALITY
, FF_DONTCARE
,
876 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
877 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
880 xBaseUnit
= charSize
.cx
;
881 yBaseUnit
= charSize
.cy
;
883 SelectObject( dc
, hOldFont
);
886 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
889 /* Create dialog main window */
891 rect
.left
= rect
.top
= 0;
892 rect
.right
= MulDiv(template.cx
, xBaseUnit
, 4);
893 rect
.bottom
= MulDiv(template.cy
, yBaseUnit
, 8);
895 if (template.style
& DS_CONTROL
)
896 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
897 template.style
|= DS_3DLOOK
;
898 if (template.style
& DS_MODALFRAME
)
899 template.exStyle
|= WS_EX_DLGMODALFRAME
;
900 if ((template.style
& DS_CONTROL
) || !(template.style
& WS_CHILD
))
901 template.exStyle
|= WS_EX_CONTROLPARENT
;
902 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
905 size
.cx
= rect
.right
- rect
.left
;
906 size
.cy
= rect
.bottom
- rect
.top
;
908 if (template.x
== CW_USEDEFAULT16
)
910 pos
.x
= pos
.y
= CW_USEDEFAULT
;
914 HMONITOR monitor
= 0;
915 MONITORINFO mon_info
;
917 mon_info
.cbSize
= sizeof(mon_info
);
918 if (template.style
& DS_CENTER
)
920 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
921 GetMonitorInfoW( monitor
, &mon_info
);
922 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
923 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
925 else if (template.style
& DS_CENTERMOUSE
)
927 GetCursorPos( &pos
);
928 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
929 GetMonitorInfoW( monitor
, &mon_info
);
933 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
934 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
935 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
))) ClientToScreen( owner
, &pos
);
937 if ( !(template.style
& WS_CHILD
) )
941 /* try to fit it into the desktop */
945 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
946 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
947 GetMonitorInfoW( monitor
, &mon_info
);
949 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
951 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
953 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
954 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
960 ownerEnabled
= DIALOG_DisableOwner( owner
);
961 if (ownerEnabled
) flags
|= DF_OWNERENABLED
;
966 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
967 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
968 owner
, hMenu
, hInst
, NULL
);
972 LPCSTR
class = (LPCSTR
)template.className
;
973 LPCSTR caption
= (LPCSTR
)template.caption
;
974 LPSTR class_tmp
= NULL
;
975 LPSTR caption_tmp
= NULL
;
977 if (!IS_INTRESOURCE(class))
979 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
980 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
981 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
984 if (!IS_INTRESOURCE(caption
))
986 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
987 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
988 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
989 caption
= caption_tmp
;
991 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
992 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
993 owner
, hMenu
, hInst
, NULL
);
994 HeapFree( GetProcessHeap(), 0, class_tmp
);
995 HeapFree( GetProcessHeap(), 0, caption_tmp
);
1000 if (hUserFont
) DeleteObject( hUserFont
);
1001 if (hMenu
) DestroyMenu( hMenu
);
1002 if (modal
&& (flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
1006 /* moved this from the top of the method to here as DIALOGINFO structure
1007 will be valid only after WM_CREATE message has been handled in DefDlgProc
1008 All the members of the structure get filled here using temp variables */
1009 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
1011 if (dlgInfo
== NULL
)
1013 if (hUserFont
) DeleteObject( hUserFont
);
1014 if (hMenu
) DestroyMenu( hMenu
);
1015 if (modal
&& (flags
& DF_OWNERENABLED
)) DIALOG_EnableOwner(owner
);
1019 dlgInfo
->hwndFocus
= 0;
1020 dlgInfo
->hUserFont
= hUserFont
;
1021 dlgInfo
->hMenu
= hMenu
;
1022 dlgInfo
->xBaseUnit
= xBaseUnit
;
1023 dlgInfo
->yBaseUnit
= yBaseUnit
;
1024 dlgInfo
->flags
= flags
;
1026 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1028 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1029 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1031 if (dlgProc
&& dlgInfo
->hUserFont
)
1032 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1034 /* Create controls */
1036 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1038 /* Send initialisation messages and set focus */
1042 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1043 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1044 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1045 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1047 /* By returning TRUE, app has requested a default focus assignment.
1048 * WM_INITDIALOG may have changed the tab order, so find the first
1049 * tabstop control again. */
1050 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1051 if (!dlgInfo
->hwndFocus
) dlgInfo
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1052 if( dlgInfo
->hwndFocus
)
1053 SetFocus( dlgInfo
->hwndFocus
);
1056 DEFDLG_SaveFocus( hwnd
);
1059 //// ReactOS Rev 30613 & 30644
1060 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1061 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1063 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1065 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1066 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1070 if (modal
&& ownerEnabled
) DIALOG_EnableOwner(owner
);
1071 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1072 if( IsWindow(hwnd
) )
1074 DestroyWindow( hwnd
);
1077 { ERR("DIALOG_CreateIndirect 1\n");
1078 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD
) && // Rule #1.
1079 !NtUserQueryWindow(owner
, QUERY_WINDOW_FOREGROUND
) )
1080 { ERR("DIALOG_CreateIndirect SFW\n");
1081 SetForegroundWindow(owner
);
1090 /***********************************************************************
1091 * DEFDLG_FindDefButton
1093 * Find the current default push-button.
1095 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1097 HWND hwndChild
, hwndTmp
;
1099 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1102 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1105 /* Recurse into WS_EX_CONTROLPARENT controls */
1106 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1108 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1109 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1110 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1113 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1119 /***********************************************************************
1122 * Set the default button id.
1124 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1126 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1127 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1128 INT old_id
= dlgInfo
->idResult
;
1130 dlgInfo
->idResult
= wParam
;
1132 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1133 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1134 return FALSE
; /* Destination is not a push button */
1136 /* Make sure the old default control is a valid push button ID */
1137 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1138 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1139 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1140 if (hwndOld
&& hwndOld
!= hwndNew
)
1141 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1145 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1146 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1152 /***********************************************************************
1153 * DEFDLG_SetDefButton
1155 * Set the new default button to be hwndNew.
1157 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1159 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1160 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1163 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1164 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1167 * Need to draw only default push button rectangle.
1168 * Since the next control is not a push button, need to draw the push
1169 * button rectangle for the default control.
1172 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1175 /* Make sure the old default control is a valid push button ID */
1176 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1177 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1178 if (hwndOld
&& hwndOld
!= hwndNew
)
1179 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1183 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1184 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1190 /***********************************************************************
1193 * Implementation of DefDlgProc(). Only handle messages that need special
1194 * handling for dialogs.
1196 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1197 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1203 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1207 HDC hdc
= (HDC
)wParam
;
1208 GetClientRect( hwnd
, &rect
);
1209 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1210 FillRect( hdc
, &rect
, brush
);
1216 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1218 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1219 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1220 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1221 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1222 NtUserxSetDialogPointer( hwnd
, 0 );
1224 /* Window clean-up */
1225 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1228 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1229 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1234 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1235 // if WA_CLICK/ACTIVE ? set dialog is active.
1236 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1237 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1239 if (wParam
) DEFDLG_RestoreFocus( hwnd
, TRUE
);
1240 else DEFDLG_SaveFocus( hwnd
);
1244 DEFDLG_RestoreFocus( hwnd
, FALSE
);
1248 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1249 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1253 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1256 if (dlgInfo
->idResult
)
1257 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1258 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1259 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1266 HWND hwndDest
= (HWND
)wParam
;
1268 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1269 if (hwndDest
) DEFDLG_SetFocus( hwndDest
);
1270 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1274 case WM_ENTERMENULOOP
:
1275 case WM_LBUTTONDOWN
:
1276 case WM_NCLBUTTONDOWN
:
1278 HWND hwndFocus
= GetFocus();
1281 /* always make combo box hide its listbox control */
1282 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1283 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1286 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1289 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1292 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1293 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1299 /***********************************************************************
1302 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1304 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1307 if (fResult
) return fResult
;
1309 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1310 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1312 if ( msg
== WM_COMPAREITEM
||
1313 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1314 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1317 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1320 /***********************************************************************
1321 * DIALOG_GetNextTabItem
1323 * Helper for GetNextDlgTabItem
1325 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1329 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1331 HWND hChildFirst
= 0;
1335 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1336 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1338 else if (IsChild( hwndMain
, hwndCtrl
))
1340 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1343 if(GetParent(hwndCtrl
) != hwndMain
)
1344 /* i.e. if we are not at the top level of the recursion */
1345 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1347 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1353 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1354 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1355 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1358 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1359 if (retWnd
) return (retWnd
);
1361 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1363 return (hChildFirst
);
1365 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1369 HWND hParent
= GetParent(hwndCtrl
);
1372 if(hParent
== hwndMain
) break;
1373 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1375 hParent
= GetParent(hParent
);
1378 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1380 return retWnd
? retWnd
: hwndCtrl
;
1384 /**********************************************************************
1385 * DIALOG_DlgDirListW
1387 * Helper function for DlgDirList*W
1389 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1390 INT idStatic
, UINT attrib
, BOOL combo
)
1393 LPWSTR orig_spec
= spec
;
1394 WCHAR any
[] = {'*','.','*',0};
1396 #define SENDMSG(msg,wparam,lparam) \
1397 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1398 : SendMessageW( hwnd, msg, wparam, lparam ))
1400 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1402 /* If the path exists and is a directory, chdir to it */
1403 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1408 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1409 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1410 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1415 if (!SetCurrentDirectoryW( spec
))
1417 *p
= sep
; /* Restore the original spec */
1424 TRACE( "mask=%s\n", spec
);
1426 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1428 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1430 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1431 if (attrib
& DDL_DIRECTORY
)
1433 if (!(attrib
& DDL_EXCLUSIVE
))
1435 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1436 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1439 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1440 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1445 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1449 /* Convert path specification to uppercase */
1450 if (spec
) CharUpperW(spec
);
1452 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1454 WCHAR temp
[MAX_PATH
];
1455 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1457 /* Can't use PostMessage() here, because the string is on the stack */
1458 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1461 if (orig_spec
&& (spec
!= orig_spec
))
1463 /* Update the original file spec */
1465 while ((*orig_spec
++ = *p
++));
1473 /**********************************************************************
1474 * DIALOG_DlgDirListA
1476 * Helper function for DlgDirList*A
1478 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1479 INT idStatic
, UINT attrib
, BOOL combo
)
1483 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1484 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1487 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1488 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1489 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1490 HeapFree( GetProcessHeap(), 0, specW
);
1493 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1496 /**********************************************************************
1497 * DIALOG_DlgDirSelect
1499 * Helper function for DlgDirSelect*
1501 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1502 INT id
, BOOL unicode
, BOOL combo
)
1504 WCHAR
*buffer
, *ptr
;
1507 HWND listbox
= GetDlgItem( hwnd
, id
);
1509 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1510 if (!listbox
) return FALSE
;
1512 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1513 if (item
== LB_ERR
) return FALSE
;
1515 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1516 if (size
== LB_ERR
) return FALSE
;
1518 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1520 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1522 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1524 if (buffer
[1] == '-') /* drive */
1532 buffer
[strlenW(buffer
)-1] = '\\';
1538 /* Filenames without a dot extension must have one tacked at the end */
1539 if (strchrW(buffer
, '.') == NULL
)
1541 buffer
[strlenW(buffer
)+1] = '\0';
1542 buffer
[strlenW(buffer
)] = '.';
1549 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1550 ((LPSTR
)str
)[len
-1] = 0;
1552 else lstrcpynW( str
, ptr
, len
);
1553 HeapFree( GetProcessHeap(), 0, buffer
);
1554 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1559 /* FUNCTIONS *****************************************************************/
1566 CreateDialogIndirectParamAorW(
1567 HINSTANCE hInstance
,
1568 LPCDLGTEMPLATE lpTemplate
,
1570 DLGPROC lpDialogFunc
,
1575 * This function might be obsolete since I don't think it is exported by NT
1576 * Also wine has one more parameter identifying weather it should call
1577 * the function with unicode or not
1579 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, FALSE
);
1588 CreateDialogIndirectParamA(
1589 HINSTANCE hInstance
,
1590 LPCDLGTEMPLATE lpTemplate
,
1592 DLGPROC lpDialogFunc
,
1595 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, DLG_ISANSI
);
1604 CreateDialogIndirectParamW(
1605 HINSTANCE hInstance
,
1606 LPCDLGTEMPLATE lpTemplate
,
1608 DLGPROC lpDialogFunc
,
1611 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, 0);
1621 HINSTANCE hInstance
,
1622 LPCSTR lpTemplateName
,
1624 DLGPROC lpDialogFunc
,
1630 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1631 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1632 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1642 HINSTANCE hInstance
,
1643 LPCWSTR lpTemplateName
,
1645 DLGPROC lpDialogFunc
,
1651 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1652 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1653 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1668 DIALOGINFO
*dlgInfo
;
1670 BOOL result
= FALSE
;
1672 /* Perform DIALOGINFO initialization if not done */
1673 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0;
1675 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1677 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1679 /* Call dialog procedure */
1680 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1683 if (!result
&& IsWindow(hDlg
))
1685 /* callback didn't process this message */
1699 case WM_ENTERMENULOOP
:
1700 case WM_LBUTTONDOWN
:
1701 case WM_NCLBUTTONDOWN
:
1702 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1705 case WM_COMPAREITEM
:
1710 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1713 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, TRUE
);
1728 DIALOGINFO
*dlgInfo
;
1730 BOOL result
= FALSE
;
1732 /* Perform DIALOGINFO initialization if not done */
1733 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0;
1735 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1737 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1739 /* Call dialog procedure */
1740 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1743 if (!result
&& IsWindow(hDlg
))
1745 /* callback didn't process this message */
1759 case WM_ENTERMENULOOP
:
1760 case WM_LBUTTONDOWN
:
1761 case WM_NCLBUTTONDOWN
:
1762 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1765 case WM_COMPAREITEM
:
1770 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1773 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, FALSE
);
1782 DialogBoxIndirectParamAorW(
1783 HINSTANCE hInstance
,
1784 LPCDLGTEMPLATE hDialogTemplate
,
1786 DLGPROC lpDialogFunc
,
1791 * This function might be obsolete since I don't think it is exported by NT
1792 * Also wine has one more parameter identifying weather it should call
1793 * the function with unicode or not
1795 HWND hWnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, TRUE
);
1796 if (hWnd
) return DIALOG_DoDialogBox( hWnd
, hWndParent
);
1806 DialogBoxIndirectParamA(
1807 HINSTANCE hInstance
,
1808 LPCDLGTEMPLATE hDialogTemplate
,
1810 DLGPROC lpDialogFunc
,
1813 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, DLG_ISANSI
);
1822 DialogBoxIndirectParamW(
1823 HINSTANCE hInstance
,
1824 LPCDLGTEMPLATE hDialogTemplate
,
1826 DLGPROC lpDialogFunc
,
1829 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, 0);
1839 HINSTANCE hInstance
,
1840 LPCSTR lpTemplateName
,
1842 DLGPROC lpDialogFunc
,
1848 //// ReactOS rev 33532
1849 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
)) ||
1850 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1852 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1855 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1857 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1860 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, TRUE
);
1861 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1872 HINSTANCE hInstance
,
1873 LPCWSTR lpTemplateName
,
1875 DLGPROC lpDialogFunc
,
1881 //// ReactOS rev 33532
1882 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
)) ||
1883 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1885 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1888 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1890 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1893 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, TRUE
);
1894 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1911 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1920 DlgDirListComboBoxA(
1927 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1936 DlgDirListComboBoxW(
1943 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1959 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1968 DlgDirSelectComboBoxExA(
1974 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, FALSE
, TRUE
);
1983 DlgDirSelectComboBoxExW(
1989 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, TRUE
, TRUE
);
2004 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
2019 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
2024 * @implemented Modified for ReactOS.
2032 BOOL wasEnabled
= TRUE
;
2033 DIALOGINFO
* dlgInfo
;
2037 TRACE("%p %ld\n", hwnd
, retval
);
2039 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2041 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2044 wasActive
= (hwnd
== GetActiveWindow());
2045 dlgInfo
->idResult
= retval
;
2046 dlgInfo
->flags
|= DF_END
;
2047 wasEnabled
= (dlgInfo
->flags
& DF_OWNERENABLED
);
2049 owner
= GetWindow( hwnd
, GW_OWNER
);
2050 if (wasEnabled
&& owner
)
2051 DIALOG_EnableOwner( owner
);
2053 /* Windows sets the focus to the dialog itself in EndDialog */
2055 if (wasActive
&& IsChild(hwnd
, GetFocus()))
2058 /* Don't have to send a ShowWindow(SW_HIDE), just do
2059 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2061 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2062 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2064 if (wasActive
&& owner
)
2066 /* If this dialog was given an owner then set the focus to that owner
2067 even when the owner is disabled (normally when a window closes any
2068 disabled windows cannot receive the focus). */
2069 SetActiveWindow(owner
);
2071 else if (hwnd
== GetActiveWindow()) // Check it again!
2073 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS
);
2076 /* unblock dialog loop */
2077 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2087 GetDialogBaseUnits(VOID
)
2096 if ((hdc
= GetDC(0)))
2098 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2099 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2100 ReleaseDC( 0, hdc
);
2115 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2132 if (!hDlg
) return 0;
2134 list
= WIN_ListChildren(hDlg
);
2135 if (!list
) return 0;
2137 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2139 HeapFree(GetProcessHeap(), 0, list
);
2140 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2158 LONG_PTR result
= 0;
2160 if (lpTranslated
) *lpTranslated
= FALSE
;
2161 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2165 result
= strtol( str
, &endptr
, 10 );
2166 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2168 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)))
2173 result
= strtoul( str
, &endptr
, 10 );
2174 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2176 if (result
== ULONG_MAX
) return 0;
2178 if (lpTranslated
) *lpTranslated
= TRUE
;
2179 return (UINT
)result
;
2194 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2195 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2196 if ( nMaxCount
) lpString
[0] = '\0';
2212 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2213 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2214 if ( nMaxCount
) lpString
[0] = '\0';
2223 GetNextDlgGroupItem(
2228 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2230 BOOL fSkipping
=FALSE
;
2232 if (hDlg
== hCtl
) hCtl
= NULL
;
2233 if (!hCtl
&& bPrevious
) return 0;
2235 /* if the hwndCtrl is the child of the control in the hwndDlg,
2236 * then the hwndDlg has to be the parent of the hwndCtrl */
2240 if (!IsChild (hDlg
, hCtl
)) return 0;
2241 /* Make sure hwndCtrl is a top-level child */
2246 /* No ctrl specified -> start from the beginning */
2247 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2248 /* MSDN is wrong. fPrevious does not result in the last child */
2250 /* No ctrl specified -> start from the beginning */
2251 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2253 /* MSDN is wrong. fPrevious does not result in the last child */
2255 /* Maybe that first one is valid. If so then we don't want to skip it*/
2256 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2263 /* Always go forward around the group and list of controls; for the
2264 * previous control keep track; for the next break when you find one
2268 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
2273 /* Climb out until there is a next sibling of the ancestor or we
2274 * reach the top (in which case we loop back to the start)
2276 if (hDlg
== GetParent (hwnd
))
2278 /* Wrap around to the beginning of the list, within the same
2279 * group. (Once only)
2281 if (fLooped
) goto end
;
2283 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2287 hwnd
= GetParent (hwnd
);
2288 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2293 /* Wander down the leading edge of controlparents */
2294 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2295 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2296 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2298 /* Question. If the control is a control parent but either has no
2299 * children or is not visible/enabled then if it has a WS_GROUP does
2300 * it count? For that matter does it count anyway?
2301 * I believe it doesn't count.
2304 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2306 hwndLastGroup
= hwnd
;
2309 /* Look for the beginning of the group */
2316 if (!fSkipping
) break;
2317 if (hwndLastGroup
== hwnd
) break;
2318 hwnd
= hwndLastGroup
;
2324 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2328 if (!bPrevious
) break;
2348 pWindow
= ValidateHwnd( hDlg
);
2349 if (!pWindow
) return NULL
;
2352 pWindow
= ValidateHwnd( hCtl
);
2353 if (!pWindow
) return NULL
;
2356 /* Undocumented but tested under Win2000 and WinME */
2357 if (hDlg
== hCtl
) hCtl
= NULL
;
2359 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2360 * NB GetLastError returns whatever was set before the function was
2363 if (!hCtl
&& bPrevious
) return 0;
2365 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2376 return IsDialogMessageW(hDlg
, lpMsg
);
2380 /***********************************************************************
2381 * DIALOG_FixOneChildOnChangeFocus
2383 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2386 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2389 /* If a default pushbutton then no longer default */
2390 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2391 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2395 /***********************************************************************
2396 * DIALOG_FixChildrenOnChangeFocus
2398 * Following the change of focus that occurs for example after handling
2399 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2400 * children may be required.
2402 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2404 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2405 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2406 /* Windows does ask for this. I don't know why yet */
2408 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2410 /* If the button that is getting the focus WAS flagged as the default
2411 * pushbutton then ask the dialog what it thinks the default is and
2412 * set that in the default style.
2414 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2416 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2417 if (HIWORD(def_id
) == DC_HASDEFID
)
2420 def_id
= LOWORD(def_id
);
2421 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2424 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2425 /* I know that if it is a button then it should already be a
2426 * UNDEFPUSHBUTTON, since we have just told the buttons to
2427 * change style. But maybe they ignored our request
2429 if ((dlgcode_def
& DLGC_BUTTON
) &&
2430 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2432 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2437 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2439 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2440 /* I wonder why it doesn't send a DM_SETDEFID */
2444 /***********************************************************************
2447 * A recursive version of GetDlgItem
2450 * The HWND for a Child ID.
2452 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2455 HWND
*list
= WIN_ListChildren( hwndDlg
);
2458 if (!list
) return 0;
2460 for (i
= 0; list
[i
]; i
++)
2462 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2468 /* Recurse into every child */
2469 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2472 HeapFree( GetProcessHeap(), 0, list
);
2488 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2490 if (hDlg
== GetDesktopWindow()) return FALSE
;
2491 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2493 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2495 switch(lpMsg
->message
)
2498 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2499 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2501 switch(lpMsg
->wParam
)
2504 if (!(dlgCode
& DLGC_WANTTAB
))
2506 BOOL fIsDialog
= TRUE
;
2507 WND
*pWnd
= ValidateHwnd(hDlg
);
2509 if (pWnd
&& TestWindowProcess(pWnd
))
2511 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2514 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2516 /* I am not sure under which circumstances the TAB is handled
2517 * each way. All I do know is that it does not always simply
2518 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2519 * do so but I presume someone has)
2522 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2525 /* It would appear that GetNextDlgTabItem can handle being
2526 * passed hwndDlg rather than NULL but that is undocumented
2527 * so let's do it properly
2529 HWND hwndFocus
= GetFocus();
2530 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2531 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2532 GetKeyState (VK_SHIFT
) & 0x8000);
2535 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2536 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2537 if (dlgCode
& DLGC_HASSETSEL
)
2539 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2540 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2544 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2545 length
= strlenW (buffer
);
2546 HeapFree (GetProcessHeap(), 0, buffer
);
2547 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2550 SetFocus (hwndNext
);
2551 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2564 if (!(dlgCode
& DLGC_WANTARROWS
))
2566 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2567 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2568 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2575 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2582 if ((GetFocus() == lpMsg
->hwnd
) &&
2583 (SendMessageW (lpMsg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2585 SendMessageW (hDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(lpMsg
->hwnd
),BN_CLICKED
), (LPARAM
)lpMsg
->hwnd
);
2587 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2589 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2590 if (!hwndDef
|| IsWindowEnabled(hwndDef
))
2591 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2595 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2604 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2605 * It does NOT get sent in the test program I have
2607 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2608 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2609 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2613 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2615 /* don't translate or dispatch */
2621 /* If the ALT key is being pressed display the keyboard cues */
2622 if ( HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
&&
2623 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2624 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2628 /* If the ALT key is being pressed display the keyboard cues */
2629 if ( lpMsg
->wParam
== SC_KEYMENU
&&
2630 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2632 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2637 TranslateMessage( lpMsg
);
2638 DispatchMessageW( lpMsg
);
2652 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2665 DIALOGINFO
* dlgInfo
;
2666 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2667 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2668 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2669 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2670 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2680 SendDlgItemMessageA(
2688 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2689 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2690 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2700 SendDlgItemMessageW(
2708 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2709 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2710 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2728 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2729 else sprintf( str
, "%u", uValue
);
2730 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2745 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2746 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2761 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2762 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2777 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2781 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2783 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2784 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2786 if((lChildID
>= lpRadioGroup
->firstID
) &&
2787 (lChildID
<= lpRadioGroup
->lastID
))
2789 if (lChildID
== lpRadioGroup
->checkID
)
2791 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2795 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2813 RADIOGROUP radioGroup
;
2815 radioGroup
.firstID
= nIDFirstButton
;
2816 radioGroup
.lastID
= nIDLastButton
;
2817 radioGroup
.checkID
= nIDCheckButton
;
2819 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);