Answered by:
VC++ equivalent of this.Controls.Add function in C#

Question
-
Hi,
I am new to VC++ and want to know if there is an VC++ equivalent function for this.Controls.Add to add my custom control to windows forms (using c++). If not, how can i add my custom control to windows form?
Many thanks.
Monday, May 16, 2011 9:47 AM
Answers
-
Hello,
Welcome to the MSDN forum.
First, different project type have different ways to add a control. Generally speaking, there are three project types, they are Win32, MFC and CLI/C++.
Win32 is based on Windows API, it will call these APIs directly. If you want to add a control in this way, you will call CreateWindow() function. MFC is using some object-oriented classes to packaging these APIs. There is a button class, based on it, you can add a button like new CButton. CLI/C++ just like C#. You need new a button first, and then use Panel->Controls->Add(button) to add the button.
If you use VC++ first time. I would like you to learn Win32 and MFC, but it is hard to learn. They are total different from C# and WinForm. CLI/C++ is fine, but if you do not understand the native code like Win32 or MFC, you can not use CLI/C++ in practice, you will puzzled on the point in CLI/C++ and I think use C# instead of CLI/C++ will be better.
I hope my suggestions can help you to solve this problem.
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jesse Jiang Tuesday, May 31, 2011 2:37 AM
- Marked as answer by Jesse Jiang Wednesday, June 1, 2011 3:13 AM
Friday, May 20, 2011 2:41 AM
All replies
-
>I am new to VC++ and want to know if there is an VC++ equivalent function for this.Controls.Add to add my custom control to windows forms (using c++). If not, how can i add my custom control to windows form?
If you're dealing with Windows Forms and C++/CLI it will be
effectively the same as doing it in C# or VB with just the language
syntax differences.Dave
Monday, May 16, 2011 10:05 AM -
Hello,
Welcome to the MSDN forum.
First, different project type have different ways to add a control. Generally speaking, there are three project types, they are Win32, MFC and CLI/C++.
Win32 is based on Windows API, it will call these APIs directly. If you want to add a control in this way, you will call CreateWindow() function. MFC is using some object-oriented classes to packaging these APIs. There is a button class, based on it, you can add a button like new CButton. CLI/C++ just like C#. You need new a button first, and then use Panel->Controls->Add(button) to add the button.
If you use VC++ first time. I would like you to learn Win32 and MFC, but it is hard to learn. They are total different from C# and WinForm. CLI/C++ is fine, but if you do not understand the native code like Win32 or MFC, you can not use CLI/C++ in practice, you will puzzled on the point in CLI/C++ and I think use C# instead of CLI/C++ will be better.
I hope my suggestions can help you to solve this problem.
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- Proposed as answer by Jesse Jiang Tuesday, May 31, 2011 2:37 AM
- Marked as answer by Jesse Jiang Wednesday, June 1, 2011 3:13 AM
Friday, May 20, 2011 2:41 AM -
Hello,
Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Thursday, May 26, 2011 5:52 AM