4 * Copyright 1993, 1994, 1996 Alexandre Julliard
15 #include "resource32.h"
16 #include "stackframe.h"
25 /* Dialog control information */
57 /* Dialog base units */
58 static WORD xBaseUnit = 0, yBaseUnit = 0;
61 /***********************************************************************
64 * Initialisation of the dialog manager.
71 /* Calculate the dialog base units */
73 if (!(hdc = CreateDC( "DISPLAY", NULL, NULL, NULL ))) return FALSE;
74 GetTextMetrics16( hdc, &tm );
76 xBaseUnit = tm.tmAveCharWidth;
77 yBaseUnit = tm.tmHeight;
79 /* Dialog units are based on a proportional system font */
80 /* so we adjust them a bit for a fixed font. */
81 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) xBaseUnit = xBaseUnit * 5 / 4;
83 dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
84 xBaseUnit, yBaseUnit );
89 /***********************************************************************
90 * DIALOG_GetFirstTabItem
92 * Return the first item of the dialog that has the WS_TABSTOP style.
94 HWND DIALOG_GetFirstTabItem( HWND hwndDlg )
96 WND *pWnd = WIN_FindWndPtr( hwndDlg );
97 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
98 if (pWnd->dwStyle & WS_TABSTOP) return pWnd->hwndSelf;
103 /***********************************************************************
104 * DIALOG_GetControl16
106 * Return the class and text of the control pointed to by ptr,
107 * fill the header structure and return a pointer to the next control.
109 static LPCSTR DIALOG_GetControl16( LPCSTR p, DLG_CONTROL_INFO *info )
111 static char buffer[10];
113 info->x = GET_WORD(p); p += sizeof(WORD);
114 info->y = GET_WORD(p); p += sizeof(WORD);
115 info->cx = GET_WORD(p); p += sizeof(WORD);
116 info->cy = GET_WORD(p); p += sizeof(WORD);
117 info->id = GET_WORD(p); p += sizeof(WORD);
118 info->style = GET_DWORD(p); p += sizeof(DWORD);
125 case 0x80: strcpy( buffer, "BUTTON" ); break;
126 case 0x81: strcpy( buffer, "EDIT" ); break;
127 case 0x82: strcpy( buffer, "STATIC" ); break;
128 case 0x83: strcpy( buffer, "LISTBOX" ); break;
129 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
130 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
131 default: buffer[0] = '\0'; break;
133 info->className = buffer;
141 dprintf_dialog(stddeb, " %s ", info->className );
143 if ((BYTE)*p == 0xff)
145 /* Integer id, not documented (?). Only works for SS_ICON controls */
146 info->windowName = (LPCSTR)(UINT32)GET_WORD(p+1);
148 dprintf_dialog( stddeb,"%04x", LOWORD(info->windowName) );
152 info->windowName = p;
154 dprintf_dialog(stddeb,"'%s'", info->windowName );
157 info->data = (LPVOID)(*p ? p + 1 : NULL); /* FIXME: should be a segptr */
160 dprintf_dialog( stddeb," %d, %d, %d, %d, %d, %08lx, %08lx\n",
161 info->id, info->x, info->y, info->cx, info->cy,
162 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 )
175 static WCHAR buffer[10];
177 info->style = GET_DWORD(p); p += 2;
178 info->exStyle = GET_DWORD(p); p += 2;
179 info->x = GET_WORD(p); p++;
180 info->y = GET_WORD(p); p++;
181 info->cx = GET_WORD(p); p++;
182 info->cy = GET_WORD(p); p++;
183 info->id = GET_WORD(p); p++;
185 if (GET_WORD(p) == 0xffff)
187 switch(GET_WORD(p+1))
189 case 0x80: STRING32_AnsiToUni( buffer, "BUTTON" ); break;
190 case 0x81: STRING32_AnsiToUni( buffer, "EDIT" ); break;
191 case 0x82: STRING32_AnsiToUni( buffer, "STATIC" ); break;
192 case 0x83: STRING32_AnsiToUni( buffer, "LISTBOX" ); break;
193 case 0x84: STRING32_AnsiToUni( buffer, "SCROLLBAR" ); break;
194 case 0x85: STRING32_AnsiToUni( buffer, "COMBOBOX" ); break;
195 default: buffer[0] = '\0'; break;
197 info->className = (LPCSTR)buffer;
202 info->className = (LPCSTR)p;
203 p += lstrlen32W( (LPCWSTR)p ) + 1;
205 dprintf_dialog(stddeb, " %p ", info->className );
207 if (GET_WORD(p) == 0xffff)
209 info->windowName = (LPCSTR)(p + 1);
211 dprintf_dialog( stddeb,"%04x", LOWORD(info->windowName) );
215 info->windowName = (LPCSTR)p;
216 p += lstrlen32W( (LPCWSTR)p ) + 1;
217 dprintf_dialog(stddeb,"'%p'", info->windowName );
222 info->data = (LPVOID)(p + 1);
223 p += GET_WORD(p) / sizeof(WORD);
225 else info->data = NULL;
228 dprintf_dialog( stddeb," %d, %d, %d, %d, %d, %08lx, %08lx, %08lx\n",
229 info->id, info->x, info->y, info->cx, info->cy,
230 info->style, info->exStyle, (DWORD)info->data);
231 /* Next control is on dword boundary */
232 return (const WORD *)((((int)p) + 3) & ~3);
236 /***********************************************************************
237 * DIALOG_CreateControls
239 * Create the control windows for a dialog.
241 static BOOL32 DIALOG_CreateControls( WND *pWnd, LPCSTR template, INT32 items,
242 HINSTANCE32 hInst, BOOL win32 )
244 DIALOGINFO *dlgInfo = (DIALOGINFO *)pWnd->wExtra;
245 DLG_CONTROL_INFO info;
246 HWND32 hwndCtrl, hwndDefButton = 0;
248 dprintf_dialog(stddeb, " BEGIN\n" );
253 HINSTANCE16 instance;
254 template = DIALOG_GetControl16( template, &info );
255 if (HIWORD(info.className) && !strcmp( info.className, "EDIT") &&
256 ((info.style & DS_LOCALEDIT) != DS_LOCALEDIT))
258 if (!dlgInfo->hDialogHeap)
260 dlgInfo->hDialogHeap = GlobalAlloc16(GMEM_FIXED, 0x10000);
261 if (!dlgInfo->hDialogHeap)
263 fprintf( stderr, "CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n" );
266 LocalInit(dlgInfo->hDialogHeap, 0, 0xffff);
268 instance = dlgInfo->hDialogHeap;
270 else instance = (HINSTANCE16)hInst;
272 hwndCtrl = CreateWindowEx16( info.exStyle | WS_EX_NOPARENTNOTIFY,
273 info.className, info.windowName,
274 info.style | WS_CHILD,
275 info.x * dlgInfo->xBaseUnit / 4,
276 info.y * dlgInfo->yBaseUnit / 8,
277 info.cx * dlgInfo->xBaseUnit / 4,
278 info.cy * dlgInfo->yBaseUnit / 8,
279 pWnd->hwndSelf, (HMENU)info.id,
280 instance, info.data );
284 template = (LPCSTR)DIALOG_GetControl32( (WORD *)template, &info );
285 hwndCtrl = CreateWindowEx32W( info.exStyle | WS_EX_NOPARENTNOTIFY,
286 (LPCWSTR)info.className,
287 (LPCWSTR)info.windowName,
288 info.style | WS_CHILD,
289 info.x * dlgInfo->xBaseUnit / 4,
290 info.y * dlgInfo->yBaseUnit / 8,
291 info.cx * dlgInfo->xBaseUnit / 4,
292 info.cy * dlgInfo->yBaseUnit / 8,
293 pWnd->hwndSelf, (HMENU)info.id,
296 if (!hwndCtrl) return FALSE;
298 /* Send initialisation messages to the control */
299 if (dlgInfo->hUserFont) SendMessage32A( hwndCtrl, WM_SETFONT,
300 (WPARAM)dlgInfo->hUserFont, 0 );
301 if (SendMessage32A(hwndCtrl, WM_GETDLGCODE, 0, 0) & DLGC_DEFPUSHBUTTON)
303 /* If there's already a default push-button, set it back */
304 /* to normal and use this one instead. */
306 SendMessage32A( hwndDefButton, BM_SETSTYLE32,
307 BS_PUSHBUTTON,FALSE );
308 hwndDefButton = hwndCtrl;
309 dlgInfo->msgResult = GetWindowWord( hwndCtrl, GWW_ID );
312 dprintf_dialog(stddeb, " END\n" );
317 /***********************************************************************
318 * DIALOG_ParseTemplate16
320 * Fill a DLG_TEMPLATE structure from the dialog template, and return
321 * a pointer to the first control.
323 static LPCSTR DIALOG_ParseTemplate16( LPCSTR p, DLG_TEMPLATE * result )
325 result->style = GET_DWORD(p); p += sizeof(DWORD);
327 result->nbItems = *p++;
328 result->x = GET_WORD(p); p += sizeof(WORD);
329 result->y = GET_WORD(p); p += sizeof(WORD);
330 result->cx = GET_WORD(p); p += sizeof(WORD);
331 result->cy = GET_WORD(p); p += sizeof(WORD);
332 dprintf_dialog( stddeb, "DIALOG %d, %d, %d, %d\n",
333 result->x, result->y, result->cx, result->cy );
334 dprintf_dialog( stddeb, " STYLE %08lx\n", result->style );
336 /* Get the menu name */
341 result->menuName = 0;
345 result->menuName = (LPCSTR)(UINT32)GET_WORD( p + 1 );
347 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
350 result->menuName = p;
351 dprintf_dialog( stddeb, " MENU '%s'\n", p );
356 /* Get the class name */
360 result->className = p;
361 dprintf_dialog( stddeb, " CLASS '%s'\n", result->className );
363 else result->className = DIALOG_CLASS_ATOM;
366 /* Get the window caption */
370 dprintf_dialog( stddeb, " CAPTION '%s'\n", result->caption );
372 /* Get the font name */
374 if (result->style & DS_SETFONT)
376 result->pointSize = GET_WORD(p);
378 result->faceName = p;
380 dprintf_dialog( stddeb, " FONT %d,'%s'\n",
381 result->pointSize, result->faceName );
387 /***********************************************************************
388 * DIALOG_ParseTemplate32
390 * Fill a DLG_TEMPLATE structure from the dialog template, and return
391 * a pointer to the first control.
393 static LPCSTR DIALOG_ParseTemplate32( LPCSTR template, DLG_TEMPLATE * result )
395 const WORD *p = (const WORD *)template;
397 result->style = GET_DWORD(p); p += 2;
398 result->exStyle = GET_DWORD(p); p += 2;
399 result->nbItems = GET_WORD(p); p++;
400 result->x = GET_WORD(p); p++;
401 result->y = GET_WORD(p); p++;
402 result->cx = GET_WORD(p); p++;
403 result->cy = GET_WORD(p); p++;
404 dprintf_dialog( stddeb, "DIALOG %d, %d, %d, %d\n",
405 result->x, result->y, result->cx, result->cy );
406 dprintf_dialog( stddeb, " STYLE %08lx\n", result->style );
407 dprintf_dialog( stddeb, " EXSTYLE %08lx\n", result->exStyle );
409 /* Get the menu name */
414 result->menuName = NULL;
418 result->menuName = (LPCSTR)(UINT32)GET_WORD( p + 1 );
420 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
423 result->menuName = (LPCSTR)p;
424 dprintf_dialog( stddeb, " MENU '%p'\n", p );
425 p += lstrlen32W( (LPCWSTR)p ) + 1;
429 /* Get the class name */
434 result->className = DIALOG_CLASS_ATOM;
438 result->className = (LPCSTR)(UINT32)GET_WORD( p + 1 );
440 dprintf_dialog(stddeb, " CLASS %04x\n", LOWORD(result->className) );
443 result->className = (LPCSTR)p;
444 dprintf_dialog( stddeb, " CLASS '%p'\n", p );
445 p += lstrlen32W( (LPCWSTR)p ) + 1;
449 /* Get the window caption */
451 result->caption = (LPCSTR)p;
452 p += lstrlen32W( (LPCWSTR)p ) + 1;
453 dprintf_dialog( stddeb, " CAPTION '%p'\n", result->caption );
455 /* Get the font name */
457 if (result->style & DS_SETFONT)
459 result->pointSize = GET_WORD(p);
461 result->faceName = (LPCSTR)p;
462 p += lstrlen32W( (LPCWSTR)p ) + 1;
463 dprintf_dialog( stddeb, " FONT %d,'%p'\n",
464 result->pointSize, result->faceName );
466 /* First control is on dword boundary */
467 return (LPCSTR)((((int)p) + 3) & ~3);
471 /***********************************************************************
472 * DIALOG_CreateIndirect
474 static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCSTR dlgTemplate,
475 HWND owner, DLGPROC16 dlgProc,
476 LPARAM param, WINDOWPROCTYPE procType )
483 DLG_TEMPLATE template;
484 DIALOGINFO * dlgInfo;
485 WORD xUnit = xBaseUnit;
486 WORD yUnit = yBaseUnit;
488 /* Parse dialog template */
490 if (!dlgTemplate) return 0;
491 if (procType != WIN_PROC_16)
492 dlgTemplate = DIALOG_ParseTemplate32( dlgTemplate, &template );
494 dlgTemplate = DIALOG_ParseTemplate16( dlgTemplate, &template );
498 if (template.menuName)
500 LPSTR str = SEGPTR_STRDUP( template.menuName ); /* FIXME: win32 */
501 hMenu = LoadMenu( hInst, SEGPTR_GET(str) );
505 /* Create custom font if needed */
507 if (template.style & DS_SETFONT)
509 /* The font height must be negative as it is a point size */
510 /* (see CreateFont() documentation in the Windows SDK). */
511 hFont = CreateFont( -template.pointSize, 0, 0, 0, FW_DONTCARE,
512 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
513 DEFAULT_QUALITY, FF_DONTCARE,
514 template.faceName ); /* FIXME: win32 */
522 oldFont = SelectObject( hdc, hFont );
523 GetTextMetrics16( hdc, &tm );
524 SelectObject( hdc, oldFont );
526 xUnit = tm.tmAveCharWidth;
528 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
529 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
533 /* Create dialog main window */
535 rect.left = rect.top = 0;
536 rect.right = template.cx * xUnit / 4;
537 rect.bottom = template.cy * yUnit / 8;
538 if (template.style & DS_MODALFRAME)
539 template.exStyle |= WS_EX_DLGMODALFRAME;
540 AdjustWindowRectEx16( &rect, template.style,
541 hMenu ? TRUE : FALSE , template.exStyle );
542 rect.right -= rect.left;
543 rect.bottom -= rect.top;
545 if ((INT16)template.x == CW_USEDEFAULT16)
547 rect.left = rect.top = (procType == WIN_PROC_16) ? CW_USEDEFAULT16
552 rect.left += template.x * xUnit / 4;
553 rect.top += template.y * yUnit / 8;
554 if (!(template.style & DS_ABSALIGN))
555 ClientToScreen16( owner, (POINT16 *)&rect );
558 if (procType != WIN_PROC_16)
559 hwnd = CreateWindowEx32W(template.exStyle, (LPCWSTR)template.className,
560 (LPCWSTR)template.caption,
561 template.style & ~WS_VISIBLE,
562 rect.left, rect.top, rect.right, rect.bottom,
563 owner, hMenu, hInst, NULL );
565 hwnd = CreateWindowEx16(template.exStyle, template.className,
566 template.caption, template.style & ~WS_VISIBLE,
567 rect.left, rect.top, rect.right, rect.bottom,
568 owner, hMenu, hInst, NULL );
571 if (hFont) DeleteObject( hFont );
572 if (hMenu) DestroyMenu( hMenu );
575 wndPtr = WIN_FindWndPtr( hwnd );
576 wndPtr->flags |= WIN_ISDIALOG;
578 /* Initialise dialog extra data */
580 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
581 dlgInfo->hUserFont = hFont;
582 dlgInfo->hMenu = hMenu;
583 dlgInfo->xBaseUnit = xUnit;
584 dlgInfo->yBaseUnit = yUnit;
585 dlgInfo->msgResult = 0; /* This is used to store the default button id */
586 dlgInfo->hDialogHeap = 0;
588 /* Create controls */
590 if (!DIALOG_CreateControls( wndPtr, dlgTemplate, template.nbItems,
591 hInst, (procType != WIN_PROC_16) ))
593 DestroyWindow( hwnd );
597 /* Send initialisation messages and set focus */
599 WINPROC_SetProc( &dlgInfo->dlgProc, dlgProc, procType );
600 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
601 if (dlgInfo->hUserFont)
602 SendMessage32A( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
603 if (SendMessage32A(hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param))
604 SetFocus( dlgInfo->hwndFocus );
605 if (template.style & WS_VISIBLE) ShowWindow( hwnd, SW_SHOW );
610 /***********************************************************************
611 * CreateDialog16 (USER.89)
613 HWND16 CreateDialog16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
614 HWND16 owner, DLGPROC16 dlgProc )
616 return CreateDialogParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
620 /***********************************************************************
621 * CreateDialogParam16 (USER.241)
623 HWND16 CreateDialogParam16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
624 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
631 dprintf_dialog(stddeb, "CreateDialogParam16: %04x,%08lx,%04x,%08lx,%ld\n",
632 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
634 if (!(hRsrc = FindResource( hInst, dlgTemplate, RT_DIALOG ))) return 0;
635 if (!(hmem = LoadResource( hInst, hRsrc ))) return 0;
636 if (!(data = LockResource( hmem ))) hwnd = 0;
637 else hwnd = CreateDialogIndirectParam16( hInst, data, owner,
639 FreeResource( hmem );
644 /***********************************************************************
645 * CreateDialogParam32A (USER32.72)
647 HWND32 CreateDialogParam32A( HINSTANCE32 hInst, LPCSTR name,
648 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
652 LPWSTR str = STRING32_DupAnsiToUni( name );
653 HWND32 hwnd = CreateDialogParam32W( hInst, str, owner, dlgProc, param);
657 return CreateDialogParam32W( hInst, (LPCWSTR)name, owner, dlgProc, param );
661 /***********************************************************************
662 * CreateDialogParam32W (USER32.73)
664 HWND32 CreateDialogParam32W( HINSTANCE32 hInst, LPCWSTR name,
665 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
667 HANDLE32 hrsrc = FindResource32W( hInst, name, (LPWSTR)RT_DIALOG );
668 if (!hrsrc) return 0;
669 return CreateDialogIndirectParam32W( hInst, LoadResource32( hInst, hrsrc ),
670 owner, dlgProc, param );
674 /***********************************************************************
675 * CreateDialogIndirect16 (USER.219)
677 HWND16 CreateDialogIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
678 HWND16 owner, DLGPROC16 dlgProc )
680 return CreateDialogIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0);
684 /***********************************************************************
685 * CreateDialogIndirectParam16 (USER.242)
687 HWND16 CreateDialogIndirectParam16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
688 HWND16 owner, DLGPROC16 dlgProc,
691 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner,
692 dlgProc, param, WIN_PROC_16 );
696 /***********************************************************************
697 * CreateDialogIndirectParam32A (USER32.69)
699 HWND32 CreateDialogIndirectParam32A( HINSTANCE32 hInst, LPCVOID dlgTemplate,
700 HWND32 owner, DLGPROC32 dlgProc,
703 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner,
704 (DLGPROC16)dlgProc, param, WIN_PROC_32A );
708 /***********************************************************************
709 * CreateDialogIndirectParam32W (USER32.71)
711 HWND32 CreateDialogIndirectParam32W( HINSTANCE32 hInst, LPCVOID dlgTemplate,
712 HWND32 owner, DLGPROC32 dlgProc,
715 return DIALOG_CreateIndirect( hInst, dlgTemplate, owner,
716 (DLGPROC16)dlgProc, param, WIN_PROC_32W );
720 /***********************************************************************
723 static INT32 DIALOG_DoDialogBox( HWND hwnd, HWND owner )
726 DIALOGINFO * dlgInfo;
731 /* Owner must be a top-level window */
732 owner = WIN_GetTopParent( owner );
733 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
734 if (!(msgHandle = USER_HEAP_ALLOC( sizeof(MSG16) ))) return -1;
735 lpmsg = (MSG16 *) USER_HEAP_LIN_ADDR( msgHandle );
736 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
737 EnableWindow( owner, FALSE );
738 ShowWindow( hwnd, SW_SHOW );
740 while (MSG_InternalGetMessage( (SEGPTR)USER_HEAP_SEG_ADDR(msgHandle), hwnd, owner,
741 MSGF_DIALOGBOX, PM_REMOVE,
742 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
744 if (!IsDialogMessage( hwnd, lpmsg))
746 TranslateMessage( lpmsg );
747 DispatchMessage( lpmsg );
749 if (dlgInfo->fEnd) break;
751 retval = dlgInfo->msgResult;
752 DestroyWindow( hwnd );
753 USER_HEAP_FREE( msgHandle );
754 EnableWindow( owner, TRUE );
759 /***********************************************************************
760 * DialogBox16 (USER.87)
762 INT16 DialogBox16( HINSTANCE16 hInst, SEGPTR dlgTemplate,
763 HWND16 owner, DLGPROC16 dlgProc )
765 return DialogBoxParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
769 /***********************************************************************
770 * DialogBoxParam16 (USER.239)
772 INT16 DialogBoxParam16( HINSTANCE16 hInst, SEGPTR template,
773 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
775 HWND16 hwnd = CreateDialogParam16( hInst, template, owner, dlgProc, param);
776 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
781 /***********************************************************************
782 * DialogBoxParam32A (USER32.138)
784 INT32 DialogBoxParam32A( HINSTANCE32 hInst, LPCSTR name,
785 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
787 HWND32 hwnd = CreateDialogParam32A( hInst, name, owner, dlgProc, param );
788 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
793 /***********************************************************************
794 * DialogBoxParam32W (USER32.139)
796 INT32 DialogBoxParam32W( HINSTANCE32 hInst, LPCWSTR name,
797 HWND32 owner, DLGPROC32 dlgProc, LPARAM param )
799 HWND32 hwnd = CreateDialogParam32W( hInst, name, owner, dlgProc, param );
800 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
805 /***********************************************************************
806 * DialogBoxIndirect16 (USER.218)
808 INT16 DialogBoxIndirect16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
809 HWND16 owner, DLGPROC16 dlgProc )
811 return DialogBoxIndirectParam16( hInst, dlgTemplate, owner, dlgProc, 0 );
815 /***********************************************************************
816 * DialogBoxIndirectParam16 (USER.240)
818 INT16 DialogBoxIndirectParam16( HINSTANCE16 hInst, HANDLE16 dlgTemplate,
819 HWND16 owner, DLGPROC16 dlgProc, LPARAM param )
824 if (!(ptr = GlobalLock16( dlgTemplate ))) return -1;
825 hwnd = CreateDialogIndirectParam16( hInst, ptr, owner, dlgProc, param );
826 GlobalUnlock16( dlgTemplate );
827 if (hwnd) return (INT16)DIALOG_DoDialogBox( hwnd, owner );
832 /***********************************************************************
833 * DialogBoxIndirectParam32A (USER32.135)
835 INT32 DialogBoxIndirectParam32A( HINSTANCE32 hInstance, LPCVOID template,
836 HWND32 owner, DLGPROC32 dlgProc ,LPARAM param)
838 HWND32 hwnd = CreateDialogIndirectParam32A( hInstance, template,
839 owner, dlgProc, param );
840 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
845 /***********************************************************************
846 * DialogBoxIndirectParam32W (USER32.137)
848 INT32 DialogBoxIndirectParam32W( HINSTANCE32 hInstance, LPCVOID template,
849 HWND32 owner, DLGPROC32 dlgProc ,LPARAM param)
851 HWND32 hwnd = CreateDialogIndirectParam32W( hInstance, template,
852 owner, dlgProc, param );
853 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
858 /***********************************************************************
859 * EndDialog (USER.88) (USER32.173)
861 BOOL16 EndDialog( HWND32 hwnd, INT32 retval )
863 WND * wndPtr = WIN_FindWndPtr( hwnd );
864 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
865 dlgInfo->msgResult = retval;
866 dlgInfo->fEnd = TRUE;
867 dprintf_dialog(stddeb, "EndDialog: %04x %d\n", hwnd, retval );
872 /***********************************************************************
873 * IsDialogMessage (USER.90)
875 BOOL IsDialogMessage( HWND hwndDlg, LPMSG16 msg )
880 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return FALSE;
881 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
883 /* Only the key messages get special processing */
884 if ((msg->message != WM_KEYDOWN) &&
885 (msg->message != WM_SYSCHAR) &&
886 (msg->message != WM_CHAR))
889 dlgCode = SendMessage16( msg->hwnd, WM_GETDLGCODE, 0, 0 );
890 if (dlgCode & DLGC_WANTMESSAGE)
892 DispatchMessage( msg );
899 if (dlgCode & DLGC_WANTALLKEYS) break;
903 if (!(dlgCode & DLGC_WANTTAB))
905 SendMessage16( hwndDlg, WM_NEXTDLGCTL,
906 (GetKeyState(VK_SHIFT) & 0x80), 0 );
913 if (!(dlgCode & DLGC_WANTARROWS))
915 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),FALSE));
922 if (!(dlgCode & DLGC_WANTARROWS))
924 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),TRUE));
930 SendMessage32A( hwndDlg, WM_COMMAND, IDCANCEL,
931 (LPARAM)GetDlgItem( hwndDlg, IDCANCEL ) );
936 DWORD dw = SendMessage16( hwndDlg, DM_GETDEFID, 0, 0 );
937 if (HIWORD(dw) == DC_HASDEFID)
938 SendMessage32A( hwndDlg, WM_COMMAND,
939 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
940 (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ));
942 SendMessage32A( hwndDlg, WM_COMMAND, IDOK,
943 (LPARAM)GetDlgItem( hwndDlg, IDOK ) );
948 TranslateMessage( msg );
950 break; /* case WM_KEYDOWN */
954 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
958 if (dlgCode & DLGC_WANTALLKEYS) break;
962 /* If we get here, the message has not been treated specially */
963 /* and can be sent to its destination window. */
964 DispatchMessage( msg );
969 /****************************************************************
970 * GetDlgCtrlID (USER.277) (USER32.233)
972 INT16 GetDlgCtrlID( HWND32 hwnd )
974 WND *wndPtr = WIN_FindWndPtr(hwnd);
975 if (wndPtr) return wndPtr->wIDmenu;
980 /***********************************************************************
981 * GetDlgItem (USER.91)
983 HWND GetDlgItem( HWND hwndDlg, WORD id )
987 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
988 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
989 if (pWnd->wIDmenu == id) return pWnd->hwndSelf;
994 /*******************************************************************
995 * SendDlgItemMessage16 (USER.101)
997 LRESULT SendDlgItemMessage16( HWND16 hwnd, INT16 id, UINT16 msg,
998 WPARAM16 wParam, LPARAM lParam )
1000 HWND16 hwndCtrl = GetDlgItem( hwnd, id );
1001 if (hwndCtrl) return SendMessage16( hwndCtrl, msg, wParam, lParam );
1006 /*******************************************************************
1007 * SendDlgItemMessage32A (USER32.451)
1009 LRESULT SendDlgItemMessage32A( HWND32 hwnd, INT32 id, UINT32 msg,
1010 WPARAM32 wParam, LPARAM lParam )
1012 HWND hwndCtrl = GetDlgItem( (HWND16)hwnd, (INT16)id );
1013 if (hwndCtrl) return SendMessage32A( hwndCtrl, msg, wParam, lParam );
1018 /*******************************************************************
1019 * SendDlgItemMessage32W (USER32.452)
1021 LRESULT SendDlgItemMessage32W( HWND32 hwnd, INT32 id, UINT32 msg,
1022 WPARAM32 wParam, LPARAM lParam )
1024 HWND hwndCtrl = GetDlgItem( (HWND16)hwnd, (INT16)id );
1025 if (hwndCtrl) return SendMessage32W( hwndCtrl, msg, wParam, lParam );
1030 /*******************************************************************
1031 * SetDlgItemText16 (USER.92)
1033 void SetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR lpString )
1035 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1039 /*******************************************************************
1040 * SetDlgItemText32A (USER32.477)
1042 void SetDlgItemText32A( HWND32 hwnd, INT32 id, LPCSTR lpString )
1044 SendDlgItemMessage32A( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1048 /*******************************************************************
1049 * SetDlgItemText32W (USER32.478)
1051 void SetDlgItemText32W( HWND32 hwnd, INT32 id, LPCWSTR lpString )
1053 SendDlgItemMessage32W( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpString );
1057 /***********************************************************************
1058 * GetDlgItemText16 (USER.93)
1060 INT16 GetDlgItemText16( HWND16 hwnd, INT16 id, SEGPTR str, UINT16 len )
1062 return (INT16)SendDlgItemMessage16( hwnd, id, WM_GETTEXT,
1067 /***********************************************************************
1068 * GetDlgItemText32A (USER32.236)
1070 INT32 GetDlgItemText32A( HWND32 hwnd, INT32 id, LPSTR str, UINT32 len )
1072 return (INT32)SendDlgItemMessage32A( hwnd, id, WM_GETTEXT,
1077 /***********************************************************************
1078 * GetDlgItemText32W (USER32.237)
1080 INT32 GetDlgItemText32W( HWND32 hwnd, INT32 id, LPWSTR str, UINT32 len )
1082 return (INT32)SendDlgItemMessage32W( hwnd, id, WM_GETTEXT,
1087 /*******************************************************************
1088 * SetDlgItemInt16 (USER.94)
1090 void SetDlgItemInt16( HWND16 hwnd, INT16 id, UINT16 value, BOOL16 fSigned )
1092 char *str = (char *)SEGPTR_ALLOC( 20 * sizeof(char) );
1095 if (fSigned) sprintf( str, "%d", (INT32)(INT16)value );
1096 else sprintf( str, "%u", value );
1097 SendDlgItemMessage16( hwnd, id, WM_SETTEXT, 0, (LPARAM)SEGPTR_GET(str) );
1102 /*******************************************************************
1103 * SetDlgItemInt32 (USER32.476)
1105 void SetDlgItemInt32( HWND32 hwnd, INT32 id, UINT32 value, BOOL32 fSigned )
1109 if (fSigned) sprintf( str, "%d", (INT32)value );
1110 else sprintf( str, "%u", value );
1111 SendDlgItemMessage32A( hwnd, id, WM_SETTEXT, 0, (LPARAM)str );
1115 /***********************************************************************
1116 * GetDlgItemInt (USER.95)
1118 WORD GetDlgItemInt( HWND hwnd, WORD id, BOOL * translated, BOOL fSigned )
1123 if (translated) *translated = FALSE;
1124 if (!(str = (char *)SEGPTR_ALLOC( 30 * sizeof(char) ))) return 0;
1125 if (SendDlgItemMessage16( hwnd, id, WM_GETTEXT, 30, (LPARAM)SEGPTR_GET(str)))
1128 result = strtol( str, &endptr, 10 );
1129 if (endptr && (endptr != str)) /* Conversion was successful */
1133 if ((result < -32767) || (result > 32767)) result = 0;
1134 else if (translated) *translated = TRUE;
1138 if ((result < 0) || (result > 65535)) result = 0;
1139 else if (translated) *translated = TRUE;
1144 return (WORD)result;
1148 /***********************************************************************
1149 * CheckDlgButton (USER.97) (USER32.44)
1151 BOOL16 CheckDlgButton( HWND32 hwnd, INT32 id, UINT32 check )
1153 SendDlgItemMessage32A( hwnd, id, BM_SETCHECK32, check, 0 );
1158 /***********************************************************************
1159 * IsDlgButtonChecked (USER.98)
1161 WORD IsDlgButtonChecked( HWND hwnd, WORD id )
1163 return (WORD)SendDlgItemMessage16( hwnd, id, BM_GETCHECK16, 0, 0 );
1167 /***********************************************************************
1168 * CheckRadioButton (USER.96) (USER32.47)
1170 BOOL16 CheckRadioButton( HWND32 hwndDlg, UINT32 firstID, UINT32 lastID,
1173 WND *pWnd = WIN_FindWndPtr( hwndDlg );
1174 if (!pWnd) return FALSE;
1176 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
1177 if ((pWnd->wIDmenu == firstID) || (pWnd->wIDmenu == lastID)) break;
1178 if (!pWnd) return FALSE;
1180 if (pWnd->wIDmenu == lastID)
1181 lastID = firstID; /* Buttons are in reverse order */
1184 SendMessage32A( pWnd->hwndSelf, BM_SETCHECK32,
1185 (pWnd->wIDmenu == checkID), 0 );
1186 if (pWnd->wIDmenu == lastID) break;
1193 /***********************************************************************
1194 * GetDialogBaseUnits (USER.243)
1196 DWORD GetDialogBaseUnits()
1198 return MAKELONG( xBaseUnit, yBaseUnit );
1202 /***********************************************************************
1203 * MapDialogRect16 (USER.103)
1205 void MapDialogRect16( HWND16 hwnd, LPRECT16 rect )
1207 DIALOGINFO * dlgInfo;
1208 WND * wndPtr = WIN_FindWndPtr( hwnd );
1209 if (!wndPtr) return;
1210 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1211 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
1212 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
1213 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
1214 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
1218 /***********************************************************************
1219 * MapDialogRect32 (USER32.381)
1221 void MapDialogRect32( HWND32 hwnd, LPRECT32 rect )
1223 DIALOGINFO * dlgInfo;
1224 WND * wndPtr = WIN_FindWndPtr( hwnd );
1225 if (!wndPtr) return;
1226 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
1227 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
1228 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
1229 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
1230 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
1234 /***********************************************************************
1235 * GetNextDlgGroupItem (USER.227)
1237 HWND GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1239 WND *pWnd, *pWndStart, *pWndCtrl, *pWndDlg;
1241 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1242 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
1243 if (pWndCtrl->parent != pWndDlg) return 0;
1245 if (!fPrevious && pWndCtrl->next) /* Check if next control is in group */
1247 if (!(pWndCtrl->next->dwStyle & WS_GROUP))
1248 return pWndCtrl->next->hwndSelf;
1251 /* Now we will have to find the start of the group */
1253 for (pWnd = pWndStart = pWndDlg->child; pWnd; pWnd = pWnd->next)
1255 if (pWnd->dwStyle & WS_GROUP) pWndStart = pWnd; /* Start of a group */
1256 if (pWnd == pWndCtrl) break;
1259 if (!pWnd) fprintf(stderr, "GetNextDlgGroupItem: hwnd not in dialog!\n");
1261 /* only case left for forward search: wraparound */
1262 if (!fPrevious) return pWndStart->hwndSelf;
1264 pWnd = pWndStart->next;
1265 while (pWnd && (pWnd != pWndCtrl))
1267 if (pWnd->dwStyle & WS_GROUP) break;
1271 return pWndStart->hwndSelf;
1275 /***********************************************************************
1276 * GetNextDlgTabItem (USER.228)
1278 HWND GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
1280 WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
1282 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
1283 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
1284 if (pWndCtrl->parent != pWndDlg) return 0;
1286 pWndLast = pWndCtrl;
1287 pWnd = pWndCtrl->next;
1290 if (!pWnd) pWnd = pWndDlg->child;
1291 if (pWnd == pWndCtrl) break;
1292 if ((pWnd->dwStyle & WS_TABSTOP) && (pWnd->dwStyle & WS_VISIBLE))
1295 if (!fPrevious) break;
1299 return pWndLast->hwndSelf;