如何使用像素布局GUI

时间:2014-06-10 14:54:37

标签: visual-studio user-interface editor labwindows

我不确定如何布局GUI,例如按钮,编辑框,文本等,当以像素为单位进行测量时。

与微软的GUI指南一样,所有细节都以像素的距离给出。当使用除Microsoft编辑器之外的其他编辑器时,如何将其转换为实际距离?

由于

2 个答案:

答案 0 :(得分:1)

对话框窗口中所有元素的尺寸及其位置都以对话框单位(DLU)定义,而不是以像素为单位,请参阅About Dialog Boxes

因此,对话框的大小不是固定大小。大小取决于对话框的字体集。在* .rc文件中,您可以在关键字 BEGIN 的行上方看到对话框的字体。

另请参阅How to calculate dialog box units based on the current font in Visual C++Correlation between DPI and dialog units

因此,如果您没有使用资源编辑器而不是文本编辑器直接在* .rc文件中编辑对话框资源,那么肯定存在问题。我只能建议不要这样做。

答案 1 :(得分:0)

对于LabWindows / CVI:

编辑 以更正功能名称:

在LabWindows / CVI开发环境中,您可以使用一系列功能(也可通过功能面板访问),这些功能提供面板和控件的状态和控制(诸如位置/尺寸/颜色......等等。 )称为用户界面库GetCtrlAttribute()SetCtrlAttribute()GetPanelAttribute()SetPanelAttribute()等功能。其中每个都使用预定义参数的枚举列表来访问您要控制的许多属性中的哪一个。

例如 ,要设置显示器上显示的面板的大小和位置,您可以使用以下内容:

SetPanelAttribute(panelHandle, ATTR_HEIGHT, height);//where height is in pixels, 0 to 32767  

SetPanelAttribute(panelHandle, ATTR_WIDTH, width);//where width is in pixels, 0 to 32767  

SetPanelAttribute(panelHandle, ATTR_TOP, top);//in pixels, 0 to 32767
//The vertical offset (in pixels) of the panel   
//relative to the origin of the screen   
//(for top-level windows) or the parent panel (for child panels).
//The screen origin is the upper-left corner of the screen.  
//The origin of a parent panel is the upper-left corner of   
//the panel below the title bar and to the right of the panel frame.  

SetPanelAttribute(panelHandle, ATTR_LEFT, left);//in pixels, 0 to 32767
//The horizontal offset (in pixels) of the panel relative to 
//the origin of the screen (for top-level windows) or the 
//parent panel (for child panels).
//The screen origin (0,0) is the upper-left corner of the screen.
//The origin of a parent panel is the upper-left corner of the 
//panel below the title bar and to the right of the panel frame.  

可以使用这四个功能设置或检索更多属性(属性),例如背景颜色,面板/控件是否处于活动状态,或者是灰色,框架颜色等。

如前所述,控件(Get/Set)CtrlAttribute()的同一系列中有一组类似的函数可以控制所有控件属性。