Skip to main content
GameDev.net gamedev.net
🔒 Locked

Visual C++ Dynamic Controls

Started by karan13 Jan 12, 2003 at 11:52 AM 3 replies 2.4k views
Original Post
karan13
karan13
I have a quick question on Visual C++... I am trying to create an application where i figured i need to dynamically create controls... mainly checkboxes... The user enters a number.. now i cant be sure how many he may enter... it could be anywhere from 10 to 25... but the thing is that when he presses okay, i need to present him with the exact amount of checkboxes... so if he entered 20... and then hits enter... then i have to display 20 checkboxes... Is there a way i can dynamically create this using code... so that i dont have to hide all the possible number of checkboxes, then make them visible, when i need them... And also, is it possible to make the values of a checkboxes to be pointed to by an array... like if i have 10 checkboxes... can i make the variables of these checkboxes as part of an array, so that if i say m_bCheck [2], it will access the 3rd checkbox.. is it possible.. if so how... I appreciate any help anyone can give me...
Colin Jeanne
Colin Jeanne
Look up CreateWindow() or CreateWindowEx(). Those can dynamically create windows. I suggest creating a generic checkbox creation function. To put your windows in an array, simple make an array of HWND''s.



Qui fut tout, et qui ne fut rien
Invader''s Realm
karan13
karan13
Alright... i tried it.. but i still couldnt get it... i dont know if u didnt understand my question or what about how to create dynamic controls...

I mean, in an edit box, a user enters a number from 10 to 30... then depending on what number he entered, i display those many checkboxes... and each one has to be independent, so i can get values from each one... so how do i implement this at runtime...

Thanks...
quasar3d
quasar3d
You probably know this, but a control like a button and an edit box, in fact is window, so you need CreateWindow to create a control. for a checkbox this is

#define IDC_CHECKBOX1 1 // we will use 1 as the id for the checkbox, however this can be any number, as long as it's unique in all the child windows in the parent window

hCheckbox = CreateWindow("BUTTON","Check this checkbox",WS_CHILD|BS_CHECKBOX,
0,0,100,32,hParent,(HMENU)IDC_CHECKBOX1,hInstance,NULL);
ShowWindow(hCheckBox,SW_SHOWNORMAL);

My Site

[edited by - Quasar3D on January 14, 2003 3:05:16 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.