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.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/dialog.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * Thomas Weidenmueller (w3seek@users.sourceforge.net)
27 * 07-26-2003 Code ported from wine
28 * 09-05-2001 CSH Created
31 /* INCLUDES ******************************************************************/
41 #include "user32/regcontrol.h"
42 #include "../controls/controls.h"
45 /* MACROS/DEFINITIONS ********************************************************/
48 #define DF_OWNERENABLED 0x0002
49 #define CW_USEDEFAULT16 ((short)0x8000)
51 #define GETDLGINFO(hwnd) (DIALOGINFO*)GetWindowLongW((hwnd), DWL_INIT)
52 #define SETDLGINFO(hwnd, info) SetWindowLongW((hwnd), DWL_INIT, (LONG)(info))
53 #define GET_WORD(ptr) (*(WORD *)(ptr))
54 #define GET_DWORD(ptr) (*(DWORD *)(ptr))
55 #define MAKEINTATOMA(atom) ((LPCSTR)((ULONG_PTR)((WORD)(atom))))
56 #define MAKEINTATOMW(atom) ((LPCWSTR)((ULONG_PTR)((WORD)(atom))))
57 #define DIALOG_CLASS_ATOMA MAKEINTATOMA(32770) /* Dialog */
58 #define DIALOG_CLASS_ATOMW MAKEINTATOMW(32770) /* Dialog */
60 /* INTERNAL STRUCTS **********************************************************/
62 /* Dialog info structure */
65 HWND hwndFocus; /* Current control with focus */
66 HFONT hUserFont; /* Dialog font */
67 HMENU hMenu; /* Dialog menu */
68 UINT xBaseUnit; /* Dialog units (depends on the font) */
70 INT idResult; /* EndDialog() result / default pushbutton ID */
71 UINT flags; /* EndDialog() called for this dialog */
74 /* Dialog control information */
111 /* GetDlgItem structure */
119 /*********************************************************************
120 * dialog class descriptor
122 const struct builtin_class_descr DIALOG_builtin_class =
124 DIALOG_CLASS_ATOMW, /* name */
125 CS_GLOBALCLASS | CS_SAVEBITS | CS_DBLCLKS, /* style */
126 (WNDPROC) DefDlgProcW, /* procW */
127 DWL_INIT + sizeof(LONG), /* extra */
128 (LPCWSTR) IDC_ARROW, /* cursor */
133 /* INTERNAL FUNCTIONS ********************************************************/
135 /***********************************************************************
138 * Despite most of MSDN insisting that the horizontal base unit is
139 * tmAveCharWidth it isn't. Knowledge base article Q145994
140 * "HOWTO: Calculate Dialog Units When Not Using the System Font",
141 * says that we should take the average of the 52 English upper and lower
144 BOOL DIALOG_GetCharSize( HDC hDC, HFONT hFont, SIZE * pSize )
147 char *alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
151 if(!hDC) return FALSE;
153 if(hFont) hFontPrev = SelectObject(hDC, hFont);
154 if(!GetTextMetricsA(hDC, &tm)) return FALSE;
155 if(!GetTextExtentPointA(hDC, alphabet, 52, &sz)) return FALSE;
157 pSize->cy = tm.tmHeight;
158 pSize->cx = (sz.cx / 26 + 1) / 2;
160 if (hFontPrev) SelectObject(hDC, hFontPrev);
165 /***********************************************************************
168 * Helper function for modal dialogs to enable again the
169 * owner of the dialog box.
171 void DIALOG_EnableOwner( HWND hOwner )
173 /* Owner must be a top-level window */
175 hOwner = GetAncestor( hOwner, GA_ROOT );
177 EnableWindow( hOwner, TRUE );
180 /***********************************************************************
181 * DIALOG_DisableOwner
183 * Helper function for modal dialogs to disable the
184 * owner of the dialog box. Returns TRUE if owner was enabled.
186 BOOL DIALOG_DisableOwner( HWND hOwner )
188 /* Owner must be a top-level window */
190 hOwner = GetAncestor( hOwner, GA_ROOT );
191 if (!hOwner) return FALSE;
192 if (IsWindowEnabled( hOwner ))
194 EnableWindow( hOwner, FALSE );
201 /***********************************************************************
202 * DIALOG_GetControl32
204 * Return the class and text of the control pointed to by ptr,
205 * fill the header structure and return a pointer to the next control.
207 static const WORD *DIALOG_GetControl32( const WORD *p, DLG_CONTROL_INFO *info,
212 info->helpId = GET_DWORD(p); p += 2;
213 info->exStyle = GET_DWORD(p); p += 2;
214 info->style = GET_DWORD(p); p += 2;
219 info->style = GET_DWORD(p); p += 2;
220 info->exStyle = GET_DWORD(p); p += 2;
222 info->x = GET_WORD(p); p++;
223 info->y = GET_WORD(p); p++;
224 info->cx = GET_WORD(p); p++;
225 info->cy = GET_WORD(p); p++;
229 /* id is a DWORD for DIALOGEX */
230 info->id = GET_DWORD(p);
235 info->id = GET_WORD(p);
239 if (GET_WORD(p) == 0xffff)
241 static const WCHAR class_names[6][10] =
243 { 'B','u','t','t','o','n', }, /* 0x80 */
244 { 'E','d','i','t', }, /* 0x81 */
245 { 'S','t','a','t','i','c', }, /* 0x82 */
246 { 'L','i','s','t','B','o','x', }, /* 0x83 */
247 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
248 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
250 WORD id = GET_WORD(p+1);
251 /* Windows treats dialog control class ids 0-5 same way as 0x80-0x85 */
252 if ((id >= 0x80) && (id <= 0x85)) id -= 0x80;
254 info->className = class_names[id];
257 info->className = NULL;
258 /* FIXME: load other classes here? */
264 info->className = (LPCWSTR)p;
265 p += wcslen( info->className ) + 1;
268 if (GET_WORD(p) == 0xffff) /* Is it an integer id? */
270 info->windowName = (LPCWSTR)(UINT)GET_WORD(p + 1);
275 info->windowName = (LPCWSTR)p;
276 p += wcslen( info->windowName ) + 1;
282 p += GET_WORD(p) / sizeof(WORD);
284 else info->data = NULL;
287 /* Next control is on dword boundary */
288 return (const WORD *)((((int)p) + 3) & ~3);
291 /***********************************************************************
292 * DIALOG_CreateControls32
294 * Create the control windows for a dialog.
296 static BOOL DIALOG_CreateControls32( HWND hwnd, LPCSTR template, const DLG_TEMPLATE *dlgTemplate,
297 HINSTANCE hInst, BOOL unicode )
299 DIALOGINFO * dlgInfo;
300 DLG_CONTROL_INFO info;
301 HWND hwndCtrl, hwndDefButton = 0;
302 INT items = dlgTemplate->nbItems;
304 if (!(dlgInfo = GETDLGINFO(hwnd))) return -1;
308 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info,
309 dlgTemplate->dialogEx );
311 if (info.style & WS_BORDER)
313 info.style &= ~WS_BORDER;
314 info.exStyle |= WS_EX_CLIENTEDGE;
318 hwndCtrl = CreateWindowExW( info.exStyle | WS_EX_NOPARENTNOTIFY,
319 info.className, info.windowName,
320 info.style | WS_CHILD,
321 MulDiv(info.x, dlgInfo->xBaseUnit, 4),
322 MulDiv(info.y, dlgInfo->yBaseUnit, 8),
323 MulDiv(info.cx, dlgInfo->xBaseUnit, 4),
324 MulDiv(info.cy, dlgInfo->yBaseUnit, 8),
325 hwnd, (HMENU)info.id,
326 hInst, (LPVOID)info.data );
330 LPSTR class = (LPSTR)info.className;
331 LPSTR caption = (LPSTR)info.windowName;
335 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.className, -1, NULL, 0, NULL, NULL );
336 class = HeapAlloc( GetProcessHeap(), 0, len );
337 WideCharToMultiByte( CP_ACP, 0, info.className, -1, class, len, NULL, NULL );
341 DWORD len = WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, NULL, 0, NULL, NULL );
342 caption = HeapAlloc( GetProcessHeap(), 0, len );
343 WideCharToMultiByte( CP_ACP, 0, info.windowName, -1, caption, len, NULL, 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)info.id,
352 hInst, (LPVOID)info.data );
353 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
354 if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
358 if (dlgTemplate->style & DS_NOFAILCREATE) continue;
362 /* Send initialisation messages to the control */
363 if (dlgInfo->hUserFont) SendMessageA( hwndCtrl, WM_SETFONT,
364 (WPARAM)dlgInfo->hUserFont, 0 );
365 if (SendMessageA(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
367 /* If there's already a default push-button, set it back */
368 /* to normal and use this one instead. */
370 SendMessageA( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE );
371 hwndDefButton = hwndCtrl;
372 dlgInfo->idResult = GetWindowLongA( hwndCtrl, GWL_ID );
378 /***********************************************************************
379 * DIALOG_FindMsgDestination
381 * The messages that IsDialogMessage sends may not go to the dialog
382 * calling IsDialogMessage if that dialog is a child, and it has the
383 * DS_CONTROL style set.
384 * We propagate up until we hit one that does not have DS_CONTROL, or
385 * whose parent is not a dialog.
387 * This is undocumented behaviour.
389 static HWND DIALOG_FindMsgDestination( HWND hwndDlg )
391 while (GetWindowLongA(hwndDlg, GWL_STYLE) & DS_CONTROL)
393 HWND hParent = GetParent(hwndDlg);
396 if (!IsWindow(hParent)) break;
398 if (!GETDLGINFO(hParent)) /* TODO: Correct? */
409 /***********************************************************************
410 * DIALOG_IsAccelerator
412 static BOOL DIALOG_IsAccelerator( HWND hwnd, HWND hwndDlg, WPARAM wParam )
414 HWND hwndControl = hwnd;
421 DWORD style = GetWindowLongW( hwndControl, GWL_STYLE );
422 if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE)
424 dlgCode = SendMessageA( hwndControl, WM_GETDLGCODE, 0, 0 );
425 if ( (dlgCode & (DLGC_BUTTON | DLGC_STATIC)) &&
426 GetWindowTextW( hwndControl, buffer, sizeof(buffer)/sizeof(WCHAR) ))
428 /* find the accelerator key */
429 LPWSTR p = buffer - 2;
433 p = wcschr( p + 2, '&' );
435 while (p != NULL && p[1] == '&');
437 /* and check if it's the one we're looking for */
438 /* FIXME: usage of towupper correct? */
439 if (p != NULL && towupper( p[1] ) == towupper( wParam ) )
441 if ((dlgCode & DLGC_STATIC) || (style & 0x0f) == BS_GROUPBOX )
443 /* set focus to the control */
444 SendMessageA( hwndDlg, WM_NEXTDLGCTL, (WPARAM)hwndControl, 1);
445 /* and bump it on to next */
446 SendMessageA( hwndDlg, WM_NEXTDLGCTL, 0, 0);
448 else if (dlgCode & DLGC_BUTTON)
450 /* send BM_CLICK message to the control */
451 SendMessageA( hwndControl, BM_CLICK, 0, 0 );
456 hwndNext = GetWindow( hwndControl, GW_CHILD );
460 if (!hwndNext) hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
462 while (!hwndNext && hwndControl)
464 hwndControl = GetParent( hwndControl );
465 if (hwndControl == hwndDlg)
467 if(hwnd==hwndDlg) /* prevent endless loop */
472 hwndNext = GetWindow( hwndDlg, GW_CHILD );
475 hwndNext = GetWindow( hwndControl, GW_HWNDNEXT );
477 hwndControl = hwndNext;
479 while (hwndControl && (hwndControl != hwnd));
484 /***********************************************************************
487 INT DIALOG_DoDialogBox( HWND hwnd, HWND owner )
489 DIALOGINFO * dlgInfo;
492 HWND ownerMsg = GetAncestor( owner, GA_ROOT );
493 if (!(dlgInfo = GETDLGINFO(hwnd))) return -1;
495 if (!(dlgInfo->flags & DF_END)) /* was EndDialog called in WM_INITDIALOG ? */
497 ShowWindow( hwnd, SW_SHOW );
500 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & DS_NOIDLEMSG))
502 if (!PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ))
504 /* No message present -> send ENTERIDLE and wait */
505 SendMessageW( ownerMsg, WM_ENTERIDLE, MSGF_DIALOGBOX, (LPARAM)hwnd );
506 if (!GetMessageW( &msg, 0, 0, 0 )) break;
509 else if (!GetMessageW( &msg, 0, 0, 0 )) break;
511 if (!IsWindow( hwnd )) return -1;
512 if (!(dlgInfo->flags & DF_END) && !IsDialogMessageW( hwnd, &msg))
514 TranslateMessage( &msg );
515 DispatchMessageW( &msg );
517 if (dlgInfo->flags & DF_END) break;
520 if (dlgInfo->flags & DF_OWNERENABLED) DIALOG_EnableOwner( owner );
521 retval = dlgInfo->idResult;
522 DestroyWindow( hwnd );
526 /***********************************************************************
527 * DIALOG_ParseTemplate32
529 * Fill a DLG_TEMPLATE structure from the dialog template, and return
530 * a pointer to the first control.
532 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
534 const WORD *p = (const WORD *)template;
536 result->style = GET_DWORD(p); p += 2;
537 if (result->style == 0xffff0001) /* DIALOGEX resource */
539 result->dialogEx = TRUE;
540 result->helpId = GET_DWORD(p); p += 2;
541 result->exStyle = GET_DWORD(p); p += 2;
542 result->style = GET_DWORD(p); p += 2;
546 result->dialogEx = FALSE;
548 result->exStyle = GET_DWORD(p); p += 2;
550 result->nbItems = GET_WORD(p); p++;
551 result->x = GET_WORD(p); p++;
552 result->y = GET_WORD(p); p++;
553 result->cx = GET_WORD(p); p++;
554 result->cy = GET_WORD(p); p++;
556 /* Get the menu name */
561 result->menuName = NULL;
565 result->menuName = (LPCWSTR)(UINT)GET_WORD( p + 1 );
569 result->menuName = (LPCWSTR)p;
570 p += wcslen( result->menuName ) + 1;
574 /* Get the class name */
579 result->className = DIALOG_CLASS_ATOMW;
583 result->className = (LPCWSTR)(UINT)GET_WORD( p + 1 );
587 result->className = (LPCWSTR)p;
588 p += wcslen( result->className ) + 1;
592 /* Get the window caption */
594 result->caption = (LPCWSTR)p;
595 p += wcslen( result->caption ) + 1;
597 /* Get the font name */
599 if (result->style & DS_SETFONT)
601 result->pointSize = GET_WORD(p);
603 if (result->dialogEx)
605 result->weight = GET_WORD(p); p++;
606 result->italic = LOBYTE(GET_WORD(p)); p++;
610 result->weight = FW_DONTCARE;
611 result->italic = FALSE;
613 result->faceName = (LPCWSTR)p;
614 p += wcslen( result->faceName ) + 1;
617 /* First control is on dword boundary */
618 return (LPCSTR)((((int)p) + 3) & ~3);
621 /***********************************************************************
622 * DIALOG_CreateIndirect
623 * Creates a dialog box window
625 * modal = TRUE if we are called from a modal dialog box.
626 * (it's more compatible to do it here, as under Windows the owner
627 * is never disabled if the dialog fails because of an invalid template)
629 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
630 HWND owner, DLGPROC dlgProc, LPARAM param,
631 BOOL unicode, BOOL modal )
635 DLG_TEMPLATE template;
636 DIALOGINFO * dlgInfo;
637 DWORD units = GetDialogBaseUnits();
638 BOOL ownerEnabled = TRUE;
640 /* Parse dialog template */
642 if (!dlgTemplate) return 0;
643 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
645 /* Initialise dialog extra data */
647 if (!(dlgInfo = HeapAlloc( GetProcessHeap(), 0, sizeof(*dlgInfo) ))) return 0;
648 dlgInfo->hwndFocus = 0;
649 dlgInfo->hUserFont = 0;
651 dlgInfo->xBaseUnit = LOWORD(units);
652 dlgInfo->yBaseUnit = HIWORD(units);
653 dlgInfo->idResult = 0;
655 //dlgInfo->hDialogHeap = 0;
659 if (template.menuName) dlgInfo->hMenu = LoadMenuW( hInst, template.menuName );
661 /* Create custom font if needed */
663 if (template.style & DS_SETFONT)
665 /* We convert the size to pixels and then make it -ve. This works
666 * for both +ve and -ve template.pointSize */
670 pixels = MulDiv(template.pointSize, GetDeviceCaps(dc , LOGPIXELSY), 72);
671 dlgInfo->hUserFont = CreateFontW( -pixels, 0, 0, 0, template.weight,
672 template.italic, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
673 PROOF_QUALITY, FF_DONTCARE,
675 if (dlgInfo->hUserFont)
678 if (DIALOG_GetCharSize( dc, dlgInfo->hUserFont, &charSize ))
680 dlgInfo->xBaseUnit = charSize.cx;
681 dlgInfo->yBaseUnit = charSize.cy;
687 /* Create dialog main window */
689 rect.left = rect.top = 0;
690 rect.right = MulDiv(template.cx, dlgInfo->xBaseUnit, 4);
691 rect.bottom = MulDiv(template.cy, dlgInfo->yBaseUnit, 8);
692 if (template.style & DS_MODALFRAME)
693 template.exStyle |= WS_EX_DLGMODALFRAME;
694 AdjustWindowRectEx( &rect, template.style, (dlgInfo->hMenu != 0), template.exStyle );
695 rect.right -= rect.left;
696 rect.bottom -= rect.top;
698 if (template.x == CW_USEDEFAULT16)
700 rect.left = rect.top = CW_USEDEFAULT;
704 if (template.style & DS_CENTER)
706 rect.left = (GetSystemMetrics(SM_CXSCREEN) - rect.right) / 2;
707 rect.top = (GetSystemMetrics(SM_CYSCREEN) - rect.bottom) / 2;
711 rect.left += MulDiv(template.x, dlgInfo->xBaseUnit, 4);
712 rect.top += MulDiv(template.y, dlgInfo->yBaseUnit, 8);
714 if ( !(template.style & WS_CHILD) )
718 if( !(template.style & DS_ABSALIGN) )
719 ClientToScreen( owner, (POINT *)&rect );
721 /* try to fit it into the desktop */
723 if( (dX = rect.left + rect.right + GetSystemMetrics(SM_CXDLGFRAME)
724 - GetSystemMetrics(SM_CXSCREEN)) > 0 ) rect.left -= dX;
725 if( (dY = rect.top + rect.bottom + GetSystemMetrics(SM_CYDLGFRAME)
726 - GetSystemMetrics(SM_CYSCREEN)) > 0 ) rect.top -= dY;
727 if( rect.left < 0 ) rect.left = 0;
728 if( rect.top < 0 ) rect.top = 0;
734 ownerEnabled = DIALOG_DisableOwner( owner );
735 if (ownerEnabled) dlgInfo->flags |= DF_OWNERENABLED;
740 hwnd = CreateWindowExW(template.exStyle, template.className, template.caption,
741 template.style & ~WS_VISIBLE,
742 rect.left, rect.top, rect.right, rect.bottom,
743 owner, dlgInfo->hMenu, hInst, NULL );
747 LPSTR class = (LPSTR)template.className;
748 LPSTR caption = (LPSTR)template.caption;
752 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.className, -1, NULL, 0, NULL, NULL );
753 class = HeapAlloc( GetProcessHeap(), 0, len );
754 WideCharToMultiByte( CP_ACP, 0, template.className, -1, class, len, NULL, NULL );
758 DWORD len = WideCharToMultiByte( CP_ACP, 0, template.caption, -1, NULL, 0, NULL, NULL );
759 caption = HeapAlloc( GetProcessHeap(), 0, len );
760 WideCharToMultiByte( CP_ACP, 0, template.caption, -1, caption, len, NULL, NULL );
762 hwnd = CreateWindowExA(template.exStyle, class, caption,
763 template.style & ~WS_VISIBLE,
764 rect.left, rect.top, rect.right, rect.bottom,
765 owner, dlgInfo->hMenu, hInst, NULL );
766 if (HIWORD(class)) HeapFree( GetProcessHeap(), 0, class );
767 if (HIWORD(caption)) HeapFree( GetProcessHeap(), 0, caption );
772 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
773 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
774 if (modal && (dlgInfo->flags & DF_OWNERENABLED)) DIALOG_EnableOwner(owner);
775 HeapFree( GetProcessHeap(), 0, dlgInfo );
780 SetWindowContextHelpId( hwnd, template.helpId );
784 SETDLGINFO(hwnd, dlgInfo); /* maybe SetPropW? */
785 SetWindowLongW( hwnd, DWL_DLGPROC, (LONG)dlgProc );
789 SETDLGINFO(hwnd, dlgInfo);
790 SetWindowLongA( hwnd, DWL_DLGPROC, (LONG)dlgProc );
793 if (dlgInfo->hUserFont)
794 SendMessageA( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
796 /* Create controls */
798 if (DIALOG_CreateControls32( hwnd, dlgTemplate, &template, hInst, unicode ))
800 HWND hwndPreInitFocus;
802 /* Send initialisation messages and set focus */
804 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
806 hwndPreInitFocus = GetFocus();
807 if (SendMessageA( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
809 /* check where the focus is again,
810 * some controls status might have changed in WM_INITDIALOG */
811 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
812 if( dlgInfo->hwndFocus )
813 SetFocus( dlgInfo->hwndFocus );
817 /* If the dlgproc has returned FALSE (indicating handling of keyboard focus)
818 but the focus has not changed, set the focus where we expect it. */
819 if ((GetFocus() == hwndPreInitFocus) &&
820 (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
822 dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
823 if( dlgInfo->hwndFocus )
824 SetFocus( dlgInfo->hwndFocus );
828 if (template.style & WS_VISIBLE && !(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE))
830 ShowWindow( hwnd, SW_SHOWNORMAL ); /* SW_SHOW doesn't always work */
835 if( IsWindow(hwnd) ) DestroyWindow( hwnd );
836 if (modal && ownerEnabled) DIALOG_EnableOwner(owner);
840 /***********************************************************************
843 * Set the focus to a control of the dialog, selecting the text if
844 * the control is an edit dialog.
846 static void DEFDLG_SetFocus( HWND hwndDlg, HWND hwndCtrl )
848 HWND hwndPrev = GetFocus();
850 if (IsChild( hwndDlg, hwndPrev ))
852 if (SendMessageW( hwndPrev, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
853 SendMessageW( hwndPrev, EM_SETSEL, -1, 0 );
855 if (SendMessageW( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_HASSETSEL)
856 SendMessageW( hwndCtrl, EM_SETSEL, 0, -1 );
857 SetFocus( hwndCtrl );
860 /***********************************************************************
863 static void DEFDLG_SaveFocus( HWND hwnd )
866 HWND hwndFocus = GetFocus();
868 if (!hwndFocus || !IsChild( hwnd, hwndFocus )) return;
869 if (!(infoPtr = GETDLGINFO(hwnd))) return;
870 infoPtr->hwndFocus = hwndFocus;
871 /* Remove default button */
874 /***********************************************************************
875 * DEFDLG_RestoreFocus
877 static void DEFDLG_RestoreFocus( HWND hwnd )
881 if (IsIconic( hwnd )) return;
882 if (!(infoPtr = GETDLGINFO(hwnd))) return;
883 if (!IsWindow( infoPtr->hwndFocus )) return;
884 /* Don't set the focus back to controls if EndDialog is already called.*/
885 if (!(infoPtr->flags & DF_END))
887 DEFDLG_SetFocus( hwnd, infoPtr->hwndFocus );
890 /* This used to set infoPtr->hwndFocus to NULL for no apparent reason,
891 sometimes losing focus when receiving WM_SETFOCUS messages. */
894 /***********************************************************************
895 * DEFDLG_FindDefButton
897 * Find the current default push-button.
899 static HWND DEFDLG_FindDefButton( HWND hwndDlg )
901 HWND hwndChild = GetWindow( hwndDlg, GW_CHILD );
904 if (SendMessageW( hwndChild, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
906 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
911 /***********************************************************************
912 * DEFDLG_SetDefButton
914 * Set the new default button to be hwndNew.
916 static BOOL DEFDLG_SetDefButton( HWND hwndDlg, DIALOGINFO *dlgInfo,
919 DWORD dlgcode=0; /* initialize just to avoid a warning */
921 !((dlgcode=SendMessageW(hwndNew, WM_GETDLGCODE, 0, 0 ))
922 & (DLGC_UNDEFPUSHBUTTON | DLGC_BUTTON)))
923 return FALSE; /* Destination is not a push button */
925 if (dlgInfo->idResult) /* There's already a default pushbutton */
927 HWND hwndOld = GetDlgItem( hwndDlg, dlgInfo->idResult );
928 if (SendMessageA( hwndOld, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
929 SendMessageA( hwndOld, BM_SETSTYLE, BS_PUSHBUTTON, TRUE );
933 if(dlgcode==DLGC_UNDEFPUSHBUTTON)
934 SendMessageA( hwndNew, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
935 dlgInfo->idResult = GetDlgCtrlID( hwndNew );
937 else dlgInfo->idResult = 0;
941 /***********************************************************************
944 * Implementation of DefDlgProc(). Only handle messages that need special
945 * handling for dialogs.
947 static LRESULT DEFDLG_Proc( HWND hwnd, UINT msg, WPARAM wParam,
948 LPARAM lParam, DIALOGINFO *dlgInfo )
954 HBRUSH brush = (HBRUSH)SendMessageW( hwnd, WM_CTLCOLORDLG, wParam, (LPARAM)hwnd );
955 if (!brush) brush = (HBRUSH)DefWindowProcW( hwnd, WM_CTLCOLORDLG, wParam, (LPARAM)hwnd );
959 HDC hdc = (HDC)wParam;
960 GetClientRect( hwnd, &rect );
961 DPtoLP( hdc, (LPPOINT)&rect, 2 );
962 FillRect( hdc, &rect, brush );
967 if ((dlgInfo = GETDLGINFO(hwnd)))
969 /* Free dialog heap (if created) */
970 /*if (dlgInfo->hDialogHeap)
972 GlobalUnlock16(dlgInfo->hDialogHeap);
973 GlobalFree16(dlgInfo->hDialogHeap);
975 if (dlgInfo->hUserFont) DeleteObject( dlgInfo->hUserFont );
976 if (dlgInfo->hMenu) DestroyMenu( dlgInfo->hMenu );
977 HeapFree( GetProcessHeap(), 0, dlgInfo );
979 /* Window clean-up */
980 return DefWindowProcA( hwnd, msg, wParam, lParam );
983 if (!wParam) DEFDLG_SaveFocus( hwnd );
984 return DefWindowProcA( hwnd, msg, wParam, lParam );
987 if (wParam) DEFDLG_RestoreFocus( hwnd );
988 else DEFDLG_SaveFocus( hwnd );
992 DEFDLG_RestoreFocus( hwnd );
996 if (dlgInfo && !(dlgInfo->flags & DF_END))
997 DEFDLG_SetDefButton( hwnd, dlgInfo, wParam ? GetDlgItem( hwnd, wParam ) : 0 );
1001 if (dlgInfo && !(dlgInfo->flags & DF_END))
1004 if (dlgInfo->idResult)
1005 return MAKELONG( dlgInfo->idResult, DC_HASDEFID );
1006 if ((hwndDefId = DEFDLG_FindDefButton( hwnd )))
1007 return MAKELONG( GetDlgCtrlID( hwndDefId ), DC_HASDEFID);
1014 HWND hwndDest = (HWND)wParam;
1016 hwndDest = GetNextDlgTabItem(hwnd, GetFocus(), wParam);
1017 if (hwndDest) DEFDLG_SetFocus( hwnd, hwndDest );
1018 DEFDLG_SetDefButton( hwnd, dlgInfo, hwndDest );
1022 case WM_ENTERMENULOOP:
1023 case WM_LBUTTONDOWN:
1024 case WM_NCLBUTTONDOWN:
1026 HWND hwndFocus = GetFocus();
1029 /* always make combo box hide its listbox control */
1030 if (!SendMessageA( hwndFocus, CB_SHOWDROPDOWN, FALSE, 0 ))
1031 SendMessageA( GetParent(hwndFocus), CB_SHOWDROPDOWN, FALSE, 0 );
1034 return DefWindowProcA( hwnd, msg, wParam, lParam );
1037 return dlgInfo ? (LRESULT)dlgInfo->hUserFont : 0;
1040 PostMessageA( hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED),
1041 (LPARAM)GetDlgItem( hwnd, IDCANCEL ) );
1044 case WM_NOTIFYFORMAT:
1045 return DefWindowProcA( hwnd, msg, wParam, lParam );
1050 /***********************************************************************
1053 static LRESULT DEFDLG_Epilog(HWND hwnd, UINT msg, BOOL fResult)
1055 // TODO: where's wine's WM_CTLCOLOR from?
1056 if ((msg >= WM_CTLCOLORMSGBOX && msg <= WM_CTLCOLORSTATIC) ||
1057 /*msg == WM_CTLCOLOR || */ msg == WM_COMPAREITEM ||
1058 msg == WM_VKEYTOITEM || msg == WM_CHARTOITEM ||
1059 msg == WM_QUERYDRAGICON || msg == WM_INITDIALOG)
1062 return GetWindowLongA( hwnd, DWL_MSGRESULT );
1065 /***********************************************************************
1066 * DIALOG_GetNextTabItem
1068 * Helper for GetNextDlgTabItem
1070 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1074 UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
1076 HWND hChildFirst = 0;
1080 hChildFirst = GetWindow(hwndDlg,GW_CHILD);
1081 if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
1083 else if (IsChild( hwndMain, hwndCtrl ))
1085 hChildFirst = GetWindow(hwndCtrl,wndSearch);
1088 if(GetParent(hwndCtrl) != hwndMain)
1089 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
1093 hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
1095 hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
1105 dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
1106 exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
1107 if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1112 else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
1114 hChildFirst = GetWindow(hChildFirst,wndSearch);
1119 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,NULL,fPrevious );
1121 retWnd = hChildFirst;
1124 hChildFirst = GetWindow(hChildFirst,wndSearch);
1126 if(!retWnd && hwndCtrl)
1128 HWND hParent = GetParent(hwndCtrl);
1131 if(hParent == hwndMain) break;
1132 retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
1134 hParent = GetParent(hParent);
1137 retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,NULL,fPrevious );
1142 /***********************************************************************
1143 * GetDlgItemEnumProc
1145 * Callback for GetDlgItem
1147 BOOL CALLBACK GetDlgItemEnumProc (HWND hwnd, LPARAM lParam )
1149 GETDLGITEMINFO * info = (GETDLGITEMINFO *)lParam;
1150 if(info->nIDDlgItem == GetWindowLongW( hwnd, GWL_ID ))
1152 info->control = hwnd;
1159 /* FUNCTIONS *****************************************************************/
1166 CreateDialogIndirectParamA(
1167 HINSTANCE hInstance,
1168 LPCDLGTEMPLATE lpTemplate,
1170 DLGPROC lpDialogFunc,
1173 return DIALOG_CreateIndirect( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, FALSE, FALSE );
1182 CreateDialogIndirectParamAorW(
1183 HINSTANCE hInstance,
1184 LPCDLGTEMPLATE lpTemplate,
1186 DLGPROC lpDialogFunc,
1190 This function might be obsolete since I don't think it is exported by NT
1191 Also wine has one more parameter identifying weather it should call
1192 the function with unicode or not */
1203 CreateDialogIndirectParamW(
1204 HINSTANCE hInstance,
1205 LPCDLGTEMPLATE lpTemplate,
1207 DLGPROC lpDialogFunc,
1210 return DIALOG_CreateIndirect( hInstance, lpTemplate, hWndParent, lpDialogFunc, lParamInit, TRUE, FALSE );
1220 HINSTANCE hInstance,
1221 LPCSTR lpTemplateName,
1223 DLGPROC lpDialogFunc,
1229 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG ))) return 0;
1230 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1231 return CreateDialogIndirectParamA( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1241 HINSTANCE hInstance,
1242 LPCWSTR lpTemplateName,
1244 DLGPROC lpDialogFunc,
1250 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG ))) return 0;
1251 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1252 return CreateDialogIndirectParamW( hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam );
1268 BOOL result = FALSE;
1269 DIALOGINFO * dlgInfo;
1271 /* if there's no dialog info property then call default windows proc?? */
1272 if (!(dlgInfo = GETDLGINFO(hDlg)))
1273 return DefWindowProcA( hDlg, Msg, wParam, lParam );
1275 SetWindowLongW( hDlg, DWL_MSGRESULT, 0 );
1277 if ((dlgproc = (WNDPROC)GetWindowLongA( hDlg, DWL_DLGPROC )))
1279 /* Call dialog procedure */
1280 result = CallWindowProcA( dlgproc, hDlg, Msg, wParam, lParam );
1283 if (!result && IsWindow(hDlg))
1285 /* callback didn't process this message */
1299 case WM_ENTERMENULOOP:
1300 case WM_LBUTTONDOWN:
1301 case WM_NCLBUTTONDOWN:
1302 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1305 case WM_COMPAREITEM:
1310 return DefWindowProcA( hDlg, Msg, wParam, lParam );
1313 return DEFDLG_Epilog(hDlg, Msg, result);
1329 BOOL result = FALSE;
1330 DIALOGINFO * dlgInfo;
1332 /* if there's no dialog info property then call default windows proc?? */
1333 if (!(dlgInfo = GETDLGINFO(hDlg)))
1334 return DefWindowProcW( hDlg, Msg, wParam, lParam );
1336 SetWindowLongW( hDlg, DWL_MSGRESULT, 0 );
1338 if ((dlgproc = (WNDPROC)GetWindowLongW( hDlg, DWL_DLGPROC )))
1340 /* Call dialog procedure */
1341 result = CallWindowProcW( dlgproc, hDlg, Msg, wParam, lParam );
1344 if (!result && IsWindow(hDlg))
1346 /* callback didn't process this message */
1360 case WM_ENTERMENULOOP:
1361 case WM_LBUTTONDOWN:
1362 case WM_NCLBUTTONDOWN:
1363 return DEFDLG_Proc( hDlg, Msg, wParam, lParam, dlgInfo );
1366 case WM_COMPAREITEM:
1371 return DefWindowProcW( hDlg, Msg, wParam, lParam );
1374 return DEFDLG_Epilog(hDlg, Msg, result);
1383 DialogBoxIndirectParamA(
1384 HINSTANCE hInstance,
1385 LPCDLGTEMPLATE hDialogTemplate,
1387 DLGPROC lpDialogFunc,
1390 HWND hwnd = DIALOG_CreateIndirect( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, FALSE, TRUE );
1391 if (hwnd) return DIALOG_DoDialogBox( hwnd, hWndParent );
1401 DialogBoxIndirectParamAorW(
1402 HINSTANCE hInstance,
1403 LPCDLGTEMPLATE hDialogTemplate,
1405 DLGPROC lpDialogFunc,
1409 This function might be obsolete since I don't think it is exported by NT
1410 Also wine has one more parameter identifying weather it should call
1411 the function with unicode or not */
1413 return (INT_PTR)NULL;
1422 DialogBoxIndirectParamW(
1423 HINSTANCE hInstance,
1424 LPCDLGTEMPLATE hDialogTemplate,
1426 DLGPROC lpDialogFunc,
1429 HWND hwnd = DIALOG_CreateIndirect( hInstance, hDialogTemplate, hWndParent, lpDialogFunc, dwInitParam, TRUE, TRUE );
1430 if (hwnd) return DIALOG_DoDialogBox( hwnd, hWndParent );
1441 HINSTANCE hInstance,
1442 LPCSTR lpTemplateName,
1444 DLGPROC lpDialogFunc,
1451 if (!(hrsrc = FindResourceA( hInstance, lpTemplateName, (LPCSTR)RT_DIALOG ))) return 0;
1452 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1453 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, FALSE, TRUE);
1454 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1465 HINSTANCE hInstance,
1466 LPCWSTR lpTemplateName,
1468 DLGPROC lpDialogFunc,
1475 if (!(hrsrc = FindResourceW( hInstance, lpTemplateName, (LPCWSTR)RT_DIALOG ))) return 0;
1476 if (!(ptr = (LPCDLGTEMPLATE)LoadResource(hInstance, hrsrc))) return 0;
1477 hwnd = DIALOG_CreateIndirect(hInstance, ptr, hWndParent, lpDialogFunc, dwInitParam, TRUE, TRUE);
1478 if (hwnd) return DIALOG_DoDialogBox(hwnd, hWndParent);
1505 DlgDirListComboBoxA(
1522 DlgDirListComboBoxW(
1556 DlgDirSelectComboBoxExA(
1572 DlgDirSelectComboBoxExW(
1624 BOOL wasEnabled = TRUE;
1625 DIALOGINFO * dlgInfo;
1628 if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
1630 dlgInfo->idResult = nResult;
1631 dlgInfo->flags |= DF_END;
1632 wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
1634 if (wasEnabled && (owner = GetWindow( hDlg, GW_OWNER )))
1635 DIALOG_EnableOwner( owner );
1637 /* Windows sets the focus to the dialog itself in EndDialog */
1639 if (IsChild(hDlg, GetFocus()))
1642 /* Don't have to send a ShowWindow(SW_HIDE), just do
1643 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1645 SetWindowPos(hDlg, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
1646 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
1648 /* unblock dialog loop */
1649 PostMessageA(hDlg, WM_NULL, 0, 0);
1659 GetDialogBaseUnits(VOID)
1668 if ((hdc = GetDC(0)))
1670 if (DIALOG_GetCharSize( hdc, 0, &size )) units = MAKELONG( size.cx, size.cy );
1671 ReleaseDC( 0, hdc );
1686 return GetWindowLongW( hwndCtl, GWL_ID );
1699 GETDLGITEMINFO info;
1700 info.nIDDlgItem = nIDDlgItem;
1702 if(hDlg && !EnumChildWindows(hDlg, (ENUMWINDOWSPROC)&GetDlgItemEnumProc, (LPARAM)&info))
1703 return info.control;
1717 WINBOOL *lpTranslated,
1724 if (lpTranslated) *lpTranslated = FALSE;
1725 if (!SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXT, sizeof(str), (LPARAM)str))
1729 result = strtol( str, &endptr, 10 );
1730 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1733 if (((result == LONG_MIN) || (result == LONG_MAX))/* && (errno == ERANGE) */)
1738 result = strtoul( str, &endptr, 10 );
1739 if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
1742 if ((result == LONG_MAX)/* && (errno == ERANGE) */) return 0;
1744 if (lpTranslated) *lpTranslated = TRUE;
1745 return (UINT)result;
1760 return (UINT)SendDlgItemMessageA( hDlg, nIDDlgItem, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
1775 return (UINT)SendDlgItemMessageW( hDlg, nIDDlgItem, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
1784 GetNextDlgGroupItem(
1789 HWND hwnd, retvalue;
1793 /* if the hwndCtrl is the child of the control in the hwndDlg,
1794 * then the hwndDlg has to be the parent of the hwndCtrl */
1795 if(GetParent(hCtl) != hDlg && GetParent(GetParent(hCtl)) == hDlg)
1796 hDlg = GetParent(hCtl);
1801 /* Make sure hwndCtrl is a top-level child */
1802 HWND parent = GetParent( hCtl );
1803 while (parent && parent != hDlg) parent = GetParent(parent);
1804 if (parent != hDlg) return 0;
1808 /* No ctrl specified -> start from the beginning */
1809 if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
1810 if (bPrevious) hCtl = GetWindow( hCtl, GW_HWNDLAST );
1814 hwnd = GetWindow( hCtl, GW_HWNDNEXT );
1817 if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
1819 /* Wrap-around to the beginning of the group */
1822 hwnd = GetWindow( hDlg, GW_CHILD );
1823 for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
1825 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
1826 if (tmp == hCtl) break;
1829 if (hwnd == hCtl) break;
1830 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
1833 if (!bPrevious) break;
1835 hwnd = GetWindow( hwnd, GW_HWNDNEXT );
1851 return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
1861 return IsDialogMessageW(hDlg, lpMsg);
1878 //if (CallMsgFilterA( lpMsg, MSGF_DIALOGBOX )) return TRUE;
1880 if ((hDlg != lpMsg->hwnd) && !IsChild( hDlg, lpMsg->hwnd )) return FALSE;
1882 hDlg = DIALOG_FindMsgDestination(hDlg);
1884 switch(lpMsg->message)
1887 dlgCode = SendMessageA( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
1888 if (dlgCode & DLGC_WANTMESSAGE) break;
1890 switch(lpMsg->wParam)
1893 if (!(dlgCode & DLGC_WANTTAB))
1895 SendMessageA( hDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1904 if (!(dlgCode & DLGC_WANTARROWS))
1906 BOOL fPrevious = (lpMsg->wParam == VK_LEFT || lpMsg->wParam == VK_UP);
1907 HWND hwndNext = GetNextDlgGroupItem (hDlg, GetFocus(), fPrevious );
1908 SendMessageA( hDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
1915 SendMessageA( hDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hDlg, IDCANCEL ) );
1921 DWORD dw = SendMessageA( hDlg, DM_GETDEFID, 0, 0 );
1922 if (HIWORD(dw) == DC_HASDEFID)
1924 SendMessageA( hDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
1925 (LPARAM)GetDlgItem(hDlg, LOWORD(dw)));
1929 SendMessageA( hDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hDlg, IDOK ) );
1938 dlgCode = SendMessageA( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
1939 if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
1940 if (lpMsg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
1944 if (DIALOG_IsAccelerator( lpMsg->hwnd, hDlg, lpMsg->wParam ))
1946 /* don't translate or dispatch */
1952 TranslateMessage( lpMsg );
1953 DispatchMessageA( lpMsg );
1970 //if (CallMsgFilterW( lpMsg, MSGF_DIALOGBOX )) return TRUE;
1972 if ((hDlg != lpMsg->hwnd) && !IsChild( hDlg, lpMsg->hwnd )) return FALSE;
1974 hDlg = DIALOG_FindMsgDestination(hDlg);
1976 switch(lpMsg->message)
1979 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
1980 if (dlgCode & DLGC_WANTMESSAGE) break;
1982 switch(lpMsg->wParam)
1985 if (!(dlgCode & DLGC_WANTTAB))
1987 SendMessageW( hDlg, WM_NEXTDLGCTL, (GetKeyState(VK_SHIFT) & 0x8000), 0 );
1996 if (!(dlgCode & DLGC_WANTARROWS))
1998 BOOL fPrevious = (lpMsg->wParam == VK_LEFT || lpMsg->wParam == VK_UP);
1999 HWND hwndNext = GetNextDlgGroupItem (hDlg, GetFocus(), fPrevious );
2000 SendMessageW( hDlg, WM_NEXTDLGCTL, (WPARAM)hwndNext, 1 );
2007 SendMessageW( hDlg, WM_COMMAND, IDCANCEL, (LPARAM)GetDlgItem( hDlg, IDCANCEL ) );
2013 DWORD dw = SendMessageW( hDlg, DM_GETDEFID, 0, 0 );
2014 if (HIWORD(dw) == DC_HASDEFID)
2016 SendMessageW( hDlg, WM_COMMAND, MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
2017 (LPARAM)GetDlgItem(hDlg, LOWORD(dw)));
2021 SendMessageW( hDlg, WM_COMMAND, IDOK, (LPARAM)GetDlgItem( hDlg, IDOK ) );
2030 dlgCode = SendMessageW( lpMsg->hwnd, WM_GETDLGCODE, lpMsg->wParam, (LPARAM)lpMsg );
2031 if (dlgCode & (DLGC_WANTCHARS|DLGC_WANTMESSAGE)) break;
2032 if (lpMsg->wParam == '\t' && (dlgCode & DLGC_WANTTAB)) break;
2036 if (DIALOG_IsAccelerator( lpMsg->hwnd, hDlg, lpMsg->wParam ))
2038 /* don't translate or dispatch */
2044 TranslateMessage( lpMsg );
2045 DispatchMessageW( lpMsg );
2059 return (UINT)SendDlgItemMessageA( hDlg, nIDButton, BM_GETCHECK, 0, 0 );
2072 DIALOGINFO * dlgInfo;
2073 if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
2074 lpRect->left = MulDiv(lpRect->left, dlgInfo->xBaseUnit, 4);
2075 lpRect->right = MulDiv(lpRect->right, dlgInfo->xBaseUnit, 4);
2076 lpRect->top = MulDiv(lpRect->top, dlgInfo->yBaseUnit, 8);
2077 lpRect->bottom = MulDiv(lpRect->bottom, dlgInfo->yBaseUnit, 8);
2087 SendDlgItemMessageA(
2094 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2095 if (hwndCtrl) return SendMessageA( hwndCtrl, Msg, wParam, lParam );
2105 SendDlgItemMessageW(
2112 HWND hwndCtrl = GetDlgItem( hDlg, nIDDlgItem );
2113 if (hwndCtrl) return SendMessageW( hwndCtrl, Msg, wParam, lParam );
2131 if (bSigned) sprintf( str, "%d", (INT)uValue );
2132 else sprintf( str, "%u", uValue );
2133 SendDlgItemMessageA( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)str );
2148 return SendDlgItemMessageA( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)lpString );
2162 return SendDlgItemMessageW( hDlg, nIDDlgItem, WM_SETTEXT, 0, (LPARAM)lpString );
2176 SendDlgItemMessageA( hDlg, nIDButton, BM_SETCHECK, uCheck, 0 );