Click here to Skip to main content
15,890,374 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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! :)
Posted
Updated 30-Jan-10 23:00pm
v7

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.)
 
Share this answer
 
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
 
Share this answer
 
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.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900