Try to search your question here, if you can't find : Ask Any Question Now ?

WinAPI C++ – resizing window with MoveWindow leaves 7 pixel boarder

HomeCategory: stackoverflowWinAPI C++ – resizing window with MoveWindow leaves 7 pixel boarder
Avatarjohn asked 3 months ago

I am trying to use MoveWindow() function to move a window to a specific position on the screen. However the window is not being moved into the correct position and is leaving a gap between the specified coordinates and the actual position the window is moved to.

Here is some example code which demonstrates the problem. Typing a letter r for right, c for center and l for left this code positions the console window to take up a third of the screen at this position. The resolution of my monitor is 3440 x 1440 so these segments each take up approximately 3440/3 pixels of horizontal space.

#include <windows.h>
#include <iostream>

int main()
{

    while (true)
    {
        HWND window = GetForegroundWindow();
        switch (getchar())
        {
        case 'l':
            MoveWindow(window, 0, 0, 1147, 1400, TRUE);
            break;

        case 'c':
            MoveWindow(window, 1147, 0, 1146, 1400, TRUE);
            break;

        case 'r':
            MoveWindow(window, 1147 + 1146, 0, 1147, 1400, TRUE);
            break;

        case 'e':
            return 0;
        }

    }

    return 0;
}

If I run three instances of this code and position them all side by side using the letter commands, this is the image of the result I get. Each window seems to be 7 pixels smaller than it should be on both the left and right sides.

Link to Image

How can I get the window to take up exactly the space I specify in the MoveWindow command rather than leaving a 7 pixel boarder around the window?

1 Answers
Best Answer
AvatarMatthias answered 3 months ago
Your Answer

20 + 10 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com