making wxMSW MSLU(unicows)-friendly

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13043 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2001-12-17 00:28:31 +00:00
parent e168b6acfd
commit eb5e4d9ac1
4 changed files with 41 additions and 11 deletions

View File

@@ -391,6 +391,9 @@ WXDLLEXPORT extern wxString wxGetWindowClass(WXHWND hWnd);
// is, for mainly historical reasons, signed) // is, for mainly historical reasons, signed)
WXDLLEXPORT extern WXWORD wxGetWindowId(WXHWND hWnd); WXDLLEXPORT extern WXWORD wxGetWindowId(WXHWND hWnd);
// check if hWnd's WNDPROC is wndProc. Return true if yes, false if they are different
extern bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc);
// Does this window style specify any border? // Does this window style specify any border?
inline bool wxStyleHasBorder(long style) inline bool wxStyleHasBorder(long style)
{ {

View File

@@ -195,7 +195,7 @@ bool wxApp::Initialize()
// the first thing to do is to check if we're trying to run an Unicode // the first thing to do is to check if we're trying to run an Unicode
// program under Win9x - if so, abort right now as it has no chance to // program under Win9x - if so, abort right now as it has no chance to
// work // work
#if wxUSE_UNICODE #if wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
if ( wxGetOsVersion() != wxWINDOWS_NT ) if ( wxGetOsVersion() != wxWINDOWS_NT )
{ {
// note that we can use MessageBoxW() as it's implemented even under // note that we can use MessageBoxW() as it's implemented even under
@@ -204,14 +204,14 @@ bool wxApp::Initialize()
::MessageBox ::MessageBox
( (
NULL, NULL,
_T("This program uses Unicode and requires Windows NT/2000.\nProgram aborted."), _T("This program uses Unicode and requires Windows NT/2000/XP.\nProgram aborted."),
_T("wxWindows Fatal Error"), _T("wxWindows Fatal Error"),
MB_ICONERROR | MB_OK MB_ICONERROR | MB_OK
); );
return FALSE; return FALSE;
} }
#endif // wxUSE_UNICODE #endif // wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
// Some people may wish to use this, but // Some people may wish to use this, but
// probably it shouldn't be here by default. // probably it shouldn't be here by default.

View File

@@ -197,10 +197,9 @@ void wxFindReplaceDialogImpl::SubclassDialog(HWND hwnd)
// check that we don't subclass the parent twice: this would be a bad idea // check that we don't subclass the parent twice: this would be a bad idea
// as then we'd have infinite recursion in wxFindReplaceWindowProc // as then we'd have infinite recursion in wxFindReplaceWindowProc
WNDPROC oldParentWndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_WNDPROC); if ( !wxCheckWindowWndProc((WXHWND)hwnd, (WXFARPROC)wxFindReplaceWindowProc) )
if ( oldParentWndProc != wxFindReplaceWindowProc )
{ {
WNDPROC oldParentWndProc = (WNDPROC)::GetWindowLong(hwnd, GWL_WNDPROC);
// save old wnd proc elsewhere to access it from // save old wnd proc elsewhere to access it from
// wxFindReplaceWindowProc // wxFindReplaceWindowProc
m_oldParentWndProc = oldParentWndProc; m_oldParentWndProc = oldParentWndProc;

View File

@@ -968,11 +968,11 @@ void wxWindowMSW::SubclassWin(WXHWND hWnd)
wxAssociateWinWithHandle(hwnd, this); wxAssociateWinWithHandle(hwnd, this);
m_oldWndProc = (WXFARPROC)::GetWindowLong(hwnd, GWL_WNDPROC); m_oldWndProc = (WXFARPROC)::GetWindowLong((HWND)hWnd, GWL_WNDPROC);
// we don't need to subclass the window of our own class (in the Windows // we don't need to subclass the window of our own class (in the Windows
// sense of the word) // sense of the word)
if ( (WXFARPROC) m_oldWndProc != (WXFARPROC) wxWndProc ) if ( !wxCheckWindowWndProc(hWnd, (WXFARPROC)wxWndProc) )
{ {
::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc); ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
} }
@@ -997,8 +997,7 @@ void wxWindowMSW::UnsubclassWin()
if ( m_oldWndProc ) if ( m_oldWndProc )
{ {
FARPROC wndProc = (FARPROC)::GetWindowLong(hwnd, GWL_WNDPROC); if ( !wxCheckWindowWndProc((WXHWND)hwnd, m_oldWndProc) )
if ( wndProc != (FARPROC) m_oldWndProc )
{ {
::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc); ::SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc);
} }
@@ -1008,6 +1007,35 @@ void wxWindowMSW::UnsubclassWin()
} }
} }
bool wxCheckWindowWndProc(WXHWND hWnd, WXFARPROC wndProc)
{
#if wxUSE_UNICODE_MSLU
// VS: We can't use GetWindowLong(hwnd, GWL_WNDPROC) together with unicows.dll
// because it doesn't return pointer to the real wnd proc but rather a handle
// of a fake proc that does Unicode<->ANSI translation.
//
// The hack bellow works, because WNDCLASS contains original window handler
// rather that the unicows fake one. This may not be on purpose, though; if
// it stops working with future versions of unicows.dll, we can override
// unicows hooks by setting Unicows_{Set,Get}WindowLong and
// Unicows_RegisterClass to our own versions that keep track of
// fake<->real wnd proc mapping.
//
// FIXME: Doesn't handle wnd procs set by SetWindowLong, only these set
// with RegisterClass!!
static wxChar buffer[512];
WNDCLASS cls;
::GetClassName((HWND)hWnd, buffer, 512);
::GetClassInfo(wxGetInstance(), buffer, &cls);
return wndProc == (WXFARPROC)cls.lpfnWndProc;
#else
return wndProc == (WXFARPROC)::GetWindowLong((HWND)hWnd, GWL_WNDPROC);
#endif
}
// Make a Windows extended style from the given wxWindows window style // Make a Windows extended style from the given wxWindows window style
WXDWORD wxWindowMSW::MakeExtendedStyle(long style, bool eliminateBorders) WXDWORD wxWindowMSW::MakeExtendedStyle(long style, bool eliminateBorders)
{ {