Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC small help please

MFC small help please

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dan60606
    wrote on last edited by
    #1

    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.

    _ 1 Reply Last reply
    0
    • D dan60606

      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.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      In the first code snippet, the CStatic object is created on the heap and will remain in memory till delete is called on the object. In the second code snippet, the CStatic object is created on the stack and will go out of scope (will be destroyed) as soon as OnCreate exits.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++) (October 2009 - September 2013)

      Polymorphism in C

      D 1 Reply Last reply
      0
      • _ _Superman_

        In the first code snippet, the CStatic object is created on the heap and will remain in memory till delete is called on the object. In the second code snippet, the CStatic object is created on the stack and will go out of scope (will be destroyed) as soon as OnCreate exits.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        D Offline
        D Offline
        dan60606
        wrote on last edited by
        #3

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

        _ 1 Reply Last reply
        0
        • D dan60606

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

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #4

          Have you tried to set

          CStatic lblPresent

          as member variable ? Something like

          CStatic m_lblPresent

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups