如何将CButton控件置于最前面[解决] [英] How to bring CButton contorl to front [solved]

查看:133
本文介绍了如何将CButton控件置于最前面[解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


非常感谢Alain Rist.问题已经解决了!!! ;)




专为Pallini

我想您是如何成为金牌会员的...只是发布了一些内容...如果您如此聪明,请不要告诉我隐藏该按钮,但请向我解释一下为什么单击背景中的按钮而不是单击按钮在前台!


我的问题似乎很愚蠢,但是...


    RECT rc;
...
    rc.right = 50;
    rc.bottom = 50;
    mpButton1 = new CButton;
    mpButton1->Create( strCaption1, WS_VISIBLE | WS_CHILD | WS_TABSTOP, rc, this, 1003 );

    rc.right = 100;
    rc.bottom = 100;

    mpButton2 = new CButton;
    mpButton2->Create( strCaption2, WS_VISIBLE | WS_CHILD | WS_TABSTOP, rc, this, 1004 );
    ::SetWindowPos( mpButton1->GetSafeHwnd(), HWND_TOP,0, 0, 100, 100, SWP_NOMOVE | SWP_NOSIZE );
...


我希望单击RECT(0,0,50,50)不会按mpButton1.但是被按下了.
有人可以解释一下为什么单击RECT(0,0,50,50)按下mpButton1吗?
以及如何将mpButton2置于最前面,因此当另一个按钮在其上方时,mpButton1将不会处于活动状态.
而且,请不要告诉我其他解决问题的方法,例如(将其禁用或使其不可见...等)

预先谢谢你

P.S. (在约翰·西蒙斯回答之后)
1.没有对话框.
2.在CWnd中动态创建按钮
3.可见性没有问题.我想两个按钮都可见.

致阿兰·里斯特.问题不在RECT中.我没有包含用于为rc.left和rc.top分配值的代码,但是请确保变量rc在应用程序中获取正确的值:)第二个按钮是较大的按钮,它覆盖第一个按钮,但是如果单击在小按钮区域上,单击小按钮.我试图将第一个按钮放置在HWND_BOTTOM上,将第二个按钮放置在HWND_TOP ...上.没有任何帮助! :)

解决方案

正确的方法是枚举对话框的子控件,找到最高的Tab键顺序,然后设置新按钮制表符顺序到找到的最高制表符顺序+1.

但是,您的问题是可见性.隐藏您不想被激活的按钮,并显示您想要被激活的按钮. (隐藏表示该按钮已禁用.)


bartello写道:

我没有包括用于为rc.left和rc.top分配值的代码,但是请确保变量rc在应用程序中获取正确的值

[在OP中回答后编辑]
是的,您的问题可能出在未发布的代码中.
如果您仅将发布的代码及其更改保留在WM_CREATE处理程序中,则它将按您的意愿工作.至少在我的系统上;).


RECT rc;更改为RECT rc = {0};
SetWindowPos()调用中的HWND_TOPHWND_BOTTOM,如果我理解的话,它应该可以根据需要工作:)
欢呼声,
AR


bartello写道:

请不要告诉我其他解决方法诸如(将其禁用或使其不可见...等)之类的问题



是的,我告诉您隐藏不需要的"按钮.
:)



Many thanks to Alain Rist. the problem is solved!!! ;)




Specially for Pallini

I guess how you became a gold member... just posting something... if you r so clever, please, don''t tell me to hide the button, but explain me WHY the button in the background is clicked instead of the button in foreground!


My question may seem to be very stupid, but...


    RECT rc;
...
    rc.right = 50;
    rc.bottom = 50;
    mpButton1 = new CButton;
    mpButton1->Create( strCaption1, WS_VISIBLE | WS_CHILD | WS_TABSTOP, rc, this, 1003 );

    rc.right = 100;
    rc.bottom = 100;

    mpButton2 = new CButton;
    mpButton2->Create( strCaption2, WS_VISIBLE | WS_CHILD | WS_TABSTOP, rc, this, 1004 );
    ::SetWindowPos( mpButton1->GetSafeHwnd(), HWND_TOP,0, 0, 100, 100, SWP_NOMOVE | SWP_NOSIZE );
...


I expect that clicking on RECT(0,0,50,50) will not press mpButton1. But it is pressed.
Can somebody explain me why the click on RECT(0,0,50,50) presses mpButton1?
And how can I bring mpButton2 to front, so the mpButton1 will not be active while the other button is over it.
And, please, don''t tell me other ways of solving the problem such as (make it disable, or make it invisible... etc)

Thank you in advance

P.S. (after John Simmons''s answer)
1. There is no dialog box.
2. Buttons are dynamically created in CWnd
3. There is no problem with visibility. I DO WANT that buttons both are visible.

To Alain Rist. The problem not in RECT. I didn''t include the code for assigning a values to rc.left and rc.top, but be sure, variable rc gets proper values in the application :) Second button is bigger button, that COVERS the first one, but if click is on the area of SMALL button the small button is clicked. I tried to place the first button to HWND_BOTTOM, and the second one to HWND_TOP.... nothing helps! :)

解决方案

The proper way to do it is to enumerate the child controls of the dialog box, find the highest tab order, and set the new button''s tab order to the highest tab order you found + 1.

However, your problem is that of visibility. Hide the button you don''t want to be active, and Show the button that you *do* want to be active. (Hiding implies that the button is disabled.)


bartello wrote:

I didn''t include the code for assigning a values to rc.left and rc.top, but be sure, variable rc gets proper values in the application



[EDIT after answer in OP]
Yes your problem is probably in not posted code.
If you keep only your posted code with my changes in your WM_CREATE handler it works as you want. On my system at least ;) .
[EDIT end]

Change RECT rc; to RECT rc = {0};
and HWND_TOP to HWND_BOTTOM in your SetWindowPos() call and it should work as you want, if I understood it :)
cheers,
AR


bartello wrote:

And, please, don''t tell me other ways of solving the problem such as (make it disable, or make it invisible... etc)



And yes, I tell you to hide the ''unwanted'' button.
:)


这篇关于如何将CButton控件置于最前面[解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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