It has escaped!:lol::DQuote:
"'label1' is not captured|"
Happy New Year
Printable View
It has escaped!:lol::DQuote:
"'label1' is not captured|"
Happy New Year
2kaud: you have right... and accept global variables too.
please see my last post
Where are you trying to use this? If it is for processing control key with keyboard or mouse messages then the message wparam for mouse and lparam for keyboard has this info.Quote:
what i need to know is if the control key is down
i'm trying, but i didn't get right results :(Code:case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN:
{
SetFocus(inst->hwnd);
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
bool blControl=(wParam==MK_CONTROL);
inst->MouseDown(wParam,blControl,GetAsyncKeyState(VK_SHIFT) & 0x8000,xPos,yPos);
break;
}
Try this:
Code:bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
see these:
why i can't compare the control?Code:case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_XBUTTONDOWN:
{
SetFocus(inst->hwnd);
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
inst->MouseDown(wParam,blControl,blshift,xPos,yPos);
break;
}
why i'm getting always '0' on that 'if'?Code:label1.MouseDown=[&label1](int Button, bool control, bool shift,int x, int y)
{
if(control==true && Button==VK_LBUTTON)
label1.SetText("mouse down");
};
seems that, when i pass the blnControl to MouseDown(), the value is losed.... why?
Button in MouseDown is wParam from the WM_xxBUTTONDOWN message. If you want to see if any mouse button is down as well as the control key then use
VK_LBUTTON is a virual key code which is not what wParam contains for these messages. You need to read the documentation for each of the messages you process to see what data is contained in wParam and lParam.Code:if (control == true && ((Button & MK_LBUTTON) || (Button & MK_RBUTTON) || (Button & MK_MBUTTON)))
Yes but no! Lets use MB_RBUTTON for the example. (Button & MK_RBUTTON) returns a non-zero value if the right mouse button is pressed and 0 if it is not. true/false are the states of a bool type (true can be taken as 1 and false as 0). As Button & MK_RBUTTON is not of type bool but of type int then the value of Button & MB_RBUTTON whilst not 0 if the mouse right button is pressed is not equal to the bool value true (it's actually 2). To test in this way you would useQuote:
if(Button & MK_LBUTTON) it's the same if((Button & MK_LBUTTON)==true)?
In the case of MK_LBUTTON it would work only because MK_LBUTTON has the value of 1. Use of any other constant here would not work. Testing against true for a non-bool type is not recommended. It is better to test != against false.Code:if ((Button & MK_RBUTTON) != false)
In the original if condition the test is simply (Button & MK_RBUTTON). In c/c++ conditions evaluate to either 0 or non-zero. If the conditon is non-zero, the condition is considered 'true' (not the c++ true but boolean true!) if the conditon is zero, then it is considered 'false'.
so
can be considered asCode:if (control == true && ((Button & MK_LBUTTON) || (Button & MK_RBUTTON) || (Button & MK_MBUTTON)))
Code:if (control == true && ((Button & MK_LBUTTON) != 0 || (Button & MK_RBUTTON) != 0 || (Button & MK_MBUTTON) != 0))
thanks for correct me.
now my MouseUp() is 'confused' :(
because these 'if'(i belive) is reciving wrong values:Code:enum MouseButtons
{
Left=0,
Right=1,
Middle=2,
X1=3,
X2=4
};
//...............................
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
case WM_XBUTTONUP:
{
SetFocus(inst->hwnd);
static int xPos = (int)(short) LOWORD(lParam);
static int yPos = (int)(short) HIWORD(lParam);
bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
MouseButtons MBButtons;
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->MouseUp(MBButtons,blControl,blshift,xPos,yPos);
}
anotherthing: the mouse click is the mouse left up, right?Code:label1.MouseUp=[&label1](MouseButtons Button, bool control, bool shift,int x, int y)
{
if (Button==Left) //only on MouseUp is 'confused', the others works fine
label1.SetText("mouse up");
};
In MouseUp() what is the value of Button when you think it has the 'wrong' value?
You really need to learn how to debug programs and locate and fix run-time issues like this rather than asking for help everytime you get a problem.
?? :confused:Quote:
the mouse click is the mouse left up, right?
using the WM_LBUTTONUP the wParam & MK_LBUTTON is valid or not?