-
January 30th, 2014, 09:58 AM
#1
[RESOLVED] [win32] - mouse move message seems not be activated :(
Code:
.................
enum MouseButtons
{
None = 0,
Left = 1,
Right = 2,
Middle = 3,
X1 = 4,
X2 = 5
};
int pos = 0;
const string lab[6] = {"qwerty", "asdfgh", "zxcvbn", "poiuyt", "lkjhgf", "mnbvcx"};
class label
{
private:
HCURSOR hCursor=(HCURSOR)LoadCursor(GetModuleHandle(NULL),IDC_APPSTARTING);
string strCaption="Label ";
string strCursor="";
color clrTextColor=0;
color clrBackColor=0;
bool blnTransparent=false;
bool blnAutoSize=false;
bool blnTabStop=false;
int intTop=0;
int intLeft=0;
int intWidth=0;
int intHeight=0;
void TrackMouse(HWND hwnd, long HoverTime=0)
{
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_HOVER | TME_LEAVE; //Type of events to track & trigger.
tme.dwHoverTime = HoverTime; //How long the mouse has to be in the window to trigger a hover event.
tme.hwndTrack = hwnd;
TrackMouseEvent(&tme);
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static bool Tracking = false;
static MouseButtons MBButtons;
static bool blControl=false;
static bool blShift=false;
WNDPROC oldproc = (WNDPROC)GetProp(GetParent(hwnd), propname);
if (oldproc == NULL)
MessageBox(NULL, "oldprocnull", "oldprocnull", MB_OK);
label *inst = (label*)GetProp(hwnd, classprop);
if (inst == NULL && msg == WM_NCCREATE)
{
inst = (label*)(((LPCREATESTRUCT)lParam)->lpCreateParams);
SetProp(hwnd, classprop, (HANDLE)inst);
}
if (inst == NULL)
MessageBox(NULL, "instnull", "instnull", MB_OK);
HBRUSH g_hbrBackground = CreateSolidBrush(NULL_BRUSH);
//Working with messages
switch(msg)
{
case WM_CREATE:
{
inst->Create(inst->intLeft, inst->intTop);
}
break;
case WM_CTLCOLORSTATIC:
{
if ( inst->blnTransparent == true)
{
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkMode( (HDC)wParam, TRANSPARENT);
return (LRESULT) GetStockObject(HOLLOW_BRUSH);
}
else
{
DeleteObject(g_hbrBackground);
SetTextColor((HDC)wParam, inst->clrTextColor);
SetBkColor((HDC)wParam,inst->clrBackColor);
SetBkMode((HDC)wParam, TRANSPARENT);
g_hbrBackground = CreateSolidBrush(inst->clrBackColor);
return (LONG)g_hbrBackground;
}
}
break;
case WM_PAINT:
{
if (inst->Paint==NULL) break;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(inst->hwnd, &ps);
inst->Paint(inst->hwnd,hdc);
EndPaint(inst->hwnd, &ps);
}
break;
case WM_NCHITTEST:
return DefWindowProc(hwnd, msg, wParam, lParam);
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP:
{
SetFocus(inst->hwnd);
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
inst->MouseUp(MBButtons, blControl, blShift, xPos, yPos);
}
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN:
{
SetFocus(inst->hwnd);
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
blShift = ((wParam & MK_SHIFT) == MK_SHIFT);
if((wParam & MK_LBUTTON)!= false)
MBButtons=Left;
else if (wParam & MK_RBUTTON)
MBButtons=Right;
else if (wParam & MK_MBUTTON)
MBButtons=Middle;
else if (wParam & MK_XBUTTON1)
MBButtons=X1;
else if (wParam & MK_XBUTTON2)
MBButtons=X2;
inst->MouseDown(MBButtons, blControl, blShift, xPos, yPos);
}
break;
case WM_MOUSEMOVE:
{
if (!Tracking)
{
inst->TrackMouse(hwnd);
Tracking = true;
inst->MouseEnter();
}
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
if((wParam & MK_LBUTTON)!= false)
MBButtons=Left;
else if (wParam & MK_RBUTTON)
MBButtons=Right;
else if (wParam & MK_MBUTTON)
MBButtons=Middle;
else if (wParam & MK_XBUTTON1)
MBButtons=X1;
else if (wParam & MK_XBUTTON2)
MBButtons=X2;
inst->MouseMove(MBButtons,blControl,blShift,xPos,yPos);
}
break;
case WM_MOUSEHOVER:
{
inst->MouseHover();
}
break;
case WM_MOUSELEAVE:
{
inst->MouseLeave();
Tracking = false;
}
break;
default:
break;
}
//If oldproc is NULL then use DefWindowProc - but shouldn't be!
return oldproc ? CallWindowProc(oldproc, hwnd, msg, wParam, lParam) : DefWindowProc(hwnd, msg, wParam, lParam);
}
.................
why the WM_MOVE is only sometimes activated?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|