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

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

  1. #91
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    Quote Originally Posted by Cambalinho View Post
    using the WM_LBUTTONUP the wParam & MK_LBUTTON is valid or not?
    This is the documentation for WM_LBUTTONUP.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Does it mention MK_LBUTTON?
    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. #92
    Join Date
    Apr 2009
    Posts
    605

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

    Quote Originally Posted by 2kaud View Post
    This is the documentation for WM_LBUTTONUP.
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Does it mention MK_LBUTTON?
    you have right.. i didn't have seen that ... sorry.
    but i combine the messages:
    Code:
    enum MouseButtons
    {
        None=-1,
        Left=0,
        Right=1,
        Middle=2,
        X1=3,
        X2=4
    };
    
    //inside of window procedure
    
    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))
                    {
                        MBButtons=Left;
                        SetWindowText(GetParent(hwnd),"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_XBUTTON1))
                        MBButtons=X2;
                    else
                        MBButtons=None;
                    inst->MouseUp(MBButtons,blControl,blshift,xPos,yPos);
                }
                break;
    but i continue with bad results

  3. #93
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    but i continue with bad results
    Correct! You can't test for the absence of a value - only for its presence. The problem is that you are trying to combine the code for all the buttons into one routine. If you debugged through the code as suggested, you would find that the WK_xBUTTON values are not set in wparam when the WM_xBUTTONUP events occur. Therefore the only way of knowing which button is up is from looking at the msg value. So your code could be

    Code:
                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 (msg == WM_LBUTTONUP)
                        //MBButtons=Left;
                        SetWindowText(GetParent(hwnd),"left");
                    else if (msg == WM_RBUTTONUP)
                        SetWindowText(GetParent(hwnd),"right");
                        //MBButtons=Right;
                    else if (msg == WM_MBUTTONUP)
                        SetWindowText(GetParent(hwnd),"middle");
                        //MBButtons=Middle;
    				else if (msg == WM_XBUTTONUP) {
    						if (wParam & MK_XBUTTON1)
    		                    SetWindowText(GetParent(hwnd),"xbut1");
    							//MBButtons=X1;
    						else if (wParam & MK_XBUTTON2)
    					        SetWindowText(GetParent(hwnd),"left");
    						//MBButtons=X2;
    					}
                    //else
                        //MBButtons=None;
    
                    //inst->MouseUp(MBButtons,blControl,blshift,xPos,yPos);
                }
                break;
    If something doesn't seem to be working as it should
    1) Make sure that where applicable you are testing for errors from API functions.
    2) Make sure you understand the documentation for the API functions.
    3) Use the debugger to see what values the API functions are actually returning. Are they as expected? I've come across several examples of where the actual return values from API functions are not the same as the documentation!
    Last edited by 2kaud; January 1st, 2014 at 05:36 AM.
    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.

  4. #94
    Join Date
    Apr 2009
    Posts
    605

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

    Quote Originally Posted by 2kaud View Post
    Correct! You can't test for the absence of a value - only for its presence. The problem is that you are trying to combine the code for all the buttons into one routine. If you debugged through the code as suggested, you would find that the WK_xBUTTON values are not set in wparam when the WM_xBUTTONUP events occur. Therefore the only way of knowing which button is up is from looking at the msg value. So your code could be

    Code:
                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 (msg == WM_LBUTTONUP)
                        //MBButtons=Left;
                        SetWindowText(GetParent(hwnd),"left");
                    else if (msg == WM_RBUTTONUP)
                        SetWindowText(GetParent(hwnd),"right");
                        //MBButtons=Right;
                    else if (msg == WM_MBUTTONUP)
                        SetWindowText(GetParent(hwnd),"middle");
                        //MBButtons=Middle;
                    else if (msg == WM_XBUTTONUP) {
                            if (wParam & MK_XBUTTON1)
                                SetWindowText(GetParent(hwnd),"xbut1");
                                //MBButtons=X1;
                            else if (wParam & MK_XBUTTON2)
                                SetWindowText(GetParent(hwnd),"left");
                            //MBButtons=X2;
                        }
                    //else
                        //MBButtons=None;
    
                    //inst->MouseUp(MBButtons,blControl,blshift,xPos,yPos);
                }
                break;
    If something doesn't seem to be working as it should
    1) Make sure that where applicable you are testing for errors from API functions.
    2) Make sure you understand the documentation for the API functions.
    3) Use the debugger to see what values the API functions are actually returning. Are they as expected? I've come across several examples of where the actual return values from API functions are not the same as the documentation!
    thanks for that... now works fine
    now think with me:
    WM_RBUTTONUP: http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
    theres the information for WM_RBUTTONUP:

    "Posted when the user releases the right mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.

    A window receives this message through its WindowProc function.


    #define WM_RBUTTONUP 0x0205

    Parameters

    wParam Indicates whether various virtual keys are down. This parameter can be one or more of the following values.




    and gives me the const's values...
    now heres the question: know only that, how i can test the wParam?
    (sorry, but i think the page don't have all information )

  5. #95
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    The info provided here re wparam is not correct as per the Cummunity Addition comment.

    To test for one of the possibilities is quite simple. All you do within the appropriate window message handler routine for the appropriate message is

    Code:
    if (wParam & MK_CONTROL) 
         //Control key pressed
    
    if (wparam & MK_SHIFT)
         //Shift key pressed
    
    etc etc
    You are not capturing the mouse, so the mouse messages are posted to the window beneath the cursor (assuming message WM_NCHITTEST is handled properly!). If the mouse is captured, the mouse messages go to window which has the capture.

    The various constants are defined in the file winuser.h
    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. #96
    Join Date
    Apr 2009
    Posts
    605

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

    Quote Originally Posted by 2kaud View Post
    The info provided here re wparam is not correct as per the Cummunity Addition comment.

    To test for one of the possibilities is quite simple. All you do within the appropriate window message handler routine for the appropriate message is

    Code:
    if (wParam & MK_CONTROL) 
         //Control key pressed
    
    if (wparam & MK_SHIFT)
         //Shift key pressed
    
    etc etc
    You are not capturing the mouse, so the mouse messages are posted to the window beneath the cursor (assuming message WM_NCHITTEST is handled properly!). If the mouse is captured, the mouse messages go to window which has the capture.

    The various constants are defined in the file winuser.h
    ok..thanks
    see these function for mouse hover\enter\leave:
    Code:
    //all inside of class
    void TrackMouse(HWND hwnd)
    {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_HOVER | TME_LEAVE; //Type of events to track & trigger.
        tme.dwHoverTime = 5000; //How long the mouse has to be in the window to trigger a hover event.
        tme.hwndTrack = hwnd;
        TrackMouseEvent(&tme);
    }
    
    //window procedure:
    static bool TrackingMouse = false;
    
    case WM_MOUSEMOVE:
                {
                    if (!TrackingMouse)
                    {
                        TrackMouse(hwnd);
                        TrackingMouse = true;
                        inst->MouseEnter();
                    }
    ...............
    my question: why i get these error?
    " cannot call member function 'void label::TrackMouse(HWND)' without object"

  7. #97
    Join Date
    Apr 2009
    Posts
    605

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

    finally i fix it:

    inst->TrackMouse(hwnd);

    like you see, i must use the pointer too.
    thanks for all

  8. #98
    Join Date
    Apr 2009
    Posts
    605

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

    i'm using the SetBkColor() and SetTextColor(), but why i can't use them with my control?
    (what i mean is that they are ignored and no error message(the GetLastError() give 0 (zero))

  9. #99
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    Quote Originally Posted by Cambalinho View Post
    i'm using the SetBkColor() and SetTextColor(), but why i can't use them with my control?
    (what i mean is that they are ignored and no error message(the GetLastError() give 0 (zero))
    How are you using them for the static control?

    Have a look at
    http://stackoverflow.com/questions/4...d-color-with-c

    As we've said before, you have to know how things are supposed to work. You can't just guess with WIndows API.
    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. #100
    Join Date
    Apr 2009
    Posts
    605

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

    Quote Originally Posted by 2kaud View Post
    How are you using them for the static control?

    Have a look at
    http://stackoverflow.com/questions/4...d-color-with-c

    As we've said before, you have to know how things are supposed to work. You can't just guess with WIndows API.
    sorry i try that code:
    Code:
    case WM_CTLCOLORSTATIC: //For painting read-only/disabled static-controls backgrounds.
                {
                    HDC hdc = (HDC)wParam;
                    SetTextColor(hdc, RGB(0, 0, 0));
                    SetBkColor(hdc, RGB(255,0,0));
                    return (LRESULT)GetStockObject(NULL_BRUSH);
                    break;
                }
    i have tryied these too: http://www.winprog.org/tutorial/dlgfaq.html
    i have tryied the WM_PAINT works, but i must use the TextOut() instead the SetWindowText()... the problem is that i lose the mouse events

  11. #101
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    And the problem is? I tried the code you posted and it seems to work OK for me. You can't tell where the static control window is because you use NULL_BRUSH.

    You have put this code in WindowProcedure() for the main window and not in WndProc() for the control haven't you?
    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. #102
    Join Date
    Apr 1999
    Posts
    27,422

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

    Quote Originally Posted by Cambalinho View Post
    sorry i try that code:
    The issue that I have with your attempt is that it is based on a very shaky foundation.

    Why didn't you start out with a solid, working, already coded Windows API application, where you didn't need to change a single line of code to get working? For example, something out of Petzold's or another author's book (or go to a website to get a stock Windows API program). Compile, run, understand how it works, and then move from there.

    Then when that works correctly, you can then experiment all you want with differing scenarios. Otherwise, all you're doing is putting together a patchwork of code from different websites and using remnants of some answers here. To be blunt, you can't write a solid, working Windows API programs that way.

    Regards,

    Paul McKenzie

  13. #103
    Join Date
    Apr 2009
    Posts
    605

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

    Quote Originally Posted by 2kaud View Post
    And the problem is? I tried the code you posted and it seems to work OK for me. You can't tell where the static control window is because you use NULL_BRUSH.

    You have put this code in WindowProcedure() for the main window and not in WndProc() for the control haven't you?
    yes... ins't in main procedure window. but can i put it in child procedure window?

  14. #104
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    Quote Originally Posted by Cambalinho View Post
    yes... ins't in main procedure window. but can i put it in child procedure window?
    No. The WM_CTLCOLORSTATIC message gets sent to the parent of the control - in this case the main window - and has to be handled there.

    See http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    As Paul and myself have repeatly emphasised - you can't write a windows program using the Windows API without knowing how everything is supposed to fit together and how the APIs work. You need to read closely the API documentation of every API you use to much sure you understand it before use. As Paul also states correctly, trying to put together a working stable windows program using bits of code obtained from several places - including here - is a recipe for disaster if you don't understand the overall framework of windows programs.
    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.

  15. #105
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,262

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

    If you really want the code to set the text/background colour to be in the child procedure window, you could do something like this

    in child window procedure
    Code:
    	case WM_CTLCOLORSTATIC:
                {
                    HDC hdc = (HDC)wParam;
                    SetTextColor(hdc, RGB(0, 0, 0));
                    SetBkColor(hdc, RGB(255,0,0));
                    return (LRESULT)GetStockObject(GRAY_BRUSH);
                }
    in parent window procedure
    Code:
             case WM_CTLCOLORSTATIC:
    		return SendMessage((HWND)lParam, WM_CTLCOLORSTATIC, wParam, lParam);
    This works because for the WM_CTLCOLORSTATIC message sent to the control parent window, lParam is a handle to the child window from which the request came.
    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.

Page 7 of 11 FirstFirst ... 45678910 ... 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center