mirror of
https://github.com/reactos/reactos.git
synced 2024-10-06 01:13:38 +00:00
- Implemented NtUserDefSetText and NtUserInternalGetWindowText.
- Fixed NtUserCreateWindowEx to correctly allocate the window name. - Fixed InternalGetWindowText to behave like MS implementation. - Changed DefWindowProc[A/W] to handle WM_GETTEXT, WM_GETTEXTLENGTH, WM_SETTEXT (and WM_NCCREATE, WM_NCDESTROY) using the above functions. svn path=/trunk/; revision=6591
This commit is contained in:
parent
2433129700
commit
60fe580231
|
@ -350,11 +350,8 @@ NtUserDeferWindowPos(HDWP WinPosInfo,
|
|||
int cx,
|
||||
int cy,
|
||||
UINT Flags);
|
||||
DWORD
|
||||
STDCALL
|
||||
NtUserDefSetText(
|
||||
DWORD Unknown0,
|
||||
DWORD Unknown1);
|
||||
BOOL STDCALL
|
||||
NtUserDefSetText(HWND WindowHandle, PANSI_STRING Text);
|
||||
|
||||
BOOL
|
||||
STDCALL
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: defwnd.c,v 1.105 2003/11/08 15:33:51 mf Exp $
|
||||
/* $Id: defwnd.c,v 1.106 2003/11/09 11:42:08 navaraf Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS user32.dll
|
||||
|
@ -1347,75 +1347,56 @@ DefWindowProcA(HWND hWnd,
|
|||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
static LPSTR WindowTextAtom = 0;
|
||||
PSTR WindowText;
|
||||
|
||||
switch (Msg)
|
||||
{
|
||||
case WM_NCCREATE:
|
||||
{
|
||||
CREATESTRUCTA *Cs = (CREATESTRUCTA*)lParam;
|
||||
if (HIWORD(Cs->lpszName))
|
||||
{
|
||||
if (0 == WindowTextAtom)
|
||||
{
|
||||
WindowTextAtom =
|
||||
(LPSTR)(ULONG)GlobalAddAtomA("USER32!WindowTextAtomA");
|
||||
}
|
||||
WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
||||
(strlen(Cs->lpszName) + 1) * sizeof(CHAR));
|
||||
strcpy(WindowText, Cs->lpszName);
|
||||
SetPropA(hWnd, WindowTextAtom, WindowText);
|
||||
}
|
||||
return (1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_GETTEXTLENGTH:
|
||||
{
|
||||
if (WindowTextAtom == 0 ||
|
||||
(WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
return (strlen(WindowText));
|
||||
return InternalGetWindowText(hWnd, NULL, 0);
|
||||
}
|
||||
|
||||
case WM_GETTEXT:
|
||||
{
|
||||
if (WindowTextAtom == 0 ||
|
||||
(WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
UNICODE_STRING UnicodeString;
|
||||
LPSTR AnsiBuffer = (LPSTR)lParam;
|
||||
BOOL Result;
|
||||
|
||||
if (wParam > 1)
|
||||
{
|
||||
*((PSTR)lParam) = '\0';
|
||||
*((PWSTR)lParam) = '\0';
|
||||
}
|
||||
return (0);
|
||||
UnicodeString.Length = UnicodeString.MaximumLength =
|
||||
wParam * sizeof(WCHAR);
|
||||
UnicodeString.Buffer = HeapAlloc(GetProcessHeap(), 0,
|
||||
UnicodeString.Length);
|
||||
if (!UnicodeString.Buffer)
|
||||
return FALSE;
|
||||
Result = InternalGetWindowText(hWnd, UnicodeString.Buffer, wParam);
|
||||
if (wParam > 0 &&
|
||||
!WideCharToMultiByte(CP_ACP, 0, UnicodeString.Buffer, -1,
|
||||
AnsiBuffer, wParam, NULL, NULL))
|
||||
{
|
||||
AnsiBuffer[wParam - 1] = 0;
|
||||
}
|
||||
strncpy((LPSTR)lParam, WindowText, wParam);
|
||||
return (min(wParam, strlen(WindowText)));
|
||||
HeapFree(GetProcessHeap(), 0, UnicodeString.Buffer);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
case WM_SETTEXT:
|
||||
{
|
||||
if (0 == WindowTextAtom)
|
||||
{
|
||||
WindowTextAtom =
|
||||
(LPSTR)(DWORD)GlobalAddAtomA("USER32!WindowTextAtomA");
|
||||
}
|
||||
if (WindowTextAtom != 0 &&
|
||||
(WindowText = GetPropA(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
|
||||
}
|
||||
WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
||||
(strlen((PSTR)lParam) + 1) * sizeof(CHAR));
|
||||
strcpy(WindowText, (PSTR)lParam);
|
||||
SetPropA(hWnd, WindowTextAtom, WindowText);
|
||||
ANSI_STRING AnsiString;
|
||||
RtlInitAnsiString(&AnsiString, (LPSTR)lParam);
|
||||
NtUserDefSetText(hWnd, &AnsiString);
|
||||
if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
|
||||
{
|
||||
DefWndNCPaint(hWnd, (HRGN)1);
|
||||
}
|
||||
return (1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1429,16 +1410,6 @@ DefWindowProcA(HWND hWnd,
|
|||
case WM_IME_SELECT:
|
||||
case WM_IME_SETCONTEXT:
|
||||
*/
|
||||
|
||||
case WM_NCDESTROY:
|
||||
{
|
||||
if (WindowTextAtom != 0 &&
|
||||
(WindowText = RemovePropA(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
RtlFreeHeap(GetProcessHeap(), 0, WindowText);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
return User32DefWindowProc(hWnd, Msg, wParam, lParam, FALSE);
|
||||
|
@ -1451,70 +1422,38 @@ DefWindowProcW(HWND hWnd,
|
|||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
static LPWSTR WindowTextAtom = 0;
|
||||
PWSTR WindowText;
|
||||
|
||||
switch (Msg)
|
||||
{
|
||||
case WM_NCCREATE:
|
||||
{
|
||||
CREATESTRUCTW* CreateStruct = (CREATESTRUCTW*)lParam;
|
||||
if (HIWORD(CreateStruct->lpszName))
|
||||
{
|
||||
if (0 == WindowTextAtom)
|
||||
{
|
||||
WindowTextAtom =
|
||||
(LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW");
|
||||
}
|
||||
WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
||||
(wcslen(CreateStruct->lpszName) + 1) * sizeof(WCHAR));
|
||||
wcscpy(WindowText, CreateStruct->lpszName);
|
||||
SetPropW(hWnd, WindowTextAtom, WindowText);
|
||||
}
|
||||
return (1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
case WM_GETTEXTLENGTH:
|
||||
{
|
||||
if (WindowTextAtom == 0 ||
|
||||
(WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
return (wcslen(WindowText));
|
||||
return InternalGetWindowText(hWnd, NULL, 0);
|
||||
}
|
||||
|
||||
case WM_GETTEXT:
|
||||
{
|
||||
if (WindowTextAtom == 0 ||
|
||||
(WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
DWORD Result;
|
||||
if (wParam > 1)
|
||||
{
|
||||
*((PWSTR)lParam) = '\0';
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
wcsncpy((PWSTR)lParam, WindowText, wParam);
|
||||
return (min(wParam, wcslen(WindowText)));
|
||||
Result = InternalGetWindowText(hWnd, (PWSTR)lParam, wParam);
|
||||
return Result;
|
||||
}
|
||||
|
||||
case WM_SETTEXT:
|
||||
{
|
||||
if (WindowTextAtom == 0)
|
||||
{
|
||||
WindowTextAtom =
|
||||
(LPWSTR)(DWORD)GlobalAddAtomW(L"USER32!WindowTextAtomW");
|
||||
}
|
||||
if (WindowTextAtom != 0 &&
|
||||
(WindowText = GetPropW(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
|
||||
}
|
||||
WindowText = RtlAllocateHeap(RtlGetProcessHeap(), 0,
|
||||
(wcslen((PWSTR)lParam) + 1) * sizeof(WCHAR));
|
||||
wcscpy(WindowText, (PWSTR)lParam);
|
||||
SetPropW(hWnd, WindowTextAtom, WindowText);
|
||||
UNICODE_STRING UnicodeString;
|
||||
ANSI_STRING AnsiString;
|
||||
|
||||
RtlInitUnicodeString(&UnicodeString, (LPWSTR)lParam);
|
||||
RtlUnicodeStringToAnsiString(&AnsiString, &UnicodeString, TRUE);
|
||||
NtUserDefSetText(hWnd, &AnsiString);
|
||||
RtlFreeAnsiString(&AnsiString);
|
||||
if ((GetWindowLongW(hWnd, GWL_STYLE) & WS_CAPTION) == WS_CAPTION)
|
||||
{
|
||||
DefWndNCPaint(hWnd, (HRGN)1);
|
||||
|
@ -1533,16 +1472,6 @@ DefWindowProcW(HWND hWnd,
|
|||
/* FIXME */
|
||||
return (0);
|
||||
}
|
||||
|
||||
case WM_NCDESTROY:
|
||||
{
|
||||
if (WindowTextAtom != 0 &&
|
||||
(WindowText = RemovePropW(hWnd, WindowTextAtom)) == NULL)
|
||||
{
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, WindowText);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
return User32DefWindowProc(hWnd, Msg, wParam, lParam, TRUE);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: window.c,v 1.78 2003/11/02 06:58:57 navaraf Exp $
|
||||
/* $Id: window.c,v 1.79 2003/11/09 11:42:08 navaraf Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS user32.dll
|
||||
|
@ -1598,29 +1598,7 @@ DWORD
|
|||
STDCALL
|
||||
InternalGetWindowText(HWND hWnd, LPWSTR lpString, int nMaxCount)
|
||||
{
|
||||
DWORD res = 0;
|
||||
LPWSTR lps = NULL;
|
||||
if(lpString && (nMaxCount > 0))
|
||||
{
|
||||
lps = RtlAllocateHeap(RtlGetProcessHeap(), 0, nMaxCount * sizeof(WCHAR));
|
||||
if(!lps)
|
||||
{
|
||||
SetLastError(ERROR_OUTOFMEMORY);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
res = NtUserInternalGetWindowText(hWnd, lps, nMaxCount);
|
||||
|
||||
if(lps)
|
||||
{
|
||||
RtlCopyMemory(lpString, lps, res * sizeof(WCHAR));
|
||||
lpString[res] = (WCHAR)"\0"; /* null-terminate the string */
|
||||
|
||||
RtlFreeHeap(RtlGetProcessHeap(), 0, lps);
|
||||
}
|
||||
|
||||
return res;
|
||||
return NtUserInternalGetWindowText(hWnd, lpString, nMaxCount);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: stubs.c,v 1.31 2003/11/02 16:33:33 ekohl Exp $
|
||||
/* $Id: stubs.c,v 1.32 2003/11/09 11:42:08 navaraf Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -265,17 +265,6 @@ NtUserDdeSetQualityOfService(
|
|||
return 0;
|
||||
}
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
NtUserDefSetText(
|
||||
DWORD Unknown0,
|
||||
DWORD Unknown1)
|
||||
{
|
||||
UNIMPLEMENTED
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DWORD
|
||||
STDCALL
|
||||
NtUserDestroyAcceleratorTable(
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
/* $Id: window.c,v 1.130 2003/11/08 15:00:36 gvg Exp $
|
||||
/* $Id: window.c,v 1.131 2003/11/09 11:42:08 navaraf Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS kernel
|
||||
|
@ -1486,7 +1486,11 @@ NtUserCreateWindowEx(DWORD dwExStyle,
|
|||
ExInitializeFastMutex(&WindowObject->ChildrenListLock);
|
||||
|
||||
RtlInitUnicodeString(&WindowObject->WindowName, WindowName.Buffer);
|
||||
/*
|
||||
This is incorrect!!! -- Filip
|
||||
|
||||
RtlFreeUnicodeString(&WindowName);
|
||||
*/
|
||||
|
||||
|
||||
/* Correct the window style. */
|
||||
|
@ -2955,44 +2959,6 @@ NtUserGetWindowThreadProcessId(HWND hWnd, LPDWORD UnsafePid)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
DWORD STDCALL
|
||||
NtUserInternalGetWindowText(HWND hWnd,
|
||||
LPWSTR lpString,
|
||||
int nMaxCount)
|
||||
{
|
||||
DWORD res = 0;
|
||||
PWINDOW_OBJECT WindowObject;
|
||||
|
||||
IntAcquireWinLockShared(); /* ??? */
|
||||
WindowObject = IntGetWindowObject(hWnd);
|
||||
if(!WindowObject)
|
||||
{
|
||||
IntReleaseWinLock(); /* ??? */
|
||||
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(lpString)
|
||||
{
|
||||
/* FIXME - Window text is currently stored
|
||||
in the Atom 'USER32!WindowTextAtomA' */
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* FIXME - return length of window text */
|
||||
}
|
||||
|
||||
IntReleaseWindowObject(WindowObject);
|
||||
|
||||
IntReleaseWinLock(); /* ??? */
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @unimplemented
|
||||
*/
|
||||
|
@ -3696,4 +3662,83 @@ NtUserWindowFromPoint(LONG X, LONG Y)
|
|||
return hWnd;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NtUserDefSetText
|
||||
*
|
||||
* Undocumented function that is called from DefWindowProc to set
|
||||
* window text.
|
||||
*
|
||||
* FIXME: Call this from user32.dll!
|
||||
*
|
||||
* Status
|
||||
* @unimplemented
|
||||
*/
|
||||
|
||||
BOOL STDCALL
|
||||
NtUserDefSetText(HWND WindowHandle, PANSI_STRING Text)
|
||||
{
|
||||
PWINDOW_OBJECT WindowObject;
|
||||
UNICODE_STRING NewWindowName;
|
||||
BOOL Result = FALSE;
|
||||
|
||||
WindowObject = IntGetWindowObject(WindowHandle);
|
||||
if (!WindowObject)
|
||||
{
|
||||
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NewWindowName, Text, TRUE)))
|
||||
{
|
||||
RtlFreeUnicodeString(&WindowObject->WindowName);
|
||||
WindowObject->WindowName.Buffer = NewWindowName.Buffer;
|
||||
WindowObject->WindowName.Length = NewWindowName.Length;
|
||||
WindowObject->WindowName.MaximumLength = NewWindowName.MaximumLength;
|
||||
Result = TRUE;
|
||||
}
|
||||
|
||||
IntReleaseWindowObject(WindowObject);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/*
|
||||
* NtUserInternalGetWindowText
|
||||
*
|
||||
* FIXME: Call this from user32.dll!
|
||||
*
|
||||
* Status
|
||||
* @implemented
|
||||
*/
|
||||
|
||||
DWORD STDCALL
|
||||
NtUserInternalGetWindowText(HWND WindowHandle, LPWSTR Text, INT MaxCount)
|
||||
{
|
||||
PWINDOW_OBJECT WindowObject;
|
||||
DWORD Result;
|
||||
|
||||
WindowObject = IntGetWindowObject(WindowHandle);
|
||||
if (!WindowObject)
|
||||
{
|
||||
SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Result = WindowObject->WindowName.Length / sizeof(WCHAR);
|
||||
if (Text)
|
||||
{
|
||||
/* FIXME: Shouldn't it be always NULL terminated? */
|
||||
wcsncpy(Text, WindowObject->WindowName.Buffer, MaxCount);
|
||||
if (MaxCount < Result)
|
||||
{
|
||||
Result = MaxCount;
|
||||
}
|
||||
}
|
||||
|
||||
IntReleaseWindowObject(WindowObject);
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
Loading…
Reference in a new issue