gpt4 book ai didi

c - 带控件的 DialogEx : Resizing?

转载 作者:行者123 更新时间:2023-11-30 15:11:24 25 4
gpt4 key购买 nike

目的是调整 DialogEx 窗口的大小,使其最适合目标计算机上配置的 Systemmetrics 屏幕高度和屏幕深度:

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
return DialogBoxW(hInstance, MAKEINTRESOURCEW(IDD_MAIN), nullptr, DlgProc);
}

IDD_MAIN 在 768p 中设置为默认值。我们将其命名为 IDD_760P,并使用其资源文件配置作为工作基础。

IDD_768P DIALOGEX 0, 0, 701, 191
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "MahProject"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
LTEXT "Add",IDC_STATIC,506,10,14,8
EDITTEXT IDC_TEXT,528,7,120,14,ES_AUTOHSCROLL
EDITTEXT IDC_NUMBER,647,7,21,14,ES_NUMBER
LTEXT "times.",IDC_STATIC,671,10,23,8
LISTBOX IDC_LIST,7,22,641,148,LBS_NOINTEGRALHEIGHT | LBS_EXTENDEDSEL | WS_VSCROLL | WS_TABSTOP //principal, main, or chief control on form
PUSHBUTTON "&Add",IDC_ADD,650,30,46,14
PUSHBUTTON "&Up",IDC_UP,650,47,47,14
PUSHBUTTON "&Down",IDC_DOWN,650,63,47,14
PUSHBUTTON "&Sideways",IDC_CREATE,650,80,47,14
PUSHBUTTON "&UpsideDown",IDC_REMOVE,650,97,47,14
PUSHBUTTON "&Less",IDC_CLEAR,650,114,47,14
PUSHBUTTON "&More",IDC_LOGON,650,131,47,14
PUSHBUTTON "&NoMore",IDC_NOLOGON,650,148,47,14
LTEXT "Great",IDC_STATIC_ONE,530,180,70,8
CTEXT "-",IDC_SHOWCOUNT,600,180,25,8
LTEXT "Fantastic",IDC_STATIC_TWO,625,180,30,8
END

这些控件可以根据此 post 使用 CreateWindow 单独重新校准但这是很多代码。
有没有一种方法可以对表单进行子类化,以使用基于上述内容的额外资源文件预设 IDD_1080PIDD_2160P、 IDD_4320P 及以上?我们应该在代码中的什么位置放置 GetSystemMetrics(SM_CXSCREEN)GetSystemMetrics(SM_CYSCREEN) 函数?

最佳答案

您可以在WM_INITDIALOG中调整对话框的大小

GetSystemMetrics(SM_CXSCREEN)/GetSystemMetrics(SM_CYSCREEN) 给出全屏宽度/高度。这将尝试重叠工具栏。您可能不希望这样。

SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcDesktop, NULL); 将获取桌面的矩形,或者您可以只显示最大化窗口

BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
if (msg == WM_INITDIALOG)
{
ShowWindow(hwnd, SW_MAXIMIZE);
return 0;
}
...
return FALSE;
}

您应该将对话框样式更改为以下内容:

样式 DS_SETFONT | DS_FIXEDSYS | DS_中心| WS_MAXIMIZEBOX | WS_POPUP | WS_CLIPCHILDREN | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_SYSMENU | WS_THICKFRAME

请注意,您必须移动/调整所有子控件的大小。移动子控件时,并不是必须先将其在屏幕坐标中的位置,然后转换为父窗口的客户端坐标。

示例

#include <Windows.h>
#include "resource.h"

#define rcwidth(rc) (rc.right - rc.left)
#define rcheight(rc) (rc.bottom - rc.top)

void move_resize(HWND child, int dx, int dy, int dw, int dh)
{
if (!child) return;
if (!IsWindow(child)) return;
if (!GetParent(child)) return;

//find child window's coordinates relative to top-left of parent:

RECT rc;
GetWindowRect(child, &rc);
//rc is now child control's rectangle in screen coordinates

POINT pt = { 0 };
ScreenToClient(GetParent(child), &pt);
OffsetRect(&rc, pt.x, pt.y);
//rc is now child control's rectangle relative to parent window

//prevent negative size
if ((rcwidth(rc) + dw) < 0) dw = -rcwidth(rc);
if ((rcheight(rc) + dh) < 0) dh = -rcheight(rc);

MoveWindow(child, rc.left + dx, rc.top + dy, rcwidth(rc) + dw, rcheight(rc), TRUE);
}

BOOL CALLBACK DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static RECT save_rect;

switch (msg)
{
case WM_INITDIALOG:
GetClientRect(hwnd, &save_rect);
ShowWindow(hwnd, SW_MAXIMIZE);
break;

case WM_SIZE:
if (lParam)
{
int cx = LOWORD(lParam);
int cy = HIWORD(lParam);
int dx = cx - save_rect.right;
int dy = cy - save_rect.bottom;

//change x/y position of OK/Cancel button
move_resize(GetDlgItem(hwnd, IDCANCEL), dx, dy, 0, 0);
move_resize(GetDlgItem(hwnd, IDOK), dx, dy, 0, 0);

//change width/height of listbox:
move_resize(GetDlgItem(hwnd, IDC_LIST1), 0, 0, dx, dy);

GetClientRect(hwnd, &save_rect);
}
break;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
EndDialog(hwnd, wParam);

if (LOWORD(wParam) == IDCANCEL)
EndDialog(hwnd, wParam);
break;

}

return FALSE;
}

int WINAPI wWinMain(HINSTANCE hinst, HINSTANCE, LPTSTR, int)
{
DialogBox(hinst, MAKEINTRESOURCE(IDD_DIALOG1), 0, DlgProc);
return 0;
}

关于c - 带控件的 DialogEx : Resizing?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35669717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com