Click here to Skip to main content
16,022,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
CButton* btnApply = new CButton;
CRect recto;
GetClientRect(&recto);
ScreenToClient(&recto);
btnApply->Create((LPCTSTR)"Apply", WS_CHILD | WS_VISIBLE, recto,this, 1234);
btnApply->ShowWindow(SW_SHOW);


The button control is not displayed. What is the problem in the above code?
Posted
Updated 26-Jan-11 12:06pm
v4
Comments
Manfred Rudolf Bihy 26-Jan-11 17:57pm    
[Moved "answer" to comment:]
It does not look as C++/CLI. It is not. This is all regular C++ and native unmanaged code (or a fragment in mixed-mode project). Please change the tag or provide C++/CLI code.

1 solution

You should not call ScreenToClient there. The rect you pass is in the coordinates relating to the parent window. And you've already called GetClientRect on the parent window. Of course this will basically create a button that fills your entire parent window (but perhaps that is what you want?)
 
Share this answer
 
Comments
Sangeetha682002 26-Jan-11 18:18pm    
Thanks. I am just starting my first MFC Application (UI Part). My ultimate aim : "How to position the controls in dialog box at runtime? (My controls will be created runtime and the number of controls vary everytime)."
Nish Nishant 26-Jan-11 18:19pm    
Yeah, then use a rect relative to the top, left of the parent window.
Nish Nishant 26-Jan-11 18:21pm    
Something like CRect(10, 10, 50, 30) should work well.
Sangeetha682002 27-Jan-11 13:12pm    
Thanks.Finally i undertsood this.
Nish Nishant 27-Jan-11 13:21pm    
You're welcome.

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