0

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?

Zoltán Schmidt
  • 1,286
  • 2
  • 28
  • 48
  • They cannot be created in C++, a language called C++/CLI needs to be used. Get yourself a book about Winforms programming to get ahead. – Hans Passant May 18 '13 at 16:06

1 Answers1

2

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);`
DarkMatter
  • 306
  • 2
  • 13