Members - Reputation: 122
Posted 06 January 2000 - 02:18 AM
Members - Reputation: 739
Posted 06 January 2000 - 03:34 AM
Have you tried explicitly casting your "this" pointer?
Also, where are you doing a Create? Try putting an Invalidate(); right after it and see what happens.
Posted 06 January 2000 - 06:31 AM
test.Create("Test button",WS_CHILD/BS_PUSHBUTTON/WS_VISIBLE, CRect(10,10,50,20), this, 1);
Are those ''/'' or ''/'' between your window and button styles?
Should be ''/''
Posted 06 January 2000 - 06:32 AM
Members - Reputation: 123
Posted 08 January 2000 - 04:37 AM
Original post by illuna
Thanks to the one who answer my last post but the problem is not there. Here are exacly the problematic lines:
test.Create("Test button", WS_CHILD/BS_PUSHBUTTON/WS_VISIBLE, CRect(10,10,50,20), this, 1);
Where "this" is my main window created before. Those lines display nothing in the window (but it should display a button right?)
Can you help?
Edited by - illuna on 1/6/00 8:46:03 AM
SHORT ANSWER: WHAT
Your problem is in your this pointer or CButton is a local instance in a short lived function.
EXTENED VERSION: HUH?
Say you mapped (CButton)test to instantiate on a paticular event. In order to do this you need to make sure of a couple of things:
1. Make sure CButton isn''t an instance created locally in a function. Otherwise your are losing it when you leave scope of the function.
2. Make sure that you are getting the correct parent window you want the control to be owned by.
Here''s in example:
Declare CButton test as a data member of your Main window class.
class CMainTestWnd : public CWnd
CButton test; // You want to instantiate here maybe?
bool bRetVal = false;
// This will make the CMainTestWnd main window
// client area the owner of your dynamic button
test.Create( "Test Button", WS_CHILD/BS_PUSHBUTTON/WS_VISIBLE, CRect( 10, 10, 100, 20 ), this->GetTopWindow()->GetParentWindow(), 1 );
bRetVal = true;
catch( ... )
bRetVal = false;
On whatever event you want to create it, for example OnOK() event, create it then and be sure you get the correct parent owner like this:
if( !CreateTempButton() )
// error stuff here
// Otherwise your good to go
// yada yada yada here...
(Hmm, I don''t know how this will look on this message board, anwyays)
So basically it''s like this:
You are creating your CButton as a local instance and it loses scope before you can see it
You are passing the this pointer without making sure it''s the CWnd* you want passed to actually own the new button control.
Hope this helps, not confuses...