README.md

December 5, 2022 · View on GitHub

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

Description

REAL C++ CONTROLS IN YOUR APP!!!

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!!!

More Info

Submitted On2000-09-19 22:10:26
ByDruid Developing
LevelAdvanced
User Rating4.6 (37 globes from 8 users)
CompatibilityVB 5.0, VB 6.0
CategoryCustom Controls/ Forms/ Menus
WorldVisual Basic
Archive FileCODE_UPLOAD99959192000.zip

Source Code

Neue Seite 1

(best viewed in 1024 x 768)

C++ 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

druid-developing@gmx.de

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 this:

 

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 difficult.

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:

 

'Declare Variable to save the WindowHandle

Public TextBoxHwnd as Long

'Create the TextBox

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

 

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

Function Get_Text_Of_Control(ByVal cHwnd as Long) as String

Dim ControlText As String

ControlText = Space(254)

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

GetWindowText cHwnd , ControlText , 254

Get_Text_Of_Control = Trim(ControlText)

End Function

 

Use this function like this:

TextBoxText = Get_Text_Of_Control(TextBoxHwnd)

MsgBox TextBoxText

 

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

 

'Declare Variable to save the WindowHandle

Public ButtonHwnd as Long

'To save the old WindowProcedure for the button

Public gButOldProc as Long

 

'Create the Button

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

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

gButOldProc& = GetWindowLong(ButtonHwnd&, GWL_WNDPROC)

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

'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&

Case WM_LBUTTONUP:

'Left button is up (user clicked the Button)

'Use "WM_LBUTTONDOWN"

MsgBox "The button was clicked"

'Call the standard window proc

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

End Function

 

3. Final Explanations

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, bye.

Maybe I update this code once more.

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

And PLEASE, PLEASE, PLEASE VOTE FOR ME!!!