单击按钮时,静态控件周围的边框会切换 [英] Border around static control toggle while click button

查看:58
本文介绍了单击按钮时,静态控件周围的边框会切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我是MFC编程的新手,或者可能是我无法通过Internet找到正确的答案,但我的运气不好,我的搜索错误.
问题:我需要在mfc对话框上显示的任何控件周围绘制一个红色边框,它可以是combobox或spin控件或其他任何控件.所以我想创建一个从CStatic类派生的新类,并实现它的OnNcPaint消息以在其周围绘制边框.

Hi guys
I am new to MFC programming or may be i cannot find the right answer over internet my bad luck my bad search.
Question: I need to draw a red border around any control displayed on mfc dialog it can be either combobox or spin control or anything else. so what i thought to create a new class derived from CStatic class and implements it OnNcPaint message for drawing border around it.

void CMystatic::OnNcPaint()
{
	if(m_bDrawBorder)
	{
		CDC* pDC = GetWindowDC( );
		//work out the coordinates of the window rectangle,
		CRect rect;
		GetWindowRect( &rect);
		rect.OffsetRect( -rect.left, -rect.top);
		
		//Draw a single line around the outside
		CBrush brush( RGB( 255, 0, 0));
		pDC->FrameRect( &rect, &brush);
		ReleaseDC( pDC);	
			
	}
	else
	{
		CStatic::OnNcPaint();
	}
}



CMyStatic派生自CStatic类,而m_DrawBorder是此类的用于绘制边框的成员变量.可以通过使用CMyStatic类对象的任何类进行设置.例如,在单击button1时,我设置为绘制边框,而在单击button2时,我再次重置为静态控件的原始行为.
问题
1.如果静态文本控件属性 BORDER 为true,则我运行该应用程序.然后,我看到一些边框,类似于Z中的某些帧,看起来像是3d或我不需要的一些深度顺序边框.另一方面,我只需要一些二维边框,就像它在执行border属性TRUE时显示的那样,并且在设计时而不是在运行时查看控件.

2.我不希望Z阶深度,我只需要2D边框,任何伙伴都可以帮助我,并在此处发布代码.我已经实现了其他方法,但没有完全帮助.下面的代码没有帮助.



CMyStatic is derived from CStatic class and m_DrawBorder is a member variable of this class for drawing border. which can set through any class which uses CMyStatic class object.For example while clicking button1 i am setting to draw border and while clicking button2 i am again resetting to original behavior of static control.
Issues
1. If a static text control property BORDER is true the i run the application.Then i see some border which is like some frame in Z order it looks like some 3d or some depth order border which i do not need. On the other hand i require some 2-d border only like it shows when you do border property TRUE and look at the control at design time not at run time.

2. i don''t want Z-order depth i just need 2-D border any buddy can help me and post code here. i have implemented other ways to but not help full.The code below is not helpful.

m_Mystatic.ModifyStyleEx(dwStyle,0,SWP_NOSIZE|SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(dwStyle,0,SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(0,WS_EX_CLIENTEDGE,SWP_FRAMECHANGED);
m_Mystatic.ModifyStyleEx(0,WS_EX_CLIENTEDGE,SWP_FRAMECHANGED);



注意:我只需要在边框和无边框之间切换,而无需其他凹陷或其他Z顺序边框,只需纯静态文本即可

(我不知道如何添加图像,否则我可以上传它.)

Plzzzzzzzzzzzzzzzzzz Reply



NOTE: i just need to toggle between border and no border but no other sunken or other Z order border just plain static text

(i don''t know how to add image otherwise i could upload it.)

Plzzzzzzzzzzzzzzzz reply

推荐答案

一个无边无际的子窗口可以用自己的颜色绘制背景
并将焦点通知给父窗口(由|WS_CLIPCHILDREN设置样式),
父母可以检查专注的孩子,然后画一个红色的矩形
进入孩子的充气区域...

...当然,最后标记的区域必须由父级累加,
也将在焦点消失通知时失效:)
A bordeless child window could paint its background by its own color
and notify the parent window (styled by |WS_CLIPCHILDREN) about the focus,
whereby the parent could check the focused child and just paint a red rectangle
into the inflated area of the child...

...of course the last marked area must be accumulated by parent,
to be invalidated at the gone-focus notification as well :)


这篇关于单击按钮时,静态控件周围的边框会切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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