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. Create CEdit dynamicly

Create CEdit dynamicly

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 5 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
    dzenan
    wrote on last edited by
    #1

    hi How do i create CEedit cotrol dynamicly, withour resoruce editor, i have crated a class subclass of CWnd how do i add a CEdit and CStatic (label) control to it, where do i create it in OnCreate function ???? thanks ~dzenan~

    C I 2 Replies Last reply
    0
    • D dzenan

      hi How do i create CEedit cotrol dynamicly, withour resoruce editor, i have crated a class subclass of CWnd how do i add a CEdit and CStatic (label) control to it, where do i create it in OnCreate function ???? thanks ~dzenan~

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      Your question is not very clear: you have derived a class from CEdit and you want to create dynamically on your window? If so, just call Create: CMyEdit NewEdit; NewEdit.Create(...); Hope this helps

      D 1 Reply Last reply
      0
      • C Cedric Moonen

        Your question is not very clear: you have derived a class from CEdit and you want to create dynamically on your window? If so, just call Create: CMyEdit NewEdit; NewEdit.Create(...); Hope this helps

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

        sorry for not clearing it up,, I have a Class wich is derived from CWnd, now i want to put a Edit control on that window. how do i do that, or do i have to first create a class wich is derived from CEdit thanks ~dzenan~

        C C 2 Replies Last reply
        0
        • D dzenan

          sorry for not clearing it up,, I have a Class wich is derived from CWnd, now i want to put a Edit control on that window. how do i do that, or do i have to first create a class wich is derived from CEdit thanks ~dzenan~

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          No sorry, I misunderstood your question, it's end of the day here X| ! So, that's a good question. I had the same kind of problem some time ago. I solve this by sending a user defined message to the window just after it was created: CYourWnd Window; ... Some code; Window.ShowWindow(SW_SHOW); Window.SendMessage(WM_MYUPDATE); Then you have to add manually a handler for this message. In this function, create dynamically the objects. Don't know if there is an easiest way :confused: ??

          D N 2 Replies Last reply
          0
          • C Cedric Moonen

            No sorry, I misunderstood your question, it's end of the day here X| ! So, that's a good question. I had the same kind of problem some time ago. I solve this by sending a user defined message to the window just after it was created: CYourWnd Window; ... Some code; Window.ShowWindow(SW_SHOW); Window.SendMessage(WM_MYUPDATE); Then you have to add manually a handler for this message. In this function, create dynamically the objects. Don't know if there is an easiest way :confused: ??

            D Offline
            D Offline
            dzenan
            wrote on last edited by
            #5

            I see, will work on it thanks ~dzenan~

            1 Reply Last reply
            0
            • D dzenan

              hi How do i create CEedit cotrol dynamicly, withour resoruce editor, i have crated a class subclass of CWnd how do i add a CEdit and CStatic (label) control to it, where do i create it in OnCreate function ???? thanks ~dzenan~

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              Here goes... In your header:

              class CMyWnd : public CWnd
              {
              ...

              protected:
              CStatic m_StaticSubWnd;
              CEdit m_EditSubWnd;
              ....

              };

              In your implementation:

              int CMyWnd::OnCreate (LPCREATESTRUCT lpC )
              {
              m_StaticSubWnd.Create ("text here", WS_CHILD | WS_VISIBLE | SS_..., // styles here, inc static styles
              CRect (0,0, lpC->cx, 24), this, 1);
              m_EditSubWnd.Create ( WS_CHILD | WS_VISIBLE | ES_..., // styles here, inc edit styles
              CRect (0,26, lpC->cx, lpC->cy - 26), this, 2);

              return CWnd::OnCreate (lpCreateStruct); // Not that it's much needed, but its good practice.
              

              }

              The coordinates are just examples. You can give them any coords you like. You should handle WM_SIZE / OnSize and change the position / size of the subwindows when the size of CMyWnd changes. OK? Iain.

              D 1 Reply Last reply
              0
              • I Iain Clarke Warrior Programmer

                Here goes... In your header:

                class CMyWnd : public CWnd
                {
                ...

                protected:
                CStatic m_StaticSubWnd;
                CEdit m_EditSubWnd;
                ....

                };

                In your implementation:

                int CMyWnd::OnCreate (LPCREATESTRUCT lpC )
                {
                m_StaticSubWnd.Create ("text here", WS_CHILD | WS_VISIBLE | SS_..., // styles here, inc static styles
                CRect (0,0, lpC->cx, 24), this, 1);
                m_EditSubWnd.Create ( WS_CHILD | WS_VISIBLE | ES_..., // styles here, inc edit styles
                CRect (0,26, lpC->cx, lpC->cy - 26), this, 2);

                return CWnd::OnCreate (lpCreateStruct); // Not that it's much needed, but its good practice.
                

                }

                The coordinates are just examples. You can give them any coords you like. You should handle WM_SIZE / OnSize and change the position / size of the subwindows when the size of CMyWnd changes. OK? Iain.

                D Offline
                D Offline
                dzenan
                wrote on last edited by
                #7

                It's working thanks :) ~dzenan~

                1 Reply Last reply
                0
                • C Cedric Moonen

                  No sorry, I misunderstood your question, it's end of the day here X| ! So, that's a good question. I had the same kind of problem some time ago. I solve this by sending a user defined message to the window just after it was created: CYourWnd Window; ... Some code; Window.ShowWindow(SW_SHOW); Window.SendMessage(WM_MYUPDATE); Then you have to add manually a handler for this message. In this function, create dynamically the objects. Don't know if there is an easiest way :confused: ??

                  N Offline
                  N Offline
                  Navin
                  wrote on last edited by
                  #8

                  Yeah, why not just override the Create function from the CWnd class and put it there? [EDIT: Whoops, Iain Clarke mentioned that very solution below. :-O] "When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein

                  1 Reply Last reply
                  0
                  • D dzenan

                    sorry for not clearing it up,, I have a Class wich is derived from CWnd, now i want to put a Edit control on that window. how do i do that, or do i have to first create a class wich is derived from CEdit thanks ~dzenan~

                    C Offline
                    C Offline
                    Cyberizen
                    wrote on last edited by
                    #9

                    hmm well you dont need to create a class derived from CEdit. Just Create a CEdit object in the OnCreate Event check out the code below void MainFrame ::OnCreate(LPCREATESTRUCT lpcs) { CRect rect; rect.SetRect(10,10,100,30); CEdit *myeditbox = new CEdit; CEdit *myedit = new CEdit; myedit->Create(WS_CHILD|WS_VISIBLE,rect,this,300); } regards Ahmed Ajmal

                    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