]> git.saurik.com Git - wxWidgets.git/commitdiff
more /Wp64 warning fixes: mostly use UINT_PTR instead of UINT and define our WX[WL...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Feb 2008 02:22:52 +0000 (02:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 28 Feb 2008 02:22:52 +0000 (02:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

24 files changed:
include/wx/defs.h
include/wx/msw/menuitem.h
include/wx/msw/private.h
include/wx/msw/window.h
include/wx/msw/wrapwin.h
src/common/utilscmn.cpp
src/msw/app.cpp
src/msw/bmpbuttn.cpp
src/msw/control.cpp
src/msw/fontenum.cpp
src/msw/frame.cpp
src/msw/helpwin.cpp
src/msw/mdi.cpp
src/msw/menu.cpp
src/msw/menuitem.cpp
src/msw/pen.cpp
src/msw/printdlg.cpp
src/msw/radiobox.cpp
src/msw/slider95.cpp
src/msw/statbr95.cpp
src/msw/tbar95.cpp
src/msw/tooltip.cpp
src/msw/toplevel.cpp
src/msw/window.cpp

index ba72a4d4fad3e7d9d41466d99b92ffd9907b097b..0c278d4f326eed32c6cc98dbd4d741f5ffe803fb 100644 (file)
@@ -2778,6 +2778,17 @@ typedef void *          WXRECTANGLEPTR;
 #    define WXFAR
 #endif
 
+// we can't rely on Windows _W64 being defined as windows.h may not be included
+// so define our own equivalent: this should be used with types like WXLPARAM
+// or WXWPARAM which are 64 bit under Win64 to avoid warnings each time we cast
+// it to a pointer or a handle (which results in hundreds of warnings as Win32
+// API often passes pointers in them)
+#if wxCHECK_VISUALC_VERSION(7)
+    #define wxW64 __w64
+#else
+    #define wxW64
+#endif
+
 /*  Stand-ins for Windows types to avoid #including all of windows.h */
 typedef void *          WXHWND;
 typedef void *          WXHANDLE;
@@ -2814,13 +2825,13 @@ typedef void *          WXLPCREATESTRUCT;
 typedef WXHWND          WXWidget;
 
 #ifdef __WIN64__
-typedef unsigned __int64    WXWPARAM;
+typedef unsigned __int64   WXWPARAM;
 typedef __int64            WXLPARAM;
 typedef __int64            WXLRESULT;
 #else
-typedef unsigned int    WXWPARAM;
-typedef long            WXLPARAM;
-typedef long            WXLRESULT;
+typedef wxW64 unsigned int WXWPARAM;
+typedef wxW64 long         WXLPARAM;
+typedef wxW64 long         WXLRESULT;
 #endif
 
 #if defined(__GNUWIN32__) || defined(__WXMICROWIN__)
index 67e4bc8dd3abc2de29687bdf447458812e0de9c8..278f166c8f8637514e4e5bc370f851370a72ebec 100644 (file)
@@ -57,7 +57,7 @@ public:
     //
     // notice that it also returns the id as an unsigned int, as required by
     // Win32 API
-    unsigned GetMSWId() const;
+    WXWPARAM GetMSWId() const;
 
     // mark item as belonging to the given radio group
     void SetAsRadioGroupStart();
index 892d81c6065134e2d410457f5f099452efe285ab..5a1d2f3fe203e7ad46dfa7c80adf4544c7d2292a 100644 (file)
@@ -901,9 +901,15 @@ inline bool wxStyleHasBorder(long style)
 // functions mapping HWND to wxWindow
 // ----------------------------------------------------------------------------
 
-// this function simply checks whether the given hWnd corresponds to a wxWindow
+// this function simply checks whether the given hwnd corresponds to a wxWindow
 // and returns either that window if it does or NULL otherwise
-extern WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd);
+extern WXDLLEXPORT wxWindow* wxFindWinFromHandle(HWND hwnd);
+
+// without STRICT WXHWND is the same as HWND anyhow
+inline wxWindow* wxFindWinFromHandle(WXHWND hWnd)
+{
+    return wxFindWinFromHandle(wx_static_cast(HWND, hWnd));
+}
 
 // find the window for HWND which is part of some wxWindow, i.e. unlike
 // wxFindWinFromHandle() above it will also work for "sub controls" of a
index 4238868df34e7021ab9043f5275df0ec8ee38aff..159c88b01dbe410f5ac1eb0028aaa6488d997562 100644 (file)
@@ -597,17 +597,4 @@ public:
     ~wxWindowCreationHook();
 };
 
-// ----------------------------------------------------------------------------
-// global objects
-// ----------------------------------------------------------------------------
-
-// notice that this hash must be defined after wxWindow declaration as it
-// needs to "see" its dtor and not just forward declaration
-#include "wx/hash.h"
-
-// pseudo-template HWND <-> wxWindow hash table
-WX_DECLARE_HASH(wxWindowMSW, wxWindowList, wxWinHashTable);
-
-extern wxWinHashTable *wxWinHandleHash;
-
 #endif // _WX_WINDOW_H_
index d6bc50a870e311d10aa517a261f0cb042d78d9ed..bcd2cf0c03c3b950ebb37b64d8d6de5cb3528cf4 100644 (file)
@@ -79,6 +79,7 @@
 // overwrite them if there is a chance that they're not defined
 #if !defined(_MSC_VER) || (_MSC_VER < 1300)
     #define UINT_PTR unsigned int
+    #define INT_PTR int
     #define LONG_PTR long
     #define ULONG_PTR unsigned long
     #define DWORD_PTR unsigned long
index df728c2228cd5cbd36539d3ea753e8d7b59de42a..e656559ad26e5f2bef1224894a959c6a4c764827 100644 (file)
@@ -1033,7 +1033,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
 
     ::ShellExecuteEx(&sei);
 
-    const int nResult = (int) sei.hInstApp;
+    const INT_PTR nResult = (INT_PTR)sei.hInstApp;
 
     // Firefox returns file not found for some reason, so make an exception
     // for it
index 474e8e4839d96e626f744cc3cfcfa652144d34cf..83b8d98d49e0bed2c9cd98a8a1a7d0cf6a18e4e5 100644 (file)
@@ -355,8 +355,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
 
     RegisterWindowClasses();
 
-    wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
-
 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
     wxSetKeyboardHook(true);
 #endif
@@ -510,10 +508,10 @@ bool wxApp::UnregisterWindowClasses()
 
 void wxApp::CleanUp()
 {
-    // all objects pending for deletion must be deleted first, otherwise we
-    // would crash when they use wxWinHandleHash (and UnregisterWindowClasses()
-    // call wouldn't succeed as long as any windows still exist), so call the
-    // base class method first and only then do our clean up
+    // all objects pending for deletion must be deleted first, otherwise
+    // UnregisterWindowClasses() call wouldn't succeed (because windows
+    // using the classes being unregistered still exist), so call the base
+    // class method first and only then do our clean up
     wxAppBase::CleanUp();
 
 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
@@ -528,9 +526,6 @@ void wxApp::CleanUp()
     // unregister the classes now
     UnregisterWindowClasses();
 
-    delete wxWinHandleHash;
-    wxWinHandleHash = NULL;
-
 #ifdef __WXWINCE__
     free( wxCanvasClassName );
     free( wxCanvasClassNameNR );
index c4344f09d99b0ff5658a48c23cff9d8a3c3f41be..b05541c6353ff74c29cc62cd93c02be8b753c7f1 100644 (file)
@@ -176,7 +176,7 @@ bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
                     msStyle,
                     0, 0, 0, 0,
                     GetWinHwnd(parent),
-                    (HMENU)m_windowId.GetValue(),
+                    (HMENU)wxUIntToPtr(m_windowId.GetValue()),
                     wxGetInstance(),
                     NULL
                    );
index d4ae78000acbcb3eeae043bcf98db54132aac22f..b58195c0cf56d8b274f99f3eb4bc4a068f1467a7 100644 (file)
@@ -144,8 +144,8 @@ bool wxControl::MSWCreateControl(const wxChar *classname,
                         label.wx_str(),     // the window name
                         style,              // the window style
                         x, y, w, h,         // the window position and size
-                        GetHwndOf(GetParent()),  // parent
-                        (HMENU)GetId(),     // child id
+                        GetHwndOf(GetParent()),         // parent
+                        (HMENU)wxUIntToPtr(GetId()),    // child id
                         wxGetInstance(),    // app instance
                         NULL                // creation parameters
                        );
index 6833fec31b1f71b3684488cd1bf084843cd4d28c..8ec371ae8ca85bf6e17eda425aeab1ab1c3722fd 100644 (file)
@@ -99,7 +99,7 @@ private:
 
 #ifndef __WXMICROWIN__
 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
-                                  DWORD dwStyle, LONG lParam);
+                                  DWORD dwStyle, LPARAM lParam);
 #endif
 
 // ============================================================================
@@ -269,7 +269,7 @@ bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
 
 #ifndef __WXMICROWIN__
 int CALLBACK wxFontEnumeratorProc(LPLOGFONT lplf, LPTEXTMETRIC lptm,
-                                  DWORD WXUNUSED(dwStyle), LONG lParam)
+                                  DWORD WXUNUSED(dwStyle), LPARAM lParam)
 {
 
     // we used to process TrueType fonts only, but there doesn't seem to be any
index b976a678c5fe8d86a8f134d909e6a4f50c890d3b..41b15c28755b7737a39873a527b599ad30565d7d 100644 (file)
@@ -853,7 +853,7 @@ bool wxFrame::HandlePaint()
             HDC hdc = ::BeginPaint(GetHwnd(), &ps);
 
             // Erase background before painting or we get white background
-            MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
+            MSWDefWindowProc(WM_ICONERASEBKGND, (WXWPARAM)ps.hdc, 0L);
 
             if ( hIcon )
             {
@@ -1118,7 +1118,7 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
                 const wxIcon& icon = GetIcon();
                 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
                                         : (HICON)GetDefaultIcon();
-                rc = (long)hIcon;
+                rc = (WXLRESULT)hIcon;
                 processed = rc != 0;
             }
             break;
index edb293ca0f664071cb1c706378d3909c5f25e45c..e33ad6c8de11f64d02ba42a8d35f494333cffc6c 100644 (file)
@@ -98,13 +98,14 @@ bool wxWinHelpController::KeywordSearch(const wxString& k,
 
     wxString str = GetValidFilename(m_helpFile);
 
-    return (WinHelp(GetSuitableHWND(this), str.wx_str(), HELP_PARTIALKEY, (DWORD)k.wx_str()) != 0);
+    return WinHelp(GetSuitableHWND(this), str.wx_str(), HELP_PARTIALKEY,
+                   (ULONG_PTR)k.wx_str()) != 0;
 }
 
 // Can't close the help window explicitly in WinHelp
 bool wxWinHelpController::Quit(void)
 {
-    return (WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0L) != 0);
+    return WinHelp(GetSuitableHWND(this), 0, HELP_QUIT, 0) != 0;
 }
 
 // Append extension if necessary.
index 25ff340af8f0af1dd797070737da79c2b255bf37..f641e35638f0ff91ba154d3b922633e6e42e1fb9 100644 (file)
@@ -756,7 +756,7 @@ bool wxMDIChildFrame::Create(wxMDIParentFrame *parent,
   wxWindowCreationHook hook(this);
 
   m_hWnd = (WXHWND)::SendMessage(GetWinHwnd(parent->GetClientWindow()),
-                                 WM_MDICREATE, 0, (LONG)(LPSTR)&mcs);
+                                 WM_MDICREATE, 0, (LPARAM)&mcs);
 
   if ( !m_hWnd )
   {
@@ -1430,14 +1430,15 @@ static void InsertWindowMenu(wxWindow *win, WXHMENU menu, HMENU subMenu)
             {
                 success = true;
                 ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
-                             (UINT)subMenu, _("&Window").wx_str());
+                             (UINT_PTR)subMenu, _("&Window").wx_str());
                 break;
             }
         }
 
         if ( !success )
         {
-            ::AppendMenu(hmenu, MF_POPUP, (UINT)subMenu, _("&Window").wx_str());
+            ::AppendMenu(hmenu, MF_POPUP,
+                         (UINT_PTR)subMenu, _("&Window").wx_str());
         }
     }
 
index 2daee69f0124f958b424fc0cc828bf064438a469..8ebd4952da6c279a3d4405943d80c9e6199e0c78 100644 (file)
@@ -387,14 +387,14 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
 
     // id is the numeric id for normal menu items and HMENU for submenus as
     // required by ::AppendMenu() API
-    UINT id;
+    UINT_PTR id;
     wxMenu *submenu = pItem->GetSubMenu();
     if ( submenu != NULL ) {
         wxASSERT_MSG( submenu->GetHMenu(), wxT("invalid submenu") );
 
         submenu->SetParent(this);
 
-        id = (UINT)submenu->GetHMenu();
+        id = (UINT_PTR)submenu->GetHMenu();
 
         flags |= MF_POPUP;
     }
@@ -980,7 +980,7 @@ WXHMENU wxMenuBar::Create()
         for ( i = 0, it = m_menus.begin(); i < count; i++, it++ )
         {
             if ( !::AppendMenu((HMENU)m_hMenu, MF_POPUP | MF_STRING,
-                               (UINT)(*it)->GetHMenu(),
+                               (UINT_PTR)(*it)->GetHMenu(),
                                m_titles[i].wx_str()) )
             {
                 wxLogLastError(wxT("AppendMenu"));
@@ -1052,7 +1052,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
 
     int mswpos = MSWPositionForWxMenu(GetMenu(pos),pos);
 
-    UINT id;
+    UINT_PTR id;
     UINT flagsOld = ::GetMenuState((HMENU)m_hMenu, mswpos, MF_BYPOSITION);
     if ( flagsOld == 0xFFFFFFFF )
     {
@@ -1065,7 +1065,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
     {
         // HIBYTE contains the number of items in the submenu in this case
         flagsOld &= 0xff;
-        id = (UINT)::GetSubMenu((HMENU)m_hMenu, mswpos);
+        id = (UINT_PTR)::GetSubMenu((HMENU)m_hMenu, mswpos);
     }
     else
     {
@@ -1080,7 +1080,7 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
     info.fType = MFT_STRING;
     info.cch = label.length();
     info.dwTypeData = wx_const_cast(wxChar *, label.wx_str());
-    if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, & info) )
+    if ( !SetMenuItemInfo(GetHmenu(), id, TRUE, &info) )
     {
         wxLogLastError(wxT("SetMenuItemInfo"));
     }
@@ -1132,7 +1132,7 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
 
         if ( !::InsertMenu(GetHmenu(), (UINT)mswpos,
                            MF_BYPOSITION | MF_POPUP | MF_STRING,
-                           (UINT)GetHmenuOf(menu), title.wx_str()) )
+                           (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
         {
             wxLogLastError(wxT("InsertMenu"));
         }
@@ -1199,7 +1199,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
 #else
         if ( !::InsertMenu(GetHmenu(), mswpos,
                            MF_BYPOSITION | MF_POPUP | MF_STRING,
-                           (UINT)GetHmenuOf(menu), title.wx_str()) )
+                           (UINT_PTR)GetHmenuOf(menu), title.wx_str()) )
         {
             wxLogLastError(wxT("InsertMenu"));
         }
@@ -1258,7 +1258,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
         }
 #else
         if ( !::AppendMenu(GetHmenu(), MF_POPUP | MF_STRING,
-                           (UINT)submenu, title.wx_str()) )
+                           (UINT_PTR)submenu, title.wx_str()) )
         {
             wxLogLastError(wxT("AppendMenu"));
         }
index 964e64892f867fa8594def0052e922a35f4f0622..32b92ee7d2c11b5a81c8b19411d9a75e9fdb82cc 100644 (file)
@@ -186,13 +186,13 @@ wxMenuItem::~wxMenuItem()
 // ----
 
 // return the id for calling Win32 API functions
-unsigned wxMenuItem::GetMSWId() const
+WXWPARAM wxMenuItem::GetMSWId() const
 {
     // we must use ids in unsigned short range with Windows functions, if we
     // pass ids > USHRT_MAX to them they get very confused (e.g. start
     // generating WM_COMMAND messages with negative high word of wParam), so
     // use the cast to ensure the id is in range
-    return m_subMenu ? wx_reinterpret_cast(unsigned, m_subMenu->GetHMenu())
+    return m_subMenu ? wxPtrToUInt(m_subMenu->GetHMenu())
                      : wx_static_cast(unsigned short, GetId());
 }
 
index 9df28c6731a3099d7deebfe97d81391690c26000..711ca1b644d10b58f416f8fbfa6566a37923c93e 100644 (file)
@@ -338,7 +338,7 @@ bool wxPenRefData::Alloc()
        {
            case wxSTIPPLE:
                lb.lbStyle = BS_PATTERN;
-               lb.lbHatch = (LONG)m_stipple.GetHBITMAP();
+               lb.lbHatch = wxPtrToUInt(m_stipple.GetHBITMAP());
                break;
 
            case wxBDIAGONAL_HATCH:
index 575fb82ffd40102ccbd247a92d79d2a16172268b..9d96491f6742461db63e620f1dd9322f1ce87e81 100644 (file)
@@ -122,19 +122,18 @@ IMPLEMENT_CLASS(wxWindowsPrintNativeData, wxPrintNativeDataBase)
 
 wxWindowsPrintNativeData::wxWindowsPrintNativeData()
 {
-    m_devMode = (void*) NULL;
-    m_devNames = (void*) NULL;
+    m_devMode = NULL;
+    m_devNames = NULL;
     m_customWindowsPaperId = 0;
 }
 
 wxWindowsPrintNativeData::~wxWindowsPrintNativeData()
 {
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
-    if ( hDevMode )
-        GlobalFree(hDevMode);
-    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-    if ( hDevNames )
-        GlobalFree(hDevNames);
+    if ( m_devMode )
+        ::GlobalFree(wx_static_cast(HGLOBAL, m_devMode));
+
+    if ( m_devNames )
+        ::GlobalFree(wx_static_cast(HGLOBAL, m_devNames));
 }
 
 bool wxWindowsPrintNativeData::IsOk() const
@@ -144,205 +143,194 @@ bool wxWindowsPrintNativeData::IsOk() const
 
 bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
 {
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
-    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-
-    if (!hDevMode)
-    {
+    if ( !m_devMode )
         return false;
-    }
-    else
-    {
-        LPDEVMODE devMode = (LPDEVMODE)GlobalLock(hDevMode);
 
-        //// Orientation
-        if (devMode->dmFields & DM_ORIENTATION)
-            data.SetOrientation( devMode->dmOrientation );
+    GlobalPtrLock lockDevMode(m_devMode);
 
-        //// Collation
-        if (devMode->dmFields & DM_COLLATE)
-        {
-            if (devMode->dmCollate == DMCOLLATE_TRUE)
-                data.SetCollate( true );
-            else
-                data.SetCollate( false );
-        }
+    LPDEVMODE devMode = wx_static_cast(LPDEVMODE, lockDevMode.Get());
 
-        //// Number of copies
-        if (devMode->dmFields & DM_COPIES)
-            data.SetNoCopies( devMode->dmCopies );
-
-        //// Bin
-        if (devMode->dmFields & DM_DEFAULTSOURCE) {
-            switch (devMode->dmDefaultSource) {
-                case DMBIN_ONLYONE        : data.SetBin(wxPRINTBIN_ONLYONE       ); break;
-                case DMBIN_LOWER          : data.SetBin(wxPRINTBIN_LOWER         ); break;
-                case DMBIN_MIDDLE         : data.SetBin(wxPRINTBIN_MIDDLE        ); break;
-                case DMBIN_MANUAL         : data.SetBin(wxPRINTBIN_MANUAL        ); break;
-                case DMBIN_ENVELOPE       : data.SetBin(wxPRINTBIN_ENVELOPE      ); break;
-                case DMBIN_ENVMANUAL      : data.SetBin(wxPRINTBIN_ENVMANUAL     ); break;
-                case DMBIN_AUTO           : data.SetBin(wxPRINTBIN_AUTO          ); break;
-                case DMBIN_TRACTOR        : data.SetBin(wxPRINTBIN_TRACTOR       ); break;
-                case DMBIN_SMALLFMT       : data.SetBin(wxPRINTBIN_SMALLFMT      ); break;
-                case DMBIN_LARGEFMT       : data.SetBin(wxPRINTBIN_LARGEFMT      ); break;
-                case DMBIN_LARGECAPACITY  : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
-                case DMBIN_CASSETTE       : data.SetBin(wxPRINTBIN_CASSETTE      ); break;
-                case DMBIN_FORMSOURCE     : data.SetBin(wxPRINTBIN_FORMSOURCE    ); break;
-                default:
-                    if (devMode->dmDefaultSource>=DMBIN_USER) {
-                        data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
-                    } else {
-                        data.SetBin(wxPRINTBIN_DEFAULT);
-                    }
-                    break;
-            }
-        } else {
-            data.SetBin(wxPRINTBIN_DEFAULT);
-        }
-        if (devMode->dmFields & DM_MEDIATYPE)
-        {
-            wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
-            data.SetMedia(devMode->dmMediaType);
-        }
-        //// Printer name
-        if (devMode->dmDeviceName[0] != 0)
-            // This syntax fixes a crash when using VS 7.1
-            data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
+    //// Orientation
+    if (devMode->dmFields & DM_ORIENTATION)
+        data.SetOrientation( devMode->dmOrientation );
 
-        //// Colour
-        if (devMode->dmFields & DM_COLOR)
-        {
-            if (devMode->dmColor == DMCOLOR_COLOR)
-                data.SetColour( true );
-            else
-                data.SetColour( false );
-        }
+    //// Collation
+    if (devMode->dmFields & DM_COLLATE)
+    {
+        if (devMode->dmCollate == DMCOLLATE_TRUE)
+            data.SetCollate( true );
         else
+            data.SetCollate( false );
+    }
+
+    //// Number of copies
+    if (devMode->dmFields & DM_COPIES)
+        data.SetNoCopies( devMode->dmCopies );
+
+    //// Bin
+    if (devMode->dmFields & DM_DEFAULTSOURCE) {
+        switch (devMode->dmDefaultSource) {
+            case DMBIN_ONLYONE        : data.SetBin(wxPRINTBIN_ONLYONE       ); break;
+            case DMBIN_LOWER          : data.SetBin(wxPRINTBIN_LOWER         ); break;
+            case DMBIN_MIDDLE         : data.SetBin(wxPRINTBIN_MIDDLE        ); break;
+            case DMBIN_MANUAL         : data.SetBin(wxPRINTBIN_MANUAL        ); break;
+            case DMBIN_ENVELOPE       : data.SetBin(wxPRINTBIN_ENVELOPE      ); break;
+            case DMBIN_ENVMANUAL      : data.SetBin(wxPRINTBIN_ENVMANUAL     ); break;
+            case DMBIN_AUTO           : data.SetBin(wxPRINTBIN_AUTO          ); break;
+            case DMBIN_TRACTOR        : data.SetBin(wxPRINTBIN_TRACTOR       ); break;
+            case DMBIN_SMALLFMT       : data.SetBin(wxPRINTBIN_SMALLFMT      ); break;
+            case DMBIN_LARGEFMT       : data.SetBin(wxPRINTBIN_LARGEFMT      ); break;
+            case DMBIN_LARGECAPACITY  : data.SetBin(wxPRINTBIN_LARGECAPACITY ); break;
+            case DMBIN_CASSETTE       : data.SetBin(wxPRINTBIN_CASSETTE      ); break;
+            case DMBIN_FORMSOURCE     : data.SetBin(wxPRINTBIN_FORMSOURCE    ); break;
+            default:
+                if (devMode->dmDefaultSource>=DMBIN_USER) {
+                    data.SetBin((wxPrintBin)((devMode->dmDefaultSource)-DMBIN_USER+(int)wxPRINTBIN_USER));
+                } else {
+                    data.SetBin(wxPRINTBIN_DEFAULT);
+                }
+                break;
+        }
+    } else {
+        data.SetBin(wxPRINTBIN_DEFAULT);
+    }
+    if (devMode->dmFields & DM_MEDIATYPE)
+    {
+        wxASSERT( (int)devMode->dmMediaType != wxPRINTMEDIA_DEFAULT );
+        data.SetMedia(devMode->dmMediaType);
+    }
+    //// Printer name
+    if (devMode->dmDeviceName[0] != 0)
+        // This syntax fixes a crash when using VS 7.1
+        data.SetPrinterName( wxString(devMode->dmDeviceName, CCHDEVICENAME) );
+
+    //// Colour
+    if (devMode->dmFields & DM_COLOR)
+    {
+        if (devMode->dmColor == DMCOLOR_COLOR)
             data.SetColour( true );
+        else
+            data.SetColour( false );
+    }
+    else
+        data.SetColour( true );
 
-        //// Paper size
+    //// Paper size
 
-        // We don't know size of user defined paper and some buggy drivers
-        // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
-        // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
-        // code wouldn't set m_paperSize correctly.
+    // We don't know size of user defined paper and some buggy drivers
+    // set both DM_PAPERSIZE and DM_PAPERWIDTH & DM_PAPERLENGTH. Since
+    // dmPaperSize >= DMPAPER_USER wouldn't be in wxWin's database, this
+    // code wouldn't set m_paperSize correctly.
 
-        bool foundPaperSize = false;
-        if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
+    bool foundPaperSize = false;
+    if ((devMode->dmFields & DM_PAPERSIZE) && (devMode->dmPaperSize < DMPAPER_USER))
+    {
+        if (wxThePrintPaperDatabase)
         {
-            if (wxThePrintPaperDatabase)
+            wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
+            if (paper)
             {
-                wxPrintPaperType* paper = wxThePrintPaperDatabase->FindPaperTypeByPlatformId(devMode->dmPaperSize);
-                if (paper)
-                {
-                    data.SetPaperId( paper->GetId() );
-                    data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
-                    m_customWindowsPaperId = 0;
-                    foundPaperSize = true;
-                }
-            }
-            else
-            {
-                // Shouldn't really get here
-                wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
-                data.SetPaperId( wxPAPER_NONE );
-                data.SetPaperSize( wxSize(0,0) );
+                data.SetPaperId( paper->GetId() );
+                data.SetPaperSize( wxSize(paper->GetWidth() / 10,paper->GetHeight() / 10) );
                 m_customWindowsPaperId = 0;
-
-                GlobalUnlock(hDevMode);
-                return false;
+                foundPaperSize = true;
             }
         }
+        else
+        {
+            // Shouldn't really get here
+            wxFAIL_MSG(wxT("Paper database wasn't initialized in wxPrintData::ConvertFromNative."));
+            data.SetPaperId( wxPAPER_NONE );
+            data.SetPaperSize( wxSize(0,0) );
+            m_customWindowsPaperId = 0;
 
-        if (!foundPaperSize) {
-            if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
-            {
-                // DEVMODE is in tenths of a millimeter
-                data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
-                data.SetPaperId( wxPAPER_NONE );
-                m_customWindowsPaperId = devMode->dmPaperSize;
-            }
-            else
-            {
-                // Often will reach this for non-standard paper sizes (sizes which
-                // wouldn't be in wxWidget's paper database). Setting
-                // m_customWindowsPaperId to devMode->dmPaperSize should be enough
-                // to get this paper size working.
-                data.SetPaperSize( wxSize(0,0) );
-                data.SetPaperId( wxPAPER_NONE );
-                m_customWindowsPaperId = devMode->dmPaperSize;
-            }
+            return false;
         }
+    }
 
-        //// Duplex
-
-        if (devMode->dmFields & DM_DUPLEX)
+    if (!foundPaperSize) {
+        if ((devMode->dmFields & DM_PAPERWIDTH) && (devMode->dmFields & DM_PAPERLENGTH))
         {
-            switch (devMode->dmDuplex)
-            {
-                case DMDUP_HORIZONTAL:   data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
-                case DMDUP_VERTICAL:     data.SetDuplex( wxDUPLEX_VERTICAL ); break;
-                default:
-                case DMDUP_SIMPLEX:      data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
-            }
+            // DEVMODE is in tenths of a millimeter
+            data.SetPaperSize( wxSize(devMode->dmPaperWidth / 10, devMode->dmPaperLength / 10) );
+            data.SetPaperId( wxPAPER_NONE );
+            m_customWindowsPaperId = devMode->dmPaperSize;
         }
         else
-            data.SetDuplex( wxDUPLEX_SIMPLEX );
+        {
+            // Often will reach this for non-standard paper sizes (sizes which
+            // wouldn't be in wxWidget's paper database). Setting
+            // m_customWindowsPaperId to devMode->dmPaperSize should be enough
+            // to get this paper size working.
+            data.SetPaperSize( wxSize(0,0) );
+            data.SetPaperId( wxPAPER_NONE );
+            m_customWindowsPaperId = devMode->dmPaperSize;
+        }
+    }
 
-        //// Quality
+    //// Duplex
 
-        if (devMode->dmFields & DM_PRINTQUALITY)
+    if (devMode->dmFields & DM_DUPLEX)
+    {
+        switch (devMode->dmDuplex)
         {
-            switch (devMode->dmPrintQuality)
+            case DMDUP_HORIZONTAL:   data.SetDuplex( wxDUPLEX_HORIZONTAL ); break;
+            case DMDUP_VERTICAL:     data.SetDuplex( wxDUPLEX_VERTICAL ); break;
+            default:
+            case DMDUP_SIMPLEX:      data.SetDuplex( wxDUPLEX_SIMPLEX ); break;
+        }
+    }
+    else
+        data.SetDuplex( wxDUPLEX_SIMPLEX );
+
+    //// Quality
+
+    if (devMode->dmFields & DM_PRINTQUALITY)
+    {
+        switch (devMode->dmPrintQuality)
+        {
+            case DMRES_MEDIUM:  data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
+            case DMRES_LOW:     data.SetQuality( wxPRINT_QUALITY_LOW ); break;
+            case DMRES_DRAFT:   data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
+            case DMRES_HIGH:    data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
+            default:
             {
-                case DMRES_MEDIUM:  data.SetQuality( wxPRINT_QUALITY_MEDIUM ); break;
-                case DMRES_LOW:     data.SetQuality( wxPRINT_QUALITY_LOW ); break;
-                case DMRES_DRAFT:   data.SetQuality( wxPRINT_QUALITY_DRAFT ); break;
-                case DMRES_HIGH:    data.SetQuality( wxPRINT_QUALITY_HIGH ); break;
-                default:
-                {
-                    // TODO: if the printer fills in the resolution in DPI, how
-                    // will the application know if it's high, low, draft etc.??
-                    //                    wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
-                    data.SetQuality( devMode->dmPrintQuality );
-                    break;
+                // TODO: if the printer fills in the resolution in DPI, how
+                // will the application know if it's high, low, draft etc.??
+                //                    wxFAIL_MSG("Warning: DM_PRINTQUALITY was not one of the standard values.");
+                data.SetQuality( devMode->dmPrintQuality );
+                break;
 
-                }
             }
         }
-        else
-            data.SetQuality( wxPRINT_QUALITY_HIGH );
-
-        if (devMode->dmDriverExtra > 0)
-            data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
-        else
-            data.SetPrivData( NULL, 0 );
-
-        GlobalUnlock(hDevMode);
     }
+    else
+        data.SetQuality( wxPRINT_QUALITY_HIGH );
 
-    if (hDevNames)
+    if (devMode->dmDriverExtra > 0)
+        data.SetPrivData( (char *)devMode+devMode->dmSize, devMode->dmDriverExtra );
+    else
+        data.SetPrivData( NULL, 0 );
+
+    if ( m_devNames )
     {
-        LPDEVNAMES lpDevNames = (LPDEVNAMES)GlobalLock(hDevNames);
-        if (lpDevNames)
-        {
-            // TODO: Unicode-ification
+        GlobalPtrLock lockDevNames(m_devNames);
+        LPDEVNAMES lpDevNames = wx_static_cast(LPDEVNAMES, lockDevNames.Get());
 
-            // Get the port name
-            // port is obsolete in WIN32
-            // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
+        // TODO: Unicode-ification
 
-            // Get the printer name
-            wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
+        // Get the port name
+        // port is obsolete in WIN32
+        // m_printData.SetPortName((LPSTR)lpDevNames + lpDevNames->wDriverOffset);
 
-            // Not sure if we should check for this mismatch
-//            wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
+        // Get the printer name
+        wxString printerName = (LPTSTR)lpDevNames + lpDevNames->wDeviceOffset;
 
-            if (!printerName.empty())
-                data.SetPrinterName( printerName );
+        // Not sure if we should check for this mismatch
+//            wxASSERT_MSG( (m_printerName.empty() || (devName == m_printerName)), "Printer name obtained from DEVMODE and DEVNAMES were different!");
 
-            GlobalUnlock(hDevNames);
-        }
+        if (!printerName.empty())
+            data.SetPrinterName( printerName );
     }
 
     return true;
@@ -350,9 +338,8 @@ bool wxWindowsPrintNativeData::TransferTo( wxPrintData &data )
 
 bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
 {
-    HGLOBAL hDevMode = (HGLOBAL)(DWORD) m_devMode;
-    HGLOBAL hDevNames = (HGLOBAL)(DWORD) m_devNames;
-    if (!hDevMode)
+    HGLOBAL hDevMode = wx_static_cast(HGLOBAL, m_devMode);
+    if ( !m_devMode )
     {
         // Use PRINTDLG as a way of creating a DEVMODE object
         PRINTDLG pd;
@@ -398,7 +385,7 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
         else
         {
             hDevMode = pd.hDevMode;
-            m_devMode = (void*)(long) hDevMode;
+            m_devMode = hDevMode;
             pd.hDevMode = NULL;
 
             // We'll create a new DEVNAMEs structure below.
@@ -415,7 +402,8 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
 
     if ( hDevMode )
     {
-        LPDEVMODE devMode = (LPDEVMODE) GlobalLock(hDevMode);
+        GlobalPtrLock lockDevMode(hDevMode);
+        DEVMODE * const devMode = wx_static_cast(DEVMODE *, lockDevMode.Get());
 
         //// Orientation
         devMode->dmOrientation = (short)data.GetOrientation();
@@ -432,9 +420,9 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
         wxString name = data.GetPrinterName();
         if (!name.empty())
         {
-            //int len = wxMin(31, m_printerName.Len());
-            wxStrncpy((wxChar*)devMode->dmDeviceName,name.c_str(),31);
-            devMode->dmDeviceName[31] = wxT('\0');
+            wxStrncpy(devMode->dmDeviceName, name.wx_str(),
+                      WXSIZEOF(devMode->dmDeviceName) - 1);
+            devMode->dmDeviceName[WXSIZEOF(devMode->dmDeviceName) - 1] = wxT('\0');
         }
 
         //// Colour
@@ -559,16 +547,15 @@ bool wxWindowsPrintNativeData::TransferFrom( const wxPrintData &data )
             devMode->dmMediaType = data.GetMedia();
             devMode->dmFields |= DM_MEDIATYPE;
         }
-        GlobalUnlock(hDevMode);
     }
 
-    if ( hDevNames )
+    if ( m_devNames )
     {
-        GlobalFree(hDevNames);
+        ::GlobalFree(wx_static_cast(HGLOBAL, m_devNames));
     }
 
     // TODO: I hope it's OK to pass some empty strings to DEVNAMES.
-    m_devNames = (void*) (long) wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
+    m_devNames = wxCreateDevNames(wxEmptyString, data.GetPrinterName(), wxEmptyString);
 
     return true;
 }
@@ -700,14 +687,14 @@ bool wxWindowsPrintDialog::ConvertToNative( wxPrintDialogData &data )
     if (pd->hDevNames)
         GlobalFree(pd->hDevNames);
 
-    pd->hDevMode = (HGLOBAL)(DWORD) native_data->GetDevMode();
-    native_data->SetDevMode( (void*) NULL);
+    pd->hDevMode = wx_static_cast(HGLOBAL, native_data->GetDevMode());
+    native_data->SetDevMode(NULL);
 
     // Shouldn't assert; we should be able to test Ok-ness at a higher level
     //wxASSERT_MSG( (pd->hDevMode), wxT("hDevMode must be non-NULL in ConvertToNative!"));
 
-    pd->hDevNames = (HGLOBAL)(DWORD) native_data->GetDevNames();
-    native_data->SetDevNames( (void*) NULL);
+    pd->hDevNames = wx_static_cast(HGLOBAL, native_data->GetDevNames());
+    native_data->SetDevNames(NULL);
 
 
     pd->hDC = (HDC) NULL;
@@ -772,10 +759,9 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
     {
         if (native_data->GetDevMode())
         {
-            // Make sure we don't leak memory
-            GlobalFree( (HGLOBAL)(DWORD) native_data->GetDevMode() );
+            ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevMode()));
         }
-        native_data->SetDevMode( (void*)(long) pd->hDevMode );
+        native_data->SetDevMode(pd->hDevMode);
         pd->hDevMode = NULL;
     }
 
@@ -784,10 +770,9 @@ bool wxWindowsPrintDialog::ConvertFromNative( wxPrintDialogData &data )
     {
         if (native_data->GetDevNames())
         {
-            // Make sure we don't leak memory
-            GlobalFree((HGLOBAL)(DWORD) native_data->GetDevNames());
+            ::GlobalFree(wx_static_cast(HGLOBAL, native_data->GetDevNames()));
         }
-        native_data->SetDevNames((void*)(long) pd->hDevNames);
+        native_data->SetDevNames(pd->hDevNames);
         pd->hDevNames = NULL;
     }
 
index e9f53d0f4628415b0b1ad9ca5a97259e24705f0f..9108095f9347df49a4308c796e3774f6e5d40b58 100644 (file)
@@ -183,7 +183,7 @@ bool wxRadioBox::Create(wxWindow *parent,
                                       styleBtn,
                                       0, 0, 0, 0,   // will be set in SetSize()
                                       GetHwndOf(parent),
-                                      (HMENU)subid.GetValue(),
+                                      (HMENU)wxUIntToPtr(subid.GetValue()),
                                       wxGetInstance(),
                                       NULL);
 
@@ -210,7 +210,8 @@ bool wxRadioBox::Create(wxWindow *parent,
                          wxEmptyString,
                          WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
                          0, 0, 0, 0, GetHwndOf(parent),
-                         (HMENU)m_dummyId.GetValue(), wxGetInstance(), NULL);
+                         (HMENU)wxUIntToPtr(m_dummyId.GetValue()),
+                         wxGetInstance(), NULL);
 
 
     m_radioButtons->SetFont(GetFont());
index 1ebdb425dce97d8f5f4873a7fe1f9d5f8abe0bc2..5eabd63b7dc049a986d26a23867cf70c80ea0785 100644 (file)
@@ -217,7 +217,7 @@ wxSlider::Create(wxWindow *parent,
                             WS_CHILD | WS_VISIBLE | SS_CENTER,
                             0, 0, 0, 0,
                             hwndParent,
-                            (HMENU)lblid.GetValue(),
+                            (HMENU)wxUIntToPtr(lblid.GetValue()),
                             wxGetInstance(),
                             NULL
                          );
index 0913dbf5aa068f54b505030fba53664c741da06b..f06e0e7c05a245e0f9746639c67f236f180a141a 100644 (file)
@@ -106,7 +106,7 @@ bool wxStatusBar95::Create(wxWindow *parent,
                 wstyle,
                 0, 0, 0, 0,
                 GetHwndOf(parent),
-                (HMENU)m_windowId.GetValue(),
+                (HMENU)wxUIntToPtr(m_windowId.GetValue()),
                 wxGetInstance(),
                 NULL
              );
index 6e9d951f76458ebbcf2509a99d24514be3f2a445..cd4f28ea225feaeb811fc643f27417a521ecb719 100644 (file)
@@ -805,8 +805,8 @@ bool wxToolBar::Realize()
                 TBREPLACEBITMAP replaceBitmap;
                 replaceBitmap.hInstOld = NULL;
                 replaceBitmap.hInstNew = NULL;
-                replaceBitmap.nIDOld = (UINToldToolBarBitmap;
-                replaceBitmap.nIDNew = (UINThBitmap;
+                replaceBitmap.nIDOld = (UINT_PTR)oldToolBarBitmap;
+                replaceBitmap.nIDNew = (UINT_PTR)hBitmap;
                 replaceBitmap.nButtons = nButtons;
                 if ( !::SendMessage(GetHwnd(), TB_REPLACEBITMAP,
                                     0, (LPARAM) &replaceBitmap) )
@@ -835,7 +835,7 @@ bool wxToolBar::Realize()
         {
             TBADDBITMAP addBitmap;
             addBitmap.hInst = 0;
-            addBitmap.nID = (UINThBitmap;
+            addBitmap.nID = (UINT_PTR)hBitmap;
             if ( ::SendMessage(GetHwnd(), TB_ADDBITMAP,
                                (WPARAM) nButtons, (LPARAM)&addBitmap) == -1 )
             {
@@ -915,7 +915,7 @@ bool wxToolBar::Realize()
                 {
                     const wxString& label = tool->GetLabel();
                     if ( !label.empty() )
-                        button.iString = (int)label.wx_str();
+                        button.iString = (INT_PTR)label.wx_str();
                 }
 
                 button.idCommand = tool->GetId();
index 909352209d6e350e7abb96eb6e8a06c4b1363011..dd3fdd076b086d079ee41fa5d05f4ac46d3484b8 100644 (file)
@@ -105,7 +105,7 @@ public:
             uFlags |= TTF_TRANSPARENT;
         }
 
-        uId = (UINT)hwndOwner;
+        uId = (UINT_PTR)hwndOwner;
     }
 };
 
@@ -374,9 +374,12 @@ void wxToolTip::Add(WXHWND hWnd)
                 }
 
                 // only set a new width if it is bigger than the current setting
-                if (max > SendTooltipMessage(GetToolTipCtrl(), TTM_GETMAXTIPWIDTH, 0))
+                if ( max > SendTooltipMessage(GetToolTipCtrl(),
+                                              TTM_GETMAXTIPWIDTH, 0) )
+                {
                     SendTooltipMessage(GetToolTipCtrl(), TTM_SETMAXTIPWIDTH,
-                                       (void *)max);
+                                       wxUIntToPtr(max));
+                }
             }
             else
 #endif // comctl32.dll >= 4.70
index 4bd6a07927820a066fc7a57325487f2032ffc460..65dfa445868cf258d7ccc5a6f6ea015fd3815155 100644 (file)
@@ -1233,7 +1233,7 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
     {
         // restore focus to the child which was last focused unless we already
         // have it
-        wxLogTrace(_T("focus"), _T("wxTLW %08x activated."), (int) m_hWnd);
+        wxLogTrace(_T("focus"), _T("wxTLW %p activated."), m_hWnd);
 
         wxWindow *winFocus = FindFocus();
         if ( !winFocus || wxGetTopLevelParent(winFocus) != this )
@@ -1266,10 +1266,9 @@ void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event)
         }
 
         wxLogTrace(_T("focus"),
-                   _T("wxTLW %08x deactivated, last focused: %08x."),
-                   (int) m_hWnd,
-                   (int) (m_winLastFocused ? GetHwndOf(m_winLastFocused)
-                                           : NULL));
+                   _T("wxTLW %p deactivated, last focused: %p."),
+                   m_hWnd,
+                   m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL);
 
         event.Skip();
     }
index 53eefe26edec236bb145e7ba44b762e616a30d97..3efc43f1e9d193c068251eec599afd9c6fa152da 100644 (file)
@@ -212,6 +212,13 @@ WX_DECLARE_HASH_MAP(int, wxWindow::MSWMessageHandler,
 
 static MSWMessageHandlers gs_messageHandlers;
 
+// hash containing all our windows, it uses HWND keys and wxWindow* values
+WX_DECLARE_HASH_MAP(HWND, wxWindow *,
+                    wxPointerHash, wxPointerEqual,
+                    WindowHandles);
+
+static WindowHandles gs_windowHandles;
+
 // ---------------------------------------------------------------------------
 // private functions
 // ---------------------------------------------------------------------------
@@ -227,7 +234,6 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message,
 
 void wxRemoveHandleAssociation(wxWindowMSW *win);
 extern void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win);
-wxWindow *wxFindWinFromHandle(WXHWND hWnd);
 
 // get the text metrics for the current font
 static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
@@ -848,7 +854,7 @@ void wxWindowMSW::DoReleaseMouse()
 /* static */ wxWindow *wxWindowBase::GetCapture()
 {
     HWND hwnd = ::GetCapture();
-    return hwnd ? wxFindWinFromHandle((WXHWND)hwnd) : (wxWindow *)NULL;
+    return hwnd ? wxFindWinFromHandle(hwnd) : NULL;
 }
 
 bool wxWindowMSW::SetFont(const wxFont& font)
@@ -2350,7 +2356,7 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                             if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
                             {
                                 // emulate the button click
-                                btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
+                                btn = wxFindWinFromHandle(msg->hwnd);
                             }
 
                             bProcess = false;
@@ -2641,11 +2647,11 @@ LRESULT WXDLLEXPORT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM w
     // trace all messages - useful for the debugging
 #ifdef __WXDEBUG__
     wxLogTrace(wxTraceMessages,
-               wxT("Processing %s(hWnd=%08lx, wParam=%8lx, lParam=%8lx)"),
-               wxGetMessageName(message), (long)hWnd, (long)wParam, lParam);
+               wxT("Processing %s(hWnd=%p, wParam=%08lx, lParam=%08lx)"),
+               wxGetMessageName(message), hWnd, (long)wParam, lParam);
 #endif // __WXDEBUG__
 
-    wxWindowMSW *wnd = wxFindWinFromHandle((WXHWND) hWnd);
+    wxWindowMSW *wnd = wxFindWinFromHandle(hWnd);
 
     // when we get the first message for the HWND we just created, we associate
     // it with wxWindow stored in gs_winBeingCreated
@@ -2781,11 +2787,11 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             break;
 
         case WM_SETFOCUS:
-            processed = HandleSetFocus((WXHWND)(HWND)wParam);
+            processed = HandleSetFocus((WXHWND)wParam);
             break;
 
         case WM_KILLFOCUS:
-            processed = HandleKillFocus((WXHWND)(HWND)wParam);
+            processed = HandleKillFocus((WXHWND)wParam);
             break;
 
         case WM_PRINTCLIENT:
@@ -3007,23 +3013,15 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             // for these messages we must return true if process the message
 #ifdef WM_DRAWITEM
         case WM_DRAWITEM:
-        case WM_MEASUREITEM:
-            {
-                int idCtrl = (UINT)wParam;
-                if ( message == WM_DRAWITEM )
-                {
-                    processed = MSWOnDrawItem(idCtrl,
-                                              (WXDRAWITEMSTRUCT *)lParam);
-                }
-                else
-                {
-                    processed = MSWOnMeasureItem(idCtrl,
-                                                 (WXMEASUREITEMSTRUCT *)lParam);
-                }
+            processed = MSWOnDrawItem(wParam, (WXDRAWITEMSTRUCT *)lParam);
+            if ( processed )
+                rc.result = TRUE;
+            break;
 
-                if ( processed )
-                    rc.result = TRUE;
-            }
+        case WM_MEASUREITEM:
+            processed = MSWOnMeasureItem(wParam, (WXMEASUREITEMSTRUCT *)lParam);
+            if ( processed )
+                rc.result = TRUE;
             break;
 #endif // defined(WM_DRAWITEM)
 
@@ -3215,11 +3213,11 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
 #endif
 
         case WM_PALETTECHANGED:
-            processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
+            processed = HandlePaletteChanged((WXHWND)wParam);
             break;
 
         case WM_CAPTURECHANGED:
-            processed = HandleCaptureChanged((WXHWND) (HWND) lParam);
+            processed = HandleCaptureChanged((WXHWND)lParam);
             break;
 
         case WM_SETTINGCHANGE:
@@ -3231,7 +3229,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             break;
 
         case WM_ERASEBKGND:
-            processed = HandleEraseBkgnd((WXHDC)(HDC)wParam);
+            processed = HandleEraseBkgnd((WXHDC)wParam);
             if ( processed )
             {
                 // we processed the message, i.e. erased the background
@@ -3246,7 +3244,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
 #endif
 
         case WM_INITDIALOG:
-            processed = HandleInitDialog((WXHWND)(HWND)wParam);
+            processed = HandleInitDialog((WXHWND)wParam);
 
             if ( processed )
             {
@@ -3270,7 +3268,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
 #endif
 
         case WM_SETCURSOR:
-            processed = HandleSetCursor((WXHWND)(HWND)wParam,
+            processed = HandleSetCursor((WXHWND)wParam,
                                         LOWORD(lParam),     // hit test
                                         HIWORD(lParam));    // mouse msg
 
@@ -3355,9 +3353,10 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
                 // we could have got an event from our child, reflect it back
                 // to it if this is the case
                 wxWindowMSW *win = NULL;
-                if ( (WXHWND)wParam != m_hWnd )
+                WXHWND hWnd = (WXHWND)wParam;
+                if ( hWnd != m_hWnd )
                 {
-                    win = FindItemByHWND((WXHWND)wParam);
+                    win = FindItemByHWND(hWnd);
                 }
 
                 if ( !win )
@@ -3409,30 +3408,33 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
 
                     // now alter the client size making room for drawing a themed border
                     NCCALCSIZE_PARAMS *csparam = NULL;
-                    RECT rect;
-                    if (wParam)
+                    RECT *rect;
+                    if ( wParam )
                     {
-                        csparam = (NCCALCSIZE_PARAMS*)lParam;
-                        rect = csparam->rgrc[0];
+                        csparam = (NCCALCSIZE_PARAMS *)lParam;
+                        rect = &csparam->rgrc[0];
                     }
                     else
                     {
-                        rect = *((RECT*)lParam);
+                        rect = (RECT *)lParam;
                     }
+
                     wxUxThemeHandle hTheme((wxWindow *)this, L"EDIT");
                     RECT rcClient = { 0, 0, 0, 0 };
                     wxClientDC dc((wxWindow *)this);
                     wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
 
-                    if (theme->GetThemeBackgroundContentRect(
-                            hTheme, GetHdcOf(*impl), EP_EDITTEXT, ETS_NORMAL,
-                            &rect, &rcClient) == S_OK)
+                    if ( theme->GetThemeBackgroundContentRect
+                                (
+                                 hTheme,
+                                 GetHdcOf(*impl),
+                                 EP_EDITTEXT,
+                                 ETS_NORMAL,
+                                 rect,
+                                 &rcClient) == S_OK )
                     {
                         InflateRect(&rcClient, -1, -1);
-                        if (wParam)
-                            csparam->rgrc[0] = rcClient;
-                        else
-                            *((RECT*)lParam) = rcClient;
+                        *rect = rcClient;
                         rc.result = WVR_REDRAW;
                     }
                 }
@@ -3513,38 +3515,40 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
 // wxWindow <-> HWND map
 // ----------------------------------------------------------------------------
 
-wxWinHashTable *wxWinHandleHash = NULL;
-
-wxWindow *wxFindWinFromHandle(WXHWND hWnd)
+wxWindow *wxFindWinFromHandle(HWND hwnd)
 {
-    return (wxWindow*)wxWinHandleHash->Get((long)hWnd);
+    WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
+    return i == gs_windowHandles.end() ? NULL : i->second;
 }
 
-void wxAssociateWinWithHandle(HWND hWnd, wxWindowMSW *win)
+void wxAssociateWinWithHandle(HWND hwnd, wxWindowMSW *win)
 {
-    // adding NULL hWnd is (first) surely a result of an error and
+    // adding NULL hwnd is (first) surely a result of an error and
     // (secondly) breaks menu command processing
-    wxCHECK_RET( hWnd != (HWND)NULL,
-                 wxT("attempt to add a NULL hWnd to window list ignored") );
+    wxCHECK_RET( hwnd != (HWND)NULL,
+                 wxT("attempt to add a NULL hwnd to window list ignored") );
 
-    wxWindow *oldWin = wxFindWinFromHandle((WXHWND) hWnd);
 #ifdef __WXDEBUG__
-    if ( oldWin && (oldWin != win) )
+    WindowHandles::const_iterator i = gs_windowHandles.find(hwnd);
+    if ( i != gs_windowHandles.end() )
     {
-        wxLogDebug(wxT("HWND %X already associated with another window (%s)"),
-                   (int) hWnd, win->GetClassInfo()->GetClassName());
+        if ( i->second != win )
+        {
+            wxLogDebug(wxT("HWND %p already associated with another window (%s)"),
+                       hwnd, win->GetClassInfo()->GetClassName());
+        }
+        //else: this actually happens currently because we associate the window
+        //      with its HWND during creation (if we create it) and also when
+        //      SubclassWin() is called later, this is ok
     }
-    else
 #endif // __WXDEBUG__
-    if (!oldWin)
-    {
-        wxWinHandleHash->Put((long)hWnd, (wxWindow *)win);
-    }
+
+    gs_windowHandles[hwnd] = win;
 }
 
 void wxRemoveHandleAssociation(wxWindowMSW *win)
 {
-    wxWinHandleHash->Delete((long)win->GetHWND());
+    gs_windowHandles.erase(GetHwndOf(win));
 }
 
 // ----------------------------------------------------------------------------
@@ -3686,7 +3690,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass,
                         style,
                         x, y, w, h,
                         (HWND)MSWGetParent(),
-                        (HMENU)controlId,
+                        (HMENU)wxUIntToPtr(controlId),
                         wxGetInstance(),
                         NULL                        // no extra data
                        );
@@ -3716,7 +3720,7 @@ bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
 #ifndef __WXMICROWIN__
     LPNMHDR hdr = (LPNMHDR)lParam;
     HWND hWnd = hdr->hwndFrom;
-    wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
+    wxWindow *win = wxFindWinFromHandle(hWnd);
 
     // if the control is one of our windows, let it handle the message itself
     if ( win )
@@ -5183,7 +5187,7 @@ static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y)
                 ::IsWindowVisible(hwndUnderMouse) &&
                     ::IsWindowEnabled(hwndUnderMouse) )
     {
-        wxWindow *winUnderMouse = wxFindWinFromHandle((WXHWND)hwndUnderMouse);
+        wxWindow *winUnderMouse = wxFindWinFromHandle(hwndUnderMouse);
         if ( winUnderMouse )
         {
             // translate the mouse coords to the other window coords
@@ -6185,7 +6189,7 @@ wxWindow *wxGetActiveWindow()
     HWND hWnd = GetActiveWindow();
     if ( hWnd != 0 )
     {
-        return wxFindWinFromHandle((WXHWND) hWnd);
+        return wxFindWinFromHandle(hWnd);
     }
     return NULL;
 }
@@ -6200,7 +6204,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
     wxWindow *win = (wxWindow *)NULL;
     if ( hwnd )
     {
-        win = wxFindWinFromHandle((WXHWND)hwnd);
+        win = wxFindWinFromHandle(hwnd);
         if ( !win )
         {
 #if wxUSE_RADIOBOX
@@ -6244,7 +6248,7 @@ extern wxWindow *wxGetWindowFromHWND(WXHWND hWnd)
 #endif
 
         hwnd = ::GetParent(hwnd);
-        win = wxFindWinFromHandle((WXHWND)hwnd);
+        win = wxFindWinFromHandle(hwnd);
     }
 
     return win;