How can I programmatically add controls.
-
Hi, well, it's for sure a simple problem for an advanced MFC user, but I don't know how to solve it X| Here's what i want to do: I want to create a MFC controls dynamically to my MFC dialog without the use of the resource editor. E.g. a simple static text at the coordinates 0,0 with text on it? The reason I'm asking is that I have to add 120 leds/labels to a dialog and I don't want to make it by hand, because if something changes, I have to redo everything, Or if I want to add tabs later. Thanks for your help.
-
Hi, well, it's for sure a simple problem for an advanced MFC user, but I don't know how to solve it X| Here's what i want to do: I want to create a MFC controls dynamically to my MFC dialog without the use of the resource editor. E.g. a simple static text at the coordinates 0,0 with text on it? The reason I'm asking is that I have to add 120 leds/labels to a dialog and I don't want to make it by hand, because if something changes, I have to redo everything, Or if I want to add tabs later. Thanks for your help.
-
Hi, This is simple window - you can add the new e.g. by CStatic class (derivied from CWnd): CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );
----------- Mila
Mila025 wrote:
M
Mila025 wrote:
CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );
don't forget to delete the MyStatic object
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
Mila025 wrote:
M
Mila025 wrote:
CStatic * myStatic = new CStatic; myStatic->Create( _T("my static"), WS_CHILD|WS_VISIBLE|SS_CENTER, CRect(0,0,150,15), pParentWnd );
don't forget to delete the MyStatic object
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you
-
Thanks for you help :) Now to the next problem :~ I'm using the following controler: http://www.codeproject.com/buttonctrl/LedButton.asp[^] It's an LED button, which interhits from CButton. I can actually create a CButton dynamically, but it doesn't work with this CLedButton class. If anyone has five free minutes, it would you could say why it doesn't work this this control :confused:
-
Thanks for you help :) Now to the next problem :~ I'm using the following controler: http://www.codeproject.com/buttonctrl/LedButton.asp[^] It's an LED button, which interhits from CButton. I can actually create a CButton dynamically, but it doesn't work with this CLedButton class. If anyone has five free minutes, it would you could say why it doesn't work this this control :confused:
Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;
----------- Mila
-
Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;
----------- Mila
Mila025 wrote:
Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;
Yes, thanks. I found it out on my own at the same time and wanted to post it here, but you were faster :) The BS_AUTOCHECKBOX flag needs to be set, otherwise the class asserts. Damn, I have the feeling that asserts are really bad implemented. I'm using my non-mfc application an custom assert, which brings me directly to the line, where the assert happend and not somewhere deep in the MFC, where I have to search the huge call stack for the place, where the real assert happend. Anyway, thanks for you help :)
-
Hi, hm do you mean something like that: CLedButton * led = new CLedButton; led->Create( "an strange text", WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, CRect( 2, 2, 120, 20 ), this, iCtrlId ); led->SetIcons(IDI_GRAY_LED_ICON, IDI_GREEN_LED_ICON); ... ... ... delete led;
----------- Mila
Mila025 wrote:
delete led;
better make a call to DestoryWindow before deleting variable or make call to delete at destructor or OnDestroy Window handller
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and you