Search Tools Links Login

C++ Controls in your app (updated) - now with tutorial

Posted: 2002-06-01
By: ArchiveBot
Viewed: 66

Filed Under:

VB6 Code Cache

Title Uploaded Size 9/3/2020 3:45:00 PM 7,799

Do you know the code "Real C++ Buttons" by Randy Mcdowell?
It sends a message to a VB Button to make it a "C++ Button". But if you look at this button with
Spy++ you will see that it is still a "ThunderCommandButton", the VB Button.
My code lets you use EVERY C++ control in your app!!! And these controls are REAL C++ controls!!!
Think of the fantastic controls you can have: e.g. the cool hotkey control. Or what about a "real"
RICHEDIT control? The only limitation is your fantasy! Control events are also supported.
Well commented, and easy to use even if you don't understand everything that happens.
The second version of this code, now with tutorial and some new stuff.
Have fun with this code, use it in your app, and if you like it VOTE FOR IT!!!

Original Author: Druid Developing


Neue Seite 1

(best viewed in 1024 x 768)

Controls in your app - Now with tutorial

Hi, this is the update to my
code "Real C++ Controls in your app" which I submitted at the
beginning of September.

Now somebody posted that this
code isnīt explained well and so I wrote this tutorial.

If there would still be any
problems just E-Mail me at

Important note: This tutorial
is also included in the .zip file. You donīt have to read it here.


1. How to use
this code in your app

First you have to include
the modMain.bas in your project.

Then goto the menu "Project"
and click "Properties of ...".

In this window set the
Start Object to "Sub Main".

In the Sub Main which is
in the modMain you can now create the controls.

Call the function like


Hwnd of the
control = CreateControl( "Edit" (Classname) , "This is a TextBox"
(Text) , 3 (Left) , 3 (Top) , 100 (Width) , 50 (Height) , (Optional Style) )


Thatīs it! No difficult API Calls, not
much code, just ONE FUNCTION!

Very easy to use, even
for beginners.


2. How to
interact with the controls

If you want to use the
controls like normal controls, with Events and Properties it is a bit more

For  every Property
and Event you firs need the WindowHandle of the control.

You get it from the
CreateControl function (look above).

If you want to get e.g.
the Text of a created TextBox control you can do it like this:


Variable to save the WindowHandle

Public TextBoxHwnd as Long

'Create the

TextBoxHwnd =
CreateControl( "Edit" , "Text to get" ,  3 , 3 , 100 ,
40 )


Using this Function you
can get the actual Text of the TextBox

Get_Text_Of_Control(ByVal cHwnd as Long) as String

ControlText As String

ControlText = Space(254)

'Use the GetWindowText API to get the actual
text of the TextBox control

Hwnd ,
ControlText , 254

= Trim(

End Function


Use this function like

TextBoxText =



To use an Event, e.g. the click Event of
a Button you can do it like this:


Variable to save the WindowHandle

Public ButtonHwnd as Long

'To save the old WindowProcedure for the button

Public gButOldProc as Long


'Create the

ButtonHwnd =
CreateControl( "Button" , "Click this button" ,  3 , 3
, 100 , 40 )

  'Get the address of the standard button procedure and save it in

gButOldProc& = GetWindowLong(ButtonHwnd&,

'Use GWL_WNDPROC to save the adress of the procedure for the

'You have to do this for every control you want to have a procedure

  Call SetWindowLong(ButtonHwnd&, GWL_WNDPROC, GetAddress(AddressOf ButtonWndProc))


'This is the procedure that is called when you click the button

Public Function ButtonWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

  Select Case uMsg&


'Left button is up (user clicked the Button)


"The button was clicked"

'Call the standard window proc

  ButtonWndProc = CallWindowProc(gButOldProc&, hwnd&, uMsg&, wParam&, lParam&)

End Function


3. Final

The special thing on this
code is that you can use every registered Windows class name for a control.

You can also create an
own class name using the API "RegisterWindowClass".

Thatīs all for today,

Maybe I update this code
once more.

PS: Please excuse me
for my bad English, Iīm German.


Comments on this post

No comments have been added for this post.

You must be logged in to make a comment.