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: win32ss/user/user32/windows/dialog.c
22 * PURPOSE: Dialog Manager
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
33 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
35 /* MACROS/DEFINITIONS ********************************************************/
38 #define DF_DIALOGACTIVE 0x4000 // ReactOS
39 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
40 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
41 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
42 #define GET_WORD(ptr) (*(WORD *)(ptr))
43 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
44 #define GET_LONG(ptr) (*(const LONG *)(ptr))
47 /* INTERNAL STRUCTS **********************************************************/
49 /* Dialog info structure */
52 HWND hwndFocus
; /* Current control with focus */
53 HFONT hUserFont
; /* Dialog font */
54 HMENU hMenu
; /* Dialog menu */
55 UINT xBaseUnit
; /* Dialog units (depends on the font) */
57 INT idResult
; /* EndDialog() result / default pushbutton ID */
58 UINT flags
; /* EndDialog() called for this dialog */
61 /* Dialog control information */
74 BOOL windowNameFree
; // ReactOS
99 /* CheckRadioButton structure */
108 /*********************************************************************
109 * dialog class descriptor
111 const struct builtin_class_descr DIALOG_builtin_class
=
113 WC_DIALOG
, /* name */
114 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
115 DefDlgProcA
, /* procA */
116 DefDlgProcW
, /* procW */
117 DLGWINDOWEXTRA
, /* extra */
118 (LPCWSTR
) IDC_ARROW
, /* cursor */
123 /* INTERNAL FUNCTIONS ********************************************************/
125 /***********************************************************************
128 * Get the DIALOGINFO structure of a window, allocating it if needed
129 * and 'create' is TRUE.
133 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
138 pWindow
= ValidateHwnd( hWnd
);
144 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
146 if (!dlgInfo
&& create
)
148 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
150 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
153 dlgInfo
->idResult
= IDOK
;
154 SETDLGINFO( hWnd
, dlgInfo
);
164 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
166 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
172 /***********************************************************************
173 * DIALOG_GetControl32
175 * Return the class and text of the control pointed to by ptr,
176 * fill the header structure and return a pointer to the next control.
178 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
183 info
->helpId
= GET_DWORD(p
); p
+= 2;
184 info
->exStyle
= GET_DWORD(p
); p
+= 2;
185 info
->style
= GET_DWORD(p
); p
+= 2;
190 info
->style
= GET_DWORD(p
); p
+= 2;
191 info
->exStyle
= GET_DWORD(p
); p
+= 2;
193 info
->x
= GET_WORD(p
); p
++;
194 info
->y
= GET_WORD(p
); p
++;
195 info
->cx
= GET_WORD(p
); p
++;
196 info
->cy
= GET_WORD(p
); p
++;
200 /* id is 4 bytes for DIALOGEX */
201 info
->id
= GET_LONG(p
);
206 info
->id
= GET_WORD(p
);
210 if (GET_WORD(p
) == 0xffff)
212 static const WCHAR class_names
[6][10] =
214 { 'B','u','t','t','o','n', }, /* 0x80 */
215 { 'E','d','i','t', }, /* 0x81 */
216 { 'S','t','a','t','i','c', }, /* 0x82 */
217 { 'L','i','s','t','B','o','x', }, /* 0x83 */
218 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
219 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
221 WORD id
= GET_WORD(p
+1);
222 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
223 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
226 info
->className
= class_names
[id
];
230 info
->className
= NULL
;
231 /* FIXME: load other classes here? */
232 ERR("Unknown built-in class id %04x\n", id
);
238 info
->className
= (LPCWSTR
)p
;
239 p
+= strlenW( info
->className
) + 1;
242 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
244 //// ReactOS Rev 6478
245 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
246 if (info
->windowName
!= NULL
)
248 wsprintf((LPWSTR
)info
->windowName
, L
"#%u", GET_WORD(p
+ 1));
249 info
->windowNameFree
= TRUE
;
253 info
->windowNameFree
= FALSE
;
259 info
->windowName
= (LPCWSTR
)p
;
260 info
->windowNameFree
= FALSE
;
261 p
+= strlenW( info
->windowName
) + 1;
264 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
265 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
266 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
267 info
->style
, info
->exStyle
, info
->helpId
);
272 p
+= GET_WORD(p
) / sizeof(WORD
);
274 else info
->data
= NULL
;
277 /* Next control is on dword boundary */
278 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
282 /***********************************************************************
283 * DIALOG_CreateControls32
285 * Create the control windows for a dialog.
287 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
288 HINSTANCE hInst
, BOOL unicode
)
290 DIALOGINFO
* dlgInfo
;
291 DLG_CONTROL_INFO info
;
292 HWND hwndCtrl
, hwndDefButton
= 0;
293 INT items
= dlgTemplate
->nbItems
;
295 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
300 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
301 dlgTemplate
->dialogEx
);
302 info
.style
&= ~WS_POPUP
;
303 info
.style
|= WS_CHILD
;
305 if (info
.style
& WS_BORDER
)
307 info
.style
&= ~WS_BORDER
;
308 info
.exStyle
|= WS_EX_CLIENTEDGE
;
313 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
314 info
.className
, info
.windowName
,
315 info
.style
| WS_CHILD
,
316 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
317 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
318 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
319 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
320 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
321 hInst
, (LPVOID
)info
.data
);
325 LPSTR
class = (LPSTR
)info
.className
;
326 LPSTR caption
= (LPSTR
)info
.windowName
;
328 if (!IS_INTRESOURCE(class))
330 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
331 class = HeapAlloc( GetProcessHeap(), 0, len
);
333 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
335 if (!IS_INTRESOURCE(caption
))
337 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
338 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
340 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
343 if (class != NULL
&& caption
!= NULL
)
345 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
346 class, caption
, info
.style
| WS_CHILD
,
347 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
348 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
349 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
350 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
351 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
352 hInst
, (LPVOID
)info
.data
);
356 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
357 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
360 if (info
.windowNameFree
)
362 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
367 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
368 debugstr_w(info
.windowName
));
369 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
373 /* Send initialisation messages to the control */
374 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
375 (WPARAM
)dlgInfo
->hUserFont
, 0 );
376 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
378 /* If there's already a default push-button, set it back */
379 /* to normal and use this one instead. */
381 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
382 hwndDefButton
= hwndCtrl
;
383 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
391 /***********************************************************************
392 * DIALOG_IsAccelerator
394 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
396 HWND hwndControl
= hwnd
;
403 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
404 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
406 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
407 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
408 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
410 /* find the accelerator key */
411 LPWSTR p
= buffer
- 2;
415 p
= strchrW( p
+ 2, '&' );
417 while (p
!= NULL
&& p
[1] == '&');
419 /* and check if it's the one we're looking for */
420 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
422 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
424 /* set focus to the control */
425 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
426 /* and bump it on to next */
427 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
429 else if (dlgCode
& DLGC_BUTTON
)
431 /* send BM_CLICK message to the control */
432 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
437 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
441 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
443 while (!hwndNext
&& hwndControl
)
445 hwndControl
= GetParent( hwndControl
);
446 if (hwndControl
== hwndDlg
)
448 if(hwnd
==hwndDlg
) /* prevent endless loop */
453 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
456 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
458 hwndControl
= hwndNext
;
460 while (hwndControl
&& (hwndControl
!= hwnd
));
465 /***********************************************************************
466 * DIALOG_FindMsgDestination
468 * The messages that IsDialogMessage sends may not go to the dialog
469 * calling IsDialogMessage if that dialog is a child, and it has the
470 * DS_CONTROL style set.
471 * We propagate up until we hit one that does not have DS_CONTROL, or
472 * whose parent is not a dialog.
474 * This is undocumented behaviour.
476 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
478 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
481 HWND hParent
= GetParent(hwndDlg
);
484 if (!IsWindow(hParent
)) break;
486 pWnd
= ValidateHwnd(hParent
);
487 // FIXME: Use pWnd->fnid == FNID_DESKTOP
488 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
490 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
501 /***********************************************************************
504 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
506 DIALOGINFO
* dlgInfo
;
512 pWnd
= ValidateHwnd(hwnd
);
513 if (!pWnd
) return -1;
515 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
518 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
522 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
526 /* ShowWindow the first time the queue goes empty */
527 ShowWindow( hwnd
, SW_SHOWNORMAL
);
530 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
532 /* No message present -> send ENTERIDLE and wait */
533 SendMessageW( owner
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
535 GetMessageW( &msg
, 0, 0, 0 );
538 if (msg
.message
== WM_QUIT
)
540 PostQuitMessage( msg
.wParam
);
541 if (!IsWindow( hwnd
)) return 0;
546 * If the user is pressing Ctrl+C, send a WM_COPY message.
547 * Guido Pola, CORE-4829, Is there another way to check if the Dialog is a MessageBox?
549 if (msg
.message
== WM_KEYDOWN
&&
550 pWnd
->state
& WNDS_MSGBOX
&& // Yes!
551 GetForegroundWindow() == hwnd
)
553 if (msg
.wParam
== L
'C' && GetKeyState(VK_CONTROL
) < 0)
554 SendMessageW(hwnd
, WM_COPY
, 0, 0);
557 if (!IsWindow( hwnd
)) return 0;
558 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
560 TranslateMessage( &msg
);
561 DispatchMessageW( &msg
);
563 if (!IsWindow( hwnd
)) return 0;
564 if (dlgInfo
->flags
& DF_END
) break;
566 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
568 ShowWindow( hwnd
, SW_SHOWNORMAL
);
573 retval
= dlgInfo
->idResult
;
574 DestroyWindow( hwnd
);
578 /***********************************************************************
579 * DIALOG_ParseTemplate32
581 * Fill a DLG_TEMPLATE structure from the dialog template, and return
582 * a pointer to the first control.
584 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
586 const WORD
*p
= (const WORD
*)template;
590 dlgver
= GET_WORD(p
); p
++;
591 signature
= GET_WORD(p
); p
++;
593 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
595 result
->dialogEx
= TRUE
;
596 result
->helpId
= GET_DWORD(p
); p
+= 2;
597 result
->exStyle
= GET_DWORD(p
); p
+= 2;
598 result
->style
= GET_DWORD(p
); p
+= 2;
602 result
->style
= GET_DWORD(p
- 2);
603 result
->dialogEx
= FALSE
;
605 result
->exStyle
= GET_DWORD(p
); p
+= 2;
607 result
->nbItems
= GET_WORD(p
); p
++;
608 result
->x
= GET_WORD(p
); p
++;
609 result
->y
= GET_WORD(p
); p
++;
610 result
->cx
= GET_WORD(p
); p
++;
611 result
->cy
= GET_WORD(p
); p
++;
612 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
613 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
614 result
->cx
, result
->cy
, result
->helpId
);
615 TRACE(" STYLE 0x%08x\n", result
->style
);
616 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
618 /* Get the menu name */
623 result
->menuName
= NULL
;
627 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
629 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
632 result
->menuName
= (LPCWSTR
)p
;
633 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
634 p
+= strlenW( result
->menuName
) + 1;
638 /* Get the class name */
643 result
->className
= WC_DIALOG
;
647 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
649 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
652 result
->className
= (LPCWSTR
)p
;
653 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
654 p
+= strlenW( result
->className
) + 1;
658 /* Get the window caption */
660 result
->caption
= (LPCWSTR
)p
;
661 p
+= strlenW( result
->caption
) + 1;
662 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
664 /* Get the font name */
666 result
->pointSize
= 0;
667 result
->faceName
= NULL
;
668 result
->weight
= FW_DONTCARE
;
669 result
->italic
= FALSE
;
671 if (result
->style
& DS_SETFONT
)
673 result
->pointSize
= GET_WORD(p
);
676 /* If pointSize is 0x7fff, it means that we need to use the font
677 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
678 * italic, and facename from the dialog template.
680 if (result
->pointSize
== 0x7fff)
682 /* We could call SystemParametersInfo here, but then we'd have
683 * to convert from pixel size to point size (which can be
686 TRACE(" FONT: Using message box font\n");
690 if (result
->dialogEx
)
692 result
->weight
= GET_WORD(p
); p
++;
693 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
695 result
->faceName
= (LPCWSTR
)p
;
696 p
+= strlenW( result
->faceName
) + 1;
698 TRACE(" FONT %d, %s, %d, %s\n",
699 result
->pointSize
, debugstr_w( result
->faceName
),
700 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
704 /* First control is on dword boundary */
705 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
708 /***********************************************************************
711 * Set the focus to a control of the dialog, selecting the text if
712 * the control is an edit dialog that has DLGC_HASSETSEL.
714 static void DEFDLG_SetFocus( HWND hwndCtrl
)
716 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
717 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
718 SetFocus( hwndCtrl
);
722 /***********************************************************************
725 static void DEFDLG_SaveFocus( HWND hwnd
)
728 HWND hwndFocus
= GetFocus();
730 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
731 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
732 infoPtr
->hwndFocus
= hwndFocus
;
733 /* Remove default button */
737 /***********************************************************************
738 * DEFDLG_RestoreFocus
740 static void DEFDLG_RestoreFocus( HWND hwnd
, BOOL justActivate
)
744 if (IsIconic( hwnd
)) return;
745 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
746 /* Don't set the focus back to controls if EndDialog is already called.*/
747 if (infoPtr
->flags
& DF_END
) return;
748 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
749 if (justActivate
) return;
750 /* If no saved focus control exists, set focus to the first visible,
751 non-disabled, WS_TABSTOP control in the dialog */
752 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
753 /* If there are no WS_TABSTOP controls, set focus to the first visible,
754 non-disabled control in the dialog */
755 if (!infoPtr
->hwndFocus
) infoPtr
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
756 if (!IsWindow( infoPtr
->hwndFocus
)) return;
759 SetFocus( infoPtr
->hwndFocus
);
761 DEFDLG_SetFocus( infoPtr
->hwndFocus
);
763 infoPtr
->hwndFocus
= NULL
;
766 /***********************************************************************
767 * DIALOG_CreateIndirect
768 * Creates a dialog box window
770 * modal = TRUE if we are called from a modal dialog box.
771 * (it's more compatible to do it here, as under Windows the owner
772 * is never disabled if the dialog fails because of an invalid template)
774 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
775 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
776 BOOL unicode
, HWND
*modal_owner
)
782 DLG_TEMPLATE
template;
783 DIALOGINFO
* dlgInfo
= NULL
;
784 DWORD units
= GetDialogBaseUnits();
785 HWND disabled_owner
= NULL
;
789 UINT xBaseUnit
= LOWORD(units
);
790 UINT yBaseUnit
= HIWORD(units
);
792 /* Parse dialog template */
794 if (!dlgTemplate
) return 0;
795 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
799 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
801 /* Create custom font if needed */
803 if (template.style
& DS_SETFONT
)
807 if (template.pointSize
== 0x7fff)
809 /* We get the message font from the non-client metrics */
810 NONCLIENTMETRICSW ncMetrics
;
812 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
813 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
814 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
816 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
821 /* We convert the size to pixels and then make it -ve. This works
822 * for both +ve and -ve template.pointSize */
823 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
824 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
825 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
826 PROOF_QUALITY
, FF_DONTCARE
,
833 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
834 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
837 xBaseUnit
= charSize
.cx
;
838 yBaseUnit
= charSize
.cy
;
840 SelectObject( dc
, hOldFont
);
843 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
846 /* Create dialog main window */
848 SetRect(&rect
, 0, 0, MulDiv(template.cx
, xBaseUnit
, 4), MulDiv(template.cy
, yBaseUnit
, 8));
849 if (template.style
& DS_CONTROL
)
850 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
851 template.style
|= DS_3DLOOK
;
852 if (template.style
& DS_MODALFRAME
)
853 template.exStyle
|= WS_EX_DLGMODALFRAME
;
854 if ((template.style
& DS_CONTROL
) || !(template.style
& WS_CHILD
))
855 template.exStyle
|= WS_EX_CONTROLPARENT
;
856 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
859 size
.cx
= rect
.right
- rect
.left
;
860 size
.cy
= rect
.bottom
- rect
.top
;
862 if (template.x
== CW_USEDEFAULT16
)
864 pos
.x
= pos
.y
= CW_USEDEFAULT
;
868 HMONITOR monitor
= 0;
869 MONITORINFO mon_info
;
871 mon_info
.cbSize
= sizeof(mon_info
);
872 if (template.style
& DS_CENTER
)
874 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
875 GetMonitorInfoW( monitor
, &mon_info
);
876 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
877 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
879 else if (template.style
& DS_CENTERMOUSE
)
881 GetCursorPos( &pos
);
882 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
883 GetMonitorInfoW( monitor
, &mon_info
);
887 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
888 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
890 // REACTOS : Need an owner to be passed!!!
892 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
)) && owner
) ClientToScreen( owner
, &pos
);
894 if ( !(template.style
& WS_CHILD
) )
898 /* try to fit it into the desktop */
902 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
903 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
904 GetMonitorInfoW( monitor
, &mon_info
);
906 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
908 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
910 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
911 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
915 if (modal_owner
&& owner
)
919 * Owner needs to be top level window. We need to duplicate the logic from server,
920 * because we need to disable it before creating dialog window. Note that we do that
921 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
924 while ((GetWindowLongW( owner
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
926 parent
= GetParent( owner
);
927 if (!parent
|| parent
== GetDesktopWindow()) break;
930 ////// Wine'ie babies need to fix your code!!!! CORE-11633
931 if (!parent
) parent
= GetAncestor( owner
, GA_ROOT
);
937 if (IsWindowEnabled( owner
))
939 disabled_owner
= owner
;
940 EnableWindow( disabled_owner
, FALSE
);
943 *modal_owner
= owner
;
948 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
949 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
950 owner
, hMenu
, hInst
, NULL
);
954 LPCSTR
class = (LPCSTR
)template.className
;
955 LPCSTR caption
= (LPCSTR
)template.caption
;
956 LPSTR class_tmp
= NULL
;
957 LPSTR caption_tmp
= NULL
;
959 if (!IS_INTRESOURCE(class))
961 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
962 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
963 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
966 if (!IS_INTRESOURCE(caption
))
968 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
969 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
970 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
971 caption
= caption_tmp
;
973 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
974 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
975 owner
, hMenu
, hInst
, NULL
);
976 HeapFree( GetProcessHeap(), 0, class_tmp
);
977 HeapFree( GetProcessHeap(), 0, caption_tmp
);
982 if (hUserFont
) DeleteObject( hUserFont
);
983 if (hMenu
) DestroyMenu( hMenu
);
984 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
988 /* moved this from the top of the method to here as DIALOGINFO structure
989 will be valid only after WM_CREATE message has been handled in DefDlgProc
990 All the members of the structure get filled here using temp variables */
991 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
995 if (hUserFont
) DeleteObject( hUserFont
);
996 if (hMenu
) DestroyMenu( hMenu
);
997 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1001 dlgInfo
->hwndFocus
= 0;
1002 dlgInfo
->hUserFont
= hUserFont
;
1003 dlgInfo
->hMenu
= hMenu
;
1004 dlgInfo
->xBaseUnit
= xBaseUnit
;
1005 dlgInfo
->yBaseUnit
= yBaseUnit
;
1006 dlgInfo
->flags
= flags
;
1008 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1010 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1011 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1013 if (dlgProc
&& dlgInfo
->hUserFont
)
1014 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1016 /* Create controls */
1018 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1020 /* Send initialisation messages and set focus */
1024 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1025 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1026 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1027 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1029 /* By returning TRUE, app has requested a default focus assignment.
1030 * WM_INITDIALOG may have changed the tab order, so find the first
1031 * tabstop control again. */
1032 focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1033 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1036 if (SendMessageW( focus
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
1037 SendMessageW( focus
, EM_SETSEL
, 0, MAXLONG
);
1042 if (!(template.style
& WS_CHILD
))
1046 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1047 //// This now breaks test_SaveRestoreFocus.
1048 //DEFDLG_SaveFocus( hwnd );
1051 //// ReactOS Rev 30613 & 30644
1052 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1053 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1055 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1057 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1058 UpdateWindow( hwnd
);
1059 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1063 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1064 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1065 if( IsWindow(hwnd
) )
1067 DestroyWindow( hwnd
);
1070 { ERR("DIALOG_CreateIndirect 1\n");
1071 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD
) && // Rule #1.
1072 !NtUserQueryWindow(owner
, QUERY_WINDOW_FOREGROUND
) )
1073 { ERR("DIALOG_CreateIndirect SFW\n");
1074 SetForegroundWindow(owner
);
1083 /***********************************************************************
1084 * DEFDLG_FindDefButton
1086 * Find the current default push-button.
1088 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1090 HWND hwndChild
, hwndTmp
;
1092 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1095 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1098 /* Recurse into WS_EX_CONTROLPARENT controls */
1099 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1101 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1102 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1103 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1106 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1112 /***********************************************************************
1115 * Set the default button id.
1117 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1119 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1120 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1121 INT old_id
= dlgInfo
->idResult
;
1123 dlgInfo
->idResult
= wParam
;
1125 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1126 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1127 return FALSE
; /* Destination is not a push button */
1129 /* Make sure the old default control is a valid push button ID */
1130 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1131 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1132 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1133 if (hwndOld
&& hwndOld
!= hwndNew
)
1134 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1138 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1139 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1145 /***********************************************************************
1146 * DEFDLG_SetDefButton
1148 * Set the new default button to be hwndNew.
1150 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1152 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1153 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1156 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1157 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1160 * Need to draw only default push button rectangle.
1161 * Since the next control is not a push button, need to draw the push
1162 * button rectangle for the default control.
1165 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1168 /* Make sure the old default control is a valid push button ID */
1169 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1170 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1171 if (hwndOld
&& hwndOld
!= hwndNew
)
1172 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1176 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1177 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1183 /***********************************************************************
1186 * Implementation of DefDlgProc(). Only handle messages that need special
1187 * handling for dialogs.
1189 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1190 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1196 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1200 HDC hdc
= (HDC
)wParam
;
1201 GetClientRect( hwnd
, &rect
);
1202 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1203 FillRect( hdc
, &rect
, brush
);
1209 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1211 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1212 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1213 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1214 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1215 NtUserxSetDialogPointer( hwnd
, 0 );
1217 /* Window clean-up */
1218 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1221 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1222 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1227 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1228 // if WA_CLICK/ACTIVE ? set dialog is active.
1229 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1230 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1232 if (wParam
) DEFDLG_RestoreFocus( hwnd
, TRUE
);
1233 else DEFDLG_SaveFocus( hwnd
);
1237 DEFDLG_RestoreFocus( hwnd
, FALSE
);
1241 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1242 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1246 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1249 if (dlgInfo
->idResult
)
1250 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1251 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1252 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1259 HWND hwndDest
= (HWND
)wParam
;
1261 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1262 if (hwndDest
) DEFDLG_SetFocus( hwndDest
);
1263 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1267 case WM_ENTERMENULOOP
:
1268 case WM_LBUTTONDOWN
:
1269 case WM_NCLBUTTONDOWN
:
1271 HWND hwndFocus
= GetFocus();
1274 /* always make combo box hide its listbox control */
1275 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1276 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1279 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1282 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1285 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1286 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1292 /***********************************************************************
1295 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1297 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1300 if (fResult
) return fResult
;
1302 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1303 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1305 if ( msg
== WM_COMPAREITEM
||
1306 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1307 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1310 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1313 /***********************************************************************
1314 * DIALOG_GetNextTabItem
1316 * Helper for GetNextDlgTabItem
1318 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1322 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1324 HWND hChildFirst
= 0;
1328 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1329 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1331 else if (IsChild( hwndMain
, hwndCtrl
))
1333 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1336 if(GetParent(hwndCtrl
) != hwndMain
)
1337 /* i.e. if we are not at the top level of the recursion */
1338 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1340 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1346 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1347 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1348 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1351 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1352 if (retWnd
) return (retWnd
);
1354 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1356 return (hChildFirst
);
1358 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1362 HWND hParent
= GetParent(hwndCtrl
);
1365 if(hParent
== hwndMain
) break;
1366 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1368 hParent
= GetParent(hParent
);
1371 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1373 return retWnd
? retWnd
: hwndCtrl
;
1377 /**********************************************************************
1378 * DIALOG_DlgDirListW
1380 * Helper function for DlgDirList*W
1382 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1383 INT idStatic
, UINT attrib
, BOOL combo
)
1386 LPWSTR orig_spec
= spec
;
1387 WCHAR any
[] = {'*','.','*',0};
1388 WCHAR star
[] = {'*',0};
1390 #define SENDMSG(msg,wparam,lparam) \
1391 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1392 : SendMessageW( hwnd, msg, wparam, lparam ))
1394 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1396 /* If the path exists and is a directory, chdir to it */
1397 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= star
;
1402 if (!strchrW(spec
, '*') && !strchrW(spec
, '?'))
1404 SetLastError(ERROR_NO_WILDCARD_CHARACTERS
);
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
, NULL
);
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; //// REACTOS : Always TRUE! See RealGetWindowClass.
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; //// REACTOS : Always TRUE! See RealGetWindowClass.
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
, &hWndParent
);
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
, &hWndParent
);
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
, &hWndParent
);
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. Do not Port Sync!!!
2032 DIALOGINFO
* dlgInfo
;
2036 TRACE("%p %ld\n", hwnd
, retval
);
2038 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2040 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2043 wasActive
= (hwnd
== GetActiveWindow());
2044 dlgInfo
->idResult
= retval
;
2045 dlgInfo
->flags
|= DF_END
;
2047 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
2049 owner
= GetAncestor( hwnd
, GA_PARENT
);
2052 owner
= GetWindow( hwnd
, GW_OWNER
);
2055 EnableWindow( owner
, TRUE
);
2057 /* Windows sets the focus to the dialog itself in EndDialog */
2059 if (wasActive
&& IsChild(hwnd
, GetFocus()))
2062 /* Don't have to send a ShowWindow(SW_HIDE), just do
2063 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2065 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2066 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2068 if (wasActive
&& owner
)
2070 /* If this dialog was given an owner then set the focus to that owner. */
2071 SetActiveWindow(owner
);
2073 else if (hwnd
== GetActiveWindow()) // Check it again!
2075 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS
);
2078 /* unblock dialog loop */
2079 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2089 GetDialogBaseUnits(VOID
)
2098 if ((hdc
= GetDC(0)))
2100 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2101 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2102 ReleaseDC( 0, hdc
);
2117 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2134 if (!hDlg
) return 0;
2136 list
= WIN_ListChildren(hDlg
);
2137 if (!list
) return 0;
2139 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2141 HeapFree(GetProcessHeap(), 0, list
);
2142 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2160 LONG_PTR result
= 0;
2162 if (lpTranslated
) *lpTranslated
= FALSE
;
2163 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2167 result
= strtol( str
, &endptr
, 10 );
2168 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2170 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)))
2175 result
= strtoul( str
, &endptr
, 10 );
2176 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2178 if (result
== ULONG_MAX
) return 0;
2180 if (lpTranslated
) *lpTranslated
= TRUE
;
2181 return (UINT
)result
;
2196 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2197 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2198 if ( nMaxCount
) lpString
[0] = '\0';
2214 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2215 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2216 if ( nMaxCount
) lpString
[0] = '\0';
2225 GetNextDlgGroupItem(
2230 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2232 BOOL fSkipping
=FALSE
;
2234 if (hDlg
== hCtl
) hCtl
= NULL
;
2235 if (!hCtl
&& bPrevious
) return 0;
2237 /* if the hwndCtrl is the child of the control in the hwndDlg,
2238 * then the hwndDlg has to be the parent of the hwndCtrl */
2242 if (!IsChild (hDlg
, hCtl
)) return 0;
2243 /* Make sure hwndCtrl is a top-level child */
2248 /* No ctrl specified -> start from the beginning */
2249 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2250 /* MSDN is wrong. fPrevious does not result in the last child */
2252 /* No ctrl specified -> start from the beginning */
2253 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2255 /* MSDN is wrong. fPrevious does not result in the last child */
2257 /* Maybe that first one is valid. If so then we don't want to skip it*/
2258 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2265 /* Always go forward around the group and list of controls; for the
2266 * previous control keep track; for the next break when you find one
2272 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2275 /* Climb out until there is a next sibling of the ancestor or we
2276 * reach the top (in which case we loop back to the start)
2278 if (hDlg
== GetParent (hwnd
))
2280 /* Wrap around to the beginning of the list, within the same
2281 * group. (Once only)
2283 if (fLooped
) goto end
;
2285 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2289 hwnd
= GetParent (hwnd
);
2290 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2295 /* Wander down the leading edge of controlparents */
2296 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2297 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2298 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2300 /* Question. If the control is a control parent but either has no
2301 * children or is not visible/enabled then if it has a WS_GROUP does
2302 * it count? For that matter does it count anyway?
2303 * I believe it doesn't count.
2306 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2308 hwndLastGroup
= hwnd
;
2311 /* Look for the beginning of the group */
2318 if (!fSkipping
) break;
2319 if (hwndLastGroup
== hwnd
) break;
2320 hwnd
= hwndLastGroup
;
2326 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2330 if (!bPrevious
) break;
2350 pWindow
= ValidateHwnd( hDlg
);
2351 if (!pWindow
) return NULL
;
2354 pWindow
= ValidateHwnd( hCtl
);
2355 if (!pWindow
) return NULL
;
2358 /* Undocumented but tested under Win2000 and WinME */
2359 if (hDlg
== hCtl
) hCtl
= NULL
;
2361 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2362 * NB GetLastError returns whatever was set before the function was
2365 if (!hCtl
&& bPrevious
) return 0;
2367 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2378 return IsDialogMessageW(hDlg
, lpMsg
);
2382 /***********************************************************************
2383 * DIALOG_FixOneChildOnChangeFocus
2385 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2388 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2391 /* If a default pushbutton then no longer default */
2392 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2393 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2397 /***********************************************************************
2398 * DIALOG_FixChildrenOnChangeFocus
2400 * Following the change of focus that occurs for example after handling
2401 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2402 * children may be required.
2404 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2406 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2407 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2408 /* Windows does ask for this. I don't know why yet */
2410 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2412 /* If the button that is getting the focus WAS flagged as the default
2413 * pushbutton then ask the dialog what it thinks the default is and
2414 * set that in the default style.
2416 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2418 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2419 if (HIWORD(def_id
) == DC_HASDEFID
)
2422 def_id
= LOWORD(def_id
);
2423 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2426 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2427 /* I know that if it is a button then it should already be a
2428 * UNDEFPUSHBUTTON, since we have just told the buttons to
2429 * change style. But maybe they ignored our request
2431 if ((dlgcode_def
& DLGC_BUTTON
) &&
2432 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2434 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2439 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2441 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2442 /* I wonder why it doesn't send a DM_SETDEFID */
2446 /***********************************************************************
2449 * A recursive version of GetDlgItem
2452 * The HWND for a Child ID.
2454 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2457 HWND
*list
= WIN_ListChildren( hwndDlg
);
2460 if (!list
) return 0;
2462 for (i
= 0; list
[i
]; i
++)
2464 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2470 /* Recurse into every child */
2471 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2474 HeapFree( GetProcessHeap(), 0, list
);
2490 if (!IsWindow( hDlg
))
2493 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2495 if (hDlg
== GetDesktopWindow()) return FALSE
;
2496 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2498 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2500 switch(lpMsg
->message
)
2503 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2504 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2506 switch(lpMsg
->wParam
)
2509 if (!(dlgCode
& DLGC_WANTTAB
))
2511 BOOL fIsDialog
= TRUE
;
2512 WND
*pWnd
= ValidateHwnd(hDlg
);
2514 if (pWnd
&& TestWindowProcess(pWnd
))
2516 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2519 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2521 /* I am not sure under which circumstances the TAB is handled
2522 * each way. All I do know is that it does not always simply
2523 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2524 * do so but I presume someone has)
2527 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2530 /* It would appear that GetNextDlgTabItem can handle being
2531 * passed hwndDlg rather than NULL but that is undocumented
2532 * so let's do it properly
2534 HWND hwndFocus
= GetFocus();
2535 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2536 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2537 GetKeyState (VK_SHIFT
) & 0x8000);
2540 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2541 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2542 if (dlgCode
& DLGC_HASSETSEL
)
2544 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2545 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2549 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2550 length
= strlenW (buffer
);
2551 HeapFree (GetProcessHeap(), 0, buffer
);
2552 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2555 SetFocus (hwndNext
);
2556 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2569 if (!(dlgCode
& DLGC_WANTARROWS
))
2571 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2572 HWND hwndNext
= GetNextDlgGroupItem( hDlg
, lpMsg
->hwnd
, fPrevious
);
2573 if (hwndNext
&& SendMessageW( hwndNext
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
) == (DLGC_BUTTON
| DLGC_RADIOBUTTON
))
2575 SetFocus( hwndNext
);
2576 if ((GetWindowLongW( hwndNext
, GWL_STYLE
) & BS_TYPEMASK
) == BS_AUTORADIOBUTTON
&&
2577 SendMessageW( hwndNext
, BM_GETCHECK
, 0, 0 ) != BST_CHECKED
)
2578 SendMessageW( hwndNext
, BM_CLICK
, 1, 0 );
2581 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2588 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2595 HWND hwndFocus
= GetFocus();
2596 if (IsChild( hDlg
, hwndFocus
) &&
2597 (SendMessageW (hwndFocus
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2599 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( GetDlgCtrlID( hwndFocus
), BN_CLICKED
), (LPARAM
)hwndFocus
);
2601 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2603 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2604 if (!hwndDef
|| IsWindowEnabled(hwndDef
))
2605 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2609 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2617 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2618 * It does NOT get sent in the test program I have
2620 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2621 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2622 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2626 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2628 /* don't translate or dispatch */
2634 /* If the ALT key is being pressed display the keyboard cues */
2635 if ( HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
&&
2636 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2637 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2641 /* If the ALT key is being pressed display the keyboard cues */
2642 if ( lpMsg
->wParam
== SC_KEYMENU
&&
2643 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2645 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2650 TranslateMessage( lpMsg
);
2651 DispatchMessageW( lpMsg
);
2665 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2678 DIALOGINFO
* dlgInfo
;
2679 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2680 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2681 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2682 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2683 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2693 SendDlgItemMessageA(
2701 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2702 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2703 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2713 SendDlgItemMessageW(
2721 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2722 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2723 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2741 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2742 else sprintf( str
, "%u", uValue
);
2743 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2758 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2759 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2774 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2775 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2790 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2794 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2796 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2797 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2799 if((lChildID
>= lpRadioGroup
->firstID
) &&
2800 (lChildID
<= lpRadioGroup
->lastID
))
2802 if (lChildID
== lpRadioGroup
->checkID
)
2804 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2808 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2826 RADIOGROUP radioGroup
;
2828 radioGroup
.firstID
= nIDFirstButton
;
2829 radioGroup
.lastID
= nIDLastButton
;
2830 radioGroup
.checkID
= nIDCheckButton
;
2832 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);