🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

MFC again.....

Started by
3 comments, last by illuna 24 years, 5 months ago
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
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
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~
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
Never mind. Just the way it shows up here.

Kyle
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...

~deadlinegrunt

This topic is closed to new replies.

Advertisement