Winapi CreateWindow滚动条对齐问题

Winapi CreateWindow滚动条对齐问题,winapi,scrollbar,alignment,createwindow,Winapi,Scrollbar,Alignment,Createwindow,考虑以下部分代码。我的问题是滚动条没有与矩形对齐。我得到一个矩形和一个滚动条,两者之间有很大的间隙。我想我可以试验一下,找出“偏移量”是什么,然后把它放进去,但我想知道为什么滚动条似乎不尊重坐标 hCDC = GetDC(hCWnd); bkgBrush = CreateSolidBrush( BGColor ); SetMapMode( hCDC, MM_TEXT ); SelectObject( hCDC, bkgBrush ); Rectangle(hCDC, VTRect->lef

考虑以下部分代码。我的问题是滚动条没有与矩形对齐。我得到一个矩形和一个滚动条,两者之间有很大的间隙。我想我可以试验一下,找出“偏移量”是什么,然后把它放进去,但我想知道为什么滚动条似乎不尊重坐标

hCDC = GetDC(hCWnd);
bkgBrush = CreateSolidBrush( BGColor );
SetMapMode( hCDC, MM_TEXT );
SelectObject( hCDC, bkgBrush );
Rectangle(hCDC, VTRect->left, VTRect->top, VTRect->right, VTRect->bottom);

iHThumb = GetSystemMetrics(SM_CXHTHUMB);
iVThumb = GetSystemMetrics(SM_CYVTHUMB);

hInstance = NULL;

if( hWndVertScroll )
DestroyWindow( hWndVertScroll );

hWndVertScroll = CreateWindow(
            "Scrollbar",
            (LPSTR)NULL,
            WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN,
            VTRect->left,VTRect->top,VTRect->right,VTRect->bottom-iVThumb ,
            hCWnd,
            NULL,
            hInstance,
            NULL);
要更正此间隙,我将使用以下命令调用CreateWindow调用:

hWndVertScroll = CreateWindow(
            "Scrollbar",
            (LPSTR)NULL,
            WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_RIGHTALIGN,
            VTRect->left,VTRect->top,VTRect->right - 100 ,VTRect->bottom-iVThumb ,
            hCWnd,
            NULL,
            hInstance,
            NULL);
但是我不明白为什么需要VTRect->right-100将滚动条向上移动到矩形的右侧。请注意,我确实尝试了VTRect->right-iHThumb,但仍然有一个差距,尽管差距较小

红色矩形和滚动条的屏幕截图以及两者之间的间隙:

VTRect->left,VTRect->top,VTRect->right-100,VTRect->bottom

使用这些值传递给CreateWindow()的参数是x、y、nWidth和nHeight。宽度和高度,而不是右侧和底部。修正:

VTRect->left,VTRect->top,VTRect->right-VTRect->left,VTRect->bottom-VTRect->top