[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? :(
Re: [win32] - mouse move message seems not be activated :(
Presumeably WM_MOUSEMOVE did work correctly at some point as you're used this code for some time. So what has changed since it last worked? How do you know that WM_MOUSEMOVE is only sometimes activated - what's it not doing that you expect it to do? Have you logged the msg's being received ? Is there a pattern to when WM_MOUSEMOVE isn't being activated as expected?
Code:
HBRUSH g_hbrBackground = CreateSolidBrush(NULL_BRUSH);
For every message received, you are creating a new brush but only deleting the current one in some cases in WM_CTLCOLORSTATIC - you have a resource leak.
Re: [win32] - mouse move message seems not be activated :(
Quote:
Originally Posted by
2kaud
Presumeably WM_MOUSEMOVE did work correctly at some point as you're used this code for some time. So what has changed since it last worked? How do you know that WM_MOUSEMOVE is only sometimes activated - what's it not doing that you expect it to do? Have you logged the msg's being received ? Is there a pattern to when WM_MOUSEMOVE isn't being activated as expected?
Code:
HBRUSH g_hbrBackground = CreateSolidBrush(NULL_BRUSH);
For every message received, you are creating a new brush but only deleting the current one in some cases in WM_CTLCOLORSTATIC - you have a resource leak.
currected:
Code:
HBRUSH g_hbrBackground = NULL;
how i know that these isn't activated:
Code:
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;
(MouseMove is like a lambda functions)
when the window is created:
Code:
case WM_CREATE:
{
label1.setParent(hwnd);
label1.setTransparent(true);
label1.setBorder(1);
label1.setAutoSize(true);
label1.MouseMove=[](int Button, bool control, bool shift,int x, int y)
{
label1.setText("X: " + to_string(x) + " Y: " + to_string(y));
};
}
i move the mouse, but isn't working :(
Re: [win32] - mouse move message seems not be activated :(
it's crazy, when i do the mouse exit the text is changed lol
Code:
case WM_MOUSEMOVE:
{
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
inst->setText("position: " + to_string(xPos));
/*if (!Tracking)
{
inst->TrackMouse(hwnd);
Tracking = true;
inst->MouseEnter();
}
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;
Re: [win32] - mouse move message seems not be activated :(
Quote:
i move the mouse, but isn't working
So is the problem you aren't receiving the WM_MOUSEMOVE message or it is being received but it isn't being processed as expected? What have you changed since this was last working?
Re: [win32] - mouse move message seems not be activated :(
Quote:
Originally Posted by
2kaud
So is the problem you aren't receiving the WM_MOUSEMOVE message or it is being received but it isn't being processed as expected? What have you changed since this was last working?
i just add more tools nothing more. i left your code. do you need the entire class?
Re: [win32] - mouse move message seems not be activated :(
So if the text is changed when you comment out the code, the problem is either in TrackMouse(), MouseEnter(), or MouseMove(). So you'll need to debug the code to see where the problem occurs. What has changed since it last worked?
Re: [win32] - mouse move message seems not be activated :(
Quote:
Originally Posted by
2kaud
So if the text is changed when you comment out the code, the problem is either in TrackMouse(), MouseEnter(), or MouseMove(). So you'll need to debug the code to see where the problem occurs. What has changed since it last worked?
the text is changed the i do the mouse leave... see these code(very code is commented):
Code:
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 = NULL;
//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:
{
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
inst->setText("position: " + to_string(xPos));
}
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);
}
these strange problem i only see it with mouse move. i said that i left you code, but i delete the log file code... sorry
Re: [win32] - mouse move message seems not be activated :(
Well now seems like a good time to get to grips with debugging windows code! :D
Re: [win32] - mouse move message seems not be activated :(
Quote:
Originally Posted by
2kaud
Well now seems like a good time to get to grips with debugging windows code! :D
the problem isn't learn how use the debug... you know that code you did, is advanced :(
so i can't acomplish that so easy :(
Re: [win32] - mouse move message seems not be activated :(
after more tests i found the problem. the problem was with window and not with label. was these extended style: WS_EX_COMPOSITED.
so i have 1 question: if the WS_EX_COMPOSITED mess with mouse move, how can i avoid flickers on controls?(i'm not speaking about WM_PAINT, on these situation i must use the double buffer way)