dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Cursor and Window position problem

  1. #1
    Join Date
    Mar 2019
    Posts
    8

    Cursor and Window position problem

    I'm trying to create 2 windows and magnet them so they stay close to each other by 10px: the main window and bottom window. The bottom window act as a resizer for main window when user drag it.
    Everything is fine with one problem: when main window is moved, the cursor points are not correct anymore. I posted below the pseudo code and a screenshot to show the effect problem.
    Code:
    hwndMain = CreateWindow(L"classMain", L"main", WS_POPUP, 50, 0, 800, 600, NULL, NULL, instanceMain, NULL);
    hwndResizer = CreateWindowEx(WS_EX_LAYERED, TEXT("classResizer"), L"", WS_POPUP, 400, 610, 55, 35, hwndMain, NULL, instanceMain, NULL);
    resizer proc
    Code:
    case WM_LBUTTONUP: {
    		ReleaseCapture();
    	} break;
    
    	case WM_LBUTTONDOWN: {
    		SetCapture(hwndBottomResizer);
    	} break;
    
    	case WM_MOUSEMOVE: {
    
    		if (wParam & MK_LBUTTON) {
    
    			RECT bottomResizerRect, mainWindowRect;
    			POINT posBottomResizer;
    			
    			GetWindowRect(hwndBottomResizer, &bottomResizerRect);
    			GetWindowRect(hwndMain, &mainWindowRect);
    
    			posBottomResizer.x = GET_X_LPARAM(lParam); //(int)(short)LOWORD(lParam);
    			posBottomResizer.y = GET_Y_LPARAM(lParam); //(int)(short)HIWORD(lParam);
    			ClientToScreen(hwndBottomResizer, &posBottomResizer);
    
    			HDWP move = BeginDeferWindowPos(2);
    			DeferWindowPos(move, hwndMain, 0, mainWindowRect.left, mainWindowRect.top, mainWindowRect.right - mainWindowRect.left, posBottomResizer.y, 0);
    			DeferWindowPos(move, hwndBottomResizer, 0, bottomResizerRect.left, posBottomResizer.y + 10, bottomResizerRect.right - bottomResizerRect.left, 35, 0);
    			EndDeferWindowPos(move);
    
    		}
    
    	} break;
    main proc
    Code:
    	case WM_NCHITTEST: {
    
    		moveWindows = DefWindowProc(hwnd, message, wParam, lParam);
    
    		RECT rc, brc;
    
    		GetWindowRect(hwnd, &rc);
    		GetWindowRect(hwndBottomResizer, &brc);
    
    		POINT pt;
    		pt.x = GET_X_LPARAM(lParam);
    		pt.y = GET_Y_LPARAM(lParam);
    		ScreenToClient(hwnd, &pt);
    
    		HDWP move = BeginDeferWindowPos(1);
    		//DeferWindowPos(move, hwndMain, 0, mainWindowRect.left, mainWindowRect.top, mainWindowRect.right - mainWindowRect.left, posBottomResizer.y, 0);
    		DeferWindowPos(move, hwndBottomResizer, 0, brc.left, rc.bottom + 10, brc.right - brc.left, 35, 0);
    		EndDeferWindowPos(move);
    
    		if (moveWindows == HTCLIENT) {
    			return HTCAPTION;
    		}
    		else {
    			return moveWindows;
    		}
    	} break;
    See below gif for effect problem.

  2. #2
    Join Date
    Mar 2019
    Posts
    8

    Re: Cursor and Window position problem

    Please watch this gif to see how the main window rect is losing control after is moved by bottom resizer
    https://ibb.co/TtTVZSM

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,906

    Re: Cursor and Window position problem

    [Thread moved]
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,545

    Re: Cursor and Window position problem

    Quote Originally Posted by Valerianel View Post
    Please watch this gif to see how the main window rect is losing control after is moved by bottom resizer
    https://ibb.co/TtTVZSM
    Unfortunately it is not clear what you are doing and what for...
    Could you explain it in more details?
    Victor Nijegorodov

  5. #5
    Join Date
    Mar 2019
    Posts
    8

    Re: Cursor and Window position problem

    I want to create a smaller window below main window to act as a resizer button. The problem is that when the main window is moved, the smaller window below it is not sending correct resize position anymore (like in gif animation). I guess this is because once the main window is moved the other window is not getting correct GetWindowRect positions for some reason

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,906

    Re: Cursor and Window position problem

    I guess this is because once the main window is moved the other window is not getting correct GetWindowRect positions for some reason
    Never guess with Windows programming! Do some debugging and find out. Determine what info you are getting and if not as expected, then understand what you are getting.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2019 (16.3.9)

Tags for this Thread

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




On-Demand Webinars (sponsored)