4 * Copyright 1993, 1994 Alexandre Julliard
15 #include "stackframe.h"
19 /* #define DEBUG_DIALOG */
22 /* Dialog base units */
23 WORD xBaseUnit = 0, yBaseUnit = 0;
26 /***********************************************************************
29 * Initialisation of the dialog manager.
36 /* Calculate the dialog base units */
38 if (!(hdc = GetDC( 0 ))) return FALSE;
39 GetTextMetrics( hdc, &tm );
41 xBaseUnit = tm.tmAveCharWidth;
42 yBaseUnit = tm.tmHeight;
44 /* Dialog units are based on a proportional system font */
45 /* so we adjust them a bit for a fixed font. */
46 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH) xBaseUnit = xBaseUnit * 5 / 4;
48 dprintf_dialog( stddeb, "DIALOG_Init: base units = %d,%d\n",
49 xBaseUnit, yBaseUnit );
54 /***********************************************************************
55 * DIALOG_GetFirstTabItem
57 * Return the first item of the dialog that has the WS_TABSTOP style.
59 HWND DIALOG_GetFirstTabItem( HWND hwndDlg )
61 WND *pWnd = WIN_FindWndPtr( hwndDlg );
62 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
63 if (pWnd->dwStyle & WS_TABSTOP) return pWnd->hwndSelf;
68 /***********************************************************************
71 * Return the class and text of the control pointed to by ptr,
72 * and return a pointer to the next control.
74 static SEGPTR DIALOG_GetControl( SEGPTR ptr, SEGPTR *class, SEGPTR *text )
76 unsigned char *base = (unsigned char *)PTR_SEG_TO_LIN( ptr );
77 unsigned char *p = base;
79 p += 14; /* size of control header */
83 *class = MAKEINTRESOURCE( *p );
88 *class = ptr + (WORD)(p - base);
94 /* Integer id, not documented (?). Only works for SS_ICON controls */
95 *text = MAKEINTRESOURCE( p[1] + 256 * p[2] );
100 *text = ptr + (WORD)(p - base);
103 return ptr + (WORD)(p - base);
107 /***********************************************************************
108 * DIALOG_ParseTemplate
110 * Fill a DLGTEMPLATE structure from the dialog template, and return
111 * a pointer to the first control.
113 static SEGPTR DIALOG_ParseTemplate( SEGPTR template, DLGTEMPLATE * result )
115 unsigned char *base = (unsigned char *)PTR_SEG_TO_LIN(template);
116 unsigned char * p = base;
118 result->header = *(DLGTEMPLATEHEADER *)p;
121 /* Get the menu name */
125 result->menuName = MAKEINTRESOURCE( p[1] + 256 * p[2] );
130 result->menuName = template + (WORD)(p - base);
135 result->menuName = 0;
139 /* Get the class name */
141 if (*p) result->className = template + (WORD)(p - base);
142 else result->className = DIALOG_CLASS_ATOM;
145 /* Get the window caption */
147 result->caption = template + (WORD)(p - base);
150 /* Get the font name */
152 if (result->header.style & DS_SETFONT)
154 result->pointSize = *(WORD *)p;
156 result->faceName = template + (WORD)(p - base);
160 return template + (WORD)(p - base);
164 /***********************************************************************
165 * DIALOG_DisplayTemplate
167 static void DIALOG_DisplayTemplate( DLGTEMPLATE * result )
169 dprintf_dialog(stddeb, "DIALOG %d, %d, %d, %d\n", result->header.x, result->header.y,
170 result->header.cx, result->header.cy );
171 dprintf_dialog(stddeb, " STYLE %08lx\n", result->header.style );
172 dprintf_dialog( stddeb, " CAPTION '%s'\n",
173 (char *)PTR_SEG_TO_LIN(result->caption) );
175 if (HIWORD(result->className))
176 dprintf_dialog( stddeb, " CLASS '%s'\n",
177 (char *)PTR_SEG_TO_LIN(result->className) );
179 dprintf_dialog( stddeb, " CLASS #%d\n", LOWORD(result->className) );
181 if (HIWORD(result->menuName))
182 dprintf_dialog( stddeb, " MENU '%s'\n",
183 (char *)PTR_SEG_TO_LIN(result->menuName) );
184 else if (LOWORD(result->menuName))
185 dprintf_dialog(stddeb, " MENU %04x\n", LOWORD(result->menuName) );
187 if (result->header.style & DS_SETFONT)
188 dprintf_dialog( stddeb, " FONT %d,'%s'\n", result->pointSize,
189 (char *)PTR_SEG_TO_LIN(result->faceName) );
193 /***********************************************************************
194 * CreateDialog (USER.89)
196 HWND CreateDialog( HINSTANCE hInst, SEGPTR dlgTemplate,
197 HWND owner, DLGPROC dlgProc )
199 return CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, 0 );
203 /***********************************************************************
204 * CreateDialogParam (USER.241)
206 HWND CreateDialogParam( HINSTANCE hInst, SEGPTR dlgTemplate,
207 HWND owner, DLGPROC dlgProc, LPARAM param )
214 dprintf_dialog(stddeb, "CreateDialogParam: %04x,%08lx,%04x,%08lx,%ld\n",
215 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
217 if (!(hRsrc = FindResource( hInst, dlgTemplate, RT_DIALOG ))) return 0;
218 if (!(hmem = LoadResource( hInst, hRsrc ))) return 0;
219 if (!(data = WIN16_LockResource( hmem ))) hwnd = 0;
220 else hwnd = CreateDialogIndirectParam(hInst, data, owner, dlgProc, param);
221 FreeResource( hmem );
226 /***********************************************************************
227 * CreateDialogIndirect (USER.219)
229 HWND CreateDialogIndirect( HINSTANCE hInst, SEGPTR dlgTemplate,
230 HWND owner, DLGPROC dlgProc )
232 return CreateDialogIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
236 /***********************************************************************
237 * CreateDialogIndirectParam (USER.242)
239 HWND CreateDialogIndirectParam( HINSTANCE hInst, SEGPTR dlgTemplate,
240 HWND owner, DLGPROC dlgProc, LPARAM param )
248 DLGTEMPLATE template;
250 DIALOGINFO * dlgInfo;
252 WORD xUnit = xBaseUnit;
253 WORD yUnit = yBaseUnit;
255 /* Parse dialog template */
257 if (!dlgTemplate) return 0;
258 headerPtr = DIALOG_ParseTemplate( dlgTemplate, &template );
259 if (debugging_dialog) DIALOG_DisplayTemplate( &template );
263 if (template.menuName) hMenu = LoadMenu( hInst, template.menuName );
265 /* Create custom font if needed */
267 if (template.header.style & DS_SETFONT)
269 /* The font height must be negative as it is a point size */
270 /* (see CreateFont() documentation in the Windows SDK). */
271 hFont = CreateFont( -template.pointSize, 0, 0, 0, FW_DONTCARE,
272 FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0, 0,
273 DEFAULT_QUALITY, FF_DONTCARE,
274 (LPSTR)PTR_SEG_TO_LIN(template.faceName) );
282 oldFont = SelectObject( hdc, hFont );
283 GetTextMetrics( hdc, &tm );
284 SelectObject( hdc, oldFont );
286 xUnit = tm.tmAveCharWidth;
288 if (tm.tmPitchAndFamily & TMPF_FIXED_PITCH)
289 xBaseUnit = xBaseUnit * 5 / 4; /* See DIALOG_Init() */
293 /* Create dialog main window */
295 rect.left = rect.top = 0;
296 rect.right = template.header.cx * xUnit / 4;
297 rect.bottom = template.header.cy * yUnit / 8;
298 if (template.header.style & DS_MODALFRAME) exStyle |= WS_EX_DLGMODALFRAME;
299 AdjustWindowRectEx( &rect, template.header.style,
300 hMenu ? TRUE : FALSE , exStyle );
301 rect.right -= rect.left;
302 rect.bottom -= rect.top;
304 if ((INT)template.header.x == CW_USEDEFAULT)
305 rect.left = rect.top = CW_USEDEFAULT;
308 rect.left += template.header.x * xUnit / 4;
309 rect.top += template.header.y * yUnit / 8;
310 if (!(template.header.style & DS_ABSALIGN))
311 ClientToScreen( owner, (POINT *)&rect );
314 hwnd = CreateWindowEx( exStyle, template.className, template.caption,
315 template.header.style & ~WS_VISIBLE,
316 rect.left, rect.top, rect.right, rect.bottom,
317 owner, hMenu, hInst, (SEGPTR)0 );
320 if (hFont) DeleteObject( hFont );
321 if (hMenu) DestroyMenu( hMenu );
324 wndPtr = WIN_FindWndPtr( hwnd );
326 /* Purge junk from system menu */
327 /* FIXME: this doesn't belong here */
329 DeleteMenu(wndPtr->hSysMenu,SC_SIZE,MF_BYCOMMAND);
330 if (!(wndPtr->dwStyle & WS_MAXIMIZEBOX) )
332 DeleteMenu(wndPtr->hSysMenu,SC_MAXIMIZE,MF_BYCOMMAND);
333 if( !(wndPtr->dwStyle & WS_MINIMIZEBOX) )
335 DeleteMenu(wndPtr->hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
336 DeleteMenu(wndPtr->hSysMenu,SC_RESTORE,MF_BYCOMMAND);
340 if (!(wndPtr->dwStyle & WS_MINIMIZEBOX) )
341 DeleteMenu(wndPtr->hSysMenu,SC_MINIMIZE,MF_BYCOMMAND);
343 /* Create control windows */
345 dprintf_dialog(stddeb, " BEGIN\n" );
347 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
348 dlgInfo->msgResult = 0; /* This is used to store the default button id */
349 dlgInfo->hDialogHeap = 0;
351 for (i = 0; i < template.header.nbItems; i++)
353 DLGCONTROLHEADER *header;
354 SEGPTR className, winName;
355 HWND hwndDefButton = 0;
358 header = (DLGCONTROLHEADER *)PTR_SEG_TO_LIN( headerPtr );
359 headerPtr = DIALOG_GetControl( headerPtr, &className, &winName );
361 if (!HIWORD(className))
363 switch(LOWORD(className))
365 case 0x80: strcpy( buffer, "BUTTON" ); break;
366 case 0x81: strcpy( buffer, "EDIT" ); break;
367 case 0x82: strcpy( buffer, "STATIC" ); break;
368 case 0x83: strcpy( buffer, "LISTBOX" ); break;
369 case 0x84: strcpy( buffer, "SCROLLBAR" ); break;
370 case 0x85: strcpy( buffer, "COMBOBOX" ); break;
371 default: buffer[0] = '\0'; break;
373 className = MAKE_SEGPTR(buffer);
376 if (HIWORD(className))
377 dprintf_dialog(stddeb, " %s ", (char*)PTR_SEG_TO_LIN(className));
378 else dprintf_dialog(stddeb, " %04x ", LOWORD(className) );
380 dprintf_dialog(stddeb,"'%s'", (char *)PTR_SEG_TO_LIN(winName) );
381 else dprintf_dialog(stddeb,"%04x", LOWORD(winName) );
383 dprintf_dialog(stddeb," %d, %d, %d, %d, %d, %08lx\n",
384 header->id, header->x, header->y,
385 header->cx, header->cy, header->style );
387 if (HIWORD(className) &&
388 !strcmp( (char *)PTR_SEG_TO_LIN(className), "EDIT") &&
389 ((header->style & DS_LOCALEDIT) != DS_LOCALEDIT))
391 if (!dlgInfo->hDialogHeap)
393 dlgInfo->hDialogHeap = GlobalAlloc(GMEM_FIXED, 0x10000);
394 if (!dlgInfo->hDialogHeap)
396 fprintf(stderr,"CreateDialogIndirectParam: Insufficient memory to create heap for edit control\n");
399 LocalInit(dlgInfo->hDialogHeap, 0, 0xffff);
401 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
402 header->style | WS_CHILD,
403 header->x * xUnit / 4,
404 header->y * yUnit / 8,
405 header->cx * xUnit / 4,
406 header->cy * yUnit / 8,
407 hwnd, (HMENU)header->id,
408 dlgInfo->hDialogHeap, (SEGPTR)0 );
412 hwndCtrl = CreateWindowEx(WS_EX_NOPARENTNOTIFY, className, winName,
413 header->style | WS_CHILD,
414 header->x * xUnit / 4,
415 header->y * yUnit / 8,
416 header->cx * xUnit / 4,
417 header->cy * yUnit / 8,
418 hwnd, (HMENU)header->id,
422 /* Make the control last one in Z-order, so that controls remain
423 in the order in which they were created */
424 SetWindowPos( hwndCtrl, HWND_BOTTOM, 0, 0, 0, 0,
425 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
427 /* Send initialisation messages to the control */
428 if (hFont) SendMessage( hwndCtrl, WM_SETFONT, (WPARAM)hFont, 0 );
429 if (SendMessage( hwndCtrl, WM_GETDLGCODE, 0, 0 ) & DLGC_DEFPUSHBUTTON)
431 /* If there's already a default push-button, set it back */
432 /* to normal and use this one instead. */
434 SendMessage( hwndDefButton, BM_SETSTYLE, BS_PUSHBUTTON, FALSE);
435 hwndDefButton = hwndCtrl;
436 dlgInfo->msgResult = GetWindowWord( hwndCtrl, GWW_ID );
440 dprintf_dialog(stddeb, " END\n" );
442 /* Initialise dialog extra data */
444 dlgInfo->dlgProc = dlgProc;
445 dlgInfo->hUserFont = hFont;
446 dlgInfo->hMenu = hMenu;
447 dlgInfo->xBaseUnit = xUnit;
448 dlgInfo->yBaseUnit = yUnit;
449 dlgInfo->hwndFocus = DIALOG_GetFirstTabItem( hwnd );
451 /* Send initialisation messages and set focus */
453 if (dlgInfo->hUserFont)
454 SendMessage( hwnd, WM_SETFONT, (WPARAM)dlgInfo->hUserFont, 0 );
455 if (SendMessage( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ))
456 SetFocus( dlgInfo->hwndFocus );
457 if (template.header.style & WS_VISIBLE) ShowWindow(hwnd, SW_SHOW);
462 /***********************************************************************
465 int DIALOG_DoDialogBox( HWND hwnd, HWND owner )
468 DIALOGINFO * dlgInfo;
473 /* Owner must be a top-level window */
474 owner = WIN_GetTopParent( owner );
475 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return -1;
476 if (!(msgHandle = USER_HEAP_ALLOC( sizeof(MSG) ))) return -1;
477 lpmsg = (MSG *) USER_HEAP_LIN_ADDR( msgHandle );
478 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
479 EnableWindow( owner, FALSE );
480 ShowWindow( hwnd, SW_SHOW );
482 while (MSG_InternalGetMessage( (SEGPTR)USER_HEAP_SEG_ADDR(msgHandle), hwnd, owner,
483 MSGF_DIALOGBOX, PM_REMOVE,
484 !(wndPtr->dwStyle & DS_NOIDLEMSG) ))
486 if (!IsDialogMessage( hwnd, lpmsg))
488 TranslateMessage( lpmsg );
489 DispatchMessage( lpmsg );
491 if (dlgInfo->fEnd) break;
493 retval = dlgInfo->msgResult;
494 DestroyWindow( hwnd );
495 USER_HEAP_FREE( msgHandle );
496 EnableWindow( owner, TRUE );
501 /***********************************************************************
502 * DialogBox (USER.87)
504 INT DialogBox( HINSTANCE hInst, SEGPTR dlgTemplate,
505 HWND owner, DLGPROC dlgProc )
507 return DialogBoxParam( hInst, dlgTemplate, owner, dlgProc, 0 );
511 /***********************************************************************
512 * DialogBoxParam (USER.239)
514 INT DialogBoxParam( HINSTANCE hInst, SEGPTR dlgTemplate,
515 HWND owner, DLGPROC dlgProc, LPARAM param )
519 dprintf_dialog(stddeb, "DialogBoxParam: %04x,%08lx,%04x,%08lx,%ld\n",
520 hInst, (DWORD)dlgTemplate, owner, (DWORD)dlgProc, param );
521 hwnd = CreateDialogParam( hInst, dlgTemplate, owner, dlgProc, param );
522 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
527 /***********************************************************************
528 * DialogBoxIndirect (USER.218)
530 INT DialogBoxIndirect( HINSTANCE hInst, HANDLE dlgTemplate,
531 HWND owner, DLGPROC dlgProc )
533 return DialogBoxIndirectParam( hInst, dlgTemplate, owner, dlgProc, 0 );
537 /***********************************************************************
538 * DialogBoxIndirectParam (USER.240)
540 INT DialogBoxIndirectParam( HINSTANCE hInst, HANDLE dlgTemplate,
541 HWND owner, DLGPROC dlgProc, LPARAM param )
546 if (!(ptr = (SEGPTR)WIN16_GlobalLock( dlgTemplate ))) return -1;
547 hwnd = CreateDialogIndirectParam( hInst, ptr, owner, dlgProc, param );
548 GlobalUnlock( dlgTemplate );
549 if (hwnd) return DIALOG_DoDialogBox( hwnd, owner );
554 /***********************************************************************
555 * EndDialog (USER.88)
557 BOOL EndDialog( HWND hwnd, INT retval )
559 WND * wndPtr = WIN_FindWndPtr( hwnd );
560 DIALOGINFO * dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
561 dlgInfo->msgResult = retval;
562 dlgInfo->fEnd = TRUE;
563 dprintf_dialog(stddeb, "EndDialog: %04x %d\n", hwnd, retval );
568 /***********************************************************************
569 * IsDialogMessage (USER.90)
571 BOOL IsDialogMessage( HWND hwndDlg, LPMSG msg )
576 if (!(wndPtr = WIN_FindWndPtr( hwndDlg ))) return FALSE;
577 if ((hwndDlg != msg->hwnd) && !IsChild( hwndDlg, msg->hwnd )) return FALSE;
579 /* Only the key messages get special processing */
580 if ((msg->message != WM_KEYDOWN) &&
581 (msg->message != WM_SYSCHAR) &&
582 (msg->message != WM_CHAR))
585 dlgCode = SendMessage( msg->hwnd, WM_GETDLGCODE, 0, 0 );
586 if (dlgCode & DLGC_WANTMESSAGE)
588 DispatchMessage( msg );
595 if (dlgCode & DLGC_WANTALLKEYS) break;
599 if (!(dlgCode & DLGC_WANTTAB))
601 SendMessage( hwndDlg, WM_NEXTDLGCTL,
602 (GetKeyState(VK_SHIFT) & 0x80), 0 );
609 if (!(dlgCode & DLGC_WANTARROWS))
611 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),FALSE));
618 if (!(dlgCode & DLGC_WANTARROWS))
620 SetFocus(GetNextDlgGroupItem(hwndDlg,GetFocus(),TRUE));
627 SendMessage( hwndDlg, WM_COMMAND,
628 MAKEWPARAM( IDCANCEL, 0 ),
629 (LPARAM)GetDlgItem(hwndDlg,IDCANCEL) );
631 SendMessage( hwndDlg, WM_COMMAND, IDCANCEL,
632 MAKELPARAM( GetDlgItem(hwndDlg,IDCANCEL), 0 ));
638 DWORD dw = SendMessage( hwndDlg, DM_GETDEFID, 0, 0 );
639 if (HIWORD(dw) == DC_HASDEFID)
641 SendMessage( hwndDlg, WM_COMMAND,
642 MAKEWPARAM( LOWORD(dw), BN_CLICKED ),
643 (LPARAM)GetDlgItem( hwndDlg, LOWORD(dw) ) );
645 SendMessage( hwndDlg, WM_COMMAND,
646 MAKEWPARAM( IDOK, 0 ),
647 (LPARAM)GetDlgItem(hwndDlg,IDOK) );
649 SendMessage( hwndDlg, WM_COMMAND, LOWORD(dw),
650 MAKELPARAM( GetDlgItem( hwndDlg, LOWORD(dw) ),
653 SendMessage( hwndDlg, WM_COMMAND, IDOK,
654 MAKELPARAM( GetDlgItem(hwndDlg,IDOK), 0 ));
659 break; /* case WM_KEYDOWN */
663 if (dlgCode & (DLGC_WANTALLKEYS | DLGC_WANTCHARS)) break;
667 if (dlgCode & DLGC_WANTALLKEYS) break;
671 /* If we get here, the message has not been treated specially */
672 /* and can be sent to its destination window. */
673 DispatchMessage( msg );
678 /****************************************************************
679 * GetDlgCtrlID (USER.277)
681 int GetDlgCtrlID( HWND hwnd )
683 WND *wndPtr = WIN_FindWndPtr(hwnd);
684 if (wndPtr) return wndPtr->wIDmenu;
689 /***********************************************************************
690 * GetDlgItem (USER.91)
692 HWND GetDlgItem( HWND hwndDlg, WORD id )
696 if (!(pWnd = WIN_FindWndPtr( hwndDlg ))) return 0;
697 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
698 if (pWnd->wIDmenu == id) return pWnd->hwndSelf;
703 /*******************************************************************
704 * SendDlgItemMessage (USER.101)
706 LRESULT SendDlgItemMessage(HWND hwnd, INT id, UINT msg, WPARAM wParam, LPARAM lParam)
708 HWND hwndCtrl = GetDlgItem( hwnd, id );
709 if (hwndCtrl) return SendMessage( hwndCtrl, msg, wParam, lParam );
714 /*******************************************************************
715 * SetDlgItemText (USER.92)
717 void SetDlgItemText( HWND hwnd, WORD id, SEGPTR lpString )
719 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (DWORD)lpString );
723 /***********************************************************************
724 * GetDlgItemText (USER.93)
726 int GetDlgItemText( HWND hwnd, WORD id, SEGPTR str, WORD max )
728 return (int)SendDlgItemMessage( hwnd, id, WM_GETTEXT, max, (DWORD)str );
732 /*******************************************************************
733 * SetDlgItemInt (USER.94)
735 void SetDlgItemInt( HWND hwnd, WORD id, WORD value, BOOL fSigned )
739 if (fSigned) sprintf( str, "%d", (int)value );
740 else sprintf( str, "%u", value );
741 SendDlgItemMessage( hwnd, id, WM_SETTEXT, 0, (LPARAM)MAKE_SEGPTR(str) );
745 /***********************************************************************
746 * GetDlgItemInt (USER.95)
748 WORD GetDlgItemInt( HWND hwnd, WORD id, BOOL * translated, BOOL fSigned )
753 if (translated) *translated = FALSE;
754 if (SendDlgItemMessage( hwnd, id, WM_GETTEXT, 30, (LPARAM)MAKE_SEGPTR(str) ))
757 result = strtol( str, &endptr, 10 );
758 if (endptr && (endptr != str)) /* Conversion was successful */
762 if ((result < -32767) || (result > 32767)) result = 0;
763 else if (translated) *translated = TRUE;
767 if ((result < 0) || (result > 65535)) result = 0;
768 else if (translated) *translated = TRUE;
776 /***********************************************************************
777 * CheckDlgButton (USER.97)
779 BOOL CheckDlgButton( HWND hwnd, INT id, UINT check )
781 SendDlgItemMessage( hwnd, id, BM_SETCHECK, check, 0 );
786 /***********************************************************************
787 * IsDlgButtonChecked (USER.98)
789 WORD IsDlgButtonChecked( HWND hwnd, WORD id )
791 return (WORD)SendDlgItemMessage( hwnd, id, BM_GETCHECK, 0, 0 );
795 /***********************************************************************
796 * CheckRadioButton (USER.96)
798 BOOL CheckRadioButton( HWND hwndDlg, UINT firstID, UINT lastID, UINT checkID )
800 WND *pWnd = WIN_FindWndPtr( hwndDlg );
801 if (!pWnd) return FALSE;
803 for (pWnd = pWnd->child; pWnd; pWnd = pWnd->next)
804 if ((pWnd->wIDmenu == firstID) || (pWnd->wIDmenu == lastID)) break;
805 if (!pWnd) return FALSE;
807 if (pWnd->wIDmenu == lastID)
808 lastID = firstID; /* Buttons are in reverse order */
811 SendMessage(pWnd->hwndSelf, BM_SETCHECK, (pWnd->wIDmenu == checkID),0);
812 if (pWnd->wIDmenu == lastID) break;
819 /***********************************************************************
820 * GetDialogBaseUnits (USER.243)
822 DWORD GetDialogBaseUnits()
824 return MAKELONG( xBaseUnit, yBaseUnit );
828 /***********************************************************************
829 * MapDialogRect (USER.103)
831 void MapDialogRect( HWND hwnd, LPRECT rect )
833 DIALOGINFO * dlgInfo;
834 WND * wndPtr = WIN_FindWndPtr( hwnd );
836 dlgInfo = (DIALOGINFO *)wndPtr->wExtra;
837 rect->left = (rect->left * dlgInfo->xBaseUnit) / 4;
838 rect->right = (rect->right * dlgInfo->xBaseUnit) / 4;
839 rect->top = (rect->top * dlgInfo->yBaseUnit) / 8;
840 rect->bottom = (rect->bottom * dlgInfo->yBaseUnit) / 8;
844 /***********************************************************************
845 * GetNextDlgGroupItem (USER.227)
847 HWND GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
849 WND *pWnd, *pWndStart, *pWndCtrl, *pWndDlg;
851 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
852 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
853 if (pWndCtrl->parent != pWndDlg) return 0;
855 if (!fPrevious && pWndCtrl->next) /* Check if next control is in group */
857 if (!(pWndCtrl->next->dwStyle & WS_GROUP))
858 return pWndCtrl->next->hwndSelf;
861 /* Now we will have to find the start of the group */
863 for (pWnd = pWndStart = pWndDlg->child; pWnd; pWnd = pWnd->next)
865 if (pWnd->dwStyle & WS_GROUP) pWndStart = pWnd; /* Start of a group */
866 if (pWnd == pWndCtrl) break;
869 if (!pWnd) fprintf(stderr, "GetNextDlgGroupItem: hwnd not in dialog!\n");
871 /* only case left for forward search: wraparound */
872 if (!fPrevious) return pWndStart->hwndSelf;
874 pWnd = pWndStart->next;
875 while (pWnd && (pWnd != pWndCtrl))
877 if (pWnd->dwStyle & WS_GROUP) break;
881 return pWndStart->hwndSelf;
885 /***********************************************************************
886 * GetNextDlgTabItem (USER.228)
888 HWND GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
890 WND *pWnd, *pWndLast, *pWndCtrl, *pWndDlg;
892 if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
893 if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl ))) return 0;
894 if (pWndCtrl->parent != pWndDlg) return 0;
897 pWnd = pWndCtrl->next;
900 if (!pWnd) pWnd = pWndDlg->child;
901 if (pWnd == pWndCtrl) break;
902 if ((pWnd->dwStyle & WS_TABSTOP) && (pWnd->dwStyle & WS_VISIBLE))
905 if (!fPrevious) break;
909 return pWndLast->hwndSelf;