eigenes control mouse-events



  • Hallo
    ich hab ein eigenes control mittels

    handleInstance = instance;
    
        WNDCLASS wc;
        wc.style		  = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
        wc.lpfnWndProc	  = (WNDPROC)wndProc;
        wc.cbClsExtra	  = 0;
        wc.cbWndExtra	  = sizeof(DevColorControl*);
        wc.hInstance	  = getInstance();
        wc.hCursor		  = LoadCursor(NULL, IDC_ARROW);
        wc.hIcon              = NULL;
        wc.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);
        wc.lpszMenuName	  = NULL;
        string caption        = getControlClass();
        wc.lpszClassName      = caption.c_str();
    
        atomClass = RegisterClass(&wc);
    

    und

    if ( instance != NULL ) handleInstance = instance;
        hwndParent = parent;
    
        SetLastError(0);
        CREATESTRUCT createstruct;
        // Übergeben des this-Zeiger an WM_CREATE
        createstruct.lpCreateParams = this;
        setHandle(CreateWindow(getControlClass().c_str(), getCaption().c_str(),
            getStyles(), getLeft(), getTop(), getWidth(), getHeight(), getParent(),
            NULL, getInstance(), &createstruct));
    

    erstellt. Das problem ist wenn ich auf das Control mit der mouse klicke, dann bekommt das parent-fenster die WM_MOUSE event. Und auch die WM_SETFOCUS wird nicht an das control geschickt. wie kann ich das machen das das control das WM_SETFOCUS und das WM_MOUSE bekommt ?



  • moin meister ...

    was das ?
    wc.lpfnWndProc = (WNDPROC)wndProc;

    doch nicht etwa die WndProc vom Parent ?

    mfg
    RB



  • 🙄
    'türlich net, das würd ja einiges erklären ...
    das ist

    static LRESULT wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    

    von der classe die das control verwaltet
    einen zeiger auf das parent hab ich nirgendwo, nur das HWND



  • moin meister ...

    aber WM_LBUTTONDOWN kommt im Control an ?

    mfg
    RB



  • moment

    WM_MOUSEMOVE
    The WM_MOUSEMOVE message is posted to a window when the cursor moves. If the mouse is not captured, the message is posted to the window that contains the cursor. Otherwise, the message is posted to the window that has captured the mouse.

    habe schnell mal ein Schnipsel geschnipselt
    Code im Control:

    case WM_LBUTTONDOWN:
         	pt.x = LOWORD(lp);
       		pt.y = HIWORD(lp) ;
       		SetCapture(hwnd) ;
       		if(PtInRect(&lpMBUTTON->aRect, pt) == TRUE)
       			lpMBUTTON->dwButtonState = MBS_DEFAULT;
    	    else if(PtInRect(&lpMBUTTON->bRect, pt) == TRUE)
    	    	lpMBUTTON->dwButtonState = MBS_SIDE;
    	    else
         	{
          		ReleaseCapture(); 
            	lpMBUTTON->dwButtonState = MBS_NORMAL;
          		lpMBUTTON->dwMovingState = 0;
       		}
          	lpMBUTTON->dwMovingState = lpMBUTTON->dwButtonState;
          	RedrawWindow(hwnd,NULL,NULL, RDW_UPDATENOW|RDW_INVALIDATE); 		// Force a Repaint ofthe control
         	break ;
    

    evtl hilft das ja

    mfg
    RB



  • danke
    aber das problem ist ja das überhaupt keine mouse ereignisse an mein control kommen, die werden alle von dem parent-wnd abgefangen.
    ich hab das grad mitn einem edit-control versucht, da wird die WM_MOUSELBUTTONDOWN hingeschickt ( an das edit-control nicht an seinen parent-wnd).
    das versteh ich eben nicht, an vordefinierten controls wird das geschickt, aber an meinen eigenen nicht.
    ich erstell das control-wnd doch ganz normal mit den styles
    WS_TABSTOP | WS_CHILD | WS_VISIBLE und RegisterClass mit den styles halt: CS_HREDRAW | CS_VREDRAW | CS_OWNDC
    eine WM_PAINT botschaft wird ja hingeschickt
    muss ich da irgendwas setzen das es mouse-events bekommt ?
    mein control verhält sich ja fast wie ein static-control ... achja und bevor die frage kommt, wc.lpszClassName ist nicht "STATIC", das ist "COLOREDIT" also ein name der in der SDK nicht vorkommt



  • mach ein kleines, minimales und compilierbares beispiel fertig und wir helfen dir.



  • ok
    danke für die hilfe aber ich habs inzwischen
    ich hab die falsche messageProc aufrufen lassen 🤡
    war versehentlich



  • moin meister ...

    das hatte ich doch versehentlich schon oben angemerkt 🙂

    aber ich wundere mich auch immer wieder warum die if Bedingung nicht ausgeführt wird

    if(blabla);
    blabla = !blabla;
    🤡

    mfg
    RB


Anmelden zum Antworten