获取静态控件的矩形坐标 [英] Getting Rectangle coordinates of a static control

查看:228
本文介绍了获取静态控件的矩形坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个基于对话框的应用程序,其中有一个组框/静态"控件.我想用颜色填充该组框/静态"控件.为此,我应该获取``组框/静态''控件的矩形坐标.我已经尝试过使用GetWindowRect().但是我无法获取坐标.我该如何移动?请帮助我.
在此先感谢..

hi all,
i''ve one dialog based application, where in i have one ''group box/static''control. i want to fill that ''group box/static''control with color. to do that, i should get the rectangle coordinates of ''group box/static'' control.i''ve tried with GetWindowRect().but i could not get the coordinates.how can i move with this?please help me.
Thanks in advance..

推荐答案

请参见下面的链接
?如何保存X,Y-文本框在TXT文件中的坐标,高度和宽度?
Please see the below link
?How to save X,Y-Coordinates, Height and Width of Textbox in TXT-File?


可以为对话框的项(如静态控件,组框等)上色,您不需要其矩形坐标.您可以在对话框的OnCtlColor()函数中完成此操作.在那里,您只需要检查控件项ID并分配像这样的文本和背景颜色
to colour the items of your dialog like static control, group box etc you dont need its rectangle coordinates. you can get it done in your OnCtlColor() function of your dialog. There you just need to check the control item id and assign text and background colour like this
if( IDC_GROUP1 == pWnd->GetDlgCtrlID())
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(0,0,255));
}

其中IDC_GROUP1是您的分组框的ID.
但这样一来,您将无法为分组框的框架上色.
为此,创建一个自己的派生自CStatic的类,例如CMyStatic.
那么您需要为Gruop Box项目创建一个控件成员变量.其类类型应为CMyStatic.
并且在CMyStatic OnPaint()中,您需要做所有事情来使用FrameRect()调用来绘制组框框架.
另外,您还需要编写代码以绘制组框文本.可以相应地修改以下代码以获取所需的内容.

where IDC_GROUP1 is the id of your group box.
but in this way you will not be able to colour the frame of your group box.
for this create a your own class derived from CStatic, say CMyStatic.
then you need to create a control member variable of your gruop box item. its class type should be CMyStatic.
and within CMyStatic OnPaint() you need to do all things to draw a group box frame using FrameRect() call.
also you need to write the code to draw group box text.you can modify the below code accordingly to get what you need.

void CMyStatic::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	CRect WndRect;
	CBrush GreenBrush;
	GreenBrush.CreateSolidBrush(RGB(0,255,0));
	dc.GetWindow()->GetClientRect( WndRect );
	dc.FrameRect( WndRect, &GreenBrush );
	dc.SetTextColor(RGB(0,255,0));
	dc.SetBkColor(RGB(255,0,0));
	dc.TextOut(WndRect.left + 5,WndRect.top - 10,"Title" );
	// Do not call CStatic::OnPaint() for painting messages
}


这篇关于获取静态控件的矩形坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆