4 * Copyright 1993, 1994, 1996 Alexandre Julliard
22 #include "sysmetrics.h"
26 /* Dialog control information */
63 /* Dialog base units */
64 static WORD xBaseUnit
= 0, yBaseUnit
= 0;
67 /***********************************************************************
70 * Initialisation of the dialog manager.
72 BOOL32
DIALOG_Init(void)
77 /* Calculate the dialog base units */
79 if (!(hdc
= CreateDC16( "DISPLAY", NULL
, NULL
, NULL
))) return FALSE
;
80 GetTextMetrics16( hdc
, &tm
);
82 xBaseUnit
= tm
.tmAveCharWidth
;
83 yBaseUnit
= tm
.tmHeight
;
85 /* Dialog units are based on a proportional system font */
86 /* so we adjust them a bit for a fixed font. */
87 if (!(tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
))
88 xBaseUnit
= xBaseUnit
* 5 / 4;
90 TRACE(dialog
, "base units = %d,%d\n",
91 xBaseUnit
, yBaseUnit
);
96 /***********************************************************************
99 * Return the class and text of the control pointed to by ptr,
100 * fill the header structure and return a pointer to the next control.
102 static LPCSTR
DIALOG_GetControl16( LPCSTR p
, DLG_CONTROL_INFO
*info
)
104 static char buffer
[10];
107 info
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
108 info
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
109 info
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
110 info
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
111 info
->id
= GET_WORD(p
); p
+= sizeof(WORD
);
112 info
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
119 case 0x80: strcpy( buffer
, "BUTTON" ); break;
120 case 0x81: strcpy( buffer
, "EDIT" ); break;
121 case 0x82: strcpy( buffer
, "STATIC" ); break;
122 case 0x83: strcpy( buffer
, "LISTBOX" ); break;
123 case 0x84: strcpy( buffer
, "SCROLLBAR" ); break;
124 case 0x85: strcpy( buffer
, "COMBOBOX" ); break;
125 default: buffer
[0] = '\0'; break;
127 info
->className
= buffer
;
136 int_id
= ((BYTE
)*p
== 0xff);
139 /* Integer id, not documented (?). Only works for SS_ICON controls */
140 info
->windowName
= (LPCSTR
)(UINT32
)GET_WORD(p
+1);
145 info
->windowName
= p
;
149 info
->data
= (LPVOID
)(*p
? p
+ 1 : NULL
); /* FIXME: should be a segptr */
153 TRACE(dialog
," %s %04x %d, %d, %d, %d, %d, %08lx, %08lx\n",
154 info
->className
, LOWORD(info
->windowName
),
155 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
156 info
->style
, (DWORD
)info
->data
);
158 TRACE(dialog
," %s '%s' %d, %d, %d, %d, %d, %08lx, %08lx\n",
159 info
->className
, info
->windowName
,
160 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
161 info
->style
, (DWORD
)info
->data
);
167 /***********************************************************************
168 * DIALOG_GetControl32
170 * Return the class and text of the control pointed to by ptr,
171 * fill the header structure and return a pointer to the next control.
173 static const WORD
*DIALOG_GetControl32( const WORD
*p
, DLG_CONTROL_INFO
*info
,
178 info
->helpId
= GET_DWORD(p
); p
+= 2;
179 info
->exStyle
= GET_DWORD(p
); p
+= 2;
180 info
->style
= GET_DWORD(p
); p
+= 2;
185 info
->style
= GET_DWORD(p
); p
+= 2;
186 info
->exStyle
= GET_DWORD(p
); p
+= 2;
188 info
->x
= GET_WORD(p
); p
++;
189 info
->y
= GET_WORD(p
); p
++;
190 info
->cx
= GET_WORD(p
); p
++;
191 info
->cy
= GET_WORD(p
); p
++;
195 /* id is a DWORD for DIALOGEX */
196 info
->id
= GET_DWORD(p
);
201 info
->id
= GET_WORD(p
);
205 if (GET_WORD(p
) == 0xffff)
207 static const WCHAR class_names
[6][10] =
209 { 'B','u','t','t','o','n', }, /* 0x80 */
210 { 'E','d','i','t', }, /* 0x81 */
211 { 'S','t','a','t','i','c', }, /* 0x82 */
212 { 'L','i','s','t','B','o','x', }, /* 0x83 */
213 { 'S','c','r','o','l','l','B','a','r', }, /* 0x84 */
214 { 'C','o','m','b','o','B','o','x', } /* 0x85 */
216 WORD id
= GET_WORD(p
+1);
217 if ((id
>= 0x80) && (id
<= 0x85))
218 info
->className
= (LPCSTR
)class_names
[id
- 0x80];
221 info
->className
= NULL
;
222 ERR( dialog
, "Unknown built-in class id %04x\n", id
);
228 info
->className
= (LPCSTR
)p
;
229 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
232 if (GET_WORD(p
) == 0xffff) /* Is it an integer id? */
234 info
->windowName
= (LPCSTR
)(UINT32
)GET_WORD(p
+ 1);
239 info
->windowName
= (LPCSTR
)p
;
240 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
243 TRACE(dialog
," %s %s %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
244 debugstr_w( (LPCWSTR
)info
->className
),
245 debugres_w( (LPCWSTR
)info
->windowName
),
246 info
->id
, info
->x
, info
->y
, info
->cx
, info
->cy
,
247 info
->style
, info
->exStyle
, info
->helpId
);
251 if (TRACE_ON(dialog
))
253 WORD i
, count
= GET_WORD(p
) / sizeof(WORD
);
254 TRACE(dialog
, " BEGIN\n");
256 for (i
= 0; i
< count
; i
++) DUMP( "%04x,", GET_WORD(p
+i
+1) );
258 TRACE(dialog
, " END\n" );
260 info
->data
= (LPVOID
)(p
+ 1);
261 p
+= GET_WORD(p
) / sizeof(WORD
);
263 else info
->data
= NULL
;
266 /* Next control is on dword boundary */
267 return (const WORD
*)((((int)p
) + 3) & ~3);
271 /***********************************************************************
272 * DIALOG_CreateControls
274 * Create the control windows for a dialog.
276 static BOOL32
DIALOG_CreateControls( WND
*pWnd
, LPCSTR
template,
277 const DLG_TEMPLATE
*dlgTemplate
,
278 HINSTANCE32 hInst
, BOOL32 win32
)
280 DIALOGINFO
*dlgInfo
= (DIALOGINFO
*)pWnd
->wExtra
;
281 DLG_CONTROL_INFO info
;
282 HWND32 hwndCtrl
, hwndDefButton
= 0;
283 INT32 items
= dlgTemplate
->nbItems
;
285 TRACE(dialog
, " BEGIN\n" );
290 HINSTANCE16 instance
;
291 template = DIALOG_GetControl16( template, &info
);
292 if (HIWORD(info
.className
) && !strcmp( info
.className
, "EDIT") &&
293 ((pWnd
->dwStyle
& DS_LOCALEDIT
) != DS_LOCALEDIT
))
295 if (!dlgInfo
->hDialogHeap
)
297 dlgInfo
->hDialogHeap
= GlobalAlloc16(GMEM_FIXED
, 0x10000);
298 if (!dlgInfo
->hDialogHeap
)
300 ERR(dialog
, "Insufficient memory to create heap for edit control\n" );
303 LocalInit(dlgInfo
->hDialogHeap
, 0, 0xffff);
305 instance
= dlgInfo
->hDialogHeap
;
307 else instance
= (HINSTANCE16
)hInst
;
309 hwndCtrl
= CreateWindowEx16( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
310 info
.className
, info
.windowName
,
311 info
.style
| WS_CHILD
,
312 info
.x
* dlgInfo
->xBaseUnit
/ 4,
313 info
.y
* dlgInfo
->yBaseUnit
/ 8,
314 info
.cx
* dlgInfo
->xBaseUnit
/ 4,
315 info
.cy
* dlgInfo
->yBaseUnit
/ 8,
316 pWnd
->hwndSelf
, (HMENU16
)info
.id
,
317 instance
, info
.data
);
321 template = (LPCSTR
)DIALOG_GetControl32( (WORD
*)template, &info
,
322 dlgTemplate
->dialogEx
);
323 hwndCtrl
= CreateWindowEx32W( info
.exStyle
| WS_EX_NOPARENTNOTIFY
,
324 (LPCWSTR
)info
.className
,
325 (LPCWSTR
)info
.windowName
,
326 info
.style
| WS_CHILD
,
327 info
.x
* dlgInfo
->xBaseUnit
/ 4,
328 info
.y
* dlgInfo
->yBaseUnit
/ 8,
329 info
.cx
* dlgInfo
->xBaseUnit
/ 4,
330 info
.cy
* dlgInfo
->yBaseUnit
/ 8,
331 pWnd
->hwndSelf
, (HMENU32
)info
.id
,
334 if (!hwndCtrl
) return FALSE
;
336 /* Send initialisation messages to the control */
337 if (dlgInfo
->hUserFont
) SendMessage32A( hwndCtrl
, WM_SETFONT
,
338 (WPARAM32
)dlgInfo
->hUserFont
, 0 );
339 if (SendMessage32A(hwndCtrl
, WM_GETDLGCODE
, 0, 0) & DLGC_DEFPUSHBUTTON
)
341 /* If there's already a default push-button, set it back */
342 /* to normal and use this one instead. */
344 SendMessage32A( hwndDefButton
, BM_SETSTYLE32
,
345 BS_PUSHBUTTON
,FALSE
);
346 hwndDefButton
= hwndCtrl
;
347 dlgInfo
->idResult
= GetWindowWord32( hwndCtrl
, GWW_ID
);
350 TRACE(dialog
, " END\n" );
355 /***********************************************************************
356 * DIALOG_ParseTemplate16
358 * Fill a DLG_TEMPLATE structure from the dialog template, and return
359 * a pointer to the first control.
361 static LPCSTR
DIALOG_ParseTemplate16( LPCSTR p
, DLG_TEMPLATE
* result
)
363 result
->style
= GET_DWORD(p
); p
+= sizeof(DWORD
);
365 result
->nbItems
= *p
++;
366 result
->x
= GET_WORD(p
); p
+= sizeof(WORD
);
367 result
->y
= GET_WORD(p
); p
+= sizeof(WORD
);
368 result
->cx
= GET_WORD(p
); p
+= sizeof(WORD
);
369 result
->cy
= GET_WORD(p
); p
+= sizeof(WORD
);
370 TRACE(dialog
, "DIALOG %d, %d, %d, %d\n",
371 result
->x
, result
->y
, result
->cx
, result
->cy
);
372 TRACE(dialog
, " STYLE %08lx\n", result
->style
);
374 /* Get the menu name */
379 result
->menuName
= 0;
383 result
->menuName
= (LPCSTR
)(UINT32
)GET_WORD( p
+ 1 );
385 TRACE(dialog
, " MENU %04x\n", LOWORD(result
->menuName
) );
388 result
->menuName
= p
;
389 TRACE(dialog
, " MENU '%s'\n", p
);
394 /* Get the class name */
398 result
->className
= p
;
399 TRACE(dialog
, " CLASS '%s'\n", result
->className
);
401 else result
->className
= DIALOG_CLASS_ATOM
;
404 /* Get the window caption */
408 TRACE(dialog
, " CAPTION '%s'\n", result
->caption
);
410 /* Get the font name */
412 if (result
->style
& DS_SETFONT
)
414 result
->pointSize
= GET_WORD(p
);
416 result
->faceName
= p
;
418 TRACE(dialog
, " FONT %d,'%s'\n",
419 result
->pointSize
, result
->faceName
);
425 /***********************************************************************
426 * DIALOG_ParseTemplate32
428 * Fill a DLG_TEMPLATE structure from the dialog template, and return
429 * a pointer to the first control.
431 static LPCSTR
DIALOG_ParseTemplate32( LPCSTR
template, DLG_TEMPLATE
* result
)
433 const WORD
*p
= (const WORD
*)template;
435 result
->style
= GET_DWORD(p
); p
+= 2;
436 if (result
->style
== 0xffff0001) /* DIALOGEX resource */
438 result
->dialogEx
= TRUE
;
439 result
->helpId
= GET_DWORD(p
); p
+= 2;
440 result
->exStyle
= GET_DWORD(p
); p
+= 2;
441 result
->style
= GET_DWORD(p
); p
+= 2;
445 result
->dialogEx
= FALSE
;
447 result
->exStyle
= GET_DWORD(p
); p
+= 2;
449 result
->nbItems
= GET_WORD(p
); p
++;
450 result
->x
= GET_WORD(p
); p
++;
451 result
->y
= GET_WORD(p
); p
++;
452 result
->cx
= GET_WORD(p
); p
++;
453 result
->cy
= GET_WORD(p
); p
++;
454 TRACE( dialog
, "DIALOG%s %d, %d, %d, %d, %ld\n",
455 result
->dialogEx
? "EX" : "", result
->x
, result
->y
,
456 result
->cx
, result
->cy
, result
->helpId
);
457 TRACE( dialog
, " STYLE 0x%08lx\n", result
->style
);
458 TRACE( dialog
, " EXSTYLE 0x%08lx\n", result
->exStyle
);
460 /* Get the menu name */
465 result
->menuName
= NULL
;
469 result
->menuName
= (LPCSTR
)(UINT32
)GET_WORD( p
+ 1 );
471 TRACE(dialog
, " MENU %04x\n", LOWORD(result
->menuName
) );
474 result
->menuName
= (LPCSTR
)p
;
475 TRACE(dialog
, " MENU %s\n", debugstr_w( (LPCWSTR
)p
));
476 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
480 /* Get the class name */
485 result
->className
= DIALOG_CLASS_ATOM
;
489 result
->className
= (LPCSTR
)(UINT32
)GET_WORD( p
+ 1 );
491 TRACE(dialog
, " CLASS %04x\n", LOWORD(result
->className
) );
494 result
->className
= (LPCSTR
)p
;
495 TRACE(dialog
, " CLASS %s\n", debugstr_w( (LPCWSTR
)p
));
496 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
500 /* Get the window caption */
502 result
->caption
= (LPCSTR
)p
;
503 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
504 TRACE(dialog
, " CAPTION %s\n", debugstr_w( (LPCWSTR
)result
->caption
) );
506 /* Get the font name */
508 if (result
->style
& DS_SETFONT
)
510 result
->pointSize
= GET_WORD(p
);
512 if (result
->dialogEx
)
514 result
->weight
= GET_WORD(p
); p
++;
515 result
->italic
= LOBYTE(GET_WORD(p
)); p
++;
519 result
->weight
= FW_DONTCARE
;
520 result
->italic
= FALSE
;
522 result
->faceName
= (LPCSTR
)p
;
523 p
+= lstrlen32W( (LPCWSTR
)p
) + 1;
524 TRACE(dialog
, " FONT %d, %s, %d, %s\n",
525 result
->pointSize
, debugstr_w( (LPCWSTR
)result
->faceName
),
526 result
->weight
, result
->italic
? "TRUE" : "FALSE" );
529 /* First control is on dword boundary */
530 return (LPCSTR
)((((int)p
) + 3) & ~3);
534 /***********************************************************************
535 * DIALOG_CreateIndirect
537 HWND32
DIALOG_CreateIndirect( HINSTANCE32 hInst
, LPCSTR dlgTemplate
,
538 BOOL32 win32Template
, HWND32 owner
,
539 DLGPROC16 dlgProc
, LPARAM param
,
540 WINDOWPROCTYPE procType
)
547 DLG_TEMPLATE
template;
548 DIALOGINFO
* dlgInfo
;
549 WORD xUnit
= xBaseUnit
;
550 WORD yUnit
= yBaseUnit
;
552 /* Parse dialog template */
554 if (!dlgTemplate
) return 0;
556 dlgTemplate
= DIALOG_ParseTemplate32( dlgTemplate
, &template );
558 dlgTemplate
= DIALOG_ParseTemplate16( dlgTemplate
, &template );
562 if (template.menuName
)
566 LPSTR str
= SEGPTR_STRDUP( template.menuName
);
567 hMenu
= LoadMenu16( hInst
, SEGPTR_GET(str
) );
570 else hMenu
= LoadMenu32W( hInst
, (LPCWSTR
)template.menuName
);
573 /* Create custom font if needed */
575 if (template.style
& DS_SETFONT
)
577 /* The font height must be negative as it is a point size */
578 /* (see CreateFont() documentation in the Windows SDK). */
581 hFont
= CreateFont32W( -template.pointSize
, 0, 0, 0,
582 template.weight
, template.italic
, FALSE
,
583 FALSE
, DEFAULT_CHARSET
, 0, 0, PROOF_QUALITY
,
584 FF_DONTCARE
, (LPCWSTR
)template.faceName
);
586 hFont
= CreateFont16( -template.pointSize
, 0, 0, 0, FW_DONTCARE
,
587 FALSE
, FALSE
, FALSE
, DEFAULT_CHARSET
, 0, 0,
588 PROOF_QUALITY
, FF_DONTCARE
,
595 HDC32 hdc
= GetDC32(0);
596 oldFont
= SelectObject32( hdc
, hFont
);
597 GetTextMetrics16( hdc
, &tm
);
598 SelectObject32( hdc
, oldFont
);
599 ReleaseDC32( 0, hdc
);
600 xUnit
= tm
.tmAveCharWidth
;
602 if (!(tm
.tmPitchAndFamily
& TMPF_FIXED_PITCH
))
603 xBaseUnit
= xBaseUnit
* 5 / 4; /* See DIALOG_Init() */
607 /* Create dialog main window */
609 rect
.left
= rect
.top
= 0;
610 rect
.right
= template.cx
* xUnit
/ 4;
611 rect
.bottom
= template.cy
* yUnit
/ 8;
612 if (template.style
& DS_MODALFRAME
)
613 template.exStyle
|= WS_EX_DLGMODALFRAME
;
614 AdjustWindowRectEx32( &rect
, template.style
,
615 hMenu
? TRUE
: FALSE
, template.exStyle
);
616 rect
.right
-= rect
.left
;
617 rect
.bottom
-= rect
.top
;
619 if ((INT16
)template.x
== CW_USEDEFAULT16
)
621 rect
.left
= rect
.top
= (procType
== WIN_PROC_16
) ? CW_USEDEFAULT16
626 rect
.left
+= template.x
* xUnit
/ 4;
627 rect
.top
+= template.y
* yUnit
/ 8;
628 if ( !(template.style
& WS_CHILD
) )
632 if( !(template.style
& DS_ABSALIGN
) )
633 ClientToScreen32( owner
, (POINT32
*)&rect
);
635 /* try to fit it into the desktop */
637 if( (dX
= rect
.left
+ rect
.right
+ SYSMETRICS_CXDLGFRAME
638 - SYSMETRICS_CXSCREEN
) > 0 ) rect
.left
-= dX
;
639 if( (dY
= rect
.top
+ rect
.bottom
+ SYSMETRICS_CYDLGFRAME
640 - SYSMETRICS_CYSCREEN
) > 0 ) rect
.top
-= dY
;
641 if( rect
.left
< 0 ) rect
.left
= 0;
642 if( rect
.top
< 0 ) rect
.top
= 0;
646 if (procType
== WIN_PROC_16
)
647 hwnd
= CreateWindowEx16(template.exStyle
, template.className
,
648 template.caption
, template.style
& ~WS_VISIBLE
,
649 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
650 owner
, hMenu
, hInst
, NULL
);
652 hwnd
= CreateWindowEx32W(template.exStyle
, (LPCWSTR
)template.className
,
653 (LPCWSTR
)template.caption
,
654 template.style
& ~WS_VISIBLE
,
655 rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
656 owner
, hMenu
, hInst
, NULL
);
660 if (hFont
) DeleteObject32( hFont
);
661 if (hMenu
) DestroyMenu32( hMenu
);
664 wndPtr
= WIN_FindWndPtr( hwnd
);
665 wndPtr
->flags
|= WIN_ISDIALOG
;
666 wndPtr
->helpContext
= template.helpId
;
668 /* Initialise dialog extra data */
670 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
671 WINPROC_SetProc( &dlgInfo
->dlgProc
, dlgProc
, procType
, WIN_PROC_WINDOW
);
672 dlgInfo
->hUserFont
= hFont
;
673 dlgInfo
->hMenu
= hMenu
;
674 dlgInfo
->xBaseUnit
= xUnit
;
675 dlgInfo
->yBaseUnit
= yUnit
;
676 dlgInfo
->msgResult
= 0;
677 dlgInfo
->idResult
= 0;
679 dlgInfo
->hDialogHeap
= 0;
681 if (dlgInfo
->hUserFont
)
682 SendMessage32A( hwnd
, WM_SETFONT
, (WPARAM32
)dlgInfo
->hUserFont
, 0 );
684 /* Create controls */
686 if (DIALOG_CreateControls( wndPtr
, dlgTemplate
, &template,
687 hInst
, win32Template
))
689 /* Send initialisation messages and set focus */
691 dlgInfo
->hwndFocus
= GetNextDlgTabItem32( hwnd
, 0, FALSE
);
693 if (SendMessage32A( hwnd
, WM_INITDIALOG
, (WPARAM32
)dlgInfo
->hwndFocus
, param
))
694 SetFocus32( dlgInfo
->hwndFocus
);
696 if (template.style
& WS_VISIBLE
&& !(wndPtr
->dwStyle
& WS_VISIBLE
))
698 ShowWindow32( hwnd
, SW_SHOWNORMAL
); /* SW_SHOW doesn't always work */
699 UpdateWindow32( hwnd
);
704 if( IsWindow32(hwnd
) ) DestroyWindow32( hwnd
);
709 /***********************************************************************
710 * CreateDialog16 (USER.89)
712 HWND16 WINAPI
CreateDialog16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
713 HWND16 owner
, DLGPROC16 dlgProc
)
715 return CreateDialogParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
719 /***********************************************************************
720 * CreateDialogParam16 (USER.241)
722 HWND16 WINAPI
CreateDialogParam16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
723 HWND16 owner
, DLGPROC16 dlgProc
,
731 TRACE(dialog
, "%04x,%08lx,%04x,%08lx,%ld\n",
732 hInst
, (DWORD
)dlgTemplate
, owner
, (DWORD
)dlgProc
, param
);
734 if (!(hRsrc
= FindResource16( hInst
, dlgTemplate
, RT_DIALOG16
))) return 0;
735 if (!(hmem
= LoadResource16( hInst
, hRsrc
))) return 0;
736 if (!(data
= LockResource16( hmem
))) hwnd
= 0;
737 else hwnd
= CreateDialogIndirectParam16( hInst
, data
, owner
,
739 FreeResource16( hmem
);
744 /***********************************************************************
745 * CreateDialogParam32A (USER32.73)
747 HWND32 WINAPI
CreateDialogParam32A( HINSTANCE32 hInst
, LPCSTR name
,
748 HWND32 owner
, DLGPROC32 dlgProc
,
753 LPWSTR str
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
754 HWND32 hwnd
= CreateDialogParam32W( hInst
, str
, owner
, dlgProc
, param
);
755 HeapFree( GetProcessHeap(), 0, str
);
758 return CreateDialogParam32W( hInst
, (LPCWSTR
)name
, owner
, dlgProc
, param
);
762 /***********************************************************************
763 * CreateDialogParam32W (USER32.74)
765 HWND32 WINAPI
CreateDialogParam32W( HINSTANCE32 hInst
, LPCWSTR name
,
766 HWND32 owner
, DLGPROC32 dlgProc
,
769 HANDLE32 hrsrc
= FindResource32W( hInst
, name
, RT_DIALOG32W
);
770 if (!hrsrc
) return 0;
771 return CreateDialogIndirectParam32W( hInst
,
772 (LPVOID
)LoadResource32(hInst
, hrsrc
),
773 owner
, dlgProc
, param
);
777 /***********************************************************************
778 * CreateDialogIndirect16 (USER.219)
780 HWND16 WINAPI
CreateDialogIndirect16( HINSTANCE16 hInst
, LPCVOID dlgTemplate
,
781 HWND16 owner
, DLGPROC16 dlgProc
)
783 return CreateDialogIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0);
787 /***********************************************************************
788 * CreateDialogIndirectParam16 (USER.242)
790 HWND16 WINAPI
CreateDialogIndirectParam16( HINSTANCE16 hInst
,
792 HWND16 owner
, DLGPROC16 dlgProc
,
795 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, FALSE
, owner
,
796 dlgProc
, param
, WIN_PROC_16
);
800 /***********************************************************************
801 * CreateDialogIndirectParam32A (USER32.69)
803 HWND32 WINAPI
CreateDialogIndirectParam32A( HINSTANCE32 hInst
,
805 HWND32 owner
, DLGPROC32 dlgProc
,
808 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
809 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32A
);
813 /***********************************************************************
814 * CreateDialogIndirectParam32W (USER32.72)
816 HWND32 WINAPI
CreateDialogIndirectParam32W( HINSTANCE32 hInst
,
818 HWND32 owner
, DLGPROC32 dlgProc
,
821 return DIALOG_CreateIndirect( hInst
, dlgTemplate
, TRUE
, owner
,
822 (DLGPROC16
)dlgProc
, param
, WIN_PROC_32W
);
826 /***********************************************************************
829 INT32
DIALOG_DoDialogBox( HWND32 hwnd
, HWND32 owner
)
832 DIALOGINFO
* dlgInfo
;
836 /* Owner must be a top-level window */
837 owner
= WIN_GetTopParent( owner
);
838 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return -1;
839 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
840 EnableWindow32( owner
, FALSE
);
841 ShowWindow32( hwnd
, SW_SHOW
);
843 while (MSG_InternalGetMessage(&msg
, hwnd
, owner
, MSGF_DIALOGBOX
, PM_REMOVE
,
844 !(wndPtr
->dwStyle
& DS_NOIDLEMSG
) ))
846 if (!IsDialogMessage16( hwnd
, &msg
))
848 TranslateMessage16( &msg
);
849 DispatchMessage16( &msg
);
851 if (dlgInfo
->flags
& DF_END
) break;
853 retval
= dlgInfo
->idResult
;
854 EnableWindow32( owner
, TRUE
);
855 DestroyWindow32( hwnd
);
860 /***********************************************************************
861 * DialogBox16 (USER.87)
863 INT16 WINAPI
DialogBox16( HINSTANCE16 hInst
, SEGPTR dlgTemplate
,
864 HWND16 owner
, DLGPROC16 dlgProc
)
866 return DialogBoxParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
870 /***********************************************************************
871 * DialogBoxParam16 (USER.239)
873 INT16 WINAPI
DialogBoxParam16( HINSTANCE16 hInst
, SEGPTR
template,
874 HWND16 owner
, DLGPROC16 dlgProc
, LPARAM param
)
876 HWND16 hwnd
= CreateDialogParam16( hInst
, template, owner
, dlgProc
, param
);
877 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
882 /***********************************************************************
883 * DialogBoxParam32A (USER32.139)
885 INT32 WINAPI
DialogBoxParam32A( HINSTANCE32 hInst
, LPCSTR name
,
886 HWND32 owner
, DLGPROC32 dlgProc
, LPARAM param
)
888 HWND32 hwnd
= CreateDialogParam32A( hInst
, name
, owner
, dlgProc
, param
);
889 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
894 /***********************************************************************
895 * DialogBoxParam32W (USER32.140)
897 INT32 WINAPI
DialogBoxParam32W( HINSTANCE32 hInst
, LPCWSTR name
,
898 HWND32 owner
, DLGPROC32 dlgProc
, LPARAM param
)
900 HWND32 hwnd
= CreateDialogParam32W( hInst
, name
, owner
, dlgProc
, param
);
901 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
906 /***********************************************************************
907 * DialogBoxIndirect16 (USER.218)
909 INT16 WINAPI
DialogBoxIndirect16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
910 HWND16 owner
, DLGPROC16 dlgProc
)
912 return DialogBoxIndirectParam16( hInst
, dlgTemplate
, owner
, dlgProc
, 0 );
916 /***********************************************************************
917 * DialogBoxIndirectParam16 (USER.240)
919 INT16 WINAPI
DialogBoxIndirectParam16( HINSTANCE16 hInst
, HANDLE16 dlgTemplate
,
920 HWND16 owner
, DLGPROC16 dlgProc
,
926 if (!(ptr
= GlobalLock16( dlgTemplate
))) return -1;
927 hwnd
= CreateDialogIndirectParam16( hInst
, ptr
, owner
, dlgProc
, param
);
928 GlobalUnlock16( dlgTemplate
);
929 if (hwnd
) return (INT16
)DIALOG_DoDialogBox( hwnd
, owner
);
934 /***********************************************************************
935 * DialogBoxIndirectParam32A (USER32.136)
937 INT32 WINAPI
DialogBoxIndirectParam32A(HINSTANCE32 hInstance
, LPCVOID
template,
938 HWND32 owner
, DLGPROC32 dlgProc
,
941 HWND32 hwnd
= CreateDialogIndirectParam32A( hInstance
, template,
942 owner
, dlgProc
, param
);
943 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
948 /***********************************************************************
949 * DialogBoxIndirectParam32W (USER32.138)
951 INT32 WINAPI
DialogBoxIndirectParam32W(HINSTANCE32 hInstance
, LPCVOID
template,
952 HWND32 owner
, DLGPROC32 dlgProc
,
955 HWND32 hwnd
= CreateDialogIndirectParam32W( hInstance
, template,
956 owner
, dlgProc
, param
);
957 if (hwnd
) return DIALOG_DoDialogBox( hwnd
, owner
);
962 /***********************************************************************
963 * EndDialog16 (USER32.173)
965 BOOL16 WINAPI
EndDialog16( HWND16 hwnd
, INT16 retval
)
967 return EndDialog32( hwnd
, retval
);
971 /***********************************************************************
972 * EndDialog32 (USER.88)
974 BOOL32 WINAPI
EndDialog32( HWND32 hwnd
, INT32 retval
)
976 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
977 DIALOGINFO
* dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
979 TRACE(dialog
, "%04x %d\n", hwnd
, retval
);
983 dlgInfo
->idResult
= retval
;
984 dlgInfo
->flags
|= DF_END
;
990 /***********************************************************************
991 * DIALOG_IsDialogMessage
993 static BOOL32
DIALOG_IsDialogMessage( HWND32 hwnd
, HWND32 hwndDlg
,
994 UINT32 message
, WPARAM32 wParam
,
995 LPARAM lParam
, BOOL32
*translate
,
1000 *translate
= *dispatch
= FALSE
;
1002 if (message
== WM_PAINT
)
1004 /* Apparently, we have to handle this one as well */
1009 /* Only the key messages get special processing */
1010 if ((message
!= WM_KEYDOWN
) &&
1011 (message
!= WM_SYSCHAR
) &&
1012 (message
!= WM_CHAR
))
1015 dlgCode
= SendMessage32A( hwnd
, WM_GETDLGCODE
, 0, 0 );
1016 if (dlgCode
& DLGC_WANTMESSAGE
)
1018 *translate
= *dispatch
= TRUE
;
1025 if (dlgCode
& DLGC_WANTALLKEYS
) break;
1029 if (!(dlgCode
& DLGC_WANTTAB
))
1031 SendMessage32A( hwndDlg
, WM_NEXTDLGCTL
,
1032 (GetKeyState32(VK_SHIFT
) & 0x8000), 0 );
1039 if (!(dlgCode
& DLGC_WANTARROWS
))
1041 SetFocus32( GetNextDlgGroupItem32( hwndDlg
, GetFocus32(),
1049 if (!(dlgCode
& DLGC_WANTARROWS
))
1051 SetFocus32( GetNextDlgGroupItem32( hwndDlg
, GetFocus32(),
1058 SendMessage32A( hwndDlg
, WM_COMMAND
, IDCANCEL
,
1059 (LPARAM
)GetDlgItem32( hwndDlg
, IDCANCEL
) );
1064 DWORD dw
= SendMessage16( hwndDlg
, DM_GETDEFID
, 0, 0 );
1065 if (HIWORD(dw
) == DC_HASDEFID
)
1066 SendMessage32A( hwndDlg
, WM_COMMAND
,
1067 MAKEWPARAM( LOWORD(dw
), BN_CLICKED
),
1068 (LPARAM
)GetDlgItem32(hwndDlg
, LOWORD(dw
)));
1070 SendMessage32A( hwndDlg
, WM_COMMAND
, IDOK
,
1071 (LPARAM
)GetDlgItem32( hwndDlg
, IDOK
) );
1079 break; /* case WM_KEYDOWN */
1083 if (dlgCode
& (DLGC_WANTALLKEYS
| DLGC_WANTCHARS
)) break;
1087 if (dlgCode
& DLGC_WANTALLKEYS
) break;
1091 /* If we get here, the message has not been treated specially */
1092 /* and can be sent to its destination window. */
1098 /***********************************************************************
1099 * IsDialogMessage16 (USER.90)
1101 BOOL16 WINAPI
IsDialogMessage16( HWND16 hwndDlg
, LPMSG16 msg
)
1103 BOOL32 ret
, translate
, dispatch
;
1105 if ((hwndDlg
!= msg
->hwnd
) && !IsChild16( hwndDlg
, msg
->hwnd
))
1108 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1109 msg
->wParam
, msg
->lParam
,
1110 &translate
, &dispatch
);
1111 if (translate
) TranslateMessage16( msg
);
1112 if (dispatch
) DispatchMessage16( msg
);
1117 /***********************************************************************
1118 * IsDialogMessage32A (USER32.342)
1120 BOOL32 WINAPI
IsDialogMessage32A( HWND32 hwndDlg
, LPMSG32 msg
)
1122 BOOL32 ret
, translate
, dispatch
;
1124 if ((hwndDlg
!= msg
->hwnd
) && !IsChild32( hwndDlg
, msg
->hwnd
))
1127 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1128 msg
->wParam
, msg
->lParam
,
1129 &translate
, &dispatch
);
1130 if (translate
) TranslateMessage32( msg
);
1131 if (dispatch
) DispatchMessage32A( msg
);
1136 /***********************************************************************
1137 * IsDialogMessage32W (USER32.343)
1139 BOOL32 WINAPI
IsDialogMessage32W( HWND32 hwndDlg
, LPMSG32 msg
)
1141 BOOL32 ret
, translate
, dispatch
;
1143 if ((hwndDlg
!= msg
->hwnd
) && !IsChild32( hwndDlg
, msg
->hwnd
))
1146 ret
= DIALOG_IsDialogMessage( msg
->hwnd
, hwndDlg
, msg
->message
,
1147 msg
->wParam
, msg
->lParam
,
1148 &translate
, &dispatch
);
1149 if (translate
) TranslateMessage32( msg
);
1150 if (dispatch
) DispatchMessage32W( msg
);
1155 /****************************************************************
1156 * GetDlgCtrlID16 (USER.277)
1158 INT16 WINAPI
GetDlgCtrlID16( HWND16 hwnd
)
1160 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1161 if (wndPtr
) return wndPtr
->wIDmenu
;
1166 /****************************************************************
1167 * GetDlgCtrlID32 (USER32.234)
1169 INT32 WINAPI
GetDlgCtrlID32( HWND32 hwnd
)
1171 WND
*wndPtr
= WIN_FindWndPtr(hwnd
);
1172 if (wndPtr
) return wndPtr
->wIDmenu
;
1177 /***********************************************************************
1178 * GetDlgItem16 (USER.91)
1180 HWND16 WINAPI
GetDlgItem16( HWND16 hwndDlg
, INT16 id
)
1184 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1185 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1186 if (pWnd
->wIDmenu
== (UINT16
)id
) return pWnd
->hwndSelf
;
1191 /***********************************************************************
1192 * GetDlgItem32 (USER32.235)
1194 HWND32 WINAPI
GetDlgItem32( HWND32 hwndDlg
, INT32 id
)
1198 if (!(pWnd
= WIN_FindWndPtr( hwndDlg
))) return 0;
1199 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1200 if (pWnd
->wIDmenu
== (UINT16
)id
) return pWnd
->hwndSelf
;
1205 /*******************************************************************
1206 * SendDlgItemMessage16 (USER.101)
1208 LRESULT WINAPI
SendDlgItemMessage16( HWND16 hwnd
, INT16 id
, UINT16 msg
,
1209 WPARAM16 wParam
, LPARAM lParam
)
1211 HWND16 hwndCtrl
= GetDlgItem16( hwnd
, id
);
1212 if (hwndCtrl
) return SendMessage16( hwndCtrl
, msg
, wParam
, lParam
);
1217 /*******************************************************************
1218 * SendDlgItemMessage32A (USER32.452)
1220 LRESULT WINAPI
SendDlgItemMessage32A( HWND32 hwnd
, INT32 id
, UINT32 msg
,
1221 WPARAM32 wParam
, LPARAM lParam
)
1223 HWND32 hwndCtrl
= GetDlgItem32( hwnd
, id
);
1224 if (hwndCtrl
) return SendMessage32A( hwndCtrl
, msg
, wParam
, lParam
);
1229 /*******************************************************************
1230 * SendDlgItemMessage32W (USER32.453)
1232 LRESULT WINAPI
SendDlgItemMessage32W( HWND32 hwnd
, INT32 id
, UINT32 msg
,
1233 WPARAM32 wParam
, LPARAM lParam
)
1235 HWND32 hwndCtrl
= GetDlgItem32( hwnd
, id
);
1236 if (hwndCtrl
) return SendMessage32W( hwndCtrl
, msg
, wParam
, lParam
);
1241 /*******************************************************************
1242 * SetDlgItemText16 (USER.92)
1244 void WINAPI
SetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR lpString
)
1246 SendDlgItemMessage16( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1250 /*******************************************************************
1251 * SetDlgItemText32A (USER32.478)
1253 void WINAPI
SetDlgItemText32A( HWND32 hwnd
, INT32 id
, LPCSTR lpString
)
1255 SendDlgItemMessage32A( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1259 /*******************************************************************
1260 * SetDlgItemText32W (USER32.479)
1262 void WINAPI
SetDlgItemText32W( HWND32 hwnd
, INT32 id
, LPCWSTR lpString
)
1264 SendDlgItemMessage32W( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1268 /***********************************************************************
1269 * GetDlgItemText16 (USER.93)
1271 INT16 WINAPI
GetDlgItemText16( HWND16 hwnd
, INT16 id
, SEGPTR str
, UINT16 len
)
1273 return (INT16
)SendDlgItemMessage16( hwnd
, id
, WM_GETTEXT
,
1278 /***********************************************************************
1279 * GetDlgItemText32A (USER32.237)
1281 INT32 WINAPI
GetDlgItemText32A( HWND32 hwnd
, INT32 id
, LPSTR str
, UINT32 len
)
1283 return (INT32
)SendDlgItemMessage32A( hwnd
, id
, WM_GETTEXT
,
1288 /***********************************************************************
1289 * GetDlgItemText32W (USER32.238)
1291 INT32 WINAPI
GetDlgItemText32W( HWND32 hwnd
, INT32 id
, LPWSTR str
, UINT32 len
)
1293 return (INT32
)SendDlgItemMessage32W( hwnd
, id
, WM_GETTEXT
,
1298 /*******************************************************************
1299 * SetDlgItemInt16 (USER.94)
1301 void WINAPI
SetDlgItemInt16( HWND16 hwnd
, INT16 id
, UINT16 value
, BOOL16 fSigned
)
1303 return SetDlgItemInt32( hwnd
, (UINT32
)(UINT16
)id
, value
, fSigned
);
1307 /*******************************************************************
1308 * SetDlgItemInt32 (USER32.477)
1310 void WINAPI
SetDlgItemInt32( HWND32 hwnd
, INT32 id
, UINT32 value
,
1315 if (fSigned
) sprintf( str
, "%d", (INT32
)value
);
1316 else sprintf( str
, "%u", value
);
1317 SendDlgItemMessage32A( hwnd
, id
, WM_SETTEXT
, 0, (LPARAM
)str
);
1321 /***********************************************************************
1322 * GetDlgItemInt16 (USER.95)
1324 UINT16 WINAPI
GetDlgItemInt16( HWND16 hwnd
, INT16 id
, BOOL16
*translated
,
1330 if (translated
) *translated
= FALSE
;
1331 result
= GetDlgItemInt32( hwnd
, (UINT32
)(UINT16
)id
, &ok
, fSigned
);
1335 if (((INT32
)result
< -32767) || ((INT32
)result
> 32767)) return 0;
1339 if (result
> 65535) return 0;
1341 if (translated
) *translated
= TRUE
;
1342 return (UINT16
)result
;
1346 /***********************************************************************
1347 * GetDlgItemInt32 (USER32.236)
1349 UINT32 WINAPI
GetDlgItemInt32( HWND32 hwnd
, INT32 id
, BOOL32
*translated
,
1356 if (translated
) *translated
= FALSE
;
1357 if (!SendDlgItemMessage32A(hwnd
, id
, WM_GETTEXT
, sizeof(str
), (LPARAM
)str
))
1361 result
= strtol( str
, &endptr
, 10 );
1362 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1364 if (((result
== LONG_MIN
) || (result
== LONG_MAX
)) && (errno
==ERANGE
))
1369 result
= strtoul( str
, &endptr
, 10 );
1370 if (!endptr
|| (endptr
== str
)) /* Conversion was unsuccessful */
1372 if ((result
== ULONG_MAX
) && (errno
== ERANGE
)) return 0;
1374 if (translated
) *translated
= TRUE
;
1375 return (UINT32
)result
;
1379 /***********************************************************************
1380 * CheckDlgButton16 (USER.97)
1382 BOOL16 WINAPI
CheckDlgButton16( HWND16 hwnd
, INT16 id
, UINT16 check
)
1384 SendDlgItemMessage32A( hwnd
, id
, BM_SETCHECK32
, check
, 0 );
1389 /***********************************************************************
1390 * CheckDlgButton32 (USER32.45)
1392 BOOL32 WINAPI
CheckDlgButton32( HWND32 hwnd
, INT32 id
, UINT32 check
)
1394 SendDlgItemMessage32A( hwnd
, id
, BM_SETCHECK32
, check
, 0 );
1399 /***********************************************************************
1400 * IsDlgButtonChecked16 (USER.98)
1402 UINT16 WINAPI
IsDlgButtonChecked16( HWND16 hwnd
, UINT16 id
)
1404 return (UINT16
)SendDlgItemMessage32A( hwnd
, id
, BM_GETCHECK32
, 0, 0 );
1408 /***********************************************************************
1409 * IsDlgButtonChecked32 (USER32.344)
1411 UINT32 WINAPI
IsDlgButtonChecked32( HWND32 hwnd
, UINT32 id
)
1413 return (UINT32
)SendDlgItemMessage32A( hwnd
, id
, BM_GETCHECK32
, 0, 0 );
1417 /***********************************************************************
1418 * CheckRadioButton16 (USER.96)
1420 BOOL16 WINAPI
CheckRadioButton16( HWND16 hwndDlg
, UINT16 firstID
,
1421 UINT16 lastID
, UINT16 checkID
)
1423 return CheckRadioButton32( hwndDlg
, firstID
, lastID
, checkID
);
1427 /***********************************************************************
1428 * CheckRadioButton32 (USER32.48)
1430 BOOL32 WINAPI
CheckRadioButton32( HWND32 hwndDlg
, UINT32 firstID
,
1431 UINT32 lastID
, UINT32 checkID
)
1433 WND
*pWnd
= WIN_FindWndPtr( hwndDlg
);
1434 if (!pWnd
) return FALSE
;
1436 for (pWnd
= pWnd
->child
; pWnd
; pWnd
= pWnd
->next
)
1437 if ((pWnd
->wIDmenu
== firstID
) || (pWnd
->wIDmenu
== lastID
)) break;
1438 if (!pWnd
) return FALSE
;
1440 if (pWnd
->wIDmenu
== lastID
)
1441 lastID
= firstID
; /* Buttons are in reverse order */
1444 SendMessage32A( pWnd
->hwndSelf
, BM_SETCHECK32
,
1445 (pWnd
->wIDmenu
== checkID
), 0 );
1446 if (pWnd
->wIDmenu
== lastID
) break;
1453 /***********************************************************************
1454 * GetDialogBaseUnits (USER.243) (USER32.233)
1456 DWORD WINAPI
GetDialogBaseUnits(void)
1458 return MAKELONG( xBaseUnit
, yBaseUnit
);
1462 /***********************************************************************
1463 * MapDialogRect16 (USER.103)
1465 void WINAPI
MapDialogRect16( HWND16 hwnd
, LPRECT16 rect
)
1467 DIALOGINFO
* dlgInfo
;
1468 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1469 if (!wndPtr
) return;
1470 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1471 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
1472 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
1473 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
1474 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
1478 /***********************************************************************
1479 * MapDialogRect32 (USER32.382)
1481 void WINAPI
MapDialogRect32( HWND32 hwnd
, LPRECT32 rect
)
1483 DIALOGINFO
* dlgInfo
;
1484 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
1485 if (!wndPtr
) return;
1486 dlgInfo
= (DIALOGINFO
*)wndPtr
->wExtra
;
1487 rect
->left
= (rect
->left
* dlgInfo
->xBaseUnit
) / 4;
1488 rect
->right
= (rect
->right
* dlgInfo
->xBaseUnit
) / 4;
1489 rect
->top
= (rect
->top
* dlgInfo
->yBaseUnit
) / 8;
1490 rect
->bottom
= (rect
->bottom
* dlgInfo
->yBaseUnit
) / 8;
1494 /***********************************************************************
1495 * GetNextDlgGroupItem16 (USER.227)
1497 HWND16 WINAPI
GetNextDlgGroupItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1500 return (HWND16
)GetNextDlgGroupItem32( hwndDlg
, hwndCtrl
, fPrevious
);
1504 /***********************************************************************
1505 * GetNextDlgGroupItem32 (USER32.275)
1507 HWND32 WINAPI
GetNextDlgGroupItem32( HWND32 hwndDlg
, HWND32 hwndCtrl
,
1510 WND
*pWnd
, *pWndLast
, *pWndCtrl
, *pWndDlg
;
1512 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1515 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
))) return 0;
1516 /* Make sure hwndCtrl is a top-level child */
1517 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1518 pWndCtrl
= pWndCtrl
->parent
;
1519 if (pWndCtrl
->parent
!= pWndDlg
) return 0;
1523 /* No ctrl specified -> start from the beginning */
1524 if (!(pWndCtrl
= pWndDlg
->child
)) return 0;
1525 if (fPrevious
) while (pWndCtrl
->next
) pWndCtrl
= pWndCtrl
->next
;
1528 pWndLast
= pWndCtrl
;
1529 pWnd
= pWndCtrl
->next
;
1532 if (!pWnd
|| (pWnd
->dwStyle
& WS_GROUP
))
1534 /* Wrap-around to the beginning of the group */
1535 WND
*pWndStart
= pWndDlg
->child
;
1536 for (pWnd
= pWndStart
; pWnd
; pWnd
= pWnd
->next
)
1538 if (pWnd
->dwStyle
& WS_GROUP
) pWndStart
= pWnd
;
1539 if (pWnd
== pWndCtrl
) break;
1543 if (pWnd
== pWndCtrl
) break;
1544 if ((pWnd
->dwStyle
& WS_VISIBLE
) && !(pWnd
->dwStyle
& WS_DISABLED
))
1547 if (!fPrevious
) break;
1551 return pWndLast
->hwndSelf
;
1555 /***********************************************************************
1556 * GetNextDlgTabItem16 (USER.228)
1558 HWND16 WINAPI
GetNextDlgTabItem16( HWND16 hwndDlg
, HWND16 hwndCtrl
,
1561 return (HWND16
)GetNextDlgTabItem32( hwndDlg
, hwndCtrl
, fPrevious
);
1565 /***********************************************************************
1566 * GetNextDlgTabItem32 (USER32.276)
1568 HWND32 WINAPI
GetNextDlgTabItem32( HWND32 hwndDlg
, HWND32 hwndCtrl
,
1571 WND
*pWnd
, *pWndLast
, *pWndCtrl
, *pWndDlg
;
1573 if (!(pWndDlg
= WIN_FindWndPtr( hwndDlg
))) return 0;
1576 if (!(pWndCtrl
= WIN_FindWndPtr( hwndCtrl
))) return 0;
1577 /* Make sure hwndCtrl is a top-level child */
1578 while ((pWndCtrl
->dwStyle
& WS_CHILD
) && (pWndCtrl
->parent
!= pWndDlg
))
1579 pWndCtrl
= pWndCtrl
->parent
;
1580 if (pWndCtrl
->parent
!= pWndDlg
) return 0;
1584 /* No ctrl specified -> start from the beginning */
1585 if (!(pWndCtrl
= pWndDlg
->child
)) return 0;
1586 if (!fPrevious
) while (pWndCtrl
->next
) pWndCtrl
= pWndCtrl
->next
;
1589 pWndLast
= pWndCtrl
;
1590 pWnd
= pWndCtrl
->next
;
1593 if (!pWnd
) pWnd
= pWndDlg
->child
;
1594 if (pWnd
== pWndCtrl
) break;
1595 if ((pWnd
->dwStyle
& WS_TABSTOP
) && (pWnd
->dwStyle
& WS_VISIBLE
) &&
1596 !(pWnd
->dwStyle
& WS_DISABLED
))
1599 if (!fPrevious
) break;
1603 return pWndLast
->hwndSelf
;
1607 /**********************************************************************
1608 * DIALOG_DlgDirSelect
1610 * Helper function for DlgDirSelect*
1612 static BOOL32
DIALOG_DlgDirSelect( HWND32 hwnd
, LPSTR str
, INT32 len
,
1613 INT32 id
, BOOL32 win32
, BOOL32 unicode
,
1619 HWND32 listbox
= GetDlgItem32( hwnd
, id
);
1621 TRACE(dialog
, "%04x '%s' %d\n", hwnd
, str
, id
);
1622 if (!listbox
) return FALSE
;
1625 item
= SendMessage32A(listbox
, combo
? CB_GETCURSEL32
1626 : LB_GETCURSEL32
, 0, 0 );
1627 if (item
== LB_ERR
) return FALSE
;
1628 size
= SendMessage32A(listbox
, combo
? CB_GETLBTEXTLEN32
1629 : LB_GETTEXTLEN32
, 0, 0 );
1630 if (size
== LB_ERR
) return FALSE
;
1634 item
= SendMessage32A(listbox
, combo
? CB_GETCURSEL16
1635 : LB_GETCURSEL16
, 0, 0 );
1636 if (item
== LB_ERR
) return FALSE
;
1637 size
= SendMessage32A(listbox
, combo
? CB_GETLBTEXTLEN16
1638 : LB_GETTEXTLEN16
, 0, 0 );
1639 if (size
== LB_ERR
) return FALSE
;
1642 if (!(buffer
= SEGPTR_ALLOC( size
+1 ))) return FALSE
;
1645 SendMessage32A( listbox
, combo
? CB_GETLBTEXT32
: LB_GETTEXT32
,
1646 item
, (LPARAM
)buffer
);
1648 SendMessage16( listbox
, combo
? CB_GETLBTEXT16
: LB_GETTEXT16
,
1649 item
, (LPARAM
)SEGPTR_GET(buffer
) );
1651 if ((ret
= (buffer
[0] == '['))) /* drive or directory */
1653 if (buffer
[1] == '-') /* drive */
1661 buffer
[strlen(buffer
)-1] = '\\';
1667 if (unicode
) lstrcpynAtoW( (LPWSTR
)str
, ptr
, len
);
1668 else lstrcpyn32A( str
, ptr
, len
);
1669 SEGPTR_FREE( buffer
);
1670 TRACE(dialog
, "Returning %d '%s'\n", ret
, str
);
1675 /**********************************************************************
1678 * Helper function for DlgDirList*
1680 static INT32
DIALOG_DlgDirList( HWND32 hDlg
, LPSTR spec
, INT32 idLBox
,
1681 INT32 idStatic
, UINT32 attrib
, BOOL32 combo
)
1685 LPSTR orig_spec
= spec
;
1687 #define SENDMSG(msg,wparam,lparam) \
1688 ((attrib & DDL_POSTMSGS) ? PostMessage32A( hwnd, msg, wparam, lparam ) \
1689 : SendMessage32A( hwnd, msg, wparam, lparam ))
1691 TRACE(dialog
, "%04x '%s' %d %d %04x\n",
1692 hDlg
, spec
? spec
: "NULL", idLBox
, idStatic
, attrib
);
1694 if (spec
&& spec
[0] && (spec
[1] == ':'))
1696 drive
= toupper( spec
[0] ) - 'A';
1698 if (!DRIVE_SetCurrentDrive( drive
)) return FALSE
;
1700 else drive
= DRIVE_GetCurrentDrive();
1702 /* If the path exists and is a directory, chdir to it */
1703 if (!spec
|| !spec
[0] || DRIVE_Chdir( drive
, spec
)) spec
= "*.*";
1708 if ((p2
= strrchr( p
, '\\' ))) p
= p2
;
1709 if ((p2
= strrchr( p
, '/' ))) p
= p2
;
1714 if (!DRIVE_Chdir( drive
, spec
))
1716 *p
= sep
; /* Restore the original spec */
1723 TRACE(dialog
, "path=%c:\\%s mask=%s\n",
1724 'A' + drive
, DRIVE_GetDosCwd(drive
), spec
);
1726 if (idLBox
&& ((hwnd
= GetDlgItem32( hDlg
, idLBox
)) != 0))
1728 SENDMSG( combo
? CB_RESETCONTENT32
: LB_RESETCONTENT32
, 0, 0 );
1729 if (attrib
& DDL_DIRECTORY
)
1731 if (!(attrib
& DDL_EXCLUSIVE
))
1733 if (SENDMSG( combo
? CB_DIR32
: LB_DIR32
,
1734 attrib
& ~(DDL_DIRECTORY
| DDL_DRIVES
),
1735 (LPARAM
)spec
) == LB_ERR
)
1738 if (SENDMSG( combo
? CB_DIR32
: LB_DIR32
,
1739 (attrib
& (DDL_DIRECTORY
| DDL_DRIVES
)) | DDL_EXCLUSIVE
,
1740 (LPARAM
)"*.*" ) == LB_ERR
)
1745 if (SENDMSG( combo
? CB_DIR32
: LB_DIR32
, attrib
,
1746 (LPARAM
)spec
) == LB_ERR
)
1751 if (idStatic
&& ((hwnd
= GetDlgItem32( hDlg
, idStatic
)) != 0))
1754 int drive
= DRIVE_GetCurrentDrive();
1755 strcpy( temp
, "A:\\" );
1757 lstrcpyn32A( temp
+ 3, DRIVE_GetDosCwd(drive
), sizeof(temp
)-3 );
1758 CharLower32A( temp
);
1759 /* Can't use PostMessage() here, because the string is on the stack */
1760 SetDlgItemText32A( hDlg
, idStatic
, temp
);
1763 if (orig_spec
&& (spec
!= orig_spec
))
1765 /* Update the original file spec */
1767 while ((*orig_spec
++ = *p
++));
1775 /**********************************************************************
1776 * DIALOG_DlgDirListW
1778 * Helper function for DlgDirList*32W
1780 static INT32
DIALOG_DlgDirListW( HWND32 hDlg
, LPWSTR spec
, INT32 idLBox
,
1781 INT32 idStatic
, UINT32 attrib
, BOOL32 combo
)
1785 LPSTR specA
= HEAP_strdupWtoA( GetProcessHeap(), 0, spec
);
1786 INT32 ret
= DIALOG_DlgDirList( hDlg
, specA
, idLBox
, idStatic
,
1788 lstrcpyAtoW( spec
, specA
);
1789 HeapFree( GetProcessHeap(), 0, specA
);
1792 return DIALOG_DlgDirList( hDlg
, NULL
, idLBox
, idStatic
, attrib
, combo
);
1796 /**********************************************************************
1797 * DlgDirSelect (USER.99)
1799 BOOL16 WINAPI
DlgDirSelect( HWND16 hwnd
, LPSTR str
, INT16 id
)
1801 return DlgDirSelectEx16( hwnd
, str
, 128, id
);
1805 /**********************************************************************
1806 * DlgDirSelectComboBox (USER.194)
1808 BOOL16 WINAPI
DlgDirSelectComboBox( HWND16 hwnd
, LPSTR str
, INT16 id
)
1810 return DlgDirSelectComboBoxEx16( hwnd
, str
, 128, id
);
1814 /**********************************************************************
1815 * DlgDirSelectEx16 (USER.422)
1817 BOOL16 WINAPI
DlgDirSelectEx16( HWND16 hwnd
, LPSTR str
, INT16 len
, INT16 id
)
1819 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, FALSE
);
1823 /**********************************************************************
1824 * DlgDirSelectEx32A (USER32.149)
1826 BOOL32 WINAPI
DlgDirSelectEx32A( HWND32 hwnd
, LPSTR str
, INT32 len
, INT32 id
)
1828 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, FALSE
);
1832 /**********************************************************************
1833 * DlgDirSelectEx32W (USER32.150)
1835 BOOL32 WINAPI
DlgDirSelectEx32W( HWND32 hwnd
, LPWSTR str
, INT32 len
, INT32 id
)
1837 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, FALSE
);
1841 /**********************************************************************
1842 * DlgDirSelectComboBoxEx16 (USER.423)
1844 BOOL16 WINAPI
DlgDirSelectComboBoxEx16( HWND16 hwnd
, LPSTR str
, INT16 len
,
1847 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, FALSE
, FALSE
, TRUE
);
1851 /**********************************************************************
1852 * DlgDirSelectComboBoxEx32A (USER32.147)
1854 BOOL32 WINAPI
DlgDirSelectComboBoxEx32A( HWND32 hwnd
, LPSTR str
, INT32 len
,
1857 return DIALOG_DlgDirSelect( hwnd
, str
, len
, id
, TRUE
, FALSE
, TRUE
);
1861 /**********************************************************************
1862 * DlgDirSelectComboBoxEx32W (USER32.148)
1864 BOOL32 WINAPI
DlgDirSelectComboBoxEx32W( HWND32 hwnd
, LPWSTR str
, INT32 len
,
1867 return DIALOG_DlgDirSelect( hwnd
, (LPSTR
)str
, len
, id
, TRUE
, TRUE
, TRUE
);
1871 /**********************************************************************
1872 * DlgDirList16 (USER.100)
1874 INT16 WINAPI
DlgDirList16( HWND16 hDlg
, LPSTR spec
, INT16 idLBox
,
1875 INT16 idStatic
, UINT16 attrib
)
1877 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1881 /**********************************************************************
1882 * DlgDirList32A (USER32.143)
1884 INT32 WINAPI
DlgDirList32A( HWND32 hDlg
, LPSTR spec
, INT32 idLBox
,
1885 INT32 idStatic
, UINT32 attrib
)
1887 return DIALOG_DlgDirList( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1891 /**********************************************************************
1892 * DlgDirList32W (USER32.146)
1894 INT32 WINAPI
DlgDirList32W( HWND32 hDlg
, LPWSTR spec
, INT32 idLBox
,
1895 INT32 idStatic
, UINT32 attrib
)
1897 return DIALOG_DlgDirListW( hDlg
, spec
, idLBox
, idStatic
, attrib
, FALSE
);
1901 /**********************************************************************
1902 * DlgDirListComboBox16 (USER.195)
1904 INT16 WINAPI
DlgDirListComboBox16( HWND16 hDlg
, LPSTR spec
, INT16 idCBox
,
1905 INT16 idStatic
, UINT16 attrib
)
1907 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
1911 /**********************************************************************
1912 * DlgDirListComboBox32A (USER32.144)
1914 INT32 WINAPI
DlgDirListComboBox32A( HWND32 hDlg
, LPSTR spec
, INT32 idCBox
,
1915 INT32 idStatic
, UINT32 attrib
)
1917 return DIALOG_DlgDirList( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);
1921 /**********************************************************************
1922 * DlgDirListComboBox32W (USER32.145)
1924 INT32 WINAPI
DlgDirListComboBox32W( HWND32 hDlg
, LPWSTR spec
, INT32 idCBox
,
1925 INT32 idStatic
, UINT32 attrib
)
1927 return DIALOG_DlgDirListW( hDlg
, spec
, idCBox
, idStatic
, attrib
, TRUE
);