📄 dialog.c
字号:
*/
BOOL
STDCALL
DlgDirSelectComboBoxExW(
HWND hDlg,
LPWSTR lpString,
int nCount,
int nIDComboBox)
{
return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDComboBox, TRUE, TRUE );
}
/*
* @implemented
*/
BOOL
STDCALL
DlgDirSelectExA(
HWND hDlg,
LPSTR lpString,
int nCount,
int nIDListBox)
{
return DIALOG_DlgDirSelect( hDlg, (LPWSTR)lpString, nCount, nIDListBox, FALSE, FALSE );
}
/*
* @implemented
*/
BOOL
STDCALL
DlgDirSelectExW(
HWND hDlg,
LPWSTR lpString,
int nCount,
int nIDListBox)
{
return DIALOG_DlgDirSelect( hDlg, lpString, nCount, nIDListBox, TRUE, FALSE );
}
/*
* @implemented
*/
BOOL
STDCALL
EndDialog(
HWND hDlg,
INT_PTR nResult)
{
BOOL wasEnabled = TRUE;
DIALOGINFO * dlgInfo;
HWND owner;
if (!(dlgInfo = GETDLGINFO(hDlg))) return FALSE;
dlgInfo->idResult = nResult;
dlgInfo->flags |= DF_END;
wasEnabled = (dlgInfo->flags & DF_OWNERENABLED);
if (wasEnabled && (owner = GetWindow( hDlg, GW_OWNER )))
DIALOG_EnableOwner( owner );
/* Windows sets the focus to the dialog itself in EndDialog */
if (IsChild(hDlg, GetFocus()))
SetFocus( hDlg );
/* Don't have to send a ShowWindow(SW_HIDE), just do
SetWindowPos with SWP_HIDEWINDOW as done in Windows */
SetWindowPos(hDlg, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE
| SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW);
if (hDlg == GetActiveWindow()) WinPosActivateOtherWindow( hDlg );
/* unblock dialog loop */
PostMessageA(hDlg, WM_NULL, 0, 0);
return TRUE;
}
/*
* @implemented
*/
LONG
STDCALL
GetDialogBaseUnits(VOID)
{
static DWORD units;
if (!units)
{
HDC hdc;
SIZE size;
if ((hdc = GetDC(0)))
{
size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy );
if (size.cx) units = MAKELONG( size.cx, size.cy );
ReleaseDC( 0, hdc );
}
}
return units;
}
/*
* @implemented
*/
int
STDCALL
GetDlgCtrlID(
HWND hwndCtl)
{
return GetWindowLongPtrW( hwndCtl, GWLP_ID );
}
/*
* @implemented
*/
HWND
STDCALL
GetDlgItem(
HWND hDlg,
int nIDDlgItem)
{
GETDLGITEMINFO info;
info.nIDDlgItem = nIDDlgItem;
info.control = 0;
if(hDlg && !EnumChildWindows(hDlg, (WNDENUMPROC)&GetDlgItemEnumProc, (LPARAM)&info))
return info.control;
else
return 0;
}
/*
* @implemented
*/
UINT
STDCALL
GetDlgItemInt(
HWND hDlg,
int nIDDlgItem,
BOOL *lpTranslated,
BOOL bSigned)
{
char str[30];
char * endptr;
long result = 0;
if (lpTranslated) *lpTranslated = FALSE;
if (!SendDlgItemMessageA(hDlg, nIDDlgItem, WM_GETTEXT, sizeof(str), (LPARAM)str))
return 0;
if (bSigned)
{
result = strtol( str, &endptr, 10 );
if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
return 0;
/* FIXME: errno? */
if (((result == 0) || (result == 0xFFFFFFFF))/* && (errno == ERANGE) */)
return 0;
}
else
{
result = strtoul( str, &endptr, 10 );
if (!endptr || (endptr == str)) /* Conversion was unsuccessful */
return 0;
/* FIXME: errno? */
if ((result == 0xFFFFFFFF)/* && (errno == ERANGE) */) return 0;
}
if (lpTranslated) *lpTranslated = TRUE;
return (UINT)result;
}
/*
* @implemented
*/
UINT
STDCALL
GetDlgItemTextA(
HWND hDlg,
int nIDDlgItem,
LPSTR lpString,
int nMaxCount)
{
if (lpString && (lpString > 0)) lpString[0] = '\0';
return (UINT)SendDlgItemMessageA( hDlg, nIDDlgItem, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
}
/*
* @implemented
*/
UINT
STDCALL
GetDlgItemTextW(
HWND hDlg,
int nIDDlgItem,
LPWSTR lpString,
int nMaxCount)
{
if (lpString && (lpString > 0)) lpString[0] = '\0';
return (UINT)SendDlgItemMessageW( hDlg, nIDDlgItem, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
}
/*
* @implemented
*/
HWND
STDCALL
GetNextDlgGroupItem(
HWND hDlg,
HWND hCtl,
BOOL bPrevious)
{
HWND hwnd, hwndNext, retvalue, hwndLastGroup = 0;
BOOL fLooped=FALSE;
BOOL fSkipping=FALSE;
if (hDlg == hCtl) hCtl = NULL;
if (!hCtl && bPrevious) return 0;
/* if the hwndCtrl is the child of the control in the hwndDlg,
* then the hwndDlg has to be the parent of the hwndCtrl */
if (hCtl)
{
if (!IsChild (hDlg, hCtl)) return 0;
/* Make sure hwndCtrl is a top-level child */
}
else
{
/* No ctrl specified -> start from the beginning */
if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
/* MSDN is wrong. fPrevious does not result in the last child */
/* No ctrl specified -> start from the beginning */
if (!(hCtl = GetWindow( hDlg, GW_CHILD ))) return 0;
/* MSDN is wrong. fPrevious does not result in the last child */
/* Maybe that first one is valid. If so then we don't want to skip it*/
if ((GetWindowLongW( hCtl, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
{
return hCtl;
}
}
/* Always go forward around the group and list of controls; for the
* previous control keep track; for the next break when you find one
*/
retvalue = hCtl;
hwnd = hCtl;
while (hwndNext = GetWindow (hwnd, GW_HWNDNEXT),
1)
{
while (!hwndNext)
{
/* Climb out until there is a next sibling of the ancestor or we
* reach the top (in which case we loop back to the start)
*/
if (hDlg == GetParent (hwnd))
{
/* Wrap around to the beginning of the list, within the same
* group. (Once only)
*/
if (fLooped) goto end;
fLooped = TRUE;
hwndNext = GetWindow (hDlg, GW_CHILD);
}
else
{
hwnd = GetParent (hwnd);
hwndNext = GetWindow (hwnd, GW_HWNDNEXT);
}
}
hwnd = hwndNext;
/* Wander down the leading edge of controlparents */
while ( (GetWindowLongW (hwnd, GWL_EXSTYLE) & WS_EX_CONTROLPARENT) &&
((GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) &&
(hwndNext = GetWindow (hwnd, GW_CHILD)))
hwnd = hwndNext;
/* Question. If the control is a control parent but either has no
* children or is not visible/enabled then if it has a WS_GROUP does
* it count? For that matter does it count anyway?
* I believe it doesn't count.
*/
if ((GetWindowLongW (hwnd, GWL_STYLE) & WS_GROUP))
{
hwndLastGroup = hwnd;
if (!fSkipping)
{
/* Look for the beginning of the group */
fSkipping = TRUE;
}
}
if (hwnd == hCtl)
{
if (!fSkipping) break;
if (hwndLastGroup == hwnd) break;
hwnd = hwndLastGroup;
fSkipping = FALSE;
fLooped = FALSE;
}
if (!fSkipping &&
(GetWindowLongW (hwnd, GWL_STYLE) & (WS_VISIBLE|WS_DISABLED)) ==
WS_VISIBLE)
{
retvalue = hwnd;
if (!bPrevious) break;
}
}
end:
return retvalue;
}
/*
* @implemented
*/
HWND
STDCALL
GetNextDlgTabItem(
HWND hDlg,
HWND hCtl,
BOOL bPrevious)
{
/* Undocumented but tested under Win2000 and WinME */
if (hDlg == hCtl) hCtl = NULL;
/* Contrary to MSDN documentation, tested under Win2000 and WinME
* NB GetLastError returns whatever was set before the function was
* called.
*/
if (!hCtl && bPrevious) return 0;
return DIALOG_GetNextTabItem(hDlg, hDlg, hCtl, bPrevious);
}
#if 0
BOOL
STDCALL
IsDialogMessage(
HWND hDlg,
LPMSG lpMsg)
{
return IsDialogMessageW(hDlg, lpMsg);
}
#endif
/***********************************************************************
* DIALOG_FixOneChildOnChangeFocus
*
* Callback helper for DIALOG_FixChildrenOnChangeFocus
*/
static BOOL CALLBACK DIALOG_FixOneChildOnChangeFocus (HWND hwndChild,
LPARAM lParam)
{
/* If a default pushbutton then no longer default */
if (DLGC_DEFPUSHBUTTON & SendMessageW (hwndChild, WM_GETDLGCODE, 0, 0))
SendMessageW (hwndChild, BM_SETSTYLE, BS_PUSHBUTTON, TRUE);
return TRUE;
}
/***********************************************************************
* DIALOG_FixChildrenOnChangeFocus
*
* Following the change of focus that occurs for example after handling
* a WM_KEYDOWN VK_TAB in IsDialogMessage, some tidying of the dialog's
* children may be required.
*/
static void DIALOG_FixChildrenOnChangeFocus (HWND hwndDlg, HWND hwndNext)
{
INT dlgcode_next = SendMessageW (hwndNext, WM_GETDLGCODE, 0, 0);
/* INT dlgcode_dlg = SendMessageW (hwndDlg, WM_GETDLGCODE, 0, 0); */
/* Windows does ask for this. I don't know why yet */
EnumChildWindows (hwndDlg, DIALOG_FixOneChildOnChangeFocus, 0);
/* If the button that is getting the focus WAS flagged as the default
* pushbutton then ask the dialog what it thinks the default is and
* set that in the default style.
*/
if (dlgcode_next & DLGC_DEFPUSHBUTTON)
{
DWORD def_id = SendMessageW (hwndDlg, DM_GETDEFID, 0, 0);
if (HIWORD(def_id) == DC_HASDEFID)
{
HWND hwndDef;
def_id = LOWORD(def_id);
hwndDef = GetDlgItem (hwndDlg, def_id);
if (hwndDef)
{
INT dlgcode_def = SendMessageW (hwndDef, WM_GETDLGCODE, 0, 0);
/* I know that if it is a button then it should already be a
* UNDEFPUSHBUTTON, since we have just told the buttons to
* change style. But maybe they ignored our request
*/
if ((dlgcode_def & DLGC_BUTTON) &&
(dlgcode_def & DLGC_UNDEFPUSHBUTTON))
{
SendMessageW (hwndDef, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
}
}
}
}
else if ((dlgcode_next & DLGC_BUTTON) && (dlgcode_next & DLGC_UNDEFPUSHBUTTON))
{
SendMessageW (hwndNext, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
/* I wonder why it doesn't send a DM_SETDEFID */
}
}
/*
* @implemented
*/
BOOL
STDCALL
IsDialogMess
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -