I'm new at using Microsoft Visual Studio, but I have some knowledge about C++ language. I'd like to create object can be found in Toolbox, such as Labels, Button, etc., but without putting them onto the window by hand.
How can I do it?
I'm new at using Microsoft Visual Studio, but I have some knowledge about C++ language. I'd like to create object can be found in Toolbox, such as Labels, Button, etc., but without putting them onto the window by hand.
How can I do it?
Objects/Controls like labels and buttons are simply a special type of window, with associated window class and window procedure. As such, you call CreateWindowEx and supply for the second parameter, lpClassName, the class name of object/control you want to create (eg. for a label use the class name STATIC
).
Check out the following tutorial for a complete example, using the BUTTON class
To create a button:
HWND hWndButton=CreateWindowEx(NULL,
"BUTTON",
"OK",
WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
50,
220,
100,
24,
hWnd,
(HMENU)IDC_MAIN_BUTTON,
GetModuleHandle(NULL),
NULL);`