📄 window.c
字号:
hHeap = GetProcessHeap();
pHwnd = HeapAlloc ( hHeap, 0, sizeof(HWND)*(dwCount+1) );
if ( !pHwnd )
{
SetLastError ( ERROR_NOT_ENOUGH_MEMORY );
return FALSE;
}
/* now call kernel again to fill the buffer this time */
dwCount = NtUserBuildHwndList (
hDesktop, hWndparent, bChildren, dwThreadId, lParam, pHwnd, dwCount );
if ( !dwCount || GetLastError() )
{
if ( pHwnd )
HeapFree ( hHeap, 0, pHwnd );
return FALSE;
}
/* call the user's callback function until we're done or
they tell us to quit */
for ( i = 0; i < dwCount; i++ )
{
/* FIXME I'm only getting NULLs from Thread Enumeration, and it's
* probably because I'm not doing it right in NtUserBuildHwndList.
* Once that's fixed, we shouldn't have to check for a NULL HWND
* here
*/
if ( !(ULONG)pHwnd[i] ) /* don't enumerate a NULL HWND */
continue;
if ( !(*lpfn)( pHwnd[i], lParam ) )
{
HeapFree ( hHeap, 0, pHwnd );
return FALSE;
}
}
if ( pHwnd )
HeapFree ( hHeap, 0, pHwnd );
return TRUE;
}
/*
* @implemented
*/
BOOL
STDCALL
EnumChildWindows(
HWND hWndParent,
WNDENUMPROC lpEnumFunc,
LPARAM lParam)
{
if ( !hWndParent )
{
return EnumWindows(lpEnumFunc, lParam);
}
return User32EnumWindows ( NULL, hWndParent, lpEnumFunc, lParam, 0, TRUE );
}
/*
* @implemented
*/
BOOL
STDCALL
EnumThreadWindows(DWORD dwThreadId,
WNDENUMPROC lpfn,
LPARAM lParam)
{
if ( !dwThreadId )
dwThreadId = GetCurrentThreadId();
return User32EnumWindows ( NULL, NULL, lpfn, lParam, dwThreadId, FALSE );
}
/*
* @implemented
*/
BOOL STDCALL
EnumWindows(WNDENUMPROC lpEnumFunc,
LPARAM lParam)
{
return User32EnumWindows ( NULL, NULL, lpEnumFunc, lParam, 0, FALSE );
}
/*
* @implemented
*/
BOOL
STDCALL
EnumDesktopWindows(
HDESK hDesktop,
WNDENUMPROC lpfn,
LPARAM lParam)
{
return User32EnumWindows ( hDesktop, NULL, lpfn, lParam, 0, FALSE );
}
/*
* @implemented
*/
HWND STDCALL
FindWindowExA(HWND hwndParent,
HWND hwndChildAfter,
LPCSTR lpszClass,
LPCSTR lpszWindow)
{
UNICODE_STRING ucClassName, *pucClassName = NULL;
UNICODE_STRING ucWindowName, *pucWindowName = NULL;
HWND Result;
if (IS_ATOM(lpszClass))
{
ucClassName.Buffer = (LPWSTR)lpszClass;
ucClassName.Length = 0;
pucClassName = &ucClassName;
}
else if (lpszClass != NULL)
{
if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName,
(LPSTR)lpszClass))
{
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
pucClassName = &ucClassName;
}
if (lpszWindow != NULL)
{
if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName,
(LPSTR)lpszWindow))
{
if (!IS_ATOM(lpszClass) && lpszClass != NULL)
RtlFreeUnicodeString(&ucWindowName);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
pucWindowName = &ucWindowName;
}
Result = NtUserFindWindowEx(hwndParent,
hwndChildAfter,
pucClassName,
pucWindowName);
if (!IS_ATOM(lpszClass) && lpszClass != NULL)
RtlFreeUnicodeString(&ucClassName);
if (lpszWindow != NULL)
RtlFreeUnicodeString(&ucWindowName);
return Result;
}
/*
* @implemented
*/
HWND STDCALL
FindWindowExW(HWND hwndParent,
HWND hwndChildAfter,
LPCWSTR lpszClass,
LPCWSTR lpszWindow)
{
UNICODE_STRING ucClassName, *pucClassName = NULL;
UNICODE_STRING ucWindowName, *pucWindowName = NULL;
if (IS_ATOM(lpszClass))
{
ucClassName.Length = 0;
ucClassName.Buffer = (LPWSTR)lpszClass;
pucClassName = &ucClassName;
}
else if (lpszClass != NULL)
{
RtlInitUnicodeString(&ucClassName,
lpszClass);
pucClassName = &ucClassName;
}
if (lpszWindow != NULL)
{
RtlInitUnicodeString(&ucWindowName,
lpszWindow);
pucWindowName = &ucWindowName;
}
return NtUserFindWindowEx(hwndParent,
hwndChildAfter,
pucClassName,
pucWindowName);
}
/*
* @implemented
*/
HWND STDCALL
FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName)
{
//FIXME: FindWindow does not search children, but FindWindowEx does.
// what should we do about this?
return FindWindowExA (NULL, NULL, lpClassName, lpWindowName);
}
/*
* @implemented
*/
HWND STDCALL
FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName)
{
/*
There was a FIXME here earlier, but I think it is just a documentation unclarity.
FindWindow only searches top level windows. What they mean is that child
windows of other windows than the desktop can be searched.
FindWindowExW never does a recursive search.
/ Joakim
*/
return FindWindowExW (NULL, NULL, lpClassName, lpWindowName);
}
/*
* @unimplemented
*/
BOOL STDCALL
GetAltTabInfoA(HWND hwnd,
int iItem,
PALTTABINFO pati,
LPSTR pszItemText,
UINT cchItemText)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
BOOL STDCALL
GetAltTabInfoW(HWND hwnd,
int iItem,
PALTTABINFO pati,
LPWSTR pszItemText,
UINT cchItemText)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @implemented
*/
HWND STDCALL
GetAncestor(HWND hwnd, UINT gaFlags)
{
return(NtUserGetAncestor(hwnd, gaFlags));
}
/*
* @implemented
*/
BOOL STDCALL
GetClientRect(HWND hWnd, LPRECT lpRect)
{
return(NtUserGetClientRect(hWnd, lpRect));
}
/*
* @implemented
*/
BOOL STDCALL
GetGUIThreadInfo(DWORD idThread,
LPGUITHREADINFO lpgui)
{
return (BOOL)NtUserGetGUIThreadInfo(idThread, lpgui);
}
/*
* @unimplemented
*/
HWND STDCALL
GetLastActivePopup(HWND hWnd)
{
return NtUserGetLastActivePopup(hWnd);
}
/*
* @implemented
*/
HWND STDCALL
GetParent(HWND hWnd)
{
return NtUserGetParent(hWnd);
}
/*
* @unimplemented
*/
BOOL STDCALL
GetProcessDefaultLayout(DWORD *pdwDefaultLayout)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @unimplemented
*/
BOOL STDCALL
GetTitleBarInfo(HWND hwnd,
PTITLEBARINFO pti)
{
UNIMPLEMENTED;
return FALSE;
}
/*
* @implemented
*/
HWND STDCALL
GetWindow(HWND hWnd,
UINT uCmd)
{
return NtUserGetWindow(hWnd, uCmd);
}
/*
* @implemented
*/
HWND STDCALL
GetTopWindow(HWND hWnd)
{
if (!hWnd) hWnd = GetDesktopWindow();
return GetWindow( hWnd, GW_CHILD );
}
/*
* @implemented
*/
BOOL STDCALL
GetWindowInfo(HWND hwnd,
PWINDOWINFO pwi)
{
return NtUserGetWindowInfo(hwnd, pwi);
}
/*
* @implemented
*/
UINT STDCALL
GetWindowModuleFileNameA(HWND hwnd,
LPSTR lpszFileName,
UINT cchFileNameMax)
{
HINSTANCE hWndInst;
if(!(hWndInst = NtUserGetWindowInstance(hwnd)))
{
return 0;
}
return GetModuleFileNameA(hWndInst, lpszFileName, cchFileNameMax);
}
/*
* @implemented
*/
UINT STDCALL
GetWindowModuleFileNameW(HWND hwnd,
LPWSTR lpszFileName,
UINT cchFileNameMax)
{
HINSTANCE hWndInst;
if(!(hWndInst = NtUserGetWindowInstance(hwnd)))
{
return 0;
}
return GetModuleFileNameW(hWndInst, lpszFileName, cchFileNameMax);
}
/*
* @implemented
*/
BOOL STDCALL
GetWindowPlacement(HWND hWnd,
WINDOWPLACEMENT *lpwndpl)
{
return (BOOL)NtUserGetWindowPlacement(hWnd, lpwndpl);
}
/*
* @implemented
*/
BOOL STDCALL
GetWindowRect(HWND hWnd,
LPRECT lpRect)
{
return(NtUserGetWindowRect(hWnd, lpRect));
}
/*
* @implemented
*/
int STDCALL
GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
{
DWORD ProcessId;
if (lpString == NULL)
return 0;
if (!NtUserGetWindowThreadProcessId(hWnd, &ProcessId))
return 0;
if (ProcessId != GetCurrentProcessId())
{
/* do not send WM_GETTEXT messages to other processes */
LPWSTR Buffer;
INT Length;
Buffer = HeapAlloc(GetProcessHeap(), 0, nMaxCount * sizeof(WCHAR));
if (!Buffer)
return FALSE;
Length = NtUserInternalGetWindowText(hWnd, Buffer, nMaxCount);
if (Length > 0 && nMaxCount > 0 &&
!WideCharToMultiByte(CP_ACP, 0, Buffer, -1,
lpString, nMaxCount, NULL, NULL))
{
lpString[0] = '\0';
}
HeapFree(GetProcessHeap(), 0, Buffer);
return (LRESULT)Length;
}
return SendMessageA(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
}
/*
* @implemented
*/
int STDCALL
GetWindowTextLengthA(HWND hWnd)
{
DWORD ProcessId;
if(!NtUserGetWindowThreadProcessId(hWnd, &ProcessId))
{
return 0;
}
if(ProcessId == GetCurrentProcessId())
{
return(SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0));
}
/* do not send WM_GETTEXT messages to other processes */
return (LRESULT)NtUserInternalGetWindowText(hWnd, NULL, 0);
}
/*
* @implemented
*/
int STDCALL
GetWindowTextLengthW(HWND hWnd)
{
DWORD ProcessId;
if(!NtUserGetWindowThreadProcessId(hWnd, &ProcessId))
{
return 0;
}
if(ProcessId == GetCurrentProcessId())
{
return(SendMessageW(hWnd, WM_GETTEXTLENGTH, 0, 0));
}
/* do not send WM_GETTEXT messages to other processes */
return (LRESULT)NtUserInternalGetWindowText(hWnd, NULL, 0);
}
/*
* @implemented
*/
int STDCALL
GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
{
DWORD ProcessId;
if (lpString == NULL)
return 0;
if (!NtUserGetWindowThreadProcessId(hWnd, &ProcessId))
return 0;
if (ProcessId == GetCurrentProcessId())
return SendMessageW(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
return NtUserInternalGetWindowText(hWnd, lpString, nMaxCount);
}
DWORD STDCALL
GetWindowThreadProcessId(HWND hWnd,
LPDWORD lpdwProcessId)
{
return NtUserGetWindowThreadProcessId(hWnd, lpdwProcessId);
}
/*
* @implemented
*/
BOOL STDCALL
IsChild(HWND hWndParent,
HWND hWnd)
{
if (! IsWindow(hWndParent) || ! IsWindow(hWnd))
{
return FALSE;
}
do
{
hWnd = (HWND)NtUserGetWindowLong(hWnd, GWL_HWNDPARENT, FALSE);
}
while (hWnd != NULL && hWnd != hWndParent);
return hWnd == hWndParent;
}
/*
* @implemented
*/
BOOL STDCALL
IsIconic(HWND hWnd)
{
return (NtUserGetWindowLong( hWnd, GWL_STYLE, FALSE) & WS_MINIMIZE) != 0;
}
/*
* @implemented
*/
BOOL STDCALL
IsWindow(HWND hWnd)
{
DWORD WndProc = NtUserGetWindowLong(hWnd, GWL_WNDPROC, FALSE);
return (0 != WndProc || ERROR_INVALID_WINDOW_HANDLE != GetLastError());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -