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;
78 /***********************************************************************
79 * DIALOG_GetCharSizeFromDC
82 * Calculates the *true* average size of English characters in the
83 * specified font as oppposed to the one returned by GetTextMetrics.
85 static BOOL
DIALOG_GetCharSizeFromDC( HDC hDC
, HFONT hFont
, SIZE
* pSize
)
89 pSize
->cx
= xBaseUnit
;
90 pSize
->cy
= yBaseUnit
;
95 memset(&tm
,0,sizeof(tm
));
96 if (hFont
) hFontPrev
= SelectFont(hDC
,hFont
);
97 if (GetTextMetricsA(hDC
,&tm
))
99 pSize
->cx
= tm
.tmAveCharWidth
;
100 pSize
->cy
= tm
.tmHeight
;
102 /* if variable width font */
103 if (tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
)
106 static const char szAvgChars
[52] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
108 /* Calculate a true average as opposed to the one returned
109 * by tmAveCharWidth. This works better when dealing with
110 * proportional spaced fonts and (more important) that's
111 * how Microsoft's dialog creation code calculates the size
114 if (GetTextExtentPointA(hDC
,szAvgChars
,sizeof(szAvgChars
),&total
))
117 pSize
->cx
= ((2*total
.cx
/sizeof(szAvgChars
)) + 1)/2;
127 /* select the original font */
128 if (hFontPrev
) SelectFont(hDC
,hFontPrev
);
134 /***********************************************************************
138 * Calculates the *true* average size of English characters in the
139 * specified font as oppposed to the one returned by GetTextMetrics.
140 * A convenient variant of DIALOG_GetCharSizeFromDC.
142 static BOOL
DIALOG_GetCharSize( HFONT hFont
, SIZE
* pSize
)
145 BOOL Success
= DIALOG_GetCharSizeFromDC( hDC
, hFont
, pSize
);
151 /***********************************************************************
154 * Initialisation of the dialog manager.
156 BOOL
DIALOG_Init(void)
161 /* Calculate the dialog base units */
163 if (!(hdc
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
))) return FALSE
;
164 if (!DIALOG_GetCharSizeFromDC( hdc
, 0, &size
)) return FALSE
;
169 TRACE("base units = %d,%d\n", xBaseUnit
, yBaseUnit
);
174 /***********************************************************************
175 * DIALOG_GetControl16
177 * Return the class and text of the control pointed to by ptr,
178 * fill the header structure and return a pointer to the next control.
180 static LPCSTR
DIALOG_GetControl16( LPCSTR p
, DLG_CONTROL_INFO
*info
)
182 static char buffer
[10];
185 info
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
186 info
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
187 info
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
188 info
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
189 info
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
190 info
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
197 case 0x80: strcpy( buffer
, "BUTTON" ); break;
198 case 0x81: strcpy( buffer
, "EDIT" ); break;
199 case 0x82: strcpy( buffer
, "STATIC" ); break;
200 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
201 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
202 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
203 default: buffer
[0] = '\0'; break;
205 info
->className
= buffer
;
214 int_id
= ((BYTE
)*p
== 0xff);
217 /* Integer id, not documented (?). Only works for SS_ICON controls */
218 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+1);
223 info
->windowName
= p
;
227 info
->data
= (LPVOID
)(*p
? p
+ 1 : NULL
); /* FIXME: should be a segptr */
231 TRACE(" %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
232 info
->className
, LOWORD(info
->windowName
),
233 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
234 info
->style
, (DWORD
)info
->data
);
236 TRACE(" %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
237 info
->className
, info
->windowName
,
238 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
239 info
->style
, (DWORD
)info
->data
);
245 /***********************************************************************
246 * DIALOG_GetControl32
248 * Return the class and text of the control pointed to by ptr,
249 * fill the header structure and return a pointer to the next control.
251 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
256 info
->helpId
= GET_DWORD(p
); p
+= 2;
257 info
->exStyle
= GET_DWORD(p
); p
+= 2;
258 info
->style
= GET_DWORD(p
); p
+= 2;
263 info
->style
= GET_DWORD(p
); p
+= 2;
264 info
->exStyle
= GET_DWORD(p
); p
+= 2;
266 info
->x
= GET_WORD(p
); p
++;
267 info
->y
= GET_WORD(p
); p
++;
268 info
->cx
= GET_WORD(p
); p
++;
269 info
->cy
= GET_WORD(p
); p
++;
273 /* id is a DWORD for DIALOGEX */
274 info
->id
= GET_DWORD(p
);
279 info
->id
= GET_WORD(p
);
283 if (GET_WORD(p
) == 0xffff)
285 static const WCHAR class_names
[6][10] =
287 { 'B','u','t','t','o','n', }, /* 0x80 */
288 { 'E','d','i','t', }, /* 0x81 */
289 { 'S','t','a','t','i','c', }, /* 0x82 */
290 { 'L','i','s','t','B','o','x', }, /* 0x83 */
291 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
292 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
294 WORD id
= GET_WORD(p
+1);
295 if ((id
>= 0x80) && (id
<= 0x85))
296 info
->className
= (LPCSTR
)class_names
[id
- 0x80];
299 info
->className
= NULL
;
300 ERR("Unknown built-in class id %04x\n", id
);
306 info
->className
= (LPCSTR
)p
;
307 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
310 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
312 info
->windowName
= (LPCSTR
)(UINT
)GET_WORD(p
+ 1);
317 info
->windowName
= (LPCSTR
)p
;
318 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
321 TRACE(" %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
322 debugstr_w( (LPCWSTR
)info
->className
),
323 debugres_w( (LPCWSTR
)info
->windowName
),
324 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
325 info
->style
, info
->exStyle
, info
->helpId
);
329 if (TRACE_ON(dialog
))
331 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
334 for (i
= 0; i
< count
; i
++) DPRINTF( "%04x,", GET_WORD(p
+i
+1) );
338 info
->data
= (LPVOID
)(p
+ 1);
339 p
+= GET_WORD(p
) / sizeof(WORD
);
341 else info
->data
= NULL
;
344 /* Next control is on dword boundary */
345 return (const WORD
*)((((int)p
) + 3) & ~3);
349 /***********************************************************************
350 * DIALOG_CreateControls
352 * Create the control windows for a dialog.
354 static BOOL
DIALOG_CreateControls( WND
*pWnd
, LPCSTR
template,
355 const DLG_TEMPLATE
*dlgTemplate
,
356 HINSTANCE hInst
, BOOL win32
)
358 DIALOGINFO
*dlgInfo
= (DIALOGINFO
*)pWnd
->wExtra
;
359 DLG_CONTROL_INFO info
;
360 HWND hwndCtrl
, hwndDefButton
= 0;
361 INT items
= dlgTemplate
->nbItems
;
368 HINSTANCE16 instance
;
369 template = DIALOG_GetControl16( template, &info
);
370 if (HIWORD(info
.className
) && !strcmp( info
.className
, "EDIT") &&
371 ((pWnd
->dwStyle
& DS_LOCALEDIT
) != DS_LOCALEDIT
))
373 if (!dlgInfo
->hDialogHeap
)
375 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
376 if (!dlgInfo
->hDialogHeap
)
378 ERR("Insufficient memory to create heap for edit control\n" );
381 LocalInit16(dlgInfo
->hDialogHeap
, 0, 0xffff);
383 instance
= dlgInfo
->hDialogHeap
;
385 else instance
= (HINSTANCE16
)hInst
;
387 hwndCtrl
= CreateWindowEx16( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
388 info
.className
, info
.windowName
,
389 info
.style
| WS_CHILD
,
390 info
.x
* dlgInfo
->xBaseUnit
/ 4,
391 info
.y
* dlgInfo
->yBaseUnit
/ 8,
392 info
.cx
* dlgInfo
->xBaseUnit
/ 4,
393 info
.cy
* dlgInfo
->yBaseUnit
/ 8,
394 pWnd
->hwndSelf
, (HMENU16
)info
.id
,
395 instance
, info
.data
);
399 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
400 dlgTemplate
->dialogEx
);
401 hwndCtrl
= CreateWindowExW( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
402 (LPCWSTR
)info
.className
,
403 (LPCWSTR
)info
.windowName
,
404 info
.style
| WS_CHILD
,
405 info
.x
* dlgInfo
->xBaseUnit
/ 4,
406 info
.y
* dlgInfo
->yBaseUnit
/ 8,
407 info
.cx
* dlgInfo
->xBaseUnit
/ 4,
408 info
.cy
* dlgInfo
->yBaseUnit
/ 8,
409 pWnd
->hwndSelf
, (HMENU
)info
.id
,
412 if (!hwndCtrl
) return FALSE
;
414 /* Send initialisation messages to the control */
415 if (dlgInfo
->hUserFont
) SendMessageA( hwndCtrl
, WM_SETFONT
,
416 (WPARAM
)dlgInfo
->hUserFont
, 0 );
417 if (SendMessageA(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
419 /* If there's already a default push-button, set it back */
420 /* to normal and use this one instead. */
422 SendMessageA( hwndDefButton
, BM_SETSTYLE
,
423 BS_PUSHBUTTON
,FALSE
);
424 hwndDefButton
= hwndCtrl
;
425 dlgInfo
->idResult
= GetWindowWord( hwndCtrl
, GWW_ID
);
433 /***********************************************************************
434 * DIALOG_ParseTemplate16
436 * Fill a DLG_TEMPLATE structure from the dialog template, and return
437 * a pointer to the first control.
439 static LPCSTR
DIALOG_ParseTemplate16( LPCSTR p
, DLG_TEMPLATE
* result
)
441 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
443 result
->nbItems
= (unsigned char) *p
++;
444 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
445 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
446 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
447 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
448 TRACE("DIALOG %d, %d, %d, %d\n",
449 result
->x
, result
->y
, result
->cx
, result
->cy
);
450 TRACE(" STYLE %08lx\n", result
->style
);
452 /* Get the menu name */
457 result
->menuName
= 0;
461 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
463 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
466 result
->menuName
= p
;
467 TRACE(" MENU '%s'\n", p
);
472 /* Get the class name */
476 result
->className
= p
;
477 TRACE(" CLASS '%s'\n", result
->className
);
479 else result
->className
= DIALOG_CLASS_ATOM
;
482 /* Get the window caption */
486 TRACE(" CAPTION '%s'\n", result
->caption
);
488 /* Get the font name */
490 if (result
->style
& DS_SETFONT
)
492 result
->pointSize
= GET_WORD(p
);
494 result
->faceName
= p
;
496 TRACE(" FONT %d,'%s'\n",
497 result
->pointSize
, result
->faceName
);
503 /***********************************************************************
504 * DIALOG_ParseTemplate32
506 * Fill a DLG_TEMPLATE structure from the dialog template, and return
507 * a pointer to the first control.
509 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
511 const WORD
*p
= (const WORD
*)template;
513 result
->style
= GET_DWORD(p
); p
+= 2;
514 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
516 result
->dialogEx
= TRUE
;
517 result
->helpId
= GET_DWORD(p
); p
+= 2;
518 result
->exStyle
= GET_DWORD(p
); p
+= 2;
519 result
->style
= GET_DWORD(p
); p
+= 2;
523 result
->dialogEx
= FALSE
;
525 result
->exStyle
= GET_DWORD(p
); p
+= 2;
527 result
->nbItems
= GET_WORD(p
); p
++;
528 result
->x
= GET_WORD(p
); p
++;
529 result
->y
= GET_WORD(p
); p
++;
530 result
->cx
= GET_WORD(p
); p
++;
531 result
->cy
= GET_WORD(p
); p
++;
532 TRACE("DIALOG%s %d, %d, %d, %d, %ld\n",
533 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
534 result
->cx
, result
->cy
, result
->helpId
);
535 TRACE(" STYLE 0x%08lx\n", result
->style
);
536 TRACE(" EXSTYLE 0x%08lx\n", result
->exStyle
);
538 /* Get the menu name */
543 result
->menuName
= NULL
;
547 result
->menuName
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
549 TRACE(" MENU %04x\n", LOWORD(result
->menuName
) );
552 result
->menuName
= (LPCSTR
)p
;
553 TRACE(" MENU %s\n", debugstr_w( (LPCWSTR
)p
));
554 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
558 /* Get the class name */
563 result
->className
= DIALOG_CLASS_ATOM
;
567 result
->className
= (LPCSTR
)(UINT
)GET_WORD( p
+ 1 );
569 TRACE(" CLASS %04x\n", LOWORD(result
->className
) );
572 result
->className
= (LPCSTR
)p
;
573 TRACE(" CLASS %s\n", debugstr_w( (LPCWSTR
)p
));
574 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
578 /* Get the window caption */
580 result
->caption
= (LPCSTR
)p
;
581 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
582 TRACE(" CAPTION %s\n", debugstr_w( (LPCWSTR
)result
->caption
) );
584 /* Get the font name */
586 if (result
->style
& DS_SETFONT
)
588 result
->pointSize
= GET_WORD(p
);
590 if (result
->dialogEx
)
592 result
->weight
= GET_WORD(p
); p
++;
593 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
597 result
->weight
= FW_DONTCARE
;
598 result
->italic
= FALSE
;
600 result
->faceName
= (LPCSTR
)p
;
601 p
+= lstrlenW( (LPCWSTR
)p
) + 1;
602 TRACE(" FONT %d, %s, %d, %s\n",
603 result
->pointSize
, debugstr_w( (LPCWSTR
)result
->faceName
),
604 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
607 /* First control is on dword boundary */
608 return (LPCSTR
)((((int)p
) + 3) & ~3);
612 /***********************************************************************
613 * DIALOG_CreateIndirect
615 HWND
DIALOG_CreateIndirect( HINSTANCE hInst
, LPCSTR dlgTemplate
,
616 BOOL win32Template
, HWND owner
,
617 DLGPROC16 dlgProc
, LPARAM param
,
618 WINDOWPROCTYPE procType
)
625 DLG_TEMPLATE
template;
626 DIALOGINFO
* dlgInfo
;
627 WORD xUnit
= xBaseUnit
;
628 WORD yUnit
= yBaseUnit
;
630 /* Parse dialog template */
632 if (!dlgTemplate
) return 0;
634 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
636 dlgTemplate
= DIALOG_ParseTemplate16( dlgTemplate
, &template );
640 if (template.menuName
)
644 LPSTR str
= SEGPTR_STRDUP( template.menuName
);
645 hMenu
= LoadMenu16( hInst
, SEGPTR_GET(str
) );
648 else hMenu
= LoadMenuW( hInst
, (LPCWSTR
)template.menuName
);
651 /* Create custom font if needed */
653 if (template.style
& DS_SETFONT
)
655 /* The font height must be negative as it is a point size */
656 /* (see CreateFont() documentation in the Windows SDK). */
659 hFont
= CreateFontW( -template.pointSize
, 0, 0, 0,
660 template.weight
, template.italic
, FALSE
,
661 FALSE
, DEFAULT_CHARSET
, 0, 0, PROOF_QUALITY
,
662 FF_DONTCARE
, (LPCWSTR
)template.faceName
);
664 hFont
= CreateFont16( -template.pointSize
, 0, 0, 0, FW_DONTCARE
,
665 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
666 PROOF_QUALITY
, FF_DONTCARE
,
671 DIALOG_GetCharSize(hFont
,&charSize
);
677 /* Create dialog main window */
679 rect
.left
= rect
.top
= 0;
680 rect
.right
= template.cx
* xUnit
/ 4;
681 rect
.bottom
= template.cy
* yUnit
/ 8;
682 if (template.style
& DS_MODALFRAME
)
683 template.exStyle
|= WS_EX_DLGMODALFRAME
;
684 AdjustWindowRectEx( &rect
, template.style
,
685 hMenu
? TRUE
: FALSE
, template.exStyle
);
686 rect
.right
-= rect
.left
;
687 rect
.bottom
-= rect
.top
;
689 if ((INT16
)template.x
== CW_USEDEFAULT16
)
691 rect
.left
= rect
.top
= win32Template
? CW_USEDEFAULT
: CW_USEDEFAULT16
;
695 if (template.style
& DS_CENTER
)
697 rect
.left
= (GetSystemMetrics(SM_CXSCREEN
) - rect
.right
) / 2;
698 rect
.top
= (GetSystemMetrics(SM_CYSCREEN
) - rect
.bottom
) / 2;
702 rect
.left
+= template.x
* xUnit
/ 4;
703 rect
.top
+= template.y
* yUnit
/ 8;
705 if ( !(template.style
& WS_CHILD
) )
709 if( !(template.style
& DS_ABSALIGN
) )
710 ClientToScreen( owner
, (POINT
*)&rect
);
712 /* try to fit it into the desktop */
714 if( (dX
= rect
.left
+ rect
.right
+ GetSystemMetrics(SM_CXDLGFRAME
)
715 - GetSystemMetrics(SM_CXSCREEN
)) > 0 ) rect
.left
-= dX
;
716 if( (dY
= rect
.top
+ rect
.bottom
+ GetSystemMetrics(SM_CYDLGFRAME
)
717 - GetSystemMetrics(SM_CYSCREEN
)) > 0 ) rect
.top
-= dY
;
718 if( rect
.left
< 0 ) rect
.left
= 0;
719 if( rect
.top
< 0 ) rect
.top
= 0;
724 hwnd
= CreateWindowEx16(template.exStyle
, template.className
,
725 template.caption
, template.style
& ~WS_VISIBLE
,
726 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
727 owner
, hMenu
, hInst
, NULL
);
729 hwnd
= CreateWindowExW(template.exStyle
, (LPCWSTR
)template.className
,
730 (LPCWSTR
)template.caption
,
731 template.style
& ~WS_VISIBLE
,
732 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
733 owner
, hMenu
, hInst
, NULL
);
737 if (hFont
) DeleteObject( hFont
);
738 if (hMenu
) DestroyMenu( hMenu
);
741 wndPtr
= WIN_FindWndPtr( hwnd
);
742 wndPtr
->flags
|= WIN_ISDIALOG
;
743 wndPtr
->helpContext
= template.helpId
;
745 /* Initialise dialog extra data */
747 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
748 WINPROC_SetProc( &dlgInfo
->dlgProc
, (WNDPROC16
)dlgProc
, procType
, WIN_PROC_WINDOW
);
749 dlgInfo
->hUserFont
= hFont
;
750 dlgInfo
->hMenu
= hMenu
;
751 dlgInfo
->xBaseUnit
= xUnit
;
752 dlgInfo
->yBaseUnit
= yUnit
;
753 dlgInfo
->msgResult
= 0;
754 dlgInfo
->idResult
= 0;
756 dlgInfo
->hDialogHeap
= 0;
758 if (dlgInfo
->hUserFont
)
759 SendMessageA( hwnd
, WM_SETFONT
, (WPARAM
)dlgInfo
->hUserFont
, 0 );
761 /* Create controls */
763 if (DIALOG_CreateControls( wndPtr
, dlgTemplate
, &template,
764 hInst
, win32Template
))
766 /* Send initialisation messages and set focus */
768 dlgInfo
->hwndFocus
= GetNextDlgTabItem( hwnd
, 0, FALSE
);
770 if (SendMessageA( hwnd
, WM_INITDIALOG
, (WPARAM
)dlgInfo
->hwndFocus
, param
))
771 SetFocus( dlgInfo
->hwndFocus
);
773 if (template.style
& WS_VISIBLE
&& !(wndPtr
->dwStyle
& WS_VISIBLE
))
775 ShowWindow( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
776 UpdateWindow( hwnd
);
778 WIN_ReleaseWndPtr(wndPtr
);
781 WIN_ReleaseWndPtr(wndPtr
);
782 if( IsWindow(hwnd
) ) DestroyWindow( hwnd
);
787 /***********************************************************************
788 * CreateDialog16 (USER.89)
790 HWND16 WINAPI
CreateDialog16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
791 HWND16 owner
, DLGPROC16 dlgProc
)
793 return CreateDialogParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
797 /***********************************************************************
798 * CreateDialogParam16 (USER.241)
800 HWND16 WINAPI
CreateDialogParam16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
801 HWND16 owner
, DLGPROC16 dlgProc
,
809 TRACE("%04x,%08lx,%04x,%08lx,%ld\n",
810 hInst
, (DWORD
)dlgTemplate
, owner
, (DWORD
)dlgProc
, param
);
812 if (!(hRsrc
= FindResource16( hInst
, dlgTemplate
, RT_DIALOG16
))) return 0;
813 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
814 if (!(data
= LockResource16( hmem
))) hwnd
= 0;
815 else hwnd
= CreateDialogIndirectParam16( hInst
, data
, owner
,
817 FreeResource16( hmem
);
821 /***********************************************************************
822 * CreateDialogParam32A (USER32.73)
824 HWND WINAPI
CreateDialogParamA( HINSTANCE hInst
, LPCSTR name
,
825 HWND owner
, DLGPROC dlgProc
,
830 LPWSTR str
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
831 HWND hwnd
= CreateDialogParamW( hInst
, str
, owner
, dlgProc
, param
);
832 HeapFree( GetProcessHeap(), 0, str
);
835 return CreateDialogParamW( hInst
, (LPCWSTR
)name
, owner
, dlgProc
, param
);
839 /***********************************************************************
840 * CreateDialogParam32W (USER32.74)
842 HWND WINAPI
CreateDialogParamW( HINSTANCE hInst
, LPCWSTR name
,
843 HWND owner
, DLGPROC dlgProc
,
846 HANDLE hrsrc
= FindResourceW( hInst
, name
, RT_DIALOGW
);
847 if (!hrsrc
) return 0;
848 return CreateDialogIndirectParamW( hInst
,
849 (LPVOID
)LoadResource(hInst
, hrsrc
),
850 owner
, dlgProc
, param
);
854 /***********************************************************************
855 * CreateDialogIndirect16 (USER.219)
857 HWND16 WINAPI
CreateDialogIndirect16( HINSTANCE16 hInst
, LPCVOID dlgTemplate
,
858 HWND16 owner
, DLGPROC16 dlgProc
)
860 return CreateDialogIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0);
864 /***********************************************************************
865 * CreateDialogIndirectParam16 (USER.242)
867 HWND16 WINAPI
CreateDialogIndirectParam16( HINSTANCE16 hInst
,
869 HWND16 owner
, DLGPROC16 dlgProc
,
872 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, FALSE
, owner
,
873 dlgProc
, param
, WIN_PROC_16
);
877 /***********************************************************************
878 * CreateDialogIndirectParam32A (USER32.69)
880 HWND WINAPI
CreateDialogIndirectParamA( HINSTANCE hInst
,
882 HWND owner
, DLGPROC dlgProc
,
885 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
886 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32A
);
889 /***********************************************************************
890 * CreateDialogIndirectParam32AorW (USER32.71)
892 HWND WINAPI
CreateDialogIndirectParamAorW( HINSTANCE hInst
,
894 HWND owner
, DLGPROC dlgProc
,
896 { FIXME("assume WIN_PROC_32W\n");
897 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
898 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32W
);
901 /***********************************************************************
902 * CreateDialogIndirectParam32W (USER32.72)
904 HWND WINAPI
CreateDialogIndirectParamW( HINSTANCE hInst
,
906 HWND owner
, DLGPROC dlgProc
,
909 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
910 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32W
);
914 /***********************************************************************
917 INT
DIALOG_DoDialogBox( HWND hwnd
, HWND owner
)
920 DIALOGINFO
* dlgInfo
;
924 /* Owner must be a top-level window */
925 owner
= WIN_GetTopParent( owner
);
926 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return -1;
927 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
929 if (!dlgInfo
->flags
& DF_END
) /* was EndDialog called in WM_INITDIALOG ? */
931 EnableWindow( owner
, FALSE
);
932 ShowWindow( hwnd
, SW_SHOW
);
933 while (MSG_InternalGetMessage(&msg
, hwnd
, owner
, MSGF_DIALOGBOX
,
934 PM_REMOVE
, !(wndPtr
->dwStyle
& DS_NOIDLEMSG
) ))
936 if (!IsDialogMessageA( hwnd
, &msg
))
938 TranslateMessage( &msg
);
939 DispatchMessageA( &msg
);
941 if (dlgInfo
->flags
& DF_END
) break;
943 EnableWindow( owner
, TRUE
);
945 retval
= dlgInfo
->idResult
;
946 WIN_ReleaseWndPtr(wndPtr
);
947 DestroyWindow( hwnd
);
952 /***********************************************************************
953 * DialogBox16 (USER.87)
955 INT16 WINAPI
DialogBox16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
956 HWND16 owner
, DLGPROC16 dlgProc
)
958 return DialogBoxParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
962 /***********************************************************************
963 * DialogBoxParam16 (USER.239)
965 INT16 WINAPI
DialogBoxParam16( HINSTANCE16 hInst
, SEGPTR
template,
966 HWND16 owner
, DLGPROC16 dlgProc
, LPARAM param
)
968 HWND16 hwnd
= CreateDialogParam16( hInst
, template, owner
, dlgProc
, param
);
969 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
974 /***********************************************************************
975 * DialogBoxParam32A (USER32.139)
977 INT WINAPI
DialogBoxParamA( HINSTANCE hInst
, LPCSTR name
,
978 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
980 HWND hwnd
= CreateDialogParamA( hInst
, name
, owner
, dlgProc
, param
);
981 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
986 /***********************************************************************
987 * DialogBoxParam32W (USER32.140)
989 INT WINAPI
DialogBoxParamW( HINSTANCE hInst
, LPCWSTR name
,
990 HWND owner
, DLGPROC dlgProc
, LPARAM param
)
992 HWND hwnd
= CreateDialogParamW( hInst
, name
, owner
, dlgProc
, param
);
993 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
998 /***********************************************************************
999 * DialogBoxIndirect16 (USER.218)
1001 INT16 WINAPI
DialogBoxIndirect16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1002 HWND16 owner
, DLGPROC16 dlgProc
)
1004 return DialogBoxIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
1008 /***********************************************************************
1009 * DialogBoxIndirectParam16 (USER.240)
1011 INT16 WINAPI
DialogBoxIndirectParam16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
1012 HWND16 owner
, DLGPROC16 dlgProc
,
1018 if (!(ptr
= GlobalLock16( dlgTemplate
))) return -1;
1019 hwnd
= CreateDialogIndirectParam16( hInst
, ptr
, owner
, dlgProc
, param
);
1020 GlobalUnlock16( dlgTemplate
);
1021 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
1026 /***********************************************************************
1027 * DialogBoxIndirectParam32A (USER32.136)
1029 INT WINAPI
DialogBoxIndirectParamA(HINSTANCE hInstance
, LPCVOID
template,
1030 HWND owner
, DLGPROC dlgProc
,
1033 HWND hwnd
= CreateDialogIndirectParamA( hInstance
, template,
1034 owner
, dlgProc
, param
);
1035 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1040 /***********************************************************************
1041 * DialogBoxIndirectParam32W (USER32.138)
1043 INT WINAPI
DialogBoxIndirectParamW(HINSTANCE hInstance
, LPCVOID
template,
1044 HWND owner
, DLGPROC dlgProc
,
1047 HWND hwnd
= CreateDialogIndirectParamW( hInstance
, template,
1048 owner
, dlgProc
, param
);
1049 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
1054 /***********************************************************************
1055 * EndDialog16 (USER.88)
1057 BOOL16 WINAPI
EndDialog16( HWND16 hwnd
, INT16 retval
)
1059 return EndDialog( hwnd
, retval
);
1063 /***********************************************************************
1064 * EndDialog32 (USER32.173)
1066 BOOL WINAPI
EndDialog( HWND hwnd
, INT retval
)
1068 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1069 DIALOGINFO
* dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1071 TRACE("%04x %d\n", hwnd
, retval
);
1075 dlgInfo
->idResult
= retval
;
1076 dlgInfo
->flags
|= DF_END
;
1079 /* Paint Shop Pro 4.14 calls EndDialog for a CreateDialog* dialog,
1080 * which isn't "normal". Only DialogBox* dialogs may be EndDialog()ed.
1081 * Just hide the window as windows does it...
1083 ShowWindow(hwnd
, SW_HIDE
);
1085 WIN_ReleaseWndPtr(wndPtr
);
1090 /***********************************************************************
1091 * DIALOG_IsAccelerator
1093 static BOOL
DIALOG_IsAccelerator( HWND hwnd
, HWND hwndDlg
, WPARAM vKey
)
1095 HWND hwndControl
= hwnd
;
1098 BOOL RetVal
= FALSE
;
1101 if (vKey
== VK_SPACE
)
1103 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1104 if (dlgCode
& DLGC_BUTTON
)
1106 SendMessageA( hwndControl
, WM_LBUTTONDOWN
, 0, 0);
1107 SendMessageA( hwndControl
, WM_LBUTTONUP
, 0, 0);
1115 wndPtr
= WIN_FindWndPtr( hwndControl
);
1116 if ( (wndPtr
!= NULL
) &&
1117 ((wndPtr
->dwStyle
& (WS_VISIBLE
| WS_DISABLED
)) == WS_VISIBLE
) )
1119 dlgCode
= SendMessageA( hwndControl
, WM_GETDLGCODE
, 0, 0 );
1120 if ( (dlgCode
& (DLGC_BUTTON
| DLGC_STATIC
)) &&
1121 (wndPtr
->text
!=NULL
))
1123 /* find the accelerator key */
1124 LPSTR p
= wndPtr
->text
- 2;
1127 p
= strchr( p
+ 2, '&' );
1129 while (p
!= NULL
&& p
[1] == '&');
1131 /* and check if it's the one we're looking for */
1132 if (p
!= NULL
&& toupper( p
[1] ) == toupper( vKey
) )
1134 if ((dlgCode
& DLGC_STATIC
) ||
1135 (wndPtr
->dwStyle
& 0x0f) == BS_GROUPBOX
)
1137 /* set focus to the control */
1138 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
,
1140 /* and bump it on to next */
1141 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, 0, 0);
1144 (DLGC_DEFPUSHBUTTON
| DLGC_UNDEFPUSHBUTTON
))
1146 /* send command message as from the control */
1147 SendMessageA( hwndDlg
, WM_COMMAND
,
1148 MAKEWPARAM( LOWORD(wndPtr
->wIDmenu
),
1150 (LPARAM
)hwndControl
);
1154 /* click the control */
1155 SendMessageA( hwndControl
, WM_LBUTTONDOWN
, 0, 0);
1156 SendMessageA( hwndControl
, WM_LBUTTONUP
, 0, 0);
1162 hwndNext
= GetWindow( hwndControl
, GW_CHILD
);
1168 WIN_ReleaseWndPtr(wndPtr
);
1171 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1175 hwndControl
= GetParent( hwndControl
);
1176 if (hwndControl
== hwndDlg
)
1178 hwndNext
= GetWindow( hwndDlg
, GW_CHILD
);
1182 hwndNext
= GetWindow( hwndControl
, GW_HWNDNEXT
);
1185 hwndControl
= hwndNext
;
1187 while (hwndControl
!= hwnd
);
1193 /***********************************************************************
1194 * DIALOG_IsDialogMessage
1196 static BOOL
DIALOG_IsDialogMessage( HWND hwnd
, HWND hwndDlg
,
1197 UINT message
, WPARAM wParam
,
1198 LPARAM lParam
, BOOL
*translate
,
1199 BOOL
*dispatch
, INT dlgCode
)
1201 *translate
= *dispatch
= FALSE
;
1203 if (message
== WM_PAINT
)
1205 /* Apparently, we have to handle this one as well */
1210 /* Only the key messages get special processing */
1211 if ((message
!= WM_KEYDOWN
) &&
1212 (message
!= WM_SYSCHAR
) &&
1213 (message
!= WM_CHAR
))
1216 if (dlgCode
& DLGC_WANTMESSAGE
)
1218 *translate
= *dispatch
= TRUE
;
1228 if (!(dlgCode
& DLGC_WANTTAB
))
1230 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
,
1231 (GetKeyState(VK_SHIFT
) & 0x8000), 0 );
1240 if (!(dlgCode
& DLGC_WANTARROWS
))
1242 BOOL fPrevious
= (wParam
== VK_LEFT
|| wParam
== VK_UP
);
1244 GetNextDlgGroupItem (hwndDlg
, GetFocus(), fPrevious
);
1245 SendMessageA( hwndDlg
, WM_NEXTDLGCTL
, hwndNext
, 1 );
1251 SendMessageA( hwndDlg
, WM_COMMAND
, IDCANCEL
,
1252 (LPARAM
)GetDlgItem( hwndDlg
, IDCANCEL
) );
1257 DWORD dw
= SendMessage16( hwndDlg
, DM_GETDEFID
, 0, 0 );
1258 if (HIWORD(dw
) == DC_HASDEFID
)
1260 SendMessageA( hwndDlg
, WM_COMMAND
,
1261 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1262 (LPARAM
)GetDlgItem(hwndDlg
, LOWORD(dw
)));
1266 SendMessageA( hwndDlg
, WM_COMMAND
, IDOK
,
1267 (LPARAM
)GetDlgItem( hwndDlg
, IDOK
) );
1274 break; /* case WM_KEYDOWN */
1277 if (dlgCode
& DLGC_WANTCHARS
) break;
1281 if (DIALOG_IsAccelerator( hwnd
, hwndDlg
, wParam
))
1283 /* don't translate or dispatch */
1289 /* If we get here, the message has not been treated specially */
1290 /* and can be sent to its destination window. */
1296 /***********************************************************************
1297 * IsDialogMessage16 (USER.90)
1299 BOOL16 WINAPI
WIN16_IsDialogMessage16( HWND16 hwndDlg
, SEGPTR msg16
)
1301 LPMSG16 msg
= PTR_SEG_TO_LIN(msg16
);
1302 BOOL ret
, translate
, dispatch
;
1305 if ((hwndDlg
!= msg
->hwnd
) && !IsChild16( hwndDlg
, msg
->hwnd
))
1308 dlgCode
= SendMessage16( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg16
);
1309 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1310 msg
->wParam
, msg
->lParam
,
1311 &translate
, &dispatch
, dlgCode
);
1312 if (translate
) TranslateMessage16( msg
);
1313 if (dispatch
) DispatchMessage16( msg
);
1318 BOOL16 WINAPI
IsDialogMessage16( HWND16 hwndDlg
, LPMSG16 msg
)
1320 LPMSG16 msg16
= SEGPTR_NEW(MSG16
);
1324 ret
= WIN16_IsDialogMessage16( hwndDlg
, SEGPTR_GET(msg16
) );
1329 /***********************************************************************
1330 * IsDialogMessage32A (USER32.342)
1332 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG msg
)
1334 BOOL ret
, translate
, dispatch
;
1337 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1340 dlgCode
= SendMessageA( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1341 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1342 msg
->wParam
, msg
->lParam
,
1343 &translate
, &dispatch
, dlgCode
);
1344 if (translate
) TranslateMessage( msg
);
1345 if (dispatch
) DispatchMessageA( msg
);
1350 /***********************************************************************
1351 * IsDialogMessage32W (USER32.343)
1353 BOOL WINAPI
IsDialogMessageW( HWND hwndDlg
, LPMSG msg
)
1355 BOOL ret
, translate
, dispatch
;
1358 if ((hwndDlg
!= msg
->hwnd
) && !IsChild( hwndDlg
, msg
->hwnd
))
1361 dlgCode
= SendMessageW( msg
->hwnd
, WM_GETDLGCODE
, 0, (LPARAM
)msg
);
1362 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1363 msg
->wParam
, msg
->lParam
,
1364 &translate
, &dispatch
, dlgCode
);
1365 if (translate
) TranslateMessage( msg
);
1366 if (dispatch
) DispatchMessageW( msg
);
1371 /****************************************************************
1372 * GetDlgCtrlID16 (USER.277)
1374 INT16 WINAPI
GetDlgCtrlID16( HWND16 hwnd
)
1376 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1379 if (!wndPtr
) return 0;
1381 retvalue
= wndPtr
->wIDmenu
;
1382 WIN_ReleaseWndPtr(wndPtr
);
1387 /****************************************************************
1388 * GetDlgCtrlID32 (USER32.234)
1390 INT WINAPI
GetDlgCtrlID( HWND hwnd
)
1393 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1394 if (!wndPtr
) return 0;
1395 retvalue
= wndPtr
->wIDmenu
;
1396 WIN_ReleaseWndPtr(wndPtr
);
1401 /***********************************************************************
1402 * GetDlgItem16 (USER.91)
1404 HWND16 WINAPI
GetDlgItem16( HWND16 hwndDlg
, INT16 id
)
1408 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1409 for (WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
; WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
1410 if (pWnd
->wIDmenu
== (UINT16
)id
)
1412 HWND16 retvalue
= pWnd
->hwndSelf
;
1413 WIN_ReleaseWndPtr(pWnd
);
1420 /***********************************************************************
1421 * GetDlgItem32 (USER32.235)
1423 HWND WINAPI
GetDlgItem( HWND hwndDlg
, INT id
)
1427 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1428 for (WIN_UpdateWndPtr(&pWnd
,pWnd
->child
); pWnd
;WIN_UpdateWndPtr(&pWnd
,pWnd
->next
))
1429 if (pWnd
->wIDmenu
== (UINT16
)id
)
1431 HWND retvalue
= pWnd
->hwndSelf
;
1432 WIN_ReleaseWndPtr(pWnd
);
1439 /*******************************************************************
1440 * SendDlgItemMessage16 (USER.101)
1442 LRESULT WINAPI
SendDlgItemMessage16( HWND16 hwnd
, INT16 id
, UINT16 msg
,
1443 WPARAM16 wParam
, LPARAM lParam
)
1445 HWND16 hwndCtrl
= GetDlgItem16( hwnd
, id
);
1446 if (hwndCtrl
) return SendMessage16( hwndCtrl
, msg
, wParam
, lParam
);
1451 /*******************************************************************
1452 * SendDlgItemMessage32A (USER32.452)
1454 LRESULT WINAPI
SendDlgItemMessageA( HWND hwnd
, INT id
, UINT msg
,
1455 WPARAM wParam
, LPARAM lParam
)
1457 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1458 if (hwndCtrl
) return SendMessageA( hwndCtrl
, msg
, wParam
, lParam
);
1463 /*******************************************************************
1464 * SendDlgItemMessage32W (USER32.453)
1466 LRESULT WINAPI
SendDlgItemMessageW( HWND hwnd
, INT id
, UINT msg
,
1467 WPARAM wParam
, LPARAM lParam
)
1469 HWND hwndCtrl
= GetDlgItem( hwnd
, id
);
1470 if (hwndCtrl
) return SendMessageW( hwndCtrl
, msg
, wParam
, lParam
);
1475 /*******************************************************************
1476 * SetDlgItemText16 (USER.92)
1478 void WINAPI
SetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR lpString
)
1480 SendDlgItemMessage16( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1484 /*******************************************************************
1485 * SetDlgItemText32A (USER32.478)
1487 BOOL WINAPI
SetDlgItemTextA( HWND hwnd
, INT id
, LPCSTR lpString
)
1489 return SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1493 /*******************************************************************
1494 * SetDlgItemText32W (USER32.479)
1496 BOOL WINAPI
SetDlgItemTextW( HWND hwnd
, INT id
, LPCWSTR lpString
)
1498 return SendDlgItemMessageW( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1502 /***********************************************************************
1503 * GetDlgItemText16 (USER.93)
1505 INT16 WINAPI
GetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR str
, UINT16 len
)
1507 return (INT16
)SendDlgItemMessage16( hwnd
, id
, WM_GETTEXT
,
1512 /***********************************************************************
1513 * GetDlgItemText32A (USER32.237)
1515 INT WINAPI
GetDlgItemTextA( HWND hwnd
, INT id
, LPSTR str
, UINT len
)
1517 return (INT
)SendDlgItemMessageA( hwnd
, id
, WM_GETTEXT
,
1522 /***********************************************************************
1523 * GetDlgItemText32W (USER32.238)
1525 INT WINAPI
GetDlgItemTextW( HWND hwnd
, INT id
, LPWSTR str
, UINT len
)
1527 return (INT
)SendDlgItemMessageW( hwnd
, id
, WM_GETTEXT
,
1532 /*******************************************************************
1533 * SetDlgItemInt16 (USER.94)
1535 void WINAPI
SetDlgItemInt16( HWND16 hwnd
, INT16 id
, UINT16 value
, BOOL16 fSigned
)
1537 SetDlgItemInt( hwnd
, (UINT
)(UINT16
)id
, value
, fSigned
);
1541 /*******************************************************************
1542 * SetDlgItemInt32 (USER32.477)
1544 BOOL WINAPI
SetDlgItemInt( HWND hwnd
, INT id
, UINT value
,
1549 if (fSigned
) sprintf( str
, "%d", (INT
)value
);
1550 else sprintf( str
, "%u", value
);
1551 SendDlgItemMessageA( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1556 /***********************************************************************
1557 * GetDlgItemInt16 (USER.95)
1559 UINT16 WINAPI
GetDlgItemInt16( HWND16 hwnd
, INT16 id
, BOOL16
*translated
,
1565 if (translated
) *translated
= FALSE
;
1566 result
= GetDlgItemInt( hwnd
, (UINT
)(UINT16
)id
, &ok
, fSigned
);
1570 if (((INT
)result
< -32767) || ((INT
)result
> 32767)) return 0;
1574 if (result
> 65535) return 0;
1576 if (translated
) *translated
= TRUE
;
1577 return (UINT16
)result
;
1581 /***********************************************************************
1582 * GetDlgItemInt32 (USER32.236)
1584 UINT WINAPI
GetDlgItemInt( HWND hwnd
, INT id
, BOOL
*translated
,
1591 if (translated
) *translated
= FALSE
;
1592 if (!SendDlgItemMessageA(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1596 result
= strtol( str
, &endptr
, 10 );
1597 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1599 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1604 result
= strtoul( str
, &endptr
, 10 );
1605 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1607 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1609 if (translated
) *translated
= TRUE
;
1610 return (UINT
)result
;
1614 /***********************************************************************
1615 * CheckDlgButton16 (USER.97)
1617 BOOL16 WINAPI
CheckDlgButton16( HWND16 hwnd
, INT16 id
, UINT16 check
)
1619 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1624 /***********************************************************************
1625 * CheckDlgButton32 (USER32.45)
1627 BOOL WINAPI
CheckDlgButton( HWND hwnd
, INT id
, UINT check
)
1629 SendDlgItemMessageA( hwnd
, id
, BM_SETCHECK
, check
, 0 );
1634 /***********************************************************************
1635 * IsDlgButtonChecked16 (USER.98)
1637 UINT16 WINAPI
IsDlgButtonChecked16( HWND16 hwnd
, UINT16 id
)
1639 return (UINT16
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1643 /***********************************************************************
1644 * IsDlgButtonChecked32 (USER32.344)
1646 UINT WINAPI
IsDlgButtonChecked( HWND hwnd
, UINT id
)
1648 return (UINT
)SendDlgItemMessageA( hwnd
, id
, BM_GETCHECK
, 0, 0 );
1652 /***********************************************************************
1653 * CheckRadioButton16 (USER.96)
1655 BOOL16 WINAPI
CheckRadioButton16( HWND16 hwndDlg
, UINT16 firstID
,
1656 UINT16 lastID
, UINT16 checkID
)
1658 return CheckRadioButton( hwndDlg
, firstID
, lastID
, checkID
);
1662 /***********************************************************************
1665 * Callback function used to check/uncheck radio buttons that fall
1666 * within a specific range of IDs.
1668 static BOOL CALLBACK
CheckRB(HWND hwndChild
, LPARAM lParam
)
1670 LONG lChildID
= GetWindowLongA(hwndChild
, GWL_ID
);
1671 RADIOGROUP
*lpRadioGroup
= (RADIOGROUP
*) lParam
;
1673 if ((lChildID
>= lpRadioGroup
->firstID
) &&
1674 (lChildID
<= lpRadioGroup
->lastID
))
1676 if (lChildID
== lpRadioGroup
->checkID
)
1678 SendMessageA(hwndChild
, BM_SETCHECK
, BST_CHECKED
, 0);
1682 SendMessageA(hwndChild
, BM_SETCHECK
, BST_UNCHECKED
, 0);
1690 /***********************************************************************
1691 * CheckRadioButton32 (USER32.48)
1693 BOOL WINAPI
CheckRadioButton( HWND hwndDlg
, UINT firstID
,
1694 UINT lastID
, UINT checkID
)
1696 RADIOGROUP radioGroup
;
1698 /* perform bounds checking for a radio button group */
1699 radioGroup
.firstID
= min(min(firstID
, lastID
), checkID
);
1700 radioGroup
.lastID
= max(max(firstID
, lastID
), checkID
);
1701 radioGroup
.checkID
= checkID
;
1703 return EnumChildWindows(hwndDlg
, (WNDENUMPROC
)CheckRB
,
1704 (LPARAM
)&radioGroup
);
1708 /***********************************************************************
1709 * GetDialogBaseUnits (USER.243) (USER32.233)
1711 DWORD WINAPI
GetDialogBaseUnits(void)
1713 return MAKELONG( xBaseUnit
, yBaseUnit
);
1717 /***********************************************************************
1718 * MapDialogRect16 (USER.103)
1720 void WINAPI
MapDialogRect16( HWND16 hwnd
, LPRECT16 rect
)
1722 DIALOGINFO
* dlgInfo
;
1723 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1724 if (!wndPtr
) return;
1725 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1726 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
1727 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
1728 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
1729 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
1730 WIN_ReleaseWndPtr(wndPtr
);
1734 /***********************************************************************
1735 * MapDialogRect32 (USER32.382)
1737 BOOL WINAPI
MapDialogRect( HWND hwnd
, LPRECT rect
)
1739 DIALOGINFO
* dlgInfo
;
1740 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1741 if (!wndPtr
) return FALSE
;
1742 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1743 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
1744 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
1745 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
1746 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
1747 WIN_ReleaseWndPtr(wndPtr
);
1752 /***********************************************************************
1753 * GetNextDlgGroupItem16 (USER.227)
1755 HWND16 WINAPI
GetNextDlgGroupItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1758 return (HWND16
)GetNextDlgGroupItem( hwndDlg
, hwndCtrl
, fPrevious
);
1762 /***********************************************************************
1763 * GetNextDlgGroupItem32 (USER32.275)
1765 HWND WINAPI
GetNextDlgGroupItem( HWND hwndDlg
, HWND hwndCtrl
,
1774 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1777 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
)))
1782 /* Make sure hwndCtrl is a top-level child */
1783 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1784 WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->parent
);
1785 if (pWndCtrl
->parent
!= pWndDlg
)
1793 /* No ctrl specified -> start from the beginning */
1794 if (!(pWndCtrl
= WIN_LockWndPtr(pWndDlg
->child
)))
1800 while (pWndCtrl
->next
) WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->next
);
1803 pWndLast
= WIN_LockWndPtr(pWndCtrl
);
1804 pWnd
= WIN_LockWndPtr(pWndCtrl
->next
);
1808 if (!pWnd
|| (pWnd
->dwStyle
& WS_GROUP
))
1810 /* Wrap-around to the beginning of the group */
1813 WIN_UpdateWndPtr( &pWnd
, pWndDlg
->child
);
1814 for ( pWndTemp
= WIN_LockWndPtr( pWnd
);
1816 WIN_UpdateWndPtr( &pWndTemp
, pWndTemp
->next
) )
1818 if (pWndTemp
->dwStyle
& WS_GROUP
) WIN_UpdateWndPtr( &pWnd
, pWndTemp
);
1819 if (pWndTemp
== pWndCtrl
) break;
1821 WIN_ReleaseWndPtr( pWndTemp
);
1823 if (pWnd
== pWndCtrl
) break;
1824 if ((pWnd
->dwStyle
& WS_VISIBLE
) && !(pWnd
->dwStyle
& WS_DISABLED
))
1826 WIN_UpdateWndPtr(&pWndLast
,pWnd
);
1827 if (!fPrevious
) break;
1829 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
1831 retvalue
= pWndLast
->hwndSelf
;
1833 WIN_ReleaseWndPtr(pWndLast
);
1834 WIN_ReleaseWndPtr(pWnd
);
1836 WIN_ReleaseWndPtr(pWndCtrl
);
1837 WIN_ReleaseWndPtr(pWndDlg
);
1843 /***********************************************************************
1844 * GetNextDlgTabItem16 (USER.228)
1846 HWND16 WINAPI
GetNextDlgTabItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1849 return (HWND16
)GetNextDlgTabItem( hwndDlg
, hwndCtrl
, fPrevious
);
1853 /***********************************************************************
1854 * GetNextDlgTabItem32 (USER32.276)
1856 HWND WINAPI
GetNextDlgTabItem( HWND hwndDlg
, HWND hwndCtrl
,
1865 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1868 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
)))
1873 /* Make sure hwndCtrl is a top-level child */
1874 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1875 WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->parent
);
1876 if (pWndCtrl
->parent
!= pWndDlg
)
1884 /* No ctrl specified -> start from the beginning */
1885 if (!(pWndCtrl
= WIN_LockWndPtr(pWndDlg
->child
)))
1892 while (pWndCtrl
->next
) WIN_UpdateWndPtr(&pWndCtrl
,pWndCtrl
->next
);
1895 pWndLast
= WIN_LockWndPtr(pWndCtrl
);
1896 pWnd
= WIN_LockWndPtr(pWndCtrl
->next
);
1899 if (!pWnd
) pWnd
= WIN_LockWndPtr(pWndDlg
->child
);
1900 if (pWnd
== pWndCtrl
) break;
1901 if ((pWnd
->dwStyle
& WS_TABSTOP
) && (pWnd
->dwStyle
& WS_VISIBLE
) &&
1902 !(pWnd
->dwStyle
& WS_DISABLED
))
1904 WIN_UpdateWndPtr(&pWndLast
,pWnd
);
1905 if (!fPrevious
) break;
1907 WIN_UpdateWndPtr(&pWnd
,pWnd
->next
);
1909 retvalue
= pWndLast
->hwndSelf
;
1911 WIN_ReleaseWndPtr(pWndLast
);
1912 WIN_ReleaseWndPtr(pWnd
);
1914 WIN_ReleaseWndPtr(pWndCtrl
);
1915 WIN_ReleaseWndPtr(pWndDlg
);
1922 /**********************************************************************
1923 * DIALOG_DlgDirSelect
1925 * Helper function for DlgDirSelect*
1927 static BOOL
DIALOG_DlgDirSelect( HWND hwnd
, LPSTR str
, INT len
,
1928 INT id
, BOOL win32
, BOOL unicode
,
1934 HWND listbox
= GetDlgItem( hwnd
, id
);
1936 TRACE("%04x '%s' %d\n", hwnd
, str
, id
);
1937 if (!listbox
) return FALSE
;
1940 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL
1941 : LB_GETCURSEL
, 0, 0 );
1942 if (item
== LB_ERR
) return FALSE
;
1943 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN
1944 : LB_GETTEXTLEN
, 0, 0 );
1945 if (size
== LB_ERR
) return FALSE
;
1949 item
= SendMessageA(listbox
, combo
? CB_GETCURSEL16
1950 : LB_GETCURSEL16
, 0, 0 );
1951 if (item
== LB_ERR
) return FALSE
;
1952 size
= SendMessageA(listbox
, combo
? CB_GETLBTEXTLEN16
1953 : LB_GETTEXTLEN16
, 0, 0 );
1954 if (size
== LB_ERR
) return FALSE
;
1957 if (!(buffer
= SEGPTR_ALLOC( size
+1 ))) return FALSE
;
1960 SendMessageA( listbox
, combo
? CB_GETLBTEXT
: LB_GETTEXT
,
1961 item
, (LPARAM
)buffer
);
1963 SendMessage16( listbox
, combo
? CB_GETLBTEXT16
: LB_GETTEXT16
,
1964 item
, (LPARAM
)SEGPTR_GET(buffer
) );
1966 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1968 if (buffer
[1] == '-') /* drive */
1976 buffer
[strlen(buffer
)-1] = '\\';
1982 if (unicode
) lstrcpynAtoW( (LPWSTR
)str
, ptr
, len
);
1983 else lstrcpynA( str
, ptr
, len
);
1984 SEGPTR_FREE( buffer
);
1985 TRACE("Returning %d '%s'\n", ret
, str
);
1990 /**********************************************************************
1993 * Helper function for DlgDirList*
1995 static INT
DIALOG_DlgDirList( HWND hDlg
, LPSTR spec
, INT idLBox
,
1996 INT idStatic
, UINT attrib
, BOOL combo
)
2000 LPSTR orig_spec
= spec
;
2002 #define SENDMSG(msg,wparam,lparam) \
2003 ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
2004 : SendMessageA( hwnd, msg, wparam, lparam ))
2006 TRACE("%04x '%s' %d %d %04x\n",
2007 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
2009 if (spec
&& spec
[0] && (spec
[1] == ':'))
2011 drive
= toupper( spec
[0] ) - 'A';
2013 if (!DRIVE_SetCurrentDrive( drive
)) return FALSE
;
2015 else drive
= DRIVE_GetCurrentDrive();
2017 /* If the path exists and is a directory, chdir to it */
2018 if (!spec
|| !spec
[0] || DRIVE_Chdir( drive
, spec
)) spec
= "*.*";
2023 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
2024 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
2029 if (!DRIVE_Chdir( drive
, spec
))
2031 *p
= sep
; /* Restore the original spec */
2038 TRACE("path=%c:\\%s mask=%s\n",
2039 'A' + drive
, DRIVE_GetDosCwd(drive
), spec
);
2041 if (idLBox
&& ((hwnd
= GetDlgItem( hDlg
, idLBox
)) != 0))
2043 SENDMSG( combo
? CB_RESETCONTENT
: LB_RESETCONTENT
, 0, 0 );
2044 if (attrib
& DDL_DIRECTORY
)
2046 if (!(attrib
& DDL_EXCLUSIVE
))
2048 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2049 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
2050 (LPARAM
)spec
) == LB_ERR
)
2053 if (SENDMSG( combo
? CB_DIR
: LB_DIR
,
2054 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
2055 (LPARAM
)"*.*" ) == LB_ERR
)
2060 if (SENDMSG( combo
? CB_DIR
: LB_DIR
, attrib
,
2061 (LPARAM
)spec
) == LB_ERR
)
2066 if (idStatic
&& ((hwnd
= GetDlgItem( hDlg
, idStatic
)) != 0))
2069 int drive
= DRIVE_GetCurrentDrive();
2070 strcpy( temp
, "A:\\" );
2072 lstrcpynA( temp
+ 3, DRIVE_GetDosCwd(drive
), sizeof(temp
)-3 );
2074 /* Can't use PostMessage() here, because the string is on the stack */
2075 SetDlgItemTextA( hDlg
, idStatic
, temp
);
2078 if (orig_spec
&& (spec
!= orig_spec
))
2080 /* Update the original file spec */
2082 while ((*orig_spec
++ = *p
++));
2090 /**********************************************************************
2091 * DIALOG_DlgDirListW
2093 * Helper function for DlgDirList*32W
2095 static INT
DIALOG_DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2096 INT idStatic
, UINT attrib
, BOOL combo
)
2100 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
2101 INT ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
2103 lstrcpyAtoW( spec
, specA
);
2104 HeapFree( GetProcessHeap(), 0, specA
);
2107 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
2111 /**********************************************************************
2112 * DlgDirSelect (USER.99)
2114 BOOL16 WINAPI
DlgDirSelect16( HWND16 hwnd
, LPSTR str
, INT16 id
)
2116 return DlgDirSelectEx16( hwnd
, str
, 128, id
);
2120 /**********************************************************************
2121 * DlgDirSelectComboBox (USER.194)
2123 BOOL16 WINAPI
DlgDirSelectComboBox16( HWND16 hwnd
, LPSTR str
, INT16 id
)
2125 return DlgDirSelectComboBoxEx16( hwnd
, str
, 128, id
);
2129 /**********************************************************************
2130 * DlgDirSelectEx16 (USER.422)
2132 BOOL16 WINAPI
DlgDirSelectEx16( HWND16 hwnd
, LPSTR str
, INT16 len
, INT16 id
)
2134 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, FALSE
);
2138 /**********************************************************************
2139 * DlgDirSelectEx32A (USER32.149)
2141 BOOL WINAPI
DlgDirSelectExA( HWND hwnd
, LPSTR str
, INT len
, INT id
)
2143 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, FALSE
);
2147 /**********************************************************************
2148 * DlgDirSelectEx32W (USER32.150)
2150 BOOL WINAPI
DlgDirSelectExW( HWND hwnd
, LPWSTR str
, INT len
, INT id
)
2152 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, FALSE
);
2156 /**********************************************************************
2157 * DlgDirSelectComboBoxEx16 (USER.423)
2159 BOOL16 WINAPI
DlgDirSelectComboBoxEx16( HWND16 hwnd
, LPSTR str
, INT16 len
,
2162 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, TRUE
);
2166 /**********************************************************************
2167 * DlgDirSelectComboBoxEx32A (USER32.147)
2169 BOOL WINAPI
DlgDirSelectComboBoxExA( HWND hwnd
, LPSTR str
, INT len
,
2172 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, TRUE
);
2176 /**********************************************************************
2177 * DlgDirSelectComboBoxEx32W (USER32.148)
2179 BOOL WINAPI
DlgDirSelectComboBoxExW( HWND hwnd
, LPWSTR str
, INT len
,
2182 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, TRUE
);
2186 /**********************************************************************
2187 * DlgDirList16 (USER.100)
2189 INT16 WINAPI
DlgDirList16( HWND16 hDlg
, LPSTR spec
, INT16 idLBox
,
2190 INT16 idStatic
, UINT16 attrib
)
2192 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2196 /**********************************************************************
2197 * DlgDirList32A (USER32.143)
2199 INT WINAPI
DlgDirListA( HWND hDlg
, LPSTR spec
, INT idLBox
,
2200 INT idStatic
, UINT attrib
)
2202 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2206 /**********************************************************************
2207 * DlgDirList32W (USER32.146)
2209 INT WINAPI
DlgDirListW( HWND hDlg
, LPWSTR spec
, INT idLBox
,
2210 INT idStatic
, UINT attrib
)
2212 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
2216 /**********************************************************************
2217 * DlgDirListComboBox16 (USER.195)
2219 INT16 WINAPI
DlgDirListComboBox16( HWND16 hDlg
, LPSTR spec
, INT16 idCBox
,
2220 INT16 idStatic
, UINT16 attrib
)
2222 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2226 /**********************************************************************
2227 * DlgDirListComboBox32A (USER32.144)
2229 INT WINAPI
DlgDirListComboBoxA( HWND hDlg
, LPSTR spec
, INT idCBox
,
2230 INT idStatic
, UINT attrib
)
2232 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
2236 /**********************************************************************
2237 * DlgDirListComboBox32W (USER32.145)
2239 INT WINAPI
DlgDirListComboBoxW( HWND hDlg
, LPWSTR spec
, INT idCBox
,
2240 INT idStatic
, UINT attrib
)
2242 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);