Like Tree3Likes
  • 1 Post By Elysia
  • 1 Post By Elysia
  • 1 Post By laserlight

why the WM_MOUSEMOVE is acting like WM_MOUSELEAVE? :(

This is a discussion on why the WM_MOUSEMOVE is acting like WM_MOUSELEAVE? :( within the Windows Programming forums, part of the Platform Specific Boards category; i did these class with some help(for connect the window procedure to control): Code: #include <Windowsx.h> #include <windows.h> #include <fstream> ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    158

    why the WM_MOUSEMOVE is acting like WM_MOUSELEAVE? :(

    i did these class with some help(for connect the window procedure to control):
    Code:
    #include <Windowsx.h>
    #include <windows.h>
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <string.h>
    #include <iomanip>
    #include <functional>
    
    #define event(eventname, ... ) std::function<void(__VA_ARGS__ )> eventname
    
    typedef COLORREF color;
    
    using namespace std;
    
    const char propname[] = "Cambalinho";
    const char classprop[] = "classaddr";
    const char debugname[] = "debug.txt";
    
    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 = 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);
        }
    
        int intMouseHover=1000;
        HWND hwnd;
        bool blnVisible=true;
        bool blnEnable=true;
    
    public:
    
        event(Create,(int x, int y))=[](int x, int y){;};
        event(Paint,(HWND hwndWindow, HDC hdcWindow))=NULL;
        event(ResizeStoped)=[](){;};
        event(Resize)=[](){;};
        event(Stoped)=[](){;};
        event(Move,(int x, int y))=[](int x, int y){;};
        event(MouseEnter)=[](){;};
        event(MouseLeave)=[](){;};
        event(MouseHover)=[](){;};
        event(MouseDown,(MouseButtons Button,bool control, bool shift, int x, int y))=[](int Button, bool control, bool shift,int x, int y){;};
        event(MouseUp,(MouseButtons Button,bool control, bool shift, int x, int y))=[](int Button, bool control, bool shift,int x, int y){;};
        event(MouseMove,(MouseButtons Button,bool control, bool shift, int x, int y))=[](int Button, bool control, bool shift,int x, int y){;};
        event(MouseStoped)=[](){;};
        event(MouseClick,(MouseButtons Button,bool control, bool shift, int x, int y))=[](int Button, bool control, bool shift,int x, int y){;};
        event(MouseDoubleClick,(MouseButtons Button,bool control, bool shift, int x, int y))=[](int Button, bool control, bool shift,int x, int y){;};
        //event(MouseWhell,(int Whell, MouseButtons Button,bool control, bool shift, int x, int y))=[](int Whell, int Button, bool alt, bool shift,int x, int y){;};
        event(KeyDown,(int repeat,int Key))=[](int repeat,int Key){;};
        event(KeyUp,(int repeat,int Key))=[](int repeat,int Key){;};
    
    
        ~label()
        {
            DestroyCursor(hCursor);
            DestroyWindow(hwnd);
            hwnd = 0;
        }
    
        label()
        {
            //nothing
        }
    
        label(HWND parent)
        {
    
            setParent(parent);
        }
    
        operator HWND()
        {
            return hwnd;
        }
    
        operator HDC()
        {
            return GetDC(hwnd);
        }
    
        HDC hdc()
        {
            return GetDC(hwnd);
        }
    
        HWND hWnd()
        {
            return hwnd;
        }
    
        void setParent(HWND parent=GetForegroundWindow())
        {
            if (hwnd==NULL)
            {
                static int i=0;
                i=i+1;
                strCaption=strCaption + to_string(i);
                WNDCLASS wc;
                HINSTANCE mod = (HINSTANCE)GetModuleHandle(NULL);
    
                ZeroMemory(&wc, sizeof(WNDCLASS));
                GetClassInfo(mod, "STATIC", &wc);
    
                wc.hInstance = mod;
                wc.lpszClassName = "CSTATIC";
    
                // store the old WNDPROC of the EDIT window class
                SetProp(parent, propname, (HANDLE)wc.lpfnWndProc);
    
                // replace it with local WNDPROC
                wc.lpfnWndProc = WndProc;
                wc.hbrBackground = (HBRUSH) ((COLOR_WINDOW)+1);
    
                // register the new window class, "ShEdit"
                RegisterClass(&wc);
    
                hwnd = CreateWindowEx(
                    WS_EX_LEFT| WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_TRANSPARENT,
                    "CSTATIC",
                    strCaption.c_str(),
                    SS_LEFT|WS_CHILD|WS_VISIBLE|SS_LEFTNOWORDWRAP,
                    0, 0, 60, 30,
                    parent,
                    NULL,
                    mod,
                    (LPVOID)this);
    
                if (hwnd == NULL)
                    MessageBox(NULL, "error in create", "error", MB_OK);
    
                if (SetProp(hwnd, classprop, (HANDLE)this) == 0)
                    MessageBox(NULL, "set class prop error", "error", MB_OK);
                clrBackColor= GetBkColor(GetDC(GetParent(hwnd)));
                clrTextColor = GetTextColor(GetDC(hwnd));
            }
            else
            {
                SetParent(hwnd,parent);
            }
    
            RECT a;
            GetClientRect(hwnd,&a);
            intTop=a.top;
            intLeft=a.left;
            intWidth=a.right-a.left;
            intHeight=a.bottom-a.top;
        }
    
    
        HWND getParent()
        {
            return GetParent(hwnd);
        }
    
        void setTabStop(bool tabstop)
        {
            blnTabStop=tabstop;
            long s;
            if (tabstop==false)
            {
                s = GetWindowLongPtr(hwnd,GWL_STYLE);
                s = s & ~(WS_TABSTOP);
            }
            else
            {
                s = GetWindowLongPtr(hwnd,GWL_STYLE);
                s = s | (WS_TABSTOP);
            }
            SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
        }
    
        bool getTabStop()
        {
            return blnTabStop;
        }
    
        void setMouseHover(int time)
        {
            intMouseHover=time;
        }
    
        int getMouseHover()
        {
            return intMouseHover;
        }
    
        void setMouseCursor()
        {
            hCursor = (HCURSOR)LoadCursor(NULL,IDC_ARROW);
            SetClassLong(hwnd,    // window handle
                GCL_HCURSOR,      // change cursor
                (LONG) hCursor);
    
        }
    
        void setMouseCursor(long cursor)
        {
            hCursor = (HCURSOR)LoadCursor(NULL,(LPCSTR)cursor);
            SetClassLong(hwnd,    // window handle
                GCL_HCURSOR,      // change cursor
                (LONG) hCursor);
    
        }
    
        HCURSOR getMouseCursor()
        {
            return hCursor;
        }
    
        void setCursor(string cursor)
        {
            strCursor=cursor;
            hCursor = (HCURSOR)LoadCursor((HINSTANCE)GetModuleHandle(NULL),(LPCSTR)cursor.c_str());
            SetClassLong(hwnd,    // window handle
                GCL_HCURSOR,      // change cursor
                (LONG) hCursor);
    
        }
    
        int getTop()
        {
            return intTop;
        }
    
        void setTop(int top)
        {
            intTop=top;
            SetWindowPos(hwnd, 0,intLeft ,  intTop, intWidth, intHeight,
                SWP_NOZORDER| SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
        int getLeft()
        {
            return intLeft;
        }
    
        void setLeft(int left)
        {
            intLeft=left;
            SetWindowPos(hwnd, 0,intLeft ,  intTop, intWidth, intHeight,
                SWP_NOZORDER| SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
        int getWidth()
        {
            return intWidth;
        }
    
        void setWidth(int width)
        {
            if (blnAutoSize==false)
            {
                intWidth=width;
                SetWindowPos(hwnd, 0,intLeft ,  intTop, intWidth, intHeight,
                    SWP_NOZORDER|SWP_NOACTIVATE|
                    SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
            }
        }
    
        int getHeight()
        {
            return intHeight;
        }
    
        void setHeight(int height)
        {
            if (blnAutoSize==false)
            {
                intHeight=height;
                SetWindowPos(hwnd, 0,intLeft ,  intTop, intWidth, intHeight,
                    SWP_NOZORDER|SWP_NOACTIVATE|
                    SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
            }
        }
    
        bool getTransparent()
        {
            return blnTransparent;
        }
    
        void setTransparent(bool transparent)
        {
            blnTransparent = transparent;
            SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
        bool getAutoSize()
        {
            return blnAutoSize;
        }
    
        HFONT getFont()
        {
            return (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
        }
    
        void setFont(HFONT font)
        {
            SendMessage(hwnd, WM_SETFONT,(WPARAM) font, true);
        }
    
        void setEnable(bool enable)
        {
            blnEnable=enable;
            EnableWindow(hwnd,enable);
        }
    
        bool getEnable()
        {
            return blnEnable;
        }
    
        void setVisible(bool visible)
        {
            blnVisible=visible;
            if (visible==true)
            {
                ShowWindow(hwnd,SW_SHOW);
            }
            else
            {
                ShowWindow(hwnd,SW_HIDE);
            }
        }
    
        void setAutoSize(bool autosize)
        {
            blnAutoSize=autosize;
            if (autosize==true)
            {
                //Getting the DC Font amd select it
                HDC hdc = GetDC(hwnd);
                HFONT hFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
                HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
    
    
                //Getting the
                RECT c = { 0, 0, 0, 0 };
    
                //Getting the text rectangle from actual caption
                char a[256];
                GetWindowText(this->hwnd,a,256);
                DrawText(hdc, a, strlen(a), &c, DT_CALCRECT | DT_EXPANDTABS);
    
                //add 2 to the size
                TEXTMETRIC v;
                GetTextMetrics (hdc,&v);
                c.right=c.right+(v.tmAveCharWidth / 2);
                c.bottom=c.bottom+(v.tmAveCharWidth / 2);
    
                //Clean the Font DC
                ReleaseDC(hwnd,hdc);
    
                //Getting the actual styles
                LONG s=GetWindowLongPtr(hwnd,GWL_EXSTYLE);
                LONG g=GetWindowLongPtr(hwnd,GWL_STYLE);
    
                //change the rectangle size for borders
                AdjustWindowRectEx (&c,g,FALSE,s );
    
                //Update the control
                SetWindowPos(hwnd, 0, 0, 0, c.right, c.bottom,
                    SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE|
                    SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
            }
        }
    
        void setBorder(int border)
        {
            long s=0;
            if(border==0)
            {
                s = GetWindowLongPtr(hwnd,GWL_EXSTYLE);
                s = s & ~(WS_EX_STATICEDGE) & ~(WS_EX_CLIENTEDGE);
                SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);
    
                s = GetWindowLongPtr(hwnd,GWL_STYLE);
                s = s & ~(WS_BORDER);
                SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
            }
            else if(border==1)
            {
                s = GetWindowLongPtr(hwnd,GWL_EXSTYLE) | WS_EX_CLIENTEDGE;
                SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);
            }
            else if(border==2)
            {
                s = GetWindowLongPtr(hwnd,GWL_STYLE) | WS_BORDER;
                SetWindowLongPtr(hwnd,GWL_STYLE,(LONG_PTR)s);
            }
            else if(border==3)
            {
                s = GetWindowLongPtr(hwnd,GWL_EXSTYLE) | WS_EX_STATICEDGE;
                SetWindowLongPtr(hwnd,GWL_EXSTYLE,(LONG_PTR)s);
            }
            //the SetWindowPos() is for update the control
            SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
        string getText()
        {
            return strCaption;
        }
    
        void setText(string text)
        {
            char* chrText = (char*)text.c_str();
            strCaption=text;
            SetWindowText(hwnd, chrText);
    
            if (blnAutoSize==true)
            {
                setAutoSize(true);
            }
            else
            {
                SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                    SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                    SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
            }
        }
    
        color getBackColor()
        {
            return clrBackColor;
        }
    
        void setBackColor(color backcolor)
        {
            clrBackColor=backcolor;
            SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
        color getTextColor()
        {
            return clrTextColor;
        }
    
        void setTextColor(color textcolor)
        {
            clrTextColor=textcolor;
            SetWindowPos(hwnd, 0, 0, 0, 0, 0,
                SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
                SWP_DRAWFRAME | SWP_FRAMECHANGED|SWP_NOCOPYBITS);
        }
    
    };
    please anyone tell me something.. i don't understand why the error... it's 'far' from me

  2. #2
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    npow i know why: because the window use the WS_EX_COMPOSITED extended style. thanks for all

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Two things:
    - First, anything that involves Windows API should go into the Windows section because C++ experts are not necessarily Windows experts. You might get better answers there.
    - When asking for help, try to post minimal examples instead of 600 lines of code. No one wants to go through all that.
    Elkvis likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    Quote Originally Posted by Elysia View Post
    Two things:
    - First, anything that involves Windows API should go into the Windows section because C++ experts are not necessarily Windows experts. You might get better answers there.
    - When asking for help, try to post minimal examples instead of 600 lines of code. No one wants to go through all that.
    1 - i can't find it in these forum...sorry;
    2 - you have right, but sometimes isn't easy to understand where is the error, that's why i give all the code
    thanks for all

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by joaquim View Post
    1 - i can't find it in these forum...sorry;
    Windows Programming

    2 - you have right, but sometimes isn't easy to understand where is the error, that's why i give all the code
    You have put effort in to reduce the code until the problem no longer occurs.
    joaquim likes this.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,313
    Moved to Windows programming forum.
    joaquim likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Aug 2013
    Posts
    158
    my problem was using WS_EX_COMPOSITED extended style with parent window.
    can i use the WS_EX_COMPOSITED without affect the windows messages?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about WM_MOUSEMOVE
    By hdragon in forum Game Programming
    Replies: 5
    Last Post: 11-14-2005, 03:23 AM
  2. very bad delay in picking up WM_MOUSEMOVE
    By hanhao in forum C++ Programming
    Replies: 7
    Last Post: 05-28-2004, 12:02 PM
  3. ignore WM_MOUSEMOVE msg on menu
    By lambs4 in forum Windows Programming
    Replies: 1
    Last Post: 05-13-2004, 08:01 PM
  4. How can I capture the WM_MOUSEMOVE message for a button?
    By pinkcheese in forum Windows Programming
    Replies: 8
    Last Post: 05-21-2002, 07:44 PM
  5. getch() acting up...
    By Govtcheez in forum C Programming
    Replies: 9
    Last Post: 08-18-2001, 01:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21