简体   繁体   English

win32控件:resource.rc和CreateWindow中的不同坐标?

[英]win32 controls: different coordinates in resource.rc and CreateWindow?

I'm creating a small win32 application. 我正在创建一个小的win32应用程序。 Currently I have 6 text labels coded in the resource file, like this: 目前我在资源文件中编码了6个文本标签,如下所示:

IDD_MAIN DIALOGEX 0, 0, 465, 279
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "SpiderPigOverseer"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    CONTROL         "sample text",IDC_STATIC1,"Static",SS_SIMPLE | WS_GROUP,344,70,33,8
    [...]
END

But I want to access these in a for loop so I thought I would create them dynamically(?) with this code: 但我想在for循环中访问这些,所以我想我会用这段代码动态创建它们(?):

IRValues[i] = CreateWindow("static", "sample text", SS_SIMPLE | WS_VISIBLE | WS_CHILD, 344, 70+10*i, 33, 8, hDlg, NULL, NULL, NULL);

But, this makes the text bigger. 但是,这使文本更大。 The x and y-position are much less then the ones created with resource file and the width and height also seems to differ. x和y位置远小于使用资源文件创建的位置,宽度和高度似乎也不同。 Why is this? 为什么是这样?

EDIT: I tried using the following code to convert, but couldn't get it to match exactly. 编辑:我尝试使用以下代码进行转换,但无法完全匹配。

HDC hdc = GetDC(hWnd);
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
cxAveChar = tm.tmAveCharWidth;
cyAveChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC( hWnd, hdc );

Coordinates in .rc files represented as Dialog units which are not equal to pixels. .rc文件中的坐标表示为不等于像素的对话单位 It is made for automatically adjust controls size depending on system font size. 它用于根据系统字体大小自动调整控件大小。 You can convert dialog units to pixels as follows: 您可以将对话框单位转换为像素,如下所示:

pixelX = MulDiv(templateunitX, LOWORD(GetDialogBaseUnits()), 4);
pixelY = MulDiv(templateunitY, HIWORD(GetDialogBaseUnits()), 8);

Or simply use MapDialogRect() 或者只是使用MapDialogRect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM