clean up _pfnTrackMouseEvent (CMU reported crash)

This commit is contained in:
David Rose 2003-01-23 17:43:40 +00:00
parent 324eb3c262
commit 8db75fced0
4 changed files with 25 additions and 22 deletions

View File

@ -28,6 +28,15 @@ TypeHandle WinGraphicsPipe::_type_handle;
////////////////////////////////////////////////////////////////////
WinGraphicsPipe::
WinGraphicsPipe() {
// these fns arent defined on win95, so get dynamic ptrs to them
// to avoid ugly DLL loader failures on w95
_pfnTrackMouseEvent = NULL;
_hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
if (_hUser32 != NULL) {
_pfnTrackMouseEvent =
(PFN_TRACKMOUSEEVENT)GetProcAddress(_hUser32, "TrackMouseEvent");
}
}
////////////////////////////////////////////////////////////////////
@ -37,4 +46,8 @@ WinGraphicsPipe() {
////////////////////////////////////////////////////////////////////
WinGraphicsPipe::
~WinGraphicsPipe() {
if (_hUser32 != NULL) {
FreeLibrary(_hUser32);
_hUser32 = NULL;
}
}

View File

@ -21,6 +21,7 @@
#include "pandabase.h"
#include "graphicsPipe.h"
#include "winGraphicsWindow.h"
////////////////////////////////////////////////////////////////////
// Class : WinGraphicsPipe
@ -40,6 +41,10 @@ public:
WinGraphicsPipe();
virtual ~WinGraphicsPipe();
private:
HINSTANCE _hUser32;
typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
public:
static TypeHandle get_class_type() {
@ -57,6 +62,8 @@ public:
private:
static TypeHandle _type_handle;
friend class WinGraphicsWindow;
};
#include "winGraphicsPipe.I"

View File

@ -29,9 +29,6 @@
TypeHandle WinGraphicsWindow::_type_handle;
bool WinGraphicsWindow::_got_dynamic_fns = false;
WinGraphicsWindow::PFN_TRACKMOUSEEVENT WinGraphicsWindow::_pfnTrackMouseEvent = NULL;
bool WinGraphicsWindow::_loaded_custom_cursor;
HCURSOR WinGraphicsWindow::_mouse_cursor;
const char * const WinGraphicsWindow::_window_class_name = "WinGraphicsWindow";
@ -72,19 +69,6 @@ WinGraphicsWindow(GraphicsPipe *pipe) :
_tracking_mouse_leaving = false;
_maximized = false;
memset(_keyboard_state, 0, sizeof(BYTE) * num_virtual_keys);
if (!_got_dynamic_fns) {
// these fns arent defined on win95, so get dynamic ptrs to them
// to avoid ugly DLL loader failures on w95
HINSTANCE hUser32 = (HINSTANCE)LoadLibrary("user32.dll");
if (hUser32) {
_pfnTrackMouseEvent =
(PFN_TRACKMOUSEEVENT)GetProcAddress(hUser32, "TrackMouseEvent");
FreeLibrary(hUser32);
}
_got_dynamic_fns = true;
}
}
////////////////////////////////////////////////////////////////////
@ -628,7 +612,10 @@ track_mouse_leaving(HWND hwnd) {
// 3.0+) which emulates TrackMouseEvent on w95, but that requires
// another 500K of memory to hold that DLL, which is lame just to
// support w95, which probably has other issues anyway
if (_pfnTrackMouseEvent != NULL) {
WinGraphicsPipe *winpipe;
DCAST_INTO_V(winpipe, _pipe);
if (winpipe->_pfnTrackMouseEvent != NULL) {
TRACKMOUSEEVENT tme = {
sizeof(TRACKMOUSEEVENT),
TME_LEAVE,
@ -637,7 +624,7 @@ track_mouse_leaving(HWND hwnd) {
};
// tell win32 to post WM_MOUSELEAVE msgs
BOOL bSucceeded = _pfnTrackMouseEvent(&tme);
BOOL bSucceeded = winpipe->_pfnTrackMouseEvent(&tme);
if ((!bSucceeded) && windisplay_cat.is_debug()) {
windisplay_cat.debug()

View File

@ -107,10 +107,6 @@ private:
bool _maximized;
DEVMODE _fullscreen_display_mode;
static bool _got_dynamic_fns;
typedef BOOL (WINAPI *PFN_TRACKMOUSEEVENT)(LPTRACKMOUSEEVENT);
static PFN_TRACKMOUSEEVENT _pfnTrackMouseEvent;
// This is used to remember the state of the keyboard when keyboard
// focus is lost.
static const int num_virtual_keys = 256;