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