• Advertisement

Archived

This topic is now archived and is closed to further replies.

MFC again.....

This topic is 6587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Thanks to the one who answer my last post but the problem is not there. Here are exacly the problematic lines: CButton test; 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? Illuna* Edited by - illuna on 1/6/00 8:46:03 AM

Share this post


Link to post
Share on other sites
Advertisement
First off, doing straight MFC is painful and should be avoided unless you absolutely cannot use the resource editor.

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.

-fel

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
CButton test;
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 ''/''

Kyle

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Never mind. Just the way it shows up here.

Kyle

Share this post


Link to post
Share on other sites
quote:
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:

CButton test;
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?
Illuna*

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?
For example:
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.

i.e:
class CMainTestWnd : public CWnd
{
public:
CButton test; // You want to instantiate here maybe?
bool CreateTempButton();
...
};

bool CMainTestWnd::CreateTempButton()
{
bool bRetVal = false;
try
{
// 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;
}
return bRetVal;
}

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:

void CMainTestWnd::OnOK()
{
if( !CreateTempButton() )
{
// error stuff here
}
// Otherwise your good to go
// yada yada yada here...
return;
}

(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
OR
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...

Share this post


Link to post
Share on other sites

  • Advertisement