我有一个基于 MFC dilog 的应用程序。我想将对话框的大小更改为设计单位的大小。我尝试将其转换为像素,但似乎不起作用。设计单位和像素之间的比例在调整大小后会发生变化 - 请参阅代码中的注释。 这段代码我在
OnInitDialog()
RECT rect;
GetWindowRect(&rect); //Window in dialog units has 300x200,, 466x364 in pixels
//I want to resize window to 200x100 in dialog units
RECT transRect{ 0,0,200,100 };
MapDialogRect(&transRect);
SetWindowPos(0, 0, 0, transRect.right, transRect.bottom, SWP_NOMOVE | SWP_NOZORDER);
GetWindowRect(&rect); //here we are checking the size of window - it is not in accordance with my idea - the scale of previous and current sizes is not rigth
// it is - 300 x 163 in pixels, but I expect 310 x 182
您可以尝试使用 MoveWindow 函数来代替
MoveWindow(0, 0, transRect.right, transRect.bottom, TRUE) instead