4 * Copyright 1993, 1994, 1996 Alexandre Julliard
14 #include "wine/winuser16.h"
15 #include "wine/winbase16.h"
24 #include "debugtools.h"
26 DEFAULT_DEBUG_CHANNEL(dialog
)
29 /* Dialog control information */
66 /* Radio button group */
74 /* Dialog base units */
75 static WORD xBaseUnit
= 0, yBaseUnit
= 0;
77 /***********************************************************************
78 * DIALOG_GetCharSizeFromDC
81 * Calculates the *true* average size of English characters in the
82 * specified font as oppposed to the one returned by GetTextMetrics.
84 * Latest: the X font driver will now compute a proper average width
85 * so this code can be removed
87 static BOOL
DIALOG_GetCharSizeFromDC( HDC hDC
, HFONT hFont
, SIZE
* pSize
)
91 pSize
->cx
= xBaseUnit
;
92 pSize
->cy
= yBaseUnit
;
97 memset(&tm
,0,sizeof(tm
));
98 if (hFont
) hFontPrev
= SelectFont(hDC
,hFont
);
99 if (GetTextMetricsA(hDC
,&tm
))
101 pSize
->cx
= tm
.tmAveCharWidth
;
102 pSize
->cy
= tm
.tmHeight
;
104 /* if variable width font */
105 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
108 const char* szAvgChars
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
110 /* Calculate a true average as opposed to the one returned
111 * by tmAveCharWidth. This works better when dealing with
112 * proportional spaced fonts and (more important) that's
113 * how Microsoft's dialog creation code calculates the size
116 if (GetTextExtentPointA(hDC
,szAvgChars
,sizeof(szAvgChars
),&total
))
119 pSize
->cx
= ((2*total
.cx
/sizeof(szAvgChars
)) + 1)/2;
127 /* Use the text metrics */
128 TRACE("Using tm: %ldx%ld (dlg: %dx%d) (%s)\n", tm
.tmAveCharWidth
, tm
.tmHeight
, pSize
->cx
, pSize
->cy
,
129 tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
? "variable" : "fixed");
130 pSize
->cx
= tm
.tmAveCharWidth
;
131 pSize
->cy
= tm
.tmHeight
;
133 /* select the original font */
134 if (hFontPrev
) SelectFont(hDC
,hFontPrev
);
139 /***********************************************************************
142 * A convenient variant of DIALOG_GetCharSizeFromDC.
144 static BOOL
DIALOG_GetCharSize( HFONT hFont
, SIZE
* pSize
)
147 BOOL Success
= DIALOG_GetCharSizeFromDC( hDC
, hFont
, pSize
);
152 /***********************************************************************
155 * Initialisation of the dialog manager.
157 BOOL
DIALOG_Init(void)
162 /* Calculate the dialog base units */
164 if (!(hdc
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
))) return FALSE
;
165 if (!DIALOG_GetCharSizeFromDC( hdc
, 0, &size
)) return FALSE
;
170 TRACE("base units = %d,%d\n", xBaseUnit
, yBaseUnit
);
175 /***********************************************************************
176 * DIALOG_GetControl16
178 * Return the class and text of the control pointed to by ptr,
179 * fill the header structure and return a pointer to the next control.
181 static LPCSTR
DIALOG_GetControl16( LPCSTR p
, DLG_CONTROL_INFO
*info
)
183 static char buffer
[10];
186 info
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
187 info
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
188 info
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
189 info
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
190 info
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
191 info
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
198 case 0x80: strcpy( buffer
, "BUTTON" ); break;
199 case 0x81: strcpy( buffer
, "EDIT" ); break;
200 case 0x82: strcpy( buffer
, "STATIC" ); break;
201 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
202 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
203 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
204 default: buffer
[0] = '\0'; break;
206 info
->className
= buffer
;
215 int_id
= ((BYTE
)*p
== 0xff);
218 /* Integer id, not documented (?). Only works for SS_ICON controls */
219 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+1);
224 info
->windowName
= p
;
228 info
->data
= (LPVOID
)(*p
? p
+ 1 : NULL
); /* FIXME: should be a segptr */
232 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
233 info
->className
, LOWORD(info
->windowName
),
234 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
235 info
->style
, (DWORD
)info
->data
);
237 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
238 info
->className
, info
->windowName
,
239 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
240 info
->style
, (DWORD
)info
->data
);
246 /***********************************************************************
247 * DIALOG_GetControl32
249 * Return the class and text of the control pointed to by ptr,
250 * fill the header structure and return a pointer to the next control.
252 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
257 info
->helpId
= GET_DWORD(p
); p
+= 2;
258 info
->exStyle
= GET_DWORD(p
); p
+= 2;
259 info
->style
= GET_DWORD(p
); p
+= 2;
264 info
->style
= GET_DWORD(p
); p
+= 2;
265 info
->exStyle
= GET_DWORD(p
); p
+= 2;
267 info
->x
= GET_WORD(p
); p
++;
268 info
->y
= GET_WORD(p
); p
++;
269 info
->cx
= GET_WORD(p
); p
++;
270 info
->cy
= GET_WORD(p
); p
++;
274 /* id is a DWORD for DIALOGEX */
275 info
->id
= GET_DWORD(p
);
280 info
->id
= GET_WORD(p
);
284 if (GET_WORD(p
) == 0xffff)
286 static const WCHAR class_names
[6][10] =
288 { 'B','u','t','t','o','n', }, /* 0x80 */
289 { 'E','d','i','t', }, /* 0x81 */
290 { 'S','t','a','t','i','c', }, /* 0x82 */
291 { 'L','i','s','t','B','o','x', }, /* 0x83 */
292 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
293 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
295 WORD id
= GET_WORD(p
+1);
296 if ((id
>= 0x80) && (id
<= 0x85))
297 info
->className
= (LPCSTR
)class_names
[id
- 0x80];
300 info
->className
= NULL
;
301 ERR("Unknown built-in class id %04x\n", id
);
307 info
->className
= (LPCSTR
)p
;
308 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
311 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
313 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+ 1);
318 info
->windowName
= (LPCSTR
)p
;
319 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
322 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
323 debugstr_w( (LPCWSTR
)info
->className
),
324 debugres_w( (LPCWSTR
)info
->windowName
),
325 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
326 info
->style
, info
->exStyle
, info
->helpId
);
330 if (TRACE_ON(dialog
))
332 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
335 for (i
= 0; i
< count
; i
++) DPRINTF( "%04x,", GET_WORD(p
+i
+1) );
339 info
->data
= (LPVOID
)(p
+ 1);
340 p
+= GET_WORD(p
) / sizeof(WORD
);
342 else info
->data
= NULL
;
345 /* Next control is on dword boundary */
346 return (const WORD
*)((((int)p
) + 3) & ~3);
350 /***********************************************************************
351 * DIALOG_CreateControls
353 * Create the control windows for a dialog.
355 static BOOL
DIALOG_CreateControls( WND
*pWnd
, LPCSTR
template,
356 const DLG_TEMPLATE
*dlgTemplate
,
357 HINSTANCE hInst
, BOOL win32
)
359 DIALOGINFO
*dlgInfo
= (DIALOGINFO
*)pWnd
->wExtra
;
360 DLG_CONTROL_INFO info
;
361 HWND hwndCtrl
, hwndDefButton
= 0;
362 INT items
= dlgTemplate
->nbItems
;
369 HINSTANCE16 instance
;
370 template = DIALOG_GetControl16( template, &info
);
371 if (HIWORD(info
.className
) && !strcmp( info
.className
, "EDIT") &&
372 ((pWnd
->dwStyle
& DS_LOCALEDIT
) != DS_LOCALEDIT
))
374 if (!dlgInfo
->hDialogHeap
)
376 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
377 if (!dlgInfo
->hDialogHeap
)
379 ERR("Insufficient memory to create heap for edit control\n" );
382 LocalInit16(dlgInfo
->hDialogHeap
, 0, 0xffff);
384 instance
= dlgInfo
->hDialogHeap
;
386 else instance
= (HINSTANCE16
)hInst
;
388 hwndCtrl
= CreateWindowEx16( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
389 info
.className
, info
.windowName
,
390 info
.style
| WS_CHILD
,
391 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
392 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
393 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
394 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
395 pWnd
->hwndSelf
, (HMENU16
)info
.id
,
396 instance
, info
.data
);
400 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
401 dlgTemplate
->dialogEx
);
402 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
403 (LPCWSTR
)info
.className
,
404 (LPCWSTR
)info
.windowName
,
405 info
.style
| WS_CHILD
,
406 MulDiv(info
.x
, dlgInfo
->xBaseUnit
, 4),
407 MulDiv(info
.y
, dlgInfo
->yBaseUnit
, 8),
408 MulDiv(info
.cx
, dlgInfo
->xBaseUnit
, 4),
409 MulDiv(info
.cy
, dlgInfo
->yBaseUnit
, 8),
410 pWnd
->hwndSelf
, (HMENU
)info
.id
,
413 if (!hwndCtrl
) return FALSE
;
415 /* Send initialisation messages to the control */
416 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
417 (WPARAM
)dlgInfo
->hUserFont
, 0 );
418 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
420 /* If there's already a default push-button, set it back */
421 /* to normal and use this one instead. */
423 SendMessageA( hwndDefButton
, BM_SETSTYLE
,
424 BS_PUSHBUTTON
,FALSE
);
425 hwndDefButton
= hwndCtrl
;
426 dlgInfo
->idResult
= GetWindowWord( hwndCtrl
, GWW_ID
);
434 /***********************************************************************
435 * DIALOG_ParseTemplate16
437 * Fill a DLG_TEMPLATE structure from the dialog template, and return
438 * a pointer to the first control.
440 static LPCSTR
DIALOG_ParseTemplate16( LPCSTR p
, DLG_TEMPLATE
* result
)
442 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
444 result
->nbItems
= (unsigned char) *p
++;
445 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
446 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
447 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
448 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
449 TRACE("DIALOG %d, %d, %d, %d\n",
450 result
->x
, result
->y
, result
->cx
, result
->cy
);
451 TRACE(" STYLE %08lx\n", result
->style
);
453 /* Get the menu name */
458 result
->menuName
= 0;
462 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
464 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
467 result
->menuName
= p
;
468 TRACE(" MENU '%s'\n", p
);
473 /* Get the class name */
477 result
->className
= p
;
478 TRACE(" CLASS '%s'\n", result
->className
);
480 else result
->className
= DIALOG_CLASS_ATOM
;
483 /* Get the window caption */
487 TRACE(" CAPTION '%s'\n", result
->caption
);
489 /* Get the font name */
491 if (result
->style
& DS_SETFONT
)
493 result
->pointSize
= GET_WORD(p
);
495 result
->faceName
= p
;
497 TRACE(" FONT %d,'%s'\n",
498 result
->pointSize
, result
->faceName
);
504 /***********************************************************************
505 * DIALOG_ParseTemplate32
507 * Fill a DLG_TEMPLATE structure from the dialog template, and return
508 * a pointer to the first control.
510 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
512 const WORD
*p
= (const WORD
*)template;
514 result
->style
= GET_DWORD(p
); p
+= 2;
515 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
517 result
->dialogEx
= TRUE
;
518 result
->helpId
= GET_DWORD(p
); p
+= 2;
519 result
->exStyle
= GET_DWORD(p
); p
+= 2;
520 result
->style
= GET_DWORD(p
); p
+= 2;
524 result
->dialogEx
= FALSE
;
526 result
->exStyle
= GET_DWORD(p
); p
+= 2;
528 result
->nbItems
= GET_WORD(p
); p
++;
529 result
->x
= GET_WORD(p
); p
++;
530 result
->y
= GET_WORD(p
); p
++;
531 result
->cx
= GET_WORD(p
); p
++;
532 result
->cy
= GET_WORD(p
); p
++;
533 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
534 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
535 result
->cx
, result
->cy
, result
->helpId
);
536 TRACE(" STYLE 0x%08lx\n", result
->style
);
537 TRACE(" EXSTYLE 0x%08lx\n", result
->exStyle
);
539 /* Get the menu name */
544 result
->menuName
= NULL
;
548 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
550 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
553 result
->menuName
= (LPCSTR
)p
;
554 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR
)p
));
555 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
559 /* Get the class name */
564 result
->className
= DIALOG_CLASS_ATOM
;
568 result
->className
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
570 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
573 result
->className
= (LPCSTR
)p
;
574 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR
)p
));
575 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
579 /* Get the window caption */
581 result
->caption
= (LPCSTR
)p
;
582 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
583 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR
)result
->caption
) );
585 /* Get the font name */
587 if (result
->style
& DS_SETFONT
)
589 result
->pointSize
= GET_WORD(p
);
591 if (result
->dialogEx
)
593 result
->weight
= GET_WORD(p
); p
++;
594 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
598 result
->weight
= FW_DONTCARE
;
599 result
->italic
= FALSE
;
601 result
->faceName
= (LPCSTR
)p
;
602 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
603 TRACE(" FONT %d, %s, %d, %s\n",
604 result
->pointSize
, debugstr_w( (LPCWSTR
)result
->faceName
),
605 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
608 /* First control is on dword boundary */
609 return (LPCSTR
)((((int)p
) + 3) & ~3);
613 /***********************************************************************
614 * DIALOG_CreateIndirect
616 HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCSTR dlgTemplate
,
617 BOOL win32Template
, HWND owner
,
618 DLGPROC16 dlgProc
, LPARAM param
,
619 WINDOWPROCTYPE procType
)
626 DLG_TEMPLATE
template;
627 DIALOGINFO
* dlgInfo
;
628 WORD xUnit
= xBaseUnit
;
629 WORD yUnit
= yBaseUnit
;
631 /* Parse dialog template */
633 if (!dlgTemplate
) return 0;
635 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
637 dlgTemplate
= DIALOG_ParseTemplate16( dlgTemplate
, &template );
641 if (template.menuName
)
645 LPSTR str
= SEGPTR_STRDUP( template.menuName
);
646 hMenu
= LoadMenu16( hInst
, SEGPTR_GET(str
) );
649 else hMenu
= LoadMenuW( hInst
, (LPCWSTR
)template.menuName
);
652 /* Create custom font if needed */
654 if (template.style
& DS_SETFONT
)
656 /* The font height must be negative as it is a point size */
657 /* and must be converted to pixels first */
658 /* (see CreateFont() documentation in the Windows SDK). */
660 int pixels
= template.pointSize
* GetDeviceCaps(dc
, LOGPIXELSY
)/72;
664 hFont
= CreateFontW( -pixels
, 0, 0, 0, template.weight
,
665 template.italic
, FALSE
, FALSE
,
666 DEFAULT_CHARSET
, 0, 0,
667 PROOF_QUALITY
, FF_DONTCARE
,
668 (LPCWSTR
)template.faceName
);
670 hFont
= CreateFont16( -pixels
, 0, 0, 0, FW_DONTCARE
,
672 DEFAULT_CHARSET
, 0, 0,
673 PROOF_QUALITY
, FF_DONTCARE
,
678 DIALOG_GetCharSize(hFont
,&charSize
);
682 TRACE("units = %d,%d\n", xUnit
, yUnit
);
685 /* Create dialog main window */
687 rect
.left
= rect
.top
= 0;
688 rect
.right
= MulDiv(template.cx
, xUnit
, 4);
689 rect
.bottom
= MulDiv(template.cy
, yUnit
, 8);
690 if (template.style
& DS_MODALFRAME
)
691 template.exStyle
|= WS_EX_DLGMODALFRAME
;
692 AdjustWindowRectEx( &rect
, template.style
,
693 hMenu
? TRUE
: FALSE
, template.exStyle
);
694 rect
.right
-= rect
.left
;
695 rect
.bottom
-= rect
.top
;
697 if ((INT16
)template.x
== CW_USEDEFAULT16
)
699 rect
.left
= rect
.top
= win32Template
? CW_USEDEFAULT
: CW_USEDEFAULT16
;
703 if (template.style
& DS_CENTER
)
705 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
706 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
710 rect
.left
+= MulDiv(template.x
, xUnit
, 4);
711 rect
.top
+= MulDiv(template.y
, yUnit
, 8);
713 if ( !(template.style
& WS_CHILD
) )
717 if( !(template.style
& DS_ABSALIGN
) )
718 ClientToScreen( owner
, (POINT
*)&rect
);
720 /* try to fit it into the desktop */
722 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
723 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
724 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
725 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
726 if( rect
.left
< 0 ) rect
.left
= 0;
727 if( rect
.top
< 0 ) rect
.top
= 0;
732 hwnd
= CreateWindowEx16(template.exStyle
, template.className
,
733 template.caption
, template.style
& ~WS_VISIBLE
,
734 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
735 owner
, hMenu
, hInst
, NULL
);
737 hwnd
= CreateWindowExW(template.exStyle
, (LPCWSTR
)template.className
,
738 (LPCWSTR
)template.caption
,
739 template.style
& ~WS_VISIBLE
,
740 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
741 owner
, hMenu
, hInst
, NULL
);
745 if (hFont
) DeleteObject( hFont
);
746 if (hMenu
) DestroyMenu( hMenu
);
749 wndPtr
= WIN_FindWndPtr( hwnd
);
750 wndPtr
->flags
|= WIN_ISDIALOG
;
751 wndPtr
->helpContext
= template.helpId
;
753 /* Initialise dialog extra data */
755 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
756 WINPROC_SetProc( &dlgInfo
->dlgProc
, (WNDPROC16
)dlgProc
, procType
, WIN_PROC_WINDOW
);
757 dlgInfo
->hUserFont
= hFont
;
758 dlgInfo
->hMenu
= hMenu
;
759 dlgInfo
->xBaseUnit
= xUnit
;
760 dlgInfo
->yBaseUnit
= yUnit
;
761 dlgInfo
->msgResult
= 0;
762 dlgInfo
->idResult
= 0;
764 dlgInfo
->hDialogHeap
= 0;
766 if (dlgInfo
->hUserFont
)
767 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
769 /* Create controls */
771 if (DIALOG_CreateControls( wndPtr
, dlgTemplate
, &template,
772 hInst
, win32Template
))
774 /* Send initialisation messages and set focus */
776 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
778 if (SendMessageA( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
779 SetFocus( dlgInfo
->hwndFocus
);
781 if (template.style
& WS_VISIBLE
&& !(wndPtr
->dwStyle
& WS_VISIBLE
))
783 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
784 UpdateWindow( hwnd
);
786 WIN_ReleaseWndPtr(wndPtr
);
789 WIN_ReleaseWndPtr(wndPtr
);
790 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
795 /***********************************************************************
796 * CreateDialog16 (USER.89)
798 HWND16 WINAPI
CreateDialog16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
799 HWND16 owner
, DLGPROC16 dlgProc
)
801 return CreateDialogParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
805 /***********************************************************************
806 * CreateDialogParam16 (USER.241)
808 HWND16 WINAPI
CreateDialogParam16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
809 HWND16 owner
, DLGPROC16 dlgProc
,
817 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
818 hInst
, (DWORD
)dlgTemplate
, owner
, (DWORD
)dlgProc
, param
);
820 if (!(hRsrc
= FindResource16( hInst
, dlgTemplate
, RT_DIALOG16
))) return 0;
821 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
822 if (!(data
= LockResource16( hmem
))) hwnd
= 0;
823 else hwnd
= CreateDialogIndirectParam16( hInst
, data
, owner
,
825 FreeResource16( hmem
);
829 /***********************************************************************
830 * CreateDialogParam32A (USER32.73)
832 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
,
833 HWND owner
, DLGPROC dlgProc
,
836 HANDLE hrsrc
= FindResourceA( hInst
, name
, RT_DIALOGA
);
837 if (!hrsrc
) return 0;
838 return CreateDialogIndirectParamA( hInst
,
839 (LPVOID
)LoadResource(hInst
, hrsrc
),
840 owner
, dlgProc
, param
);
844 /***********************************************************************
845 * CreateDialogParam32W (USER32.74)
847 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
,
848 HWND owner
, DLGPROC dlgProc
,
851 HANDLE hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
852 if (!hrsrc
) return 0;
853 return CreateDialogIndirectParamW( hInst
,
854 (LPVOID
)LoadResource(hInst
, hrsrc
),
855 owner
, dlgProc
, param
);
859 /***********************************************************************
860 * CreateDialogIndirect16 (USER.219)
862 HWND16 WINAPI
CreateDialogIndirect16( HINSTANCE16 hInst
, LPCVOID dlgTemplate
,
863 HWND16 owner
, DLGPROC16 dlgProc
)
865 return CreateDialogIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0);
869 /***********************************************************************
870 * CreateDialogIndirectParam16 (USER.242)
872 HWND16 WINAPI
CreateDialogIndirectParam16( HINSTANCE16 hInst
,
874 HWND16 owner
, DLGPROC16 dlgProc
,
877 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, FALSE
, owner
,
878 dlgProc
, param
, WIN_PROC_16
);
882 /***********************************************************************
883 * CreateDialogIndirectParam32A (USER32.69)
885 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
,
887 HWND owner
, DLGPROC dlgProc
,
890 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
891 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32A
);
894 /***********************************************************************
895 * CreateDialogIndirectParam32AorW (USER32.71)
897 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
,
899 HWND owner
, DLGPROC dlgProc
,
901 { FIXME("assume WIN_PROC_32W\n");
902 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
903 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32W
);
906 /***********************************************************************
907 * CreateDialogIndirectParam32W (USER32.72)
909 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
,
911 HWND owner
, DLGPROC dlgProc
,
914 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
915 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32W
);
919 /***********************************************************************
922 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
925 DIALOGINFO
* dlgInfo
;
929 /* Owner must be a top-level window */
930 owner
= WIN_GetTopParent( owner
);
931 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return -1;
932 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
934 if (!dlgInfo
->flags
& DF_END
) /* was EndDialog called in WM_INITDIALOG ? */
936 EnableWindow( owner
, FALSE
);
937 ShowWindow( hwnd
, SW_SHOW
);
938 while (MSG_InternalGetMessage(&msg
, hwnd
, owner
, MSGF_DIALOGBOX
,
939 PM_REMOVE
, !(wndPtr
->dwStyle
& DS_NOIDLEMSG
), NULL
))
941 if (!IsDialogMessageA( hwnd
, &msg
))
943 TranslateMessage( &msg
);
944 DispatchMessageA( &msg
);
946 if (dlgInfo
->flags
& DF_END
) break;
948 EnableWindow( owner
, TRUE
);
950 retval
= dlgInfo
->idResult
;
951 WIN_ReleaseWndPtr(wndPtr
);
952 DestroyWindow( hwnd
);
957 /***********************************************************************
958 * DialogBox16 (USER.87)
960 INT16 WINAPI
DialogBox16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
961 HWND16 owner
, DLGPROC16 dlgProc
)
963 return DialogBoxParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
967 /***********************************************************************
968 * DialogBoxParam16 (USER.239)
970 INT16 WINAPI
DialogBoxParam16( HINSTANCE16 hInst
, SEGPTR
template,
971 HWND16 owner
, DLGPROC16 dlgProc
, LPARAM param
)
973 HWND16 hwnd
= CreateDialogParam16( hInst
, template, owner
, dlgProc
, param
);
974 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
979 /***********************************************************************
980 * DialogBoxParam32A (USER32.139)
982 INT WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
983 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
985 HWND hwnd
= CreateDialogParamA( hInst
, name
, owner
, dlgProc
, param
);
986 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
991 /***********************************************************************
992 * DialogBoxParam32W (USER32.140)
994 INT WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
995 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
997 HWND hwnd
= CreateDialogParamW( hInst
, name
, owner
, dlgProc
, param
);
998 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1003 /***********************************************************************
1004 * DialogBoxIndirect16 (USER.218)
1006 INT16 WINAPI
DialogBoxIndirect16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1007 HWND16 owner
, DLGPROC16 dlgProc
)
1009 return DialogBoxIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1013 /***********************************************************************
1014 * DialogBoxIndirectParam16 (USER.240)
1016 INT16 WINAPI
DialogBoxIndirectParam16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1017 HWND16 owner
, DLGPROC16 dlgProc
,
1023 if (!(ptr
= GlobalLock16( dlgTemplate
))) return -1;
1024 hwnd
= CreateDialogIndirectParam16( hInst
, ptr
, owner
, dlgProc
, param
);
1025 GlobalUnlock16( dlgTemplate
);
1026 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
1031 /***********************************************************************
1032 * DialogBoxIndirectParam32A (USER32.136)
1034 INT WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCVOID
template,
1035 HWND owner
, DLGPROC dlgProc
,
1038 HWND hwnd
= CreateDialogIndirectParamA( hInstance
, template,
1039 owner
, dlgProc
, param
);
1040 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1045 /***********************************************************************
1046 * DialogBoxIndirectParam32W (USER32.138)
1048 INT WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCVOID
template,
1049 HWND owner
, DLGPROC dlgProc
,
1052 HWND hwnd
= CreateDialogIndirectParamW( hInstance
, template,
1053 owner
, dlgProc
, param
);
1054 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1059 /***********************************************************************
1060 * EndDialog16 (USER.88)
1062 BOOL16 WINAPI
EndDialog16( HWND16 hwnd
, INT16 retval
)
1064 return EndDialog( hwnd
, retval
);
1068 /***********************************************************************
1069 * EndDialog32 (USER32.173)
1071 BOOL WINAPI
EndDialog( HWND hwnd
, INT retval
)
1073 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1074 DIALOGINFO
* dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1077 TRACE("%04x %d\n", hwnd
, retval
);
1081 dlgInfo
->idResult
= retval
;
1082 dlgInfo
->flags
|= DF_END
;
1086 hOwner
= WIN_GetTopParent( wndPtr
->owner
->hwndSelf
);
1088 /* Enable the owner first */
1089 if (hOwner
&& !IsWindowEnabled(hOwner
))
1090 EnableWindow( hOwner
, TRUE
);
1092 /* Windows sets the focus to the dialog itself in EndDialog */
1094 if (IsChild(hwnd
, GetFocus()))
1095 SetFocus(wndPtr
->hwndSelf
);
1097 /* Don't have to send a ShowWindow(SW_HIDE), just do
1098 SetWindowPos with SWP_HIDEWINDOW as done in Windows */
1100 SetWindowPos(hwnd
, (HWND
)0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
1101 | SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1103 WIN_ReleaseWndPtr(wndPtr
);
1109 /***********************************************************************
1110 * DIALOG_IsAccelerator
1112 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM vKey
)
1114 HWND hwndControl
= hwnd
;
1117 BOOL RetVal
= FALSE
;
1120 if (vKey
== VK_SPACE
)
1122 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1123 if (dlgCode
& DLGC_BUTTON
)
1125 SendMessageA( hwndControl
, WM_LBUTTONDOWN
, 0, 0);
1126 SendMessageA( hwndControl
, WM_LBUTTONUP
, 0, 0);
1134 wndPtr
= WIN_FindWndPtr( hwndControl
);
1135 if ( (wndPtr
!= NULL
) &&
1136 ((wndPtr
->dwStyle
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) )
1138 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1139 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
1140 (wndPtr
->text
!=NULL
))
1142 /* find the accelerator key */
1143 LPSTR p
= wndPtr
->text
- 2;
1146 p
= strchr( p
+ 2, '&' );
1148 while (p
!= NULL
&& p
[1] == '&');
1150 /* and check if it's the one we're looking for */
1151 if (p
!= NULL
&& toupper( p
[1] ) == toupper( vKey
) )
1153 if ((dlgCode
& DLGC_STATIC
) ||
1154 (wndPtr
->dwStyle
& 0x0f) == BS_GROUPBOX
)
1156 /* set focus to the control */
1157 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
,
1159 /* and bump it on to next */
1160 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
1163 (DLGC_DEFPUSHBUTTON
| DLGC_UNDEFPUSHBUTTON
))
1165 /* send command message as from the control */
1166 SendMessageA( hwndDlg
, WM_COMMAND
,
1167 MAKEWPARAM( LOWORD(wndPtr
->wIDmenu
),
1169 (LPARAM
)hwndControl
);
1173 /* click the control */
1174 SendMessageA( hwndControl
, WM_LBUTTONDOWN
, 0, 0);
1175 SendMessageA( hwndControl
, WM_LBUTTONUP
, 0, 0);
1178 WIN_ReleaseWndPtr(wndPtr
);
1182 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
1188 WIN_ReleaseWndPtr(wndPtr
);
1191 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1193 while (!hwndNext
&& hwndControl
)
1195 hwndControl
= GetParent( hwndControl
);
1196 if (hwndControl
== hwndDlg
)
1198 if(hwnd
==hwndDlg
){ /* prevent endless loop */
1202 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
1206 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1209 hwndControl
= hwndNext
;
1211 while (hwndControl
&& (hwndControl
!= hwnd
));
1217 /***********************************************************************
1218 * DIALOG_IsDialogMessage
1220 static BOOL
DIALOG_IsDialogMessage( HWND hwnd
, HWND hwndDlg
,
1221 UINT message
, WPARAM wParam
,
1222 LPARAM lParam
, BOOL
*translate
,
1223 BOOL
*dispatch
, INT dlgCode
)
1225 *translate
= *dispatch
= FALSE
;
1227 if (message
== WM_PAINT
)
1229 /* Apparently, we have to handle this one as well */
1234 /* Only the key messages get special processing */
1235 if ((message
!= WM_KEYDOWN
) &&
1236 (message
!= WM_SYSCHAR
) &&
1237 (message
!= WM_CHAR
))
1240 if (dlgCode
& DLGC_WANTMESSAGE
)
1242 *translate
= *dispatch
= TRUE
;
1252 if (!(dlgCode
& DLGC_WANTTAB
))
1254 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
,
1255 (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1264 if (!(dlgCode
& DLGC_WANTARROWS
))
1266 BOOL fPrevious
= (wParam
== VK_LEFT
|| wParam
== VK_UP
);
1268 GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1269 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, hwndNext
, 1 );
1275 SendMessageA( hwndDlg
, WM_COMMAND
, IDCANCEL
,
1276 (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1281 DWORD dw
= SendMessage16( hwndDlg
, DM_GETDEFID
, 0, 0 );
1282 if (HIWORD(dw
) == DC_HASDEFID
)
1284 SendMessageA( hwndDlg
, WM_COMMAND
,
1285 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1286 (LPARAM
)GetDlgItem(hwndDlg
, LOWORD(dw
)));
1290 SendMessageA( hwndDlg
, WM_COMMAND
, IDOK
,
1291 (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1298 break; /* case WM_KEYDOWN */
1301 if (dlgCode
& DLGC_WANTCHARS
) break;
1305 if (DIALOG_IsAccelerator( hwnd
, hwndDlg
, wParam
))
1307 /* don't translate or dispatch */
1313 /* If we get here, the message has not been treated specially */
1314 /* and can be sent to its destination window. */
1320 /***********************************************************************
1321 * IsDialogMessage16 (USER.90)
1323 BOOL16 WINAPI
WIN16_IsDialogMessage16( HWND16 hwndDlg
, SEGPTR msg16
)
1325 LPMSG16 msg
= PTR_SEG_TO_LIN(msg16
);
1326 BOOL ret
, translate
, dispatch
;
1329 if ((hwndDlg
!= msg
->hwnd
) && !IsChild16( hwndDlg
, msg
->hwnd
))
1332 dlgCode
= SendMessage16( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg16
);
1333 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1334 msg
->wParam
, msg
->lParam
,
1335 &translate
, &dispatch
, dlgCode
);
1336 if (translate
) TranslateMessage16( msg
);
1337 if (dispatch
) DispatchMessage16( msg
);
1342 BOOL16 WINAPI
IsDialogMessage16( HWND16 hwndDlg
, LPMSG16 msg
)
1344 LPMSG16 msg16
= SEGPTR_NEW(MSG16
);
1348 ret
= WIN16_IsDialogMessage16( hwndDlg
, SEGPTR_GET(msg16
) );
1353 /***********************************************************************
1354 * IsDialogMessage32A (USER32.342)
1356 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG msg
)
1358 BOOL ret
, translate
, dispatch
;
1361 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1364 dlgCode
= SendMessageA( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1365 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1366 msg
->wParam
, msg
->lParam
,
1367 &translate
, &dispatch
, dlgCode
);
1368 if (translate
) TranslateMessage( msg
);
1369 if (dispatch
) DispatchMessageA( msg
);
1374 /***********************************************************************
1375 * IsDialogMessage32W (USER32.343)
1377 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1379 BOOL ret
, translate
, dispatch
;
1382 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1385 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1386 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1387 msg
->wParam
, msg
->lParam
,
1388 &translate
, &dispatch
, dlgCode
);
1389 if (translate
) TranslateMessage( msg
);
1390 if (dispatch
) DispatchMessageW( msg
);
1395 /****************************************************************
1396 * GetDlgCtrlID16 (USER.277)
1398 INT16 WINAPI
GetDlgCtrlID16( HWND16 hwnd
)
1400 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1403 if (!wndPtr
) return 0;
1405 retvalue
= wndPtr
->wIDmenu
;
1406 WIN_ReleaseWndPtr(wndPtr
);
1411 /****************************************************************
1412 * GetDlgCtrlID32 (USER32.234)
1414 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1417 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1418 if (!wndPtr
) return 0;
1419 retvalue
= wndPtr
->wIDmenu
;
1420 WIN_ReleaseWndPtr(wndPtr
);
1425 /***********************************************************************
1426 * GetDlgItem16 (USER.91)
1428 HWND16 WINAPI
GetDlgItem16( HWND16 hwndDlg
, INT16 id
)
1432 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1433 for (WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
1434 if (pWnd
->wIDmenu
== (UINT16
)id
)
1436 HWND16 retvalue
= pWnd
->hwndSelf
;
1437 WIN_ReleaseWndPtr(pWnd
);
1444 /***********************************************************************
1445 * GetDlgItem32 (USER32.235)
1447 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1451 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1452 for (WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
;WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
1453 if (pWnd
->wIDmenu
== (UINT16
)id
)
1455 HWND retvalue
= pWnd
->hwndSelf
;
1456 WIN_ReleaseWndPtr(pWnd
);
1463 /*******************************************************************
1464 * SendDlgItemMessage16 (USER.101)
1466 LRESULT WINAPI
SendDlgItemMessage16( HWND16 hwnd
, INT16 id
, UINT16 msg
,
1467 WPARAM16 wParam
, LPARAM lParam
)
1469 HWND16 hwndCtrl
= GetDlgItem16( hwnd
, id
);
1470 if (hwndCtrl
) return SendMessage16( hwndCtrl
, msg
, wParam
, lParam
);
1475 /*******************************************************************
1476 * SendDlgItemMessage32A (USER32.452)
1478 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1479 WPARAM wParam
, LPARAM lParam
)
1481 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1482 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1487 /*******************************************************************
1488 * SendDlgItemMessage32W (USER32.453)
1490 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1491 WPARAM wParam
, LPARAM lParam
)
1493 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1494 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1499 /*******************************************************************
1500 * SetDlgItemText16 (USER.92)
1502 void WINAPI
SetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR lpString
)
1504 SendDlgItemMessage16( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1508 /*******************************************************************
1509 * SetDlgItemText32A (USER32.478)
1511 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1513 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1517 /*******************************************************************
1518 * SetDlgItemText32W (USER32.479)
1520 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1522 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1526 /***********************************************************************
1527 * GetDlgItemText16 (USER.93)
1529 INT16 WINAPI
GetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR str
, UINT16 len
)
1531 return (INT16
)SendDlgItemMessage16( hwnd
, id
, WM_GETTEXT
,
1536 /***********************************************************************
1537 * GetDlgItemText32A (USER32.237)
1539 INT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, UINT len
)
1541 return (INT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1546 /***********************************************************************
1547 * GetDlgItemText32W (USER32.238)
1549 INT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, UINT len
)
1551 return (INT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1556 /*******************************************************************
1557 * SetDlgItemInt16 (USER.94)
1559 void WINAPI
SetDlgItemInt16( HWND16 hwnd
, INT16 id
, UINT16 value
, BOOL16 fSigned
)
1561 SetDlgItemInt( hwnd
, (UINT
)(UINT16
)id
, value
, fSigned
);
1565 /*******************************************************************
1566 * SetDlgItemInt32 (USER32.477)
1568 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1573 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1574 else sprintf( str
, "%u", value
);
1575 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1580 /***********************************************************************
1581 * GetDlgItemInt16 (USER.95)
1583 UINT16 WINAPI
GetDlgItemInt16( HWND16 hwnd
, INT16 id
, BOOL16
*translated
,
1589 if (translated
) *translated
= FALSE
;
1590 result
= GetDlgItemInt( hwnd
, (UINT
)(UINT16
)id
, &ok
, fSigned
);
1594 if (((INT
)result
< -32767) || ((INT
)result
> 32767)) return 0;
1598 if (result
> 65535) return 0;
1600 if (translated
) *translated
= TRUE
;
1601 return (UINT16
)result
;
1605 /***********************************************************************
1606 * GetDlgItemInt32 (USER32.236)
1608 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1615 if (translated
) *translated
= FALSE
;
1616 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1620 result
= strtol( str
, &endptr
, 10 );
1621 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1623 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1628 result
= strtoul( str
, &endptr
, 10 );
1629 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1631 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1633 if (translated
) *translated
= TRUE
;
1634 return (UINT
)result
;
1638 /***********************************************************************
1639 * CheckDlgButton16 (USER.97)
1641 BOOL16 WINAPI
CheckDlgButton16( HWND16 hwnd
, INT16 id
, UINT16 check
)
1643 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1648 /***********************************************************************
1649 * CheckDlgButton32 (USER32.45)
1651 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1653 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1658 /***********************************************************************
1659 * IsDlgButtonChecked16 (USER.98)
1661 UINT16 WINAPI
IsDlgButtonChecked16( HWND16 hwnd
, UINT16 id
)
1663 return (UINT16
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1667 /***********************************************************************
1668 * IsDlgButtonChecked32 (USER32.344)
1670 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, UINT id
)
1672 return (UINT
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1676 /***********************************************************************
1677 * CheckRadioButton16 (USER.96)
1679 BOOL16 WINAPI
CheckRadioButton16( HWND16 hwndDlg
, UINT16 firstID
,
1680 UINT16 lastID
, UINT16 checkID
)
1682 return CheckRadioButton( hwndDlg
, firstID
, lastID
, checkID
);
1686 /***********************************************************************
1689 * Callback function used to check/uncheck radio buttons that fall
1690 * within a specific range of IDs.
1692 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1694 LONG lChildID
= GetWindowLongA(hwndChild
, GWL_ID
);
1695 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1697 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1698 (lChildID
<= lpRadioGroup
->lastID
))
1700 if (lChildID
== lpRadioGroup
->checkID
)
1702 SendMessageA(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1706 SendMessageA(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1714 /***********************************************************************
1715 * CheckRadioButton32 (USER32.48)
1717 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, UINT firstID
,
1718 UINT lastID
, UINT checkID
)
1720 RADIOGROUP radioGroup
;
1722 /* perform bounds checking for a radio button group */
1723 radioGroup
.firstID
= min(min(firstID
, lastID
), checkID
);
1724 radioGroup
.lastID
= max(max(firstID
, lastID
), checkID
);
1725 radioGroup
.checkID
= checkID
;
1727 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1728 (LPARAM
)&radioGroup
);
1732 /***********************************************************************
1733 * GetDialogBaseUnits (USER.243) (USER32.233)
1735 DWORD WINAPI
GetDialogBaseUnits(void)
1737 return MAKELONG( xBaseUnit
, yBaseUnit
);
1741 /***********************************************************************
1742 * MapDialogRect16 (USER.103)
1744 void WINAPI
MapDialogRect16( HWND16 hwnd
, LPRECT16 rect
)
1746 DIALOGINFO
* dlgInfo
;
1747 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1748 if (!wndPtr
) return;
1749 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1750 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1751 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1752 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1753 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1754 WIN_ReleaseWndPtr(wndPtr
);
1758 /***********************************************************************
1759 * MapDialogRect32 (USER32.382)
1761 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1763 DIALOGINFO
* dlgInfo
;
1764 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1765 if (!wndPtr
) return FALSE
;
1766 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1767 rect
->left
= MulDiv(rect
->left
, dlgInfo
->xBaseUnit
, 4);
1768 rect
->right
= MulDiv(rect
->right
, dlgInfo
->xBaseUnit
, 4);
1769 rect
->top
= MulDiv(rect
->top
, dlgInfo
->yBaseUnit
, 8);
1770 rect
->bottom
= MulDiv(rect
->bottom
, dlgInfo
->yBaseUnit
, 8);
1771 WIN_ReleaseWndPtr(wndPtr
);
1776 /***********************************************************************
1777 * GetNextDlgGroupItem16 (USER.227)
1779 HWND16 WINAPI
GetNextDlgGroupItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1782 return (HWND16
)GetNextDlgGroupItem( hwndDlg
, hwndCtrl
, fPrevious
);
1786 /***********************************************************************
1787 * GetNextDlgGroupItem32 (USER32.275)
1789 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
,
1798 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1801 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
)))
1806 /* Make sure hwndCtrl is a top-level child */
1807 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1808 WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->parent
);
1809 if (pWndCtrl
->parent
!= pWndDlg
)
1817 /* No ctrl specified -> start from the beginning */
1818 if (!(pWndCtrl
= WIN_LockWndPtr(pWndDlg
->child
)))
1824 while (pWndCtrl
->next
) WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->next
);
1827 pWndLast
= WIN_LockWndPtr(pWndCtrl
);
1828 pWnd
= WIN_LockWndPtr(pWndCtrl
->next
);
1832 if (!pWnd
|| (pWnd
->dwStyle
& WS_GROUP
))
1834 /* Wrap-around to the beginning of the group */
1837 WIN_UpdateWndPtr( &pWnd
, pWndDlg
->child
);
1838 for ( pWndTemp
= WIN_LockWndPtr( pWnd
);
1840 WIN_UpdateWndPtr( &pWndTemp
, pWndTemp
->next
) )
1842 if (pWndTemp
->dwStyle
& WS_GROUP
) WIN_UpdateWndPtr( &pWnd
, pWndTemp
);
1843 if (pWndTemp
== pWndCtrl
) break;
1845 WIN_ReleaseWndPtr( pWndTemp
);
1847 if (pWnd
== pWndCtrl
) break;
1848 if ((pWnd
->dwStyle
& WS_VISIBLE
) && !(pWnd
->dwStyle
& WS_DISABLED
))
1850 WIN_UpdateWndPtr(&pWndLast
,pWnd
);
1851 if (!fPrevious
) break;
1853 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
1855 retvalue
= pWndLast
->hwndSelf
;
1857 WIN_ReleaseWndPtr(pWndLast
);
1858 WIN_ReleaseWndPtr(pWnd
);
1860 WIN_ReleaseWndPtr(pWndCtrl
);
1861 WIN_ReleaseWndPtr(pWndDlg
);
1867 /***********************************************************************
1868 * GetNextDlgTabItem16 (USER.228)
1870 HWND16 WINAPI
GetNextDlgTabItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1873 return (HWND16
)GetNextDlgTabItem( hwndDlg
, hwndCtrl
, fPrevious
);
1877 /***********************************************************************
1878 * GetNextDlgTabItem32 (USER32.276)
1880 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1889 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1892 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
)))
1897 /* Make sure hwndCtrl is a top-level child */
1898 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1899 WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->parent
);
1900 if (pWndCtrl
->parent
!= pWndDlg
)
1908 /* No ctrl specified -> start from the beginning */
1909 if (!(pWndCtrl
= WIN_LockWndPtr(pWndDlg
->child
)))
1916 while (pWndCtrl
->next
) WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->next
);
1919 pWndLast
= WIN_LockWndPtr(pWndCtrl
);
1920 pWnd
= WIN_LockWndPtr(pWndCtrl
->next
);
1923 if (!pWnd
) pWnd
= WIN_LockWndPtr(pWndDlg
->child
);
1924 if (pWnd
== pWndCtrl
) break;
1925 if ((pWnd
->dwStyle
& WS_TABSTOP
) && (pWnd
->dwStyle
& WS_VISIBLE
) &&
1926 !(pWnd
->dwStyle
& WS_DISABLED
))
1928 WIN_UpdateWndPtr(&pWndLast
,pWnd
);
1929 if (!fPrevious
) break;
1931 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
1933 retvalue
= pWndLast
->hwndSelf
;
1935 WIN_ReleaseWndPtr(pWndLast
);
1936 WIN_ReleaseWndPtr(pWnd
);
1938 WIN_ReleaseWndPtr(pWndCtrl
);
1939 WIN_ReleaseWndPtr(pWndDlg
);
1946 /**********************************************************************
1947 * DIALOG_DlgDirSelect
1949 * Helper function for DlgDirSelect*
1951 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1952 INT id
, BOOL win32
, BOOL unicode
,
1958 HWND listbox
= GetDlgItem( hwnd
, id
);
1960 TRACE("%04x '%s' %d\n", hwnd
, str
, id
);
1961 if (!listbox
) return FALSE
;
1964 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
1965 : LB_GETCURSEL
, 0, 0 );
1966 if (item
== LB_ERR
) return FALSE
;
1967 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
1968 : LB_GETTEXTLEN
, 0, 0 );
1969 if (size
== LB_ERR
) return FALSE
;
1973 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL16
1974 : LB_GETCURSEL16
, 0, 0 );
1975 if (item
== LB_ERR
) return FALSE
;
1976 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN16
1977 : LB_GETTEXTLEN16
, 0, 0 );
1978 if (size
== LB_ERR
) return FALSE
;
1981 if (!(buffer
= SEGPTR_ALLOC( size
+1 ))) return FALSE
;
1984 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
,
1985 item
, (LPARAM
)buffer
);
1987 SendMessage16( listbox
, combo
? CB_GETLBTEXT16
: LB_GETTEXT16
,
1988 item
, (LPARAM
)SEGPTR_GET(buffer
) );
1990 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1992 if (buffer
[1] == '-') /* drive */
2000 buffer
[strlen(buffer
)-1] = '\\';
2006 if (unicode
) lstrcpynAtoW( (LPWSTR
)str
, ptr
, len
);
2007 else lstrcpynA( str
, ptr
, len
);
2008 SEGPTR_FREE( buffer
);
2009 TRACE("Returning %d '%s'\n", ret
, str
);
2014 /**********************************************************************
2017 * Helper function for DlgDirList*
2019 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
2020 INT idStatic
, UINT attrib
, BOOL combo
)
2024 LPSTR orig_spec
= spec
;
2026 #define SENDMSG(msg,wparam,lparam) \
2027 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2028 : SendMessageA( hwnd, msg, wparam, lparam ))
2030 TRACE("%04x '%s' %d %d %04x\n",
2031 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
2033 if (spec
&& spec
[0] && (spec
[1] == ':'))
2035 drive
= toupper( spec
[0] ) - 'A';
2037 if (!DRIVE_SetCurrentDrive( drive
)) return FALSE
;
2039 else drive
= DRIVE_GetCurrentDrive();
2041 /* If the path exists and is a directory, chdir to it */
2042 if (!spec
|| !spec
[0] || DRIVE_Chdir( drive
, spec
)) spec
= "*.*";
2047 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
2048 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
2053 if (!DRIVE_Chdir( drive
, spec
))
2055 *p
= sep
; /* Restore the original spec */
2062 TRACE("path=%c:\\%s mask=%s\n",
2063 'A' + drive
, DRIVE_GetDosCwd(drive
), spec
);
2065 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
2067 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
2068 if (attrib
& DDL_DIRECTORY
)
2070 if (!(attrib
& DDL_EXCLUSIVE
))
2072 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2073 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
2074 (LPARAM
)spec
) == LB_ERR
)
2077 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2078 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
2079 (LPARAM
)"*.*" ) == LB_ERR
)
2084 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
2085 (LPARAM
)spec
) == LB_ERR
)
2090 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
2093 int drive
= DRIVE_GetCurrentDrive();
2094 strcpy( temp
, "A:\\" );
2096 lstrcpynA( temp
+ 3, DRIVE_GetDosCwd(drive
), sizeof(temp
)-3 );
2098 /* Can't use PostMessage() here, because the string is on the stack */
2099 SetDlgItemTextA( hDlg
, idStatic
, temp
);
2102 if (orig_spec
&& (spec
!= orig_spec
))
2104 /* Update the original file spec */
2106 while ((*orig_spec
++ = *p
++));
2114 /**********************************************************************
2115 * DIALOG_DlgDirListW
2117 * Helper function for DlgDirList*32W
2119 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2120 INT idStatic
, UINT attrib
, BOOL combo
)
2124 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
2125 INT ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
2127 lstrcpyAtoW( spec
, specA
);
2128 HeapFree( GetProcessHeap(), 0, specA
);
2131 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
2135 /**********************************************************************
2136 * DlgDirSelect (USER.99)
2138 BOOL16 WINAPI
DlgDirSelect16( HWND16 hwnd
, LPSTR str
, INT16 id
)
2140 return DlgDirSelectEx16( hwnd
, str
, 128, id
);
2144 /**********************************************************************
2145 * DlgDirSelectComboBox (USER.194)
2147 BOOL16 WINAPI
DlgDirSelectComboBox16( HWND16 hwnd
, LPSTR str
, INT16 id
)
2149 return DlgDirSelectComboBoxEx16( hwnd
, str
, 128, id
);
2153 /**********************************************************************
2154 * DlgDirSelectEx16 (USER.422)
2156 BOOL16 WINAPI
DlgDirSelectEx16( HWND16 hwnd
, LPSTR str
, INT16 len
, INT16 id
)
2158 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, FALSE
);
2162 /**********************************************************************
2163 * DlgDirSelectEx32A (USER32.149)
2165 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
2167 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, FALSE
);
2171 /**********************************************************************
2172 * DlgDirSelectEx32W (USER32.150)
2174 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
2176 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, FALSE
);
2180 /**********************************************************************
2181 * DlgDirSelectComboBoxEx16 (USER.423)
2183 BOOL16 WINAPI
DlgDirSelectComboBoxEx16( HWND16 hwnd
, LPSTR str
, INT16 len
,
2186 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, TRUE
);
2190 /**********************************************************************
2191 * DlgDirSelectComboBoxEx32A (USER32.147)
2193 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
2196 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, TRUE
);
2200 /**********************************************************************
2201 * DlgDirSelectComboBoxEx32W (USER32.148)
2203 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
2206 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, TRUE
);
2210 /**********************************************************************
2211 * DlgDirList16 (USER.100)
2213 INT16 WINAPI
DlgDirList16( HWND16 hDlg
, LPSTR spec
, INT16 idLBox
,
2214 INT16 idStatic
, UINT16 attrib
)
2216 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2220 /**********************************************************************
2221 * DlgDirList32A (USER32.143)
2223 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
2224 INT idStatic
, UINT attrib
)
2226 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2230 /**********************************************************************
2231 * DlgDirList32W (USER32.146)
2233 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2234 INT idStatic
, UINT attrib
)
2236 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2240 /**********************************************************************
2241 * DlgDirListComboBox16 (USER.195)
2243 INT16 WINAPI
DlgDirListComboBox16( HWND16 hDlg
, LPSTR spec
, INT16 idCBox
,
2244 INT16 idStatic
, UINT16 attrib
)
2246 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2250 /**********************************************************************
2251 * DlgDirListComboBox32A (USER32.144)
2253 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
2254 INT idStatic
, UINT attrib
)
2256 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2260 /**********************************************************************
2261 * DlgDirListComboBox32W (USER32.145)
2263 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
2264 INT idStatic
, UINT attrib
)
2266 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);