[win32] - creating controls using class's - Page 6
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 6 of 11 FirstFirst ... 3456789 ... LastLast
Results 76 to 90 of 155

Thread: [win32] - creating controls using class's

  1. #76
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    "'label1' is not captured|"
    It has escaped!

    Happy New Year
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  2. #77
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,470

    Re: [win32] - creating controls using class's

    Quote Originally Posted by Cambalinho View Post
    see these lines:

    Code:
    label label1(hwnd);
        label1.MouseDown=[](int Button, bool alt, bool shift,int x, int y)
        {
            if(alt==true  && Button==VK_LBUTTON) label1.SetText("mouse left down");//error message
        };
    what means these error:
    "'label1' is not captured|"
    ???
    Perhaps you would first explain what you were trying to achive with this code snippet?
    Besides, it would also help if you were format this code properly!
    Victor Nijegorodov

  3. #78
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    It has escaped!

    Happy New Year
    good one
    the problem was that i didn't declare the label1 global(in global scope) and now works.
    sorry i continue with problems in these line:
    Code:
    GetAsyncKeyState(VK_CONTROL) & 0x8000
    what i need to know is if the control key is down

  4. #79
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    2kaud: you have right... and accept global variables too.
    please see my last post

  5. #80
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    what i need to know is if the control key is down
    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.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  6. #81
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View 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.
    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;
                }
    i'm trying, but i didn't get right results

  7. #82
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    Try this:
    Code:
    bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
    
    bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #83
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    Try this:
    Code:
    bool blControl = ((wParam & MK_CONTROL) == MK_CONTROL);
    
    bool blshift = ((wParam & MK_SHIFT) == MK_SHIFT);
    see these:
    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 can't compare the control?
    Code:
    label1.MouseDown=[&label1](int Button, bool control, bool shift,int x, int y)
        {
            if(control==true && Button==VK_LBUTTON)
                label1.SetText("mouse down");
        };
    why i'm getting always '0' on that 'if'?
    seems that, when i pass the blnControl to MouseDown(), the value is losed.... why?

  9. #84
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    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
    Code:
    if (control == true && ((Button & MK_LBUTTON) || (Button & MK_RBUTTON) || (Button & MK_MBUTTON)))
    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.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  10. #85
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    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
    Code:
    if (control == true && ((Button & MK_LBUTTON) || (Button & MK_RBUTTON) || (Button & MK_MBUTTON)))
    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.
    thanks for correct me between VK an MK. i never knew that the buttons was wParam & MK_XBUTTON.
    sorry the if(Button & MK_LBUTTON) it's the same if((Button & MK_LBUTTON)==true)?
    (sorry ask these, but it's for build my own const's)

  11. #86
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    if(Button & MK_LBUTTON) it's the same if((Button & MK_LBUTTON)==true)?
    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 use

    Code:
     if ((Button & MK_RBUTTON) != false)
    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.

    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
    Code:
    if (control == true && ((Button & MK_LBUTTON) || (Button & MK_RBUTTON) || (Button & MK_MBUTTON)))
    can be considered as
    Code:
    if (control == true && ((Button & MK_LBUTTON) != 0 || (Button & MK_RBUTTON) != 0 || (Button & MK_MBUTTON) != 0))
    Last edited by 2kaud; December 31st, 2013 at 05:38 PM.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  12. #87
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    thanks for correct me.
    now my MouseUp() is 'confused'
    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);
                }
    because these 'if'(i belive) is reciving wrong values:
    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");
        };
    anotherthing: the mouse click is the mouse left up, right?

  13. #88
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,547

    Re: [win32] - creating controls using class's

    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.

    the mouse click is the mouse left up, right?
    ??
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  14. #89
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    Quote Originally Posted by 2kaud View Post
    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.



    ??
    ok.. tomorrow i will see better.
    the MouseClick event(the mouse click) it's the mouse left button up, right?

  15. #90
    Join Date
    Apr 2009
    Posts
    678

    Re: [win32] - creating controls using class's

    using the WM_LBUTTONUP the wParam & MK_LBUTTON is valid or not?

Page 6 of 11 FirstFirst ... 3456789 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center