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
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_DIALOGACTIVE 0x4000 // ReactOS
42 #define DWLP_ROS_DIALOGINFO (DWLP_USER+sizeof(ULONG_PTR))
43 #define GETDLGINFO(hwnd) DIALOG_get_info(hwnd, FALSE)
44 #define SETDLGINFO(hwnd, info) SetWindowLongPtrW((hwnd), DWLP_ROS_DIALOGINFO, (LONG_PTR)(info))
45 #define GET_WORD(ptr) (*(WORD *)(ptr))
46 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
49 /* INTERNAL STRUCTS **********************************************************/
51 /* Dialog info structure */
54 HWND hwndFocus
; /* Current control with focus */
55 HFONT hUserFont
; /* Dialog font */
56 HMENU hMenu
; /* Dialog menu */
57 UINT xBaseUnit
; /* Dialog units (depends on the font) */
59 INT idResult
; /* EndDialog() result / default pushbutton ID */
60 UINT flags
; /* EndDialog() called for this dialog */
63 /* Dialog control information */
76 BOOL windowNameFree
; // ReactOS
101 /* CheckRadioButton structure */
110 /*********************************************************************
111 * dialog class descriptor
113 const struct builtin_class_descr DIALOG_builtin_class
=
115 WC_DIALOG
, /* name */
116 CS_SAVEBITS
| CS_DBLCLKS
, /* style */
117 DefDlgProcA
, /* procA */
118 DefDlgProcW
, /* procW */
119 DLGWINDOWEXTRA
, /* extra */
120 (LPCWSTR
) IDC_ARROW
, /* cursor */
125 /* INTERNAL FUNCTIONS ********************************************************/
127 /***********************************************************************
130 * Get the DIALOGINFO structure of a window, allocating it if needed
131 * and 'create' is TRUE.
135 DIALOGINFO
*DIALOG_get_info( HWND hWnd
, BOOL create
)
140 pWindow
= ValidateHwnd( hWnd
);
146 dlgInfo
= (DIALOGINFO
*)GetWindowLongPtrW( hWnd
, DWLP_ROS_DIALOGINFO
);
148 if (!dlgInfo
&& create
)
150 if (pWindow
&& pWindow
->cbwndExtra
>= DLGWINDOWEXTRA
)
152 if (!(dlgInfo
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dlgInfo
) )))
155 dlgInfo
->idResult
= IDOK
;
156 SETDLGINFO( hWnd
, dlgInfo
);
166 if (!(pWindow
->state
& WNDS_DIALOGWINDOW
))
168 NtUserxSetDialogPointer( hWnd
, dlgInfo
);
174 /***********************************************************************
175 * DIALOG_GetControl32
177 * Return the class and text of the control pointed to by ptr,
178 * fill the header structure and return a pointer to the next control.
180 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
185 info
->helpId
= GET_DWORD(p
); p
+= 2;
186 info
->exStyle
= GET_DWORD(p
); p
+= 2;
187 info
->style
= GET_DWORD(p
); p
+= 2;
192 info
->style
= GET_DWORD(p
); p
+= 2;
193 info
->exStyle
= GET_DWORD(p
); p
+= 2;
195 info
->x
= GET_WORD(p
); p
++;
196 info
->y
= GET_WORD(p
); p
++;
197 info
->cx
= GET_WORD(p
); p
++;
198 info
->cy
= GET_WORD(p
); p
++;
202 /* id is a DWORD for DIALOGEX */
203 info
->id
= GET_DWORD(p
);
208 info
->id
= GET_WORD(p
);
212 if (GET_WORD(p
) == 0xffff)
214 static const WCHAR class_names
[6][10] =
216 { 'B','u','t','t','o','n', }, /* 0x80 */
217 { 'E','d','i','t', }, /* 0x81 */
218 { 'S','t','a','t','i','c', }, /* 0x82 */
219 { 'L','i','s','t','B','o','x', }, /* 0x83 */
220 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
221 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
223 WORD id
= GET_WORD(p
+1);
224 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
225 if ((id
>= 0x80) && (id
<= 0x85)) id
-= 0x80;
228 info
->className
= class_names
[id
];
232 info
->className
= NULL
;
233 /* FIXME: load other classes here? */
234 ERR("Unknown built-in class id %04x\n", id
);
240 info
->className
= (LPCWSTR
)p
;
241 p
+= strlenW( info
->className
) + 1;
244 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
246 //// ReactOS Rev 6478
247 info
->windowName
= HeapAlloc( GetProcessHeap(), 0, sizeof(L
"#65535") );
248 if (info
->windowName
!= NULL
)
250 wsprintf((LPWSTR
)info
->windowName
, L
"#%u", GET_WORD(p
+ 1));
251 info
->windowNameFree
= TRUE
;
255 info
->windowNameFree
= FALSE
;
261 info
->windowName
= (LPCWSTR
)p
;
262 info
->windowNameFree
= FALSE
;
263 p
+= strlenW( info
->windowName
) + 1;
266 TRACE(" %s %s %ld, %d, %d, %d, %d, %08x, %08x, %08x\n",
267 debugstr_w( info
->className
), debugstr_w( info
->windowName
),
268 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
269 info
->style
, info
->exStyle
, info
->helpId
);
274 p
+= GET_WORD(p
) / sizeof(WORD
);
276 else info
->data
= NULL
;
279 /* Next control is on dword boundary */
280 return (const WORD
*)(((UINT_PTR
)p
+ 3) & ~3);
284 /***********************************************************************
285 * DIALOG_CreateControls32
287 * Create the control windows for a dialog.
289 static BOOL
DIALOG_CreateControls32( HWND hwnd
, LPCSTR
template, const DLG_TEMPLATE
*dlgTemplate
,
290 HINSTANCE hInst
, BOOL unicode
)
292 DIALOGINFO
* dlgInfo
;
293 DLG_CONTROL_INFO info
;
294 HWND hwndCtrl
, hwndDefButton
= 0;
295 INT items
= dlgTemplate
->nbItems
;
297 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return FALSE
;
302 template = (LPCSTR
)DIALOG_GetControl32( (const WORD
*)template, &info
,
303 dlgTemplate
->dialogEx
);
304 info
.style
&= ~WS_POPUP
;
305 info
.style
|= WS_CHILD
;
307 if (info
.style
& WS_BORDER
)
309 info
.style
&= ~WS_BORDER
;
310 info
.exStyle
|= WS_EX_CLIENTEDGE
;
315 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
316 info
.className
, info
.windowName
,
317 info
.style
| WS_CHILD
,
318 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
319 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
320 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
321 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
322 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
323 hInst
, (LPVOID
)info
.data
);
327 LPSTR
class = (LPSTR
)info
.className
;
328 LPSTR caption
= (LPSTR
)info
.windowName
;
330 if (!IS_INTRESOURCE(class))
332 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, NULL
, 0, NULL
, NULL
);
333 class = HeapAlloc( GetProcessHeap(), 0, len
);
335 WideCharToMultiByte( CP_ACP
, 0, info
.className
, -1, class, len
, NULL
, NULL
);
337 if (!IS_INTRESOURCE(caption
))
339 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, NULL
, 0, NULL
, NULL
);
340 caption
= HeapAlloc( GetProcessHeap(), 0, len
);
342 WideCharToMultiByte( CP_ACP
, 0, info
.windowName
, -1, caption
, len
, NULL
, NULL
);
345 if (class != NULL
&& caption
!= NULL
)
347 hwndCtrl
= CreateWindowExA( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
348 class, caption
, info
.style
| WS_CHILD
,
349 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
350 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
351 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
352 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
353 hwnd
, (HMENU
)(ULONG_PTR
)info
.id
,
354 hInst
, (LPVOID
)info
.data
);
358 if (!IS_INTRESOURCE(class)) HeapFree( GetProcessHeap(), 0, class );
359 if (!IS_INTRESOURCE(caption
)) HeapFree( GetProcessHeap(), 0, caption
);
362 if (info
.windowNameFree
)
364 HeapFree( GetProcessHeap(), 0, (LPVOID
)info
.windowName
);
369 WARN("control %s %s creation failed\n", debugstr_w(info
.className
),
370 debugstr_w(info
.windowName
));
371 if (dlgTemplate
->style
& DS_NOFAILCREATE
) continue;
375 /* Send initialisation messages to the control */
376 if (dlgInfo
->hUserFont
) SendMessageW( hwndCtrl
, WM_SETFONT
,
377 (WPARAM
)dlgInfo
->hUserFont
, 0 );
378 if (SendMessageW(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
380 /* If there's already a default push-button, set it back */
381 /* to normal and use this one instead. */
383 SendMessageW( hwndDefButton
, BM_SETSTYLE
, BS_PUSHBUTTON
, FALSE
);
384 hwndDefButton
= hwndCtrl
;
385 dlgInfo
->idResult
= GetWindowLongPtrA( hwndCtrl
, GWLP_ID
);
393 /***********************************************************************
394 * DIALOG_IsAccelerator
396 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM wParam
)
398 HWND hwndControl
= hwnd
;
405 DWORD style
= GetWindowLongPtrW( hwndControl
, GWL_STYLE
);
406 if ((style
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
)
408 dlgCode
= SendMessageW( hwndControl
, WM_GETDLGCODE
, 0, 0 );
409 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
410 GetWindowTextW( hwndControl
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
412 /* find the accelerator key */
413 LPWSTR p
= buffer
- 2;
417 p
= strchrW( p
+ 2, '&' );
419 while (p
!= NULL
&& p
[1] == '&');
421 /* and check if it's the one we're looking for */
422 if (p
!= NULL
&& toupperW( p
[1] ) == toupperW( wParam
) )
424 if ((dlgCode
& DLGC_STATIC
) || (style
& 0x0f) == BS_GROUPBOX
)
426 /* set focus to the control */
427 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndControl
, 1);
428 /* and bump it on to next */
429 SendMessageW( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
431 else if (dlgCode
& DLGC_BUTTON
)
433 /* send BM_CLICK message to the control */
434 SendMessageW( hwndControl
, BM_CLICK
, 0, 0 );
439 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
443 if (!hwndNext
) hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
445 while (!hwndNext
&& hwndControl
)
447 hwndControl
= GetParent( hwndControl
);
448 if (hwndControl
== hwndDlg
)
450 if(hwnd
==hwndDlg
) /* prevent endless loop */
455 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
458 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
460 hwndControl
= hwndNext
;
462 while (hwndControl
&& (hwndControl
!= hwnd
));
467 /***********************************************************************
468 * DIALOG_FindMsgDestination
470 * The messages that IsDialogMessage sends may not go to the dialog
471 * calling IsDialogMessage if that dialog is a child, and it has the
472 * DS_CONTROL style set.
473 * We propagate up until we hit one that does not have DS_CONTROL, or
474 * whose parent is not a dialog.
476 * This is undocumented behaviour.
478 static HWND
DIALOG_FindMsgDestination( HWND hwndDlg
)
480 while (GetWindowLongA(hwndDlg
, GWL_STYLE
) & DS_CONTROL
)
483 HWND hParent
= GetParent(hwndDlg
);
486 if (!IsWindow(hParent
)) break;
488 pWnd
= ValidateHwnd(hParent
);
489 // FIXME: Use pWnd->fnid == FNID_DESKTOP
490 if (!pWnd
|| !TestWindowProcess(pWnd
) || hParent
== GetDesktopWindow()) break;
492 if (!(pWnd
->state
& WNDS_DIALOGWINDOW
))
503 /***********************************************************************
506 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
508 DIALOGINFO
* dlgInfo
;
514 pWnd
= ValidateHwnd(hwnd
);
515 if (!pWnd
) return -1;
517 if (!(dlgInfo
= GETDLGINFO(hwnd
))) return -1;
520 if (!(dlgInfo
->flags
& DF_END
)) /* was EndDialog called in WM_INITDIALOG ? */
524 if (!PeekMessageW( &msg
, 0, 0, 0, PM_REMOVE
))
528 /* ShowWindow the first time the queue goes empty */
529 ShowWindow( hwnd
, SW_SHOWNORMAL
);
532 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & DS_NOIDLEMSG
))
534 /* No message present -> send ENTERIDLE and wait */
535 SendMessageW( owner
, WM_ENTERIDLE
, MSGF_DIALOGBOX
, (LPARAM
)hwnd
);
537 GetMessageW( &msg
, 0, 0, 0 );
540 if (msg
.message
== WM_QUIT
)
542 PostQuitMessage( msg
.wParam
);
543 if (!IsWindow( hwnd
)) return 0;
548 * If the user is pressing Ctrl+C, send a WM_COPY message.
549 * Guido Pola, CORE-4829, Is there another way to check if the Dialog is a MessageBox?
551 if (msg
.message
== WM_KEYDOWN
&&
552 pWnd
->state
& WNDS_MSGBOX
&& // Yes!
553 GetForegroundWindow() == hwnd
)
555 if (msg
.wParam
== L
'C' && GetKeyState(VK_CONTROL
) < 0)
556 SendMessageW(hwnd
, WM_COPY
, 0, 0);
559 if (!IsWindow( hwnd
)) return 0;
560 if (!(dlgInfo
->flags
& DF_END
) && !IsDialogMessageW( hwnd
, &msg
))
562 TranslateMessage( &msg
);
563 DispatchMessageW( &msg
);
565 if (!IsWindow( hwnd
)) return 0;
566 if (dlgInfo
->flags
& DF_END
) break;
568 if (bFirstEmpty
&& msg
.message
== WM_TIMER
)
570 ShowWindow( hwnd
, SW_SHOWNORMAL
);
575 retval
= dlgInfo
->idResult
;
576 DestroyWindow( hwnd
);
580 /***********************************************************************
581 * DIALOG_ParseTemplate32
583 * Fill a DLG_TEMPLATE structure from the dialog template, and return
584 * a pointer to the first control.
586 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
588 const WORD
*p
= (const WORD
*)template;
592 dlgver
= GET_WORD(p
); p
++;
593 signature
= GET_WORD(p
); p
++;
595 if (dlgver
== 1 && signature
== 0xffff) /* DIALOGEX resource */
597 result
->dialogEx
= TRUE
;
598 result
->helpId
= GET_DWORD(p
); p
+= 2;
599 result
->exStyle
= GET_DWORD(p
); p
+= 2;
600 result
->style
= GET_DWORD(p
); p
+= 2;
604 result
->style
= GET_DWORD(p
- 2);
605 result
->dialogEx
= FALSE
;
607 result
->exStyle
= GET_DWORD(p
); p
+= 2;
609 result
->nbItems
= GET_WORD(p
); p
++;
610 result
->x
= GET_WORD(p
); p
++;
611 result
->y
= GET_WORD(p
); p
++;
612 result
->cx
= GET_WORD(p
); p
++;
613 result
->cy
= GET_WORD(p
); p
++;
614 TRACE("DIALOG%s %d, %d, %d, %d, %d\n",
615 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
616 result
->cx
, result
->cy
, result
->helpId
);
617 TRACE(" STYLE 0x%08x\n", result
->style
);
618 TRACE(" EXSTYLE 0x%08x\n", result
->exStyle
);
620 /* Get the menu name */
625 result
->menuName
= NULL
;
629 result
->menuName
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
631 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
634 result
->menuName
= (LPCWSTR
)p
;
635 TRACE(" MENU %s\n", debugstr_w(result
->menuName
) );
636 p
+= strlenW( result
->menuName
) + 1;
640 /* Get the class name */
645 result
->className
= WC_DIALOG
;
649 result
->className
= (LPCWSTR
)(UINT_PTR
)GET_WORD( p
+ 1 );
651 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
654 result
->className
= (LPCWSTR
)p
;
655 TRACE(" CLASS %s\n", debugstr_w( result
->className
));
656 p
+= strlenW( result
->className
) + 1;
660 /* Get the window caption */
662 result
->caption
= (LPCWSTR
)p
;
663 p
+= strlenW( result
->caption
) + 1;
664 TRACE(" CAPTION %s\n", debugstr_w( result
->caption
) );
666 /* Get the font name */
668 result
->pointSize
= 0;
669 result
->faceName
= NULL
;
670 result
->weight
= FW_DONTCARE
;
671 result
->italic
= FALSE
;
673 if (result
->style
& DS_SETFONT
)
675 result
->pointSize
= GET_WORD(p
);
678 /* If pointSize is 0x7fff, it means that we need to use the font
679 * in NONCLIENTMETRICSW.lfMessageFont, and NOT read the weight,
680 * italic, and facename from the dialog template.
682 if (result
->pointSize
== 0x7fff)
684 /* We could call SystemParametersInfo here, but then we'd have
685 * to convert from pixel size to point size (which can be
688 TRACE(" FONT: Using message box font\n");
692 if (result
->dialogEx
)
694 result
->weight
= GET_WORD(p
); p
++;
695 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
697 result
->faceName
= (LPCWSTR
)p
;
698 p
+= strlenW( result
->faceName
) + 1;
700 TRACE(" FONT %d, %s, %d, %s\n",
701 result
->pointSize
, debugstr_w( result
->faceName
),
702 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
706 /* First control is on dword boundary */
707 return (LPCSTR
)((((UINT_PTR
)p
) + 3) & ~3);
710 /***********************************************************************
713 * Set the focus to a control of the dialog, selecting the text if
714 * the control is an edit dialog that has DLGC_HASSETSEL.
716 static void DEFDLG_SetFocus( HWND hwndCtrl
)
718 if (SendMessageW( hwndCtrl
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
719 SendMessageW( hwndCtrl
, EM_SETSEL
, 0, -1 );
720 SetFocus( hwndCtrl
);
724 /***********************************************************************
727 static void DEFDLG_SaveFocus( HWND hwnd
)
730 HWND hwndFocus
= GetFocus();
732 if (!hwndFocus
|| !IsChild( hwnd
, hwndFocus
)) return;
733 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
734 infoPtr
->hwndFocus
= hwndFocus
;
735 /* Remove default button */
739 /***********************************************************************
740 * DEFDLG_RestoreFocus
742 static void DEFDLG_RestoreFocus( HWND hwnd
, BOOL justActivate
)
746 if (IsIconic( hwnd
)) return;
747 if (!(infoPtr
= GETDLGINFO(hwnd
))) return;
748 /* Don't set the focus back to controls if EndDialog is already called.*/
749 if (infoPtr
->flags
& DF_END
) return;
750 if (!IsWindow(infoPtr
->hwndFocus
) || infoPtr
->hwndFocus
== hwnd
) {
751 if (justActivate
) return;
752 /* If no saved focus control exists, set focus to the first visible,
753 non-disabled, WS_TABSTOP control in the dialog */
754 infoPtr
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
755 /* If there are no WS_TABSTOP controls, set focus to the first visible,
756 non-disabled control in the dialog */
757 if (!infoPtr
->hwndFocus
) infoPtr
->hwndFocus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
758 if (!IsWindow( infoPtr
->hwndFocus
)) return;
761 SetFocus( infoPtr
->hwndFocus
);
763 DEFDLG_SetFocus( infoPtr
->hwndFocus
);
765 infoPtr
->hwndFocus
= NULL
;
768 /***********************************************************************
769 * DIALOG_CreateIndirect
770 * Creates a dialog box window
772 * modal = TRUE if we are called from a modal dialog box.
773 * (it's more compatible to do it here, as under Windows the owner
774 * is never disabled if the dialog fails because of an invalid template)
776 static HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCVOID dlgTemplate
,
777 HWND owner
, DLGPROC dlgProc
, LPARAM param
,
778 BOOL unicode
, HWND
*modal_owner
)
784 DLG_TEMPLATE
template;
785 DIALOGINFO
* dlgInfo
= NULL
;
786 DWORD units
= GetDialogBaseUnits();
787 HWND disabled_owner
= NULL
;
791 UINT xBaseUnit
= LOWORD(units
);
792 UINT yBaseUnit
= HIWORD(units
);
794 /* Parse dialog template */
796 if (!dlgTemplate
) return 0;
797 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
801 if (template.menuName
) hMenu
= LoadMenuW( hInst
, template.menuName
);
803 /* Create custom font if needed */
805 if (template.style
& DS_SETFONT
)
809 if (template.pointSize
== 0x7fff)
811 /* We get the message font from the non-client metrics */
812 NONCLIENTMETRICSW ncMetrics
;
814 ncMetrics
.cbSize
= sizeof(NONCLIENTMETRICSW
);
815 if (SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
816 sizeof(NONCLIENTMETRICSW
), &ncMetrics
, 0))
818 hUserFont
= CreateFontIndirectW( &ncMetrics
.lfMessageFont
);
823 /* We convert the size to pixels and then make it -ve. This works
824 * for both +ve and -ve template.pointSize */
825 int pixels
= MulDiv(template.pointSize
, GetDeviceCaps(dc
, LOGPIXELSY
), 72);
826 hUserFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
827 template.italic
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
828 PROOF_QUALITY
, FF_DONTCARE
,
835 HFONT hOldFont
= SelectObject( dc
, hUserFont
);
836 charSize
.cx
= GdiGetCharDimensions( dc
, NULL
, &charSize
.cy
);
839 xBaseUnit
= charSize
.cx
;
840 yBaseUnit
= charSize
.cy
;
842 SelectObject( dc
, hOldFont
);
845 TRACE("units = %d,%d\n", xBaseUnit
, yBaseUnit
);
848 /* Create dialog main window */
850 SetRect(&rect
, 0, 0, MulDiv(template.cx
, xBaseUnit
, 4), MulDiv(template.cy
, yBaseUnit
, 8));
851 if (template.style
& DS_CONTROL
)
852 template.style
&= ~(WS_CAPTION
|WS_SYSMENU
);
853 template.style
|= DS_3DLOOK
;
854 if (template.style
& DS_MODALFRAME
)
855 template.exStyle
|= WS_EX_DLGMODALFRAME
;
856 if ((template.style
& DS_CONTROL
) || !(template.style
& WS_CHILD
))
857 template.exStyle
|= WS_EX_CONTROLPARENT
;
858 AdjustWindowRectEx( &rect
, template.style
, (hMenu
!= 0), template.exStyle
);
861 size
.cx
= rect
.right
- rect
.left
;
862 size
.cy
= rect
.bottom
- rect
.top
;
864 if (template.x
== CW_USEDEFAULT16
)
866 pos
.x
= pos
.y
= CW_USEDEFAULT
;
870 HMONITOR monitor
= 0;
871 MONITORINFO mon_info
;
873 mon_info
.cbSize
= sizeof(mon_info
);
874 if (template.style
& DS_CENTER
)
876 monitor
= MonitorFromWindow( owner
? owner
: GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY
);
877 GetMonitorInfoW( monitor
, &mon_info
);
878 pos
.x
= (mon_info
.rcWork
.left
+ mon_info
.rcWork
.right
- size
.cx
) / 2;
879 pos
.y
= (mon_info
.rcWork
.top
+ mon_info
.rcWork
.bottom
- size
.cy
) / 2;
881 else if (template.style
& DS_CENTERMOUSE
)
883 GetCursorPos( &pos
);
884 monitor
= MonitorFromPoint( pos
, MONITOR_DEFAULTTOPRIMARY
);
885 GetMonitorInfoW( monitor
, &mon_info
);
889 pos
.x
+= MulDiv(template.x
, xBaseUnit
, 4);
890 pos
.y
+= MulDiv(template.y
, yBaseUnit
, 8);
892 // REACTOS : Need an owner to be passed!!!
894 if (!(template.style
& (WS_CHILD
|DS_ABSALIGN
)) && owner
) ClientToScreen( owner
, &pos
);
896 if ( !(template.style
& WS_CHILD
) )
900 /* try to fit it into the desktop */
904 SetRect( &rect
, pos
.x
, pos
.y
, pos
.x
+ size
.cx
, pos
.y
+ size
.cy
);
905 monitor
= MonitorFromRect( &rect
, MONITOR_DEFAULTTOPRIMARY
);
906 GetMonitorInfoW( monitor
, &mon_info
);
908 if ((dX
= pos
.x
+ size
.cx
+ GetSystemMetrics(SM_CXDLGFRAME
) - mon_info
.rcWork
.right
) > 0)
910 if ((dY
= pos
.y
+ size
.cy
+ GetSystemMetrics(SM_CYDLGFRAME
) - mon_info
.rcWork
.bottom
) > 0)
912 if( pos
.x
< mon_info
.rcWork
.left
) pos
.x
= mon_info
.rcWork
.left
;
913 if( pos
.y
< mon_info
.rcWork
.top
) pos
.y
= mon_info
.rcWork
.top
;
917 if (modal_owner
&& owner
)
921 * Owner needs to be top level window. We need to duplicate the logic from server,
922 * because we need to disable it before creating dialog window. Note that we do that
923 * even if dialog has WS_CHILD, but only for modal dialogs, which matched what
926 while ((GetWindowLongW( owner
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
928 parent
= GetParent( owner
);
929 if (!parent
|| parent
== GetDesktopWindow()) break;
932 ////// Wine'ie babies need to fix your code!!!! CORE-11633
933 if (!parent
) parent
= GetAncestor( owner
, GA_ROOT
);
939 if (IsWindowEnabled( owner
))
941 disabled_owner
= owner
;
942 EnableWindow( disabled_owner
, FALSE
);
945 *modal_owner
= owner
;
950 hwnd
= CreateWindowExW(template.exStyle
, template.className
, template.caption
,
951 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
952 owner
, hMenu
, hInst
, NULL
);
956 LPCSTR
class = (LPCSTR
)template.className
;
957 LPCSTR caption
= (LPCSTR
)template.caption
;
958 LPSTR class_tmp
= NULL
;
959 LPSTR caption_tmp
= NULL
;
961 if (!IS_INTRESOURCE(class))
963 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, NULL
, 0, NULL
, NULL
);
964 class_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
965 WideCharToMultiByte( CP_ACP
, 0, template.className
, -1, class_tmp
, len
, NULL
, NULL
);
968 if (!IS_INTRESOURCE(caption
))
970 DWORD len
= WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, NULL
, 0, NULL
, NULL
);
971 caption_tmp
= HeapAlloc( GetProcessHeap(), 0, len
);
972 WideCharToMultiByte( CP_ACP
, 0, template.caption
, -1, caption_tmp
, len
, NULL
, NULL
);
973 caption
= caption_tmp
;
975 hwnd
= CreateWindowExA(template.exStyle
, class, caption
,
976 template.style
& ~WS_VISIBLE
, pos
.x
, pos
.y
, size
.cx
, size
.cy
,
977 owner
, hMenu
, hInst
, NULL
);
978 HeapFree( GetProcessHeap(), 0, class_tmp
);
979 HeapFree( GetProcessHeap(), 0, caption_tmp
);
984 if (hUserFont
) DeleteObject( hUserFont
);
985 if (hMenu
) DestroyMenu( hMenu
);
986 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
990 /* moved this from the top of the method to here as DIALOGINFO structure
991 will be valid only after WM_CREATE message has been handled in DefDlgProc
992 All the members of the structure get filled here using temp variables */
993 dlgInfo
= DIALOG_get_info( hwnd
, TRUE
);
997 if (hUserFont
) DeleteObject( hUserFont
);
998 if (hMenu
) DestroyMenu( hMenu
);
999 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1003 dlgInfo
->hwndFocus
= 0;
1004 dlgInfo
->hUserFont
= hUserFont
;
1005 dlgInfo
->hMenu
= hMenu
;
1006 dlgInfo
->xBaseUnit
= xBaseUnit
;
1007 dlgInfo
->yBaseUnit
= yBaseUnit
;
1008 dlgInfo
->flags
= flags
;
1010 if (template.helpId
) SetWindowContextHelpId( hwnd
, template.helpId
);
1012 if (unicode
) SetWindowLongPtrW( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1013 else SetWindowLongPtrA( hwnd
, DWLP_DLGPROC
, (ULONG_PTR
)dlgProc
);
1015 if (dlgProc
&& dlgInfo
->hUserFont
)
1016 SendMessageW( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
1018 /* Create controls */
1020 if (DIALOG_CreateControls32( hwnd
, dlgTemplate
, &template, hInst
, unicode
))
1022 /* Send initialisation messages and set focus */
1026 HWND focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1027 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1028 if (SendMessageW( hwnd
, WM_INITDIALOG
, (WPARAM
)focus
, param
) && IsWindow( hwnd
) &&
1029 ((~template.style
& DS_CONTROL
) || (template.style
& WS_VISIBLE
)))
1031 /* By returning TRUE, app has requested a default focus assignment.
1032 * WM_INITDIALOG may have changed the tab order, so find the first
1033 * tabstop control again. */
1034 focus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
1035 if (!focus
) focus
= GetNextDlgGroupItem( hwnd
, 0, FALSE
);
1038 if (SendMessageW( focus
, WM_GETDLGCODE
, 0, 0 ) & DLGC_HASSETSEL
)
1039 SendMessageW( focus
, EM_SETSEL
, 0, MAXLONG
);
1043 //// ReactOS see 43396, Fixes setting focus on Open and Close dialogs to the FileName edit control in OpenOffice.
1044 //// This now breaks test_SaveRestoreFocus.
1045 //DEFDLG_SaveFocus( hwnd );
1048 //// ReactOS Rev 30613 & 30644
1049 if (!(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_CHILD
))
1050 SendMessageW( hwnd
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_INITIALIZE
, 0), 0);
1052 if (template.style
& WS_VISIBLE
&& !(GetWindowLongPtrW( hwnd
, GWL_STYLE
) & WS_VISIBLE
))
1054 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
1055 UpdateWindow( hwnd
);
1056 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGSTART
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1060 if (disabled_owner
) EnableWindow( disabled_owner
, TRUE
);
1061 IntNotifyWinEvent(EVENT_SYSTEM_DIALOGEND
, hwnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
1062 if( IsWindow(hwnd
) )
1064 DestroyWindow( hwnd
);
1067 { ERR("DIALOG_CreateIndirect 1\n");
1068 if ( NtUserGetThreadState(THREADSTATE_FOREGROUNDTHREAD
) && // Rule #1.
1069 !NtUserQueryWindow(owner
, QUERY_WINDOW_FOREGROUND
) )
1070 { ERR("DIALOG_CreateIndirect SFW\n");
1071 SetForegroundWindow(owner
);
1080 /***********************************************************************
1081 * DEFDLG_FindDefButton
1083 * Find the current default push-button.
1085 static HWND
DEFDLG_FindDefButton( HWND hwndDlg
)
1087 HWND hwndChild
, hwndTmp
;
1089 hwndChild
= GetWindow( hwndDlg
, GW_CHILD
);
1092 if (SendMessageW( hwndChild
, WM_GETDLGCODE
, 0, 0 ) & DLGC_DEFPUSHBUTTON
)
1095 /* Recurse into WS_EX_CONTROLPARENT controls */
1096 if (GetWindowLongPtrW( hwndChild
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
)
1098 LONG dsStyle
= GetWindowLongPtrW( hwndChild
, GWL_STYLE
);
1099 if ((dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
) &&
1100 (hwndTmp
= DEFDLG_FindDefButton(hwndChild
)) != NULL
)
1103 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
1109 /***********************************************************************
1112 * Set the default button id.
1114 static BOOL
DEFDLG_SetDefId( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, WPARAM wParam
)
1116 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1117 HWND hwndOld
, hwndNew
= GetDlgItem(hwndDlg
, wParam
);
1118 INT old_id
= dlgInfo
->idResult
;
1120 dlgInfo
->idResult
= wParam
;
1122 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1123 & (DLGC_UNDEFPUSHBUTTON
| DLGC_BUTTON
)))
1124 return FALSE
; /* Destination is not a push button */
1126 /* Make sure the old default control is a valid push button ID */
1127 hwndOld
= GetDlgItem( hwndDlg
, old_id
);
1128 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1129 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1130 if (hwndOld
&& hwndOld
!= hwndNew
)
1131 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1135 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1136 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1142 /***********************************************************************
1143 * DEFDLG_SetDefButton
1145 * Set the new default button to be hwndNew.
1147 static BOOL
DEFDLG_SetDefButton( HWND hwndDlg
, DIALOGINFO
*dlgInfo
, HWND hwndNew
)
1149 DWORD dlgcode
=0; /* initialize just to avoid a warning */
1150 HWND hwndOld
= GetDlgItem( hwndDlg
, dlgInfo
->idResult
);
1153 !((dlgcode
=SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 ))
1154 & (DLGC_UNDEFPUSHBUTTON
| DLGC_DEFPUSHBUTTON
)))
1157 * Need to draw only default push button rectangle.
1158 * Since the next control is not a push button, need to draw the push
1159 * button rectangle for the default control.
1162 dlgcode
= SendMessageW(hwndNew
, WM_GETDLGCODE
, 0, 0 );
1165 /* Make sure the old default control is a valid push button ID */
1166 if (!hwndOld
|| !(SendMessageW( hwndOld
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
1167 hwndOld
= DEFDLG_FindDefButton( hwndDlg
);
1168 if (hwndOld
&& hwndOld
!= hwndNew
)
1169 SendMessageW( hwndOld
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
1173 if(dlgcode
& DLGC_UNDEFPUSHBUTTON
)
1174 SendMessageW( hwndNew
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
1180 /***********************************************************************
1183 * Implementation of DefDlgProc(). Only handle messages that need special
1184 * handling for dialogs.
1186 static LRESULT
DEFDLG_Proc( HWND hwnd
, UINT msg
, WPARAM wParam
,
1187 LPARAM lParam
, DIALOGINFO
*dlgInfo
)
1193 HBRUSH brush
= GetControlColor( hwnd
, hwnd
, (HDC
)wParam
, WM_CTLCOLORDLG
);
1197 HDC hdc
= (HDC
)wParam
;
1198 GetClientRect( hwnd
, &rect
);
1199 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
1200 FillRect( hdc
, &rect
, brush
);
1206 if ((dlgInfo
= (DIALOGINFO
*)SetWindowLongPtrW( hwnd
, DWLP_ROS_DIALOGINFO
, 0 )))
1208 if (dlgInfo
->hUserFont
) DeleteObject( dlgInfo
->hUserFont
);
1209 if (dlgInfo
->hMenu
) DestroyMenu( dlgInfo
->hMenu
);
1210 HeapFree( GetProcessHeap(), 0, dlgInfo
);
1211 NtUserSetThreadState(0,DF_DIALOGACTIVE
);
1212 NtUserxSetDialogPointer( hwnd
, 0 );
1214 /* Window clean-up */
1215 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1218 if (!wParam
) DEFDLG_SaveFocus( hwnd
);
1219 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1224 HWND hwndparent
= DIALOG_FindMsgDestination( hwnd
);
1225 // if WA_CLICK/ACTIVE ? set dialog is active.
1226 dwSetFlag
= wParam
? DF_DIALOGACTIVE
: 0;
1227 if (hwndparent
!= hwnd
) NtUserSetThreadState(dwSetFlag
, DF_DIALOGACTIVE
);
1229 if (wParam
) DEFDLG_RestoreFocus( hwnd
, TRUE
);
1230 else DEFDLG_SaveFocus( hwnd
);
1234 DEFDLG_RestoreFocus( hwnd
, FALSE
);
1238 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1239 DEFDLG_SetDefId( hwnd
, dlgInfo
, wParam
);
1243 if (dlgInfo
&& !(dlgInfo
->flags
& DF_END
))
1246 if (dlgInfo
->idResult
)
1247 return MAKELONG( dlgInfo
->idResult
, DC_HASDEFID
);
1248 if ((hwndDefId
= DEFDLG_FindDefButton( hwnd
)))
1249 return MAKELONG( GetDlgCtrlID( hwndDefId
), DC_HASDEFID
);
1256 HWND hwndDest
= (HWND
)wParam
;
1258 hwndDest
= GetNextDlgTabItem(hwnd
, GetFocus(), wParam
);
1259 if (hwndDest
) DEFDLG_SetFocus( hwndDest
);
1260 DEFDLG_SetDefButton( hwnd
, dlgInfo
, hwndDest
);
1264 case WM_ENTERMENULOOP
:
1265 case WM_LBUTTONDOWN
:
1266 case WM_NCLBUTTONDOWN
:
1268 HWND hwndFocus
= GetFocus();
1271 /* always make combo box hide its listbox control */
1272 if (!SendMessageW( hwndFocus
, CB_SHOWDROPDOWN
, FALSE
, 0 ))
1273 SendMessageW( GetParent(hwndFocus
), CB_SHOWDROPDOWN
, FALSE
, 0 );
1276 return DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
1279 return dlgInfo
? (LRESULT
)dlgInfo
->hUserFont
: 0;
1282 PostMessageA( hwnd
, WM_COMMAND
, MAKEWPARAM(IDCANCEL
, BN_CLICKED
),
1283 (LPARAM
)GetDlgItem( hwnd
, IDCANCEL
) );
1289 /***********************************************************************
1292 static LRESULT
DEFDLG_Epilog(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, BOOL fResult
, BOOL fAnsi
)
1294 if ((msg
>= WM_CTLCOLORMSGBOX
&& msg
<= WM_CTLCOLORSTATIC
) ||
1297 if (fResult
) return fResult
;
1299 return fAnsi
? DefWindowProcA(hwnd
, msg
, wParam
, lParam
):
1300 DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
1302 if ( msg
== WM_COMPAREITEM
||
1303 msg
== WM_VKEYTOITEM
|| msg
== WM_CHARTOITEM
||
1304 msg
== WM_QUERYDRAGICON
|| msg
== WM_INITDIALOG
)
1307 return GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
1310 /***********************************************************************
1311 * DIALOG_GetNextTabItem
1313 * Helper for GetNextDlgTabItem
1315 static HWND
DIALOG_GetNextTabItem( HWND hwndMain
, HWND hwndDlg
, HWND hwndCtrl
, BOOL fPrevious
)
1319 UINT wndSearch
= fPrevious
? GW_HWNDPREV
: GW_HWNDNEXT
;
1321 HWND hChildFirst
= 0;
1325 hChildFirst
= GetWindow(hwndDlg
,GW_CHILD
);
1326 if(fPrevious
) hChildFirst
= GetWindow(hChildFirst
,GW_HWNDLAST
);
1328 else if (IsChild( hwndMain
, hwndCtrl
))
1330 hChildFirst
= GetWindow(hwndCtrl
,wndSearch
);
1333 if(GetParent(hwndCtrl
) != hwndMain
)
1334 /* i.e. if we are not at the top level of the recursion */
1335 hChildFirst
= GetWindow(GetParent(hwndCtrl
),wndSearch
);
1337 hChildFirst
= GetWindow(hwndCtrl
, fPrevious
? GW_HWNDLAST
: GW_HWNDFIRST
);
1343 dsStyle
= GetWindowLongPtrA(hChildFirst
,GWL_STYLE
);
1344 exStyle
= GetWindowLongPtrA(hChildFirst
,GWL_EXSTYLE
);
1345 if( (exStyle
& WS_EX_CONTROLPARENT
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1348 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hChildFirst
,NULL
,fPrevious
);
1349 if (retWnd
) return (retWnd
);
1351 else if( (dsStyle
& WS_TABSTOP
) && (dsStyle
& WS_VISIBLE
) && !(dsStyle
& WS_DISABLED
))
1353 return (hChildFirst
);
1355 hChildFirst
= GetWindow(hChildFirst
,wndSearch
);
1359 HWND hParent
= GetParent(hwndCtrl
);
1362 if(hParent
== hwndMain
) break;
1363 retWnd
= DIALOG_GetNextTabItem(hwndMain
,GetParent(hParent
),hParent
,fPrevious
);
1365 hParent
= GetParent(hParent
);
1368 retWnd
= DIALOG_GetNextTabItem(hwndMain
,hwndMain
,NULL
,fPrevious
);
1370 return retWnd
? retWnd
: hwndCtrl
;
1374 /**********************************************************************
1375 * DIALOG_DlgDirListW
1377 * Helper function for DlgDirList*W
1379 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
1380 INT idStatic
, UINT attrib
, BOOL combo
)
1383 LPWSTR orig_spec
= spec
;
1384 WCHAR any
[] = {'*','.','*',0};
1386 #define SENDMSG(msg,wparam,lparam) \
1387 ((attrib & DDL_POSTMSGS) ? PostMessageW( hwnd, msg, wparam, lparam ) \
1388 : SendMessageW( hwnd, msg, wparam, lparam ))
1390 TRACE("%p %s %d %d %04x\n", hDlg
, debugstr_w(spec
), idLBox
, idStatic
, attrib
);
1392 /* If the path exists and is a directory, chdir to it */
1393 if (!spec
|| !spec
[0] || SetCurrentDirectoryW( spec
)) spec
= any
;
1398 if ((p2
= strchrW( p
, ':' ))) p
= p2
+ 1;
1399 if ((p2
= strrchrW( p
, '\\' ))) p
= p2
;
1400 if ((p2
= strrchrW( p
, '/' ))) p
= p2
;
1405 if (!SetCurrentDirectoryW( spec
))
1407 *p
= sep
; /* Restore the original spec */
1414 TRACE( "mask=%s\n", spec
);
1416 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
1418 if (attrib
== DDL_DRIVES
) attrib
|= DDL_EXCLUSIVE
;
1420 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
1421 if (attrib
& DDL_DIRECTORY
)
1423 if (!(attrib
& DDL_EXCLUSIVE
))
1425 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1426 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1429 SENDMSG( combo
? CB_DIR
: LB_DIR
,
1430 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1435 SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
, (LPARAM
)spec
);
1439 /* Convert path specification to uppercase */
1440 if (spec
) CharUpperW(spec
);
1442 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
1444 WCHAR temp
[MAX_PATH
];
1445 GetCurrentDirectoryW( sizeof(temp
)/sizeof(WCHAR
), temp
);
1447 /* Can't use PostMessage() here, because the string is on the stack */
1448 SetDlgItemTextW( hDlg
, idStatic
, temp
);
1451 if (orig_spec
&& (spec
!= orig_spec
))
1453 /* Update the original file spec */
1455 while ((*orig_spec
++ = *p
++));
1463 /**********************************************************************
1464 * DIALOG_DlgDirListA
1466 * Helper function for DlgDirList*A
1468 static INT
DIALOG_DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
1469 INT idStatic
, UINT attrib
, BOOL combo
)
1473 INT ret
, len
= MultiByteToWideChar( CP_ACP
, 0, spec
, -1, NULL
, 0 );
1474 LPWSTR specW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1477 MultiByteToWideChar( CP_ACP
, 0, spec
, -1, specW
, len
);
1478 ret
= DIALOG_DlgDirListW( hDlg
, specW
, idLBox
, idStatic
, attrib
, combo
);
1479 WideCharToMultiByte( CP_ACP
, 0, specW
, -1, spec
, 0x7fffffff, NULL
, NULL
);
1480 HeapFree( GetProcessHeap(), 0, specW
);
1483 return DIALOG_DlgDirListW( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1486 /**********************************************************************
1487 * DIALOG_DlgDirSelect
1489 * Helper function for DlgDirSelect*
1491 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPWSTR str
, INT len
,
1492 INT id
, BOOL unicode
, BOOL combo
)
1494 WCHAR
*buffer
, *ptr
;
1497 HWND listbox
= GetDlgItem( hwnd
, id
);
1499 TRACE("%p %s %d\n", hwnd
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
), id
);
1500 if (!listbox
) return FALSE
;
1502 item
= SendMessageW(listbox
, combo
? CB_GETCURSEL
: LB_GETCURSEL
, 0, 0 );
1503 if (item
== LB_ERR
) return FALSE
;
1505 size
= SendMessageW(listbox
, combo
? CB_GETLBTEXTLEN
: LB_GETTEXTLEN
, item
, 0 );
1506 if (size
== LB_ERR
) return FALSE
;
1508 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (size
+2) * sizeof(WCHAR
) ))) return FALSE
;
1510 SendMessageW( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
, item
, (LPARAM
)buffer
);
1512 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1514 if (buffer
[1] == '-') /* drive */
1522 buffer
[strlenW(buffer
)-1] = '\\';
1528 /* Filenames without a dot extension must have one tacked at the end */
1529 if (strchrW(buffer
, '.') == NULL
)
1531 buffer
[strlenW(buffer
)+1] = '\0';
1532 buffer
[strlenW(buffer
)] = '.';
1539 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, ptr
, -1, (LPSTR
)str
, len
, 0, 0 ))
1540 ((LPSTR
)str
)[len
-1] = 0;
1542 else lstrcpynW( str
, ptr
, len
);
1543 HeapFree( GetProcessHeap(), 0, buffer
);
1544 TRACE("Returning %d %s\n", ret
, unicode
? debugstr_w(str
) : debugstr_a((LPSTR
)str
) );
1549 /* FUNCTIONS *****************************************************************/
1556 CreateDialogIndirectParamAorW(
1557 HINSTANCE hInstance
,
1558 LPCDLGTEMPLATE lpTemplate
,
1560 DLGPROC lpDialogFunc
,
1565 * This function might be obsolete since I don't think it is exported by NT
1566 * Also wine has one more parameter identifying weather it should call
1567 * the function with unicode or not
1569 return DIALOG_CreateIndirect( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, NULL
);
1578 CreateDialogIndirectParamA(
1579 HINSTANCE hInstance
,
1580 LPCDLGTEMPLATE lpTemplate
,
1582 DLGPROC lpDialogFunc
,
1585 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, DLG_ISANSI
);
1594 CreateDialogIndirectParamW(
1595 HINSTANCE hInstance
,
1596 LPCDLGTEMPLATE lpTemplate
,
1598 DLGPROC lpDialogFunc
,
1601 return CreateDialogIndirectParamAorW( hInstance
, lpTemplate
, hWndParent
, lpDialogFunc
, lParamInit
, 0);
1611 HINSTANCE hInstance
,
1612 LPCSTR lpTemplateName
,
1614 DLGPROC lpDialogFunc
,
1620 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
))) return 0;
1621 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1622 return CreateDialogIndirectParamA( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1632 HINSTANCE hInstance
,
1633 LPCWSTR lpTemplateName
,
1635 DLGPROC lpDialogFunc
,
1641 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
))) return 0;
1642 if (!(ptr
= (LPCDLGTEMPLATE
)LoadResource(hInstance
, hrsrc
))) return 0;
1643 return CreateDialogIndirectParamW( hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
);
1658 DIALOGINFO
*dlgInfo
;
1660 BOOL result
= FALSE
;
1662 /* Perform DIALOGINFO initialization if not done */
1663 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1665 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1667 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1669 /* Call dialog procedure */
1670 result
= CallWindowProcA( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1673 if (!result
&& IsWindow(hDlg
))
1675 /* callback didn't process this message */
1689 case WM_ENTERMENULOOP
:
1690 case WM_LBUTTONDOWN
:
1691 case WM_NCLBUTTONDOWN
:
1692 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1695 case WM_COMPAREITEM
:
1700 return DefWindowProcA( hDlg
, Msg
, wParam
, lParam
);
1703 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, TRUE
);
1718 DIALOGINFO
*dlgInfo
;
1720 BOOL result
= FALSE
;
1722 /* Perform DIALOGINFO initialization if not done */
1723 if(!(dlgInfo
= DIALOG_get_info( hDlg
, TRUE
))) return 0; //// REACTOS : Always TRUE! See RealGetWindowClass.
1725 SetWindowLongPtrW( hDlg
, DWLP_MSGRESULT
, 0 );
1727 if ((dlgproc
= (WNDPROC
)GetWindowLongPtrW( hDlg
, DWLP_DLGPROC
)))
1729 /* Call dialog procedure */
1730 result
= CallWindowProcW( dlgproc
, hDlg
, Msg
, wParam
, lParam
);
1733 if (!result
&& IsWindow(hDlg
))
1735 /* callback didn't process this message */
1749 case WM_ENTERMENULOOP
:
1750 case WM_LBUTTONDOWN
:
1751 case WM_NCLBUTTONDOWN
:
1752 return DEFDLG_Proc( hDlg
, Msg
, wParam
, lParam
, dlgInfo
);
1755 case WM_COMPAREITEM
:
1760 return DefWindowProcW( hDlg
, Msg
, wParam
, lParam
);
1763 return DEFDLG_Epilog(hDlg
, Msg
, wParam
, lParam
, result
, FALSE
);
1772 DialogBoxIndirectParamAorW(
1773 HINSTANCE hInstance
,
1774 LPCDLGTEMPLATE hDialogTemplate
,
1776 DLGPROC lpDialogFunc
,
1781 * This function might be obsolete since I don't think it is exported by NT
1782 * Also wine has one more parameter identifying weather it should call
1783 * the function with unicode or not
1785 HWND hWnd
= DIALOG_CreateIndirect( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, Flags
== DLG_ISANSI
? FALSE
: TRUE
, &hWndParent
);
1786 if (hWnd
) return DIALOG_DoDialogBox( hWnd
, hWndParent
);
1796 DialogBoxIndirectParamA(
1797 HINSTANCE hInstance
,
1798 LPCDLGTEMPLATE hDialogTemplate
,
1800 DLGPROC lpDialogFunc
,
1803 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, DLG_ISANSI
);
1812 DialogBoxIndirectParamW(
1813 HINSTANCE hInstance
,
1814 LPCDLGTEMPLATE hDialogTemplate
,
1816 DLGPROC lpDialogFunc
,
1819 return DialogBoxIndirectParamAorW( hInstance
, hDialogTemplate
, hWndParent
, lpDialogFunc
, dwInitParam
, 0);
1829 HINSTANCE hInstance
,
1830 LPCSTR lpTemplateName
,
1832 DLGPROC lpDialogFunc
,
1838 //// ReactOS rev 33532
1839 if (!(hrsrc
= FindResourceA( hInstance
, lpTemplateName
, (LPCSTR
)RT_DIALOG
)) ||
1840 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1842 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1845 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1847 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1850 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, FALSE
, &hWndParent
);
1851 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1862 HINSTANCE hInstance
,
1863 LPCWSTR lpTemplateName
,
1865 DLGPROC lpDialogFunc
,
1871 //// ReactOS rev 33532
1872 if (!(hrsrc
= FindResourceW( hInstance
, lpTemplateName
, (LPCWSTR
)RT_DIALOG
)) ||
1873 !(ptr
= LoadResource(hInstance
, hrsrc
)))
1875 SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND
);
1878 if (hWndParent
!= NULL
&& !IsWindow(hWndParent
))
1880 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
1883 hwnd
= DIALOG_CreateIndirect(hInstance
, ptr
, hWndParent
, lpDialogFunc
, dwInitParam
, TRUE
, &hWndParent
);
1884 if (hwnd
) return DIALOG_DoDialogBox(hwnd
, hWndParent
);
1901 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1910 DlgDirListComboBoxA(
1917 return DIALOG_DlgDirListA( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1926 DlgDirListComboBoxW(
1933 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDComboBox
, nIDStaticPath
, uFiletype
, TRUE
);
1949 return DIALOG_DlgDirListW( hDlg
, lpPathSpec
, nIDListBox
, nIDStaticPath
, uFileType
, FALSE
);
1958 DlgDirSelectComboBoxExA(
1964 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, FALSE
, TRUE
);
1973 DlgDirSelectComboBoxExW(
1979 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDComboBox
, TRUE
, TRUE
);
1994 return DIALOG_DlgDirSelect( hDlg
, (LPWSTR
)lpString
, nCount
, nIDListBox
, FALSE
, FALSE
);
2009 return DIALOG_DlgDirSelect( hDlg
, lpString
, nCount
, nIDListBox
, TRUE
, FALSE
);
2014 * @implemented Modified for ReactOS. Do not Port Sync!!!
2022 DIALOGINFO
* dlgInfo
;
2026 TRACE("%p %ld\n", hwnd
, retval
);
2028 if (!(dlgInfo
= GETDLGINFO(hwnd
)))
2030 ERR("got invalid window handle (%p); buggy app !?\n", hwnd
);
2033 wasActive
= (hwnd
== GetActiveWindow());
2034 dlgInfo
->idResult
= retval
;
2035 dlgInfo
->flags
|= DF_END
;
2037 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
2039 owner
= GetAncestor( hwnd
, GA_PARENT
);
2042 owner
= GetWindow( hwnd
, GW_OWNER
);
2045 EnableWindow( owner
, TRUE
);
2047 /* Windows sets the focus to the dialog itself in EndDialog */
2049 if (wasActive
&& IsChild(hwnd
, GetFocus()))
2052 /* Don't have to send a ShowWindow(SW_HIDE), just do
2053 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
2055 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
2056 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2058 if (wasActive
&& owner
)
2060 /* If this dialog was given an owner then set the focus to that owner. */
2061 SetActiveWindow(owner
);
2063 else if (hwnd
== GetActiveWindow()) // Check it again!
2065 NtUserCallNoParam(NOPARAM_ROUTINE_ZAPACTIVEANDFOUS
);
2068 /* unblock dialog loop */
2069 PostMessageA(hwnd
, WM_NULL
, 0, 0);
2079 GetDialogBaseUnits(VOID
)
2088 if ((hdc
= GetDC(0)))
2090 size
.cx
= GdiGetCharDimensions( hdc
, NULL
, &size
.cy
);
2091 if (size
.cx
) units
= MAKELONG( size
.cx
, size
.cy
);
2092 ReleaseDC( 0, hdc
);
2107 return GetWindowLongPtrW( hwndCtl
, GWLP_ID
);
2124 if (!hDlg
) return 0;
2126 list
= WIN_ListChildren(hDlg
);
2127 if (!list
) return 0;
2129 for (i
= 0; list
[i
]; i
++) if (GetWindowLongPtrW(list
[i
], GWLP_ID
) == nIDDlgItem
) break;
2131 HeapFree(GetProcessHeap(), 0, list
);
2132 // if (!ret) SetLastError(ERROR_CONTROL_ID_NOT_FOUND);
2150 LONG_PTR result
= 0;
2152 if (lpTranslated
) *lpTranslated
= FALSE
;
2153 if (!SendDlgItemMessageA(hDlg
, nIDDlgItem
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
2157 result
= strtol( str
, &endptr
, 10 );
2158 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2160 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)))
2165 result
= strtoul( str
, &endptr
, 10 );
2166 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
2168 if (result
== ULONG_MAX
) return 0;
2170 if (lpTranslated
) *lpTranslated
= TRUE
;
2171 return (UINT
)result
;
2186 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2187 if ( hWnd
) return GetWindowTextA(hWnd
, lpString
, nMaxCount
);
2188 if ( nMaxCount
) lpString
[0] = '\0';
2204 HWND hWnd
= GetDlgItem(hDlg
, nIDDlgItem
);
2205 if ( hWnd
) return GetWindowTextW(hWnd
, lpString
, nMaxCount
);
2206 if ( nMaxCount
) lpString
[0] = '\0';
2215 GetNextDlgGroupItem(
2220 HWND hwnd
, hwndNext
, retvalue
, hwndLastGroup
= 0;
2222 BOOL fSkipping
=FALSE
;
2224 if (hDlg
== hCtl
) hCtl
= NULL
;
2225 if (!hCtl
&& bPrevious
) return 0;
2227 /* if the hwndCtrl is the child of the control in the hwndDlg,
2228 * then the hwndDlg has to be the parent of the hwndCtrl */
2232 if (!IsChild (hDlg
, hCtl
)) return 0;
2233 /* Make sure hwndCtrl is a top-level child */
2238 /* No ctrl specified -> start from the beginning */
2239 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2240 /* MSDN is wrong. fPrevious does not result in the last child */
2242 /* No ctrl specified -> start from the beginning */
2243 if (!(hCtl
= GetWindow( hDlg
, GW_CHILD
))) return 0;
2245 /* MSDN is wrong. fPrevious does not result in the last child */
2247 /* Maybe that first one is valid. If so then we don't want to skip it*/
2248 if ((GetWindowLongPtrW( hCtl
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) == WS_VISIBLE
)
2255 /* Always go forward around the group and list of controls; for the
2256 * previous control keep track; for the next break when you find one
2260 while (hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
),
2265 /* Climb out until there is a next sibling of the ancestor or we
2266 * reach the top (in which case we loop back to the start)
2268 if (hDlg
== GetParent (hwnd
))
2270 /* Wrap around to the beginning of the list, within the same
2271 * group. (Once only)
2273 if (fLooped
) goto end
;
2275 hwndNext
= GetWindow (hDlg
, GW_CHILD
);
2279 hwnd
= GetParent (hwnd
);
2280 hwndNext
= GetWindow (hwnd
, GW_HWNDNEXT
);
2285 /* Wander down the leading edge of controlparents */
2286 while ( (GetWindowLongPtrW (hwnd
, GWL_EXSTYLE
) & WS_EX_CONTROLPARENT
) &&
2287 ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) &&
2288 (hwndNext
= GetWindow (hwnd
, GW_CHILD
)))
2290 /* Question. If the control is a control parent but either has no
2291 * children or is not visible/enabled then if it has a WS_GROUP does
2292 * it count? For that matter does it count anyway?
2293 * I believe it doesn't count.
2296 if ((GetWindowLongPtrW (hwnd
, GWL_STYLE
) & WS_GROUP
))
2298 hwndLastGroup
= hwnd
;
2301 /* Look for the beginning of the group */
2308 if (!fSkipping
) break;
2309 if (hwndLastGroup
== hwnd
) break;
2310 hwnd
= hwndLastGroup
;
2316 (GetWindowLongPtrW (hwnd
, GWL_STYLE
) & (WS_VISIBLE
|WS_DISABLED
)) ==
2320 if (!bPrevious
) break;
2340 pWindow
= ValidateHwnd( hDlg
);
2341 if (!pWindow
) return NULL
;
2344 pWindow
= ValidateHwnd( hCtl
);
2345 if (!pWindow
) return NULL
;
2348 /* Undocumented but tested under Win2000 and WinME */
2349 if (hDlg
== hCtl
) hCtl
= NULL
;
2351 /* Contrary to MSDN documentation, tested under Win2000 and WinME
2352 * NB GetLastError returns whatever was set before the function was
2355 if (!hCtl
&& bPrevious
) return 0;
2357 return DIALOG_GetNextTabItem(hDlg
, hDlg
, hCtl
, bPrevious
);
2368 return IsDialogMessageW(hDlg
, lpMsg
);
2372 /***********************************************************************
2373 * DIALOG_FixOneChildOnChangeFocus
2375 * Callback helper for DIALOG_FixChildrenOnChangeFocus
2378 static BOOL CALLBACK
DIALOG_FixOneChildOnChangeFocus (HWND hwndChild
,
2381 /* If a default pushbutton then no longer default */
2382 if (DLGC_DEFPUSHBUTTON
& SendMessageW (hwndChild
, WM_GETDLGCODE
, 0, 0))
2383 SendMessageW (hwndChild
, BM_SETSTYLE
, BS_PUSHBUTTON
, TRUE
);
2387 /***********************************************************************
2388 * DIALOG_FixChildrenOnChangeFocus
2390 * Following the change of focus that occurs for example after handling
2391 * a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
2392 * children may be required.
2394 static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg
, HWND hwndNext
)
2396 INT dlgcode_next
= SendMessageW (hwndNext
, WM_GETDLGCODE
, 0, 0);
2397 /* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
2398 /* Windows does ask for this. I don't know why yet */
2400 EnumChildWindows (hwndDlg
, DIALOG_FixOneChildOnChangeFocus
, 0);
2402 /* If the button that is getting the focus WAS flagged as the default
2403 * pushbutton then ask the dialog what it thinks the default is and
2404 * set that in the default style.
2406 if (dlgcode_next
& DLGC_DEFPUSHBUTTON
)
2408 DWORD def_id
= SendMessageW (hwndDlg
, DM_GETDEFID
, 0, 0);
2409 if (HIWORD(def_id
) == DC_HASDEFID
)
2412 def_id
= LOWORD(def_id
);
2413 hwndDef
= GetDlgItem (hwndDlg
, def_id
);
2416 INT dlgcode_def
= SendMessageW (hwndDef
, WM_GETDLGCODE
, 0, 0);
2417 /* I know that if it is a button then it should already be a
2418 * UNDEFPUSHBUTTON, since we have just told the buttons to
2419 * change style. But maybe they ignored our request
2421 if ((dlgcode_def
& DLGC_BUTTON
) &&
2422 (dlgcode_def
& DLGC_UNDEFPUSHBUTTON
))
2424 SendMessageW (hwndDef
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2429 else if ((dlgcode_next
& DLGC_BUTTON
) && (dlgcode_next
& DLGC_UNDEFPUSHBUTTON
))
2431 SendMessageW (hwndNext
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
2432 /* I wonder why it doesn't send a DM_SETDEFID */
2436 /***********************************************************************
2439 * A recursive version of GetDlgItem
2442 * The HWND for a Child ID.
2444 static HWND
DIALOG_IdToHwnd( HWND hwndDlg
, INT id
)
2447 HWND
*list
= WIN_ListChildren( hwndDlg
);
2450 if (!list
) return 0;
2452 for (i
= 0; list
[i
]; i
++)
2454 if (GetWindowLongPtrW( list
[i
], GWLP_ID
) == id
)
2460 /* Recurse into every child */
2461 if ((ret
= DIALOG_IdToHwnd( list
[i
], id
))) break;
2464 HeapFree( GetProcessHeap(), 0, list
);
2480 if (!IsWindow( hDlg
))
2483 if (CallMsgFilterW( lpMsg
, MSGF_DIALOGBOX
)) return TRUE
;
2485 if (hDlg
== GetDesktopWindow()) return FALSE
;
2486 if ((hDlg
!= lpMsg
->hwnd
) && !IsChild( hDlg
, lpMsg
->hwnd
)) return FALSE
;
2488 hDlg
= DIALOG_FindMsgDestination(hDlg
);
2490 switch(lpMsg
->message
)
2493 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2494 if (dlgCode
& DLGC_WANTMESSAGE
) break;
2496 switch(lpMsg
->wParam
)
2499 if (!(dlgCode
& DLGC_WANTTAB
))
2501 BOOL fIsDialog
= TRUE
;
2502 WND
*pWnd
= ValidateHwnd(hDlg
);
2504 if (pWnd
&& TestWindowProcess(pWnd
))
2506 fIsDialog
= (GETDLGINFO(hDlg
) != NULL
);
2509 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEFOCUS
), 0);
2511 /* I am not sure under which circumstances the TAB is handled
2512 * each way. All I do know is that it does not always simply
2513 * send WM_NEXTDLGCTL. (Personally I have never yet seen it
2514 * do so but I presume someone has)
2517 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
2520 /* It would appear that GetNextDlgTabItem can handle being
2521 * passed hwndDlg rather than NULL but that is undocumented
2522 * so let's do it properly
2524 HWND hwndFocus
= GetFocus();
2525 HWND hwndNext
= GetNextDlgTabItem (hDlg
,
2526 hwndFocus
== hDlg
? NULL
: hwndFocus
,
2527 GetKeyState (VK_SHIFT
) & 0x8000);
2530 dlgCode
= SendMessageW (hwndNext
, WM_GETDLGCODE
,
2531 lpMsg
->wParam
, (LPARAM
)lpMsg
);
2532 if (dlgCode
& DLGC_HASSETSEL
)
2534 INT maxlen
= 1 + SendMessageW (hwndNext
, WM_GETTEXTLENGTH
, 0, 0);
2535 WCHAR
*buffer
= HeapAlloc (GetProcessHeap(), 0, maxlen
* sizeof(WCHAR
));
2539 SendMessageW (hwndNext
, WM_GETTEXT
, maxlen
, (LPARAM
) buffer
);
2540 length
= strlenW (buffer
);
2541 HeapFree (GetProcessHeap(), 0, buffer
);
2542 SendMessageW (hwndNext
, EM_SETSEL
, 0, length
);
2545 SetFocus (hwndNext
);
2546 DIALOG_FixChildrenOnChangeFocus (hDlg
, hwndNext
);
2559 if (!(dlgCode
& DLGC_WANTARROWS
))
2561 BOOL fPrevious
= (lpMsg
->wParam
== VK_LEFT
|| lpMsg
->wParam
== VK_UP
);
2562 HWND hwndNext
= GetNextDlgGroupItem (hDlg
, GetFocus(), fPrevious
);
2563 SendMessageW( hDlg
, WM_NEXTDLGCTL
, (WPARAM
)hwndNext
, 1 );
2570 SendMessageW( hDlg
, WM_COMMAND
, IDCANCEL
, (LPARAM
)GetDlgItem( hDlg
, IDCANCEL
) );
2577 if ((GetFocus() == lpMsg
->hwnd
) &&
2578 (SendMessageW (lpMsg
->hwnd
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
))
2580 SendMessageW (hDlg
, WM_COMMAND
, MAKEWPARAM (GetDlgCtrlID(lpMsg
->hwnd
),BN_CLICKED
), (LPARAM
)lpMsg
->hwnd
);
2582 else if (DC_HASDEFID
== HIWORD(dw
= SendMessageW (hDlg
, DM_GETDEFID
, 0, 0)))
2584 HWND hwndDef
= DIALOG_IdToHwnd(hDlg
, LOWORD(dw
));
2585 if (!hwndDef
|| IsWindowEnabled(hwndDef
))
2586 SendMessageW( hDlg
, WM_COMMAND
, MAKEWPARAM( LOWORD(dw
), BN_CLICKED
), (LPARAM
)hwndDef
);
2590 SendMessageW( hDlg
, WM_COMMAND
, IDOK
, (LPARAM
)GetDlgItem( hDlg
, IDOK
) );
2599 /* FIXME Under what circumstances does WM_GETDLGCODE get sent?
2600 * It does NOT get sent in the test program I have
2602 dlgCode
= SendMessageW( lpMsg
->hwnd
, WM_GETDLGCODE
, lpMsg
->wParam
, (LPARAM
)lpMsg
);
2603 if (dlgCode
& (DLGC_WANTCHARS
|DLGC_WANTMESSAGE
)) break;
2604 if (lpMsg
->wParam
== '\t' && (dlgCode
& DLGC_WANTTAB
)) break;
2608 if (DIALOG_IsAccelerator( lpMsg
->hwnd
, hDlg
, lpMsg
->wParam
))
2610 /* don't translate or dispatch */
2616 /* If the ALT key is being pressed display the keyboard cues */
2617 if ( HIWORD(lpMsg
->lParam
) & KF_ALTDOWN
&&
2618 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2619 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2623 /* If the ALT key is being pressed display the keyboard cues */
2624 if ( lpMsg
->wParam
== SC_KEYMENU
&&
2625 !(gpsi
->dwSRVIFlags
& SRVINFO_KBDPREF
) && !(gpsi
->PUSIFlags
& PUSIF_KEYBOARDCUES
) )
2627 SendMessageW(hDlg
, WM_CHANGEUISTATE
, MAKEWPARAM(UIS_CLEAR
, UISF_HIDEACCEL
| UISF_HIDEFOCUS
), 0);
2632 TranslateMessage( lpMsg
);
2633 DispatchMessageW( lpMsg
);
2647 return (UINT
)SendDlgItemMessageW( hDlg
, nIDButton
, BM_GETCHECK
, 0, 0 );
2660 DIALOGINFO
* dlgInfo
;
2661 if (!(dlgInfo
= GETDLGINFO(hDlg
))) return FALSE
;
2662 lpRect
->left
= MulDiv(lpRect
->left
, dlgInfo
->xBaseUnit
, 4);
2663 lpRect
->right
= MulDiv(lpRect
->right
, dlgInfo
->xBaseUnit
, 4);
2664 lpRect
->top
= MulDiv(lpRect
->top
, dlgInfo
->yBaseUnit
, 8);
2665 lpRect
->bottom
= MulDiv(lpRect
->bottom
, dlgInfo
->yBaseUnit
, 8);
2675 SendDlgItemMessageA(
2683 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2684 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2685 if (hwndCtrl
) return SendMessageA( hwndCtrl
, Msg
, wParam
, lParam
);
2695 SendDlgItemMessageW(
2703 if ( hDlg
== HWND_TOPMOST
|| hDlg
== HWND_BROADCAST
) return 0; // ReactOS
2704 hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
);
2705 if (hwndCtrl
) return SendMessageW( hwndCtrl
, Msg
, wParam
, lParam
);
2723 if (bSigned
) sprintf( str
, "%d", (INT
)uValue
);
2724 else sprintf( str
, "%u", uValue
);
2725 SendDlgItemMessageA( hDlg
, nIDDlgItem
, WM_SETTEXT
, 0, (LPARAM
)str
);
2740 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2741 if (hwndCtrl
) return SetWindowTextA( hwndCtrl
, lpString
);
2756 HWND hwndCtrl
= GetDlgItem( hDlg
, nIDDlgItem
); // ReactOS Themes
2757 if (hwndCtrl
) return SetWindowTextW( hwndCtrl
, lpString
);
2772 SendDlgItemMessageW( hDlg
, nIDButton
, BM_SETCHECK
, uCheck
, 0 );
2776 static BOOL CALLBACK
CheckRB(HWND hwnd
, LPARAM lParam
)
2778 LONG lChildID
= GetWindowLongPtrW(hwnd
, GWLP_ID
);
2779 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*)lParam
;
2781 if((lChildID
>= lpRadioGroup
->firstID
) &&
2782 (lChildID
<= lpRadioGroup
->lastID
))
2784 if (lChildID
== lpRadioGroup
->checkID
)
2786 SendMessageW(hwnd
, BM_SETCHECK
, BST_CHECKED
, 0);
2790 SendMessageW(hwnd
, BM_SETCHECK
, BST_UNCHECKED
, 0);
2808 RADIOGROUP radioGroup
;
2810 radioGroup
.firstID
= nIDFirstButton
;
2811 radioGroup
.lastID
= nIDLastButton
;
2812 radioGroup
.checkID
= nIDCheckButton
;
2814 return EnumChildWindows(hDlg
, CheckRB
, (LPARAM
)&radioGroup
);