Beispiel #1
0
void
CheckDefPushButton(HWND hDlg, HWND hWndCurrent, HWND hWndNextItem)
{
    WORD wDlgCode;
    UINT wDefID;
    DWORD dwDefID;
    DWORD dwStyle;
    HWND hWndTemp, hDefItem;

    wDlgCode = (hWndNextItem)?
               (WORD)SendMessage(hWndNextItem,WM_GETDLGCODE,0,0L):0;

    if (hWndNextItem == hWndCurrent) {
        if (wDlgCode & DLGC_UNDEFPUSHBUTTON)
            SendMessage(hWndCurrent,BM_SETSTYLE,
                        (WPARAM)BS_DEFPUSHBUTTON,MAKELPARAM(TRUE,0));
    }
    else {
        if ((hWndCurrent && ((WORD)SendMessage(hWndCurrent,WM_GETDLGCODE,0,0L) &
                             (DLGC_UNDEFPUSHBUTTON|DLGC_DEFPUSHBUTTON))) ||
                (hWndNextItem && (wDlgCode &
                                  (DLGC_UNDEFPUSHBUTTON|DLGC_DEFPUSHBUTTON)))) {
            /* we have to find an ancestor of hWndNextItem whose parent is hDlg */
            if (wDlgCode & DLGC_DEFPUSHBUTTON)
                SendMessage(hWndNextItem,BM_SETSTYLE,
                            (WPARAM)BS_PUSHBUTTON,MAKELPARAM(TRUE,0));
            for (hWndTemp = GetNextDlgItem(hDlg,hWndNextItem);
                    hWndTemp != hWndNextItem;
                    hWndTemp = GetNextDlgItem(hDlg,hWndTemp))
                if ((WORD)SendMessage(hWndTemp,WM_GETDLGCODE,0,0L) &
                        DLGC_DEFPUSHBUTTON)
                    SendMessage(hWndTemp,BM_SETSTYLE,
                                (WPARAM)BS_PUSHBUTTON,MAKELPARAM(TRUE,0));
        }
        if (wDlgCode & DLGC_UNDEFPUSHBUTTON)
            SendMessage(hWndNextItem,BM_SETSTYLE,
                        (WPARAM)BS_DEFPUSHBUTTON,MAKELPARAM(TRUE,0));
        else {
            dwDefID = SendMessage(hDlg,DM_GETDEFID,0,0L);
            if (HIWORD(dwDefID) != DC_HASDEFID)
                wDefID = IDOK;
            else
                wDefID = LOWORD(dwDefID);
            if ((hDefItem = GetDlgItem(hDlg,wDefID))) {
                wDlgCode = (WORD)SendMessage(hDefItem,WM_GETDLGCODE,0,0L);
                dwStyle = GetWindowLong(hDefItem,GWL_STYLE);
                if (!(wDlgCode & DLGC_DEFPUSHBUTTON) &&
                        (wDlgCode & DLGC_UNDEFPUSHBUTTON) &&
                        !(dwStyle & WS_DISABLED))
                    SendMessage(hDefItem,BM_SETSTYLE,
                                (WPARAM)BS_DEFPUSHBUTTON,MAKELPARAM(TRUE,0));
            }
        }
    }
}
Beispiel #2
0
void SmartEnableWindow(HWND Win, BOOL Enable)
{
	UIETWASSERT(Win);
	if (!Enable)
	{
		HWND hasfocus = GetFocus();
		bool FocusProblem = false;
		HWND focuscopy;
		for (focuscopy = hasfocus; focuscopy; focuscopy = (GetParent)(focuscopy))
			if (focuscopy == Win)
				FocusProblem = true;
		if (FocusProblem)
		{
			HWND nextctrl = GetNextDlgItem(Win, true);
			if (nextctrl)
				SetFocus(nextctrl);
		}
	}
	::EnableWindow(Win, Enable);
}