Jump to content

  • Log In with Google      Sign In   
  • Create Account

MFC again.....


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 illuna   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 January 2000 - 02:18 AM

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

Sponsor:

#2 felisandria   Members   -  Reputation: 739

Like
Likes
Like

Posted 06 January 2000 - 03:34 AM

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

#3 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 January 2000 - 06:31 AM

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

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 January 2000 - 06:32 AM

Never mind. Just the way it shows up here.

Kyle

#5 deadlinegrunt   Members   -  Reputation: 123

Like
Likes
Like

Posted 08 January 2000 - 04:37 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS