Dymanic windows
-
I would like to know how create child windows at runtime and get them all displyed Yes I've used:
- a pointer for the control
- the new operator for the window type
- CWnd::Create method
- CWnd::ShowWindow method
- CWnd::MoveWindow method
All I'm getting is a blank dialog box. I can't understand why. What do I have to do display them?
Please show us a little bit of your source code...
-
I would like to know how create child windows at runtime and get them all displyed Yes I've used:
- a pointer for the control
- the new operator for the window type
- CWnd::Create method
- CWnd::ShowWindow method
- CWnd::MoveWindow method
All I'm getting is a blank dialog box. I can't understand why. What do I have to do display them?
Most of the time, creating controls at runtime is not necessary. Can you explain a bit more of what you are doing?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
I would like to know how create child windows at runtime and get them all displyed Yes I've used:
- a pointer for the control
- the new operator for the window type
- CWnd::Create method
- CWnd::ShowWindow method
- CWnd::MoveWindow method
All I'm getting is a blank dialog box. I can't understand why. What do I have to do display them?
-
Please show us a little bit of your source code...
This is a snippets of my code in the dialog header file
class CMyDialouge : public CDialog{ public CEdit *m_EditWnd; CRect m_WndRect; };
The dialog's constructorCMyDialouge::CMyDialouge(CWnd* pParent /*=NULL*/) : CDialog(CMyDialogue::IDD, pParent) { m_EditWnd = NULL; m_Rect = CRect(23,30,54,14); }
Create 5 versions of the edit controlBOOL CMyDialouge::OnInitDialog() { // TODO: Add extra initialization here this->m_EditWnd = new CEdit[5]; for(int i = 0; i < 5; i++) { m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); m_EditWnd[i].MoveWindow(m_Rect); m_EditWnd[i].ShowWindow(SW_SHOW); m_Rect.top += 30; } return TRUE; // return TRUE unless you set the focus to a control }
void CMyDialouge::OnDestroy { for (int i=0; i <5; i++) m_EditWnd[i].DestroyWindow(); CDialog::OnDestroy(); // TODO: Add your message handler code here delete[] m_EditWnd; }
I hope I've clarified it. Thanks Alton -
Most of the time, creating controls at runtime is not necessary. Can you explain a bit more of what you are doing?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
I just wanted to play around with dynamic controls I've given code snippets in the reply before yours. Thanks Alton
-
This is a snippets of my code in the dialog header file
class CMyDialouge : public CDialog{ public CEdit *m_EditWnd; CRect m_WndRect; };
The dialog's constructorCMyDialouge::CMyDialouge(CWnd* pParent /*=NULL*/) : CDialog(CMyDialogue::IDD, pParent) { m_EditWnd = NULL; m_Rect = CRect(23,30,54,14); }
Create 5 versions of the edit controlBOOL CMyDialouge::OnInitDialog() { // TODO: Add extra initialization here this->m_EditWnd = new CEdit[5]; for(int i = 0; i < 5; i++) { m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); m_EditWnd[i].MoveWindow(m_Rect); m_EditWnd[i].ShowWindow(SW_SHOW); m_Rect.top += 30; } return TRUE; // return TRUE unless you set the focus to a control }
void CMyDialouge::OnDestroy { for (int i=0; i <5; i++) m_EditWnd[i].DestroyWindow(); CDialog::OnDestroy(); // TODO: Add your message handler code here delete[] m_EditWnd; }
I hope I've clarified it. Thanks AltonIn CMyDialouge::OnInitDialog() you wrote m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); m_EditWnd[i].MoveWindow(m You used m_EditBox AND m_EditWnd, may it be that this is your mistake? Jens
-
Yes, I understand!! I'm trying to create a MenuBar at runtime but all itens in the menu is GRAYED (disabled) when created!!! I don't know why?!?!? Maybe some help in your doubt helps in mine!!! :) Thanks Marcos Vinícius
If your using MFC one of the more common mistakes is that there is no command handler yet. In that case MFC grayes all the unavailable menu commands. Jens
-
In CMyDialouge::OnInitDialog() you wrote m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); m_EditWnd[i].MoveWindow(m You used m_EditBox AND m_EditWnd, may it be that this is your mistake? Jens
Jens Doose wrote: m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); Correct to (compiler will complain): m_EditWnd[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i);
-
Jens Doose wrote: m_EditBox[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i); Correct to (compiler will complain): m_EditWnd[i].Create(WS_CHILD|ES_MULTILINE| WS_VISIBLE|ES_WANTRETURN,CRect(0,0,0,0),this,1000 + i);
You used CRect(23,30,54,14); as the location to move the window to. This statement create a rect with the following settings:
- m_Rect {top=30 bottom=14 left=23 right=54}
- tagRECT {top=30 bottom=14 left=23 right=54}
left 23
top 30
right 54
bottom 14
Since "bottom" is less than "top" this is a rect with a negativ height. I am pretty sure that was not your intention, was it? ;-) Jens
- tagRECT {top=30 bottom=14 left=23 right=54}
-
If your using MFC one of the more common mistakes is that there is no command handler yet. In that case MFC grayes all the unavailable menu commands. Jens
But, why is it unavailable? I can't just put a Message_Map in my class that handle the App MenuBar and that will enable the MenuItens? Take a look in my last thread posted: Menu at runtime (dynamic menu) Thanks. Marcos Vinícius