MFC small help please
-
Quote:
This code work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;CStatic * lblPresent = new CStatic();
lblPresent->Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);return 0;
}This code dont work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;CStatic lblPresent;
lblPresent.Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);return 0;
}Please help i dont understand. Thank.
-
Quote:
This code work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;CStatic * lblPresent = new CStatic();
lblPresent->Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);return 0;
}This code dont work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;CStatic lblPresent;
lblPresent.Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);return 0;
}Please help i dont understand. Thank.
In the first code snippet, the
CStatic
object is created on the heap and will remain in memory tilldelete
is called on the object. In the second code snippet, theCStatic
object is created on the stack and will go out of scope (will be destroyed) as soon asOnCreate
exits.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
In the first code snippet, the
CStatic
object is created on the heap and will remain in memory tilldelete
is called on the object. In the second code snippet, theCStatic
object is created on the stack and will go out of scope (will be destroyed) as soon asOnCreate
exits.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
yea thank and if i make
private:
CStatic mpStatic;like private member variable End block in OnCreate not destroyed CStatic object and dont work. If use pointer all OK. OMG it is work and before 1 hour not =( sorry fkn bug. Thank you for help. =)