Button Bar

When working on a Visual Basic program and was going to use the API call ShellExecute I remembered another function entitled WinExec.

WinExec is much simpler to use than ShellExecute, It uses less amount of code and is easier to understand.

With WinExec you can run not only MS Windows applications, but also, .com, hlp, pif files with one line of code, sorry it doesn’t work with chm files. EG

To run Windows Control Panel this code will do it: WinExec “Control.exe”, 10. The number at the end refers to the window state (maximized).

The API declare looks like this:

Declare Function WinExec Lib "kernel32" Alias "WinExec" (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long

If this seems confusing to those of you who aren’t familiar with API calls just check out The Code

Along with the code I’m including all resources need to create the program. This includes Bitmap, Wav file, HTML documents used to create this help, and the HTML Help Workshop project file.

The Buttons

The Code

This is just the beginning of API calls I’ll be transferring to RapidQ. My next project is to make a form stay on top until it’s closed. I’ve found this handy with dialog boxes.

If you should have any questions or suggestions then please send them to me at:

Danny846842@yahoo.com


The Buttons

* - Runs Windows Control Panel

- Runs Windows Explorer

- Runs the Calculator

- Runs Internet Explorer

- Invoke the MS-DOS Prompt

- Invokes the Help File

- About Button Bar

- Exit the program.


The Code

Declare Function WinExec Lib "kernel32" Alias "WinExec" _

(ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long ‘the WinExec function declaration

DECLARE SUB Button1Click (Sender AS QBUTTON)

DECLARE SUB Button2Click (Sender AS QBUTTON)

DECLARE SUB Button3Click (Sender AS QBUTTON)

DECLARE SUB Button4Click (Sender AS QBUTTON)

DECLARE SUB Button5Click (Sender AS QBUTTON)

DECLARE SUB Button6Click (Sender AS QBUTTON)

DECLARE SUB Button7Click (Sender AS QBUTTON)

DECLARE SUB Button8Click (Sender AS QBUTTON)

DECLARE SUB Button10Click (Sender AS QBUTTON)

$Option ICON "ButtonBar.ico"

CREATE Form AS QFORM

Caption = "Button Bar"

Cursor = crHandPoint

Width = 275

Height = 75

Center

CREATE Button1 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\Control Panel.bmp"

Left = 0

Top = 5

Width = 25

ShowHint = 1

Hint = "Run Control Panel"

Default = 1

OnClick = Button1Click

END CREATE

CREATE Button2 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\Exit.bmp"

Left = 227

Top = 5

Width = 25

ShowHint = 1

Hint = "Exit the program"

TabOrder = 1

OnClick = Button2Click

END CREATE

CREATE Button3 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\WExplorer.bmp"

Left = 29

Top = 5

Width = 25

ShowHint = 1

Hint = "Run Windows Explorer"

TabOrder = 2

OnClick = Button3Click

END CREATE

CREATE Button4 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\Calc.bmp"

Left = 58

Top = 5

Width = 25

ShowHint = 1

Hint = "Run Windows Calculator"

TabOrder = 3

OnClick = Button4Click

END CREATE

CREATE Button5 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\CharMap.bmp"

Left = 87

Top = 5

Width = 25

ShowHint = 1

Hint = "Run Character Map"

TabOrder = 4

OnClick = Button5Click

END CREATE

CREATE Button6 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\IExplorer.bmp"

Left = 115

Top = 5

Width = 25

ShowHint = 1

Hint = "Run Internet Explorer"

TabOrder = 5

OnClick = Button6Click

END CREATE

CREATE Button7 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\about.bmp"

Left = 199

Top = 5

Width = 25

ShowHint = 1

Hint = "About Button Bar"

TabOrder = 6

OnClick = Button7Click

END CREATE

CREATE Button8 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\Dos.bmp"

Left = 143

Top = 5

Width = 25

ShowHint = 1

Hint = "Ms Dor Promt"

TabOrder = 7

OnClick = Button8Click

END CREATE

CREATE Button9 AS QBUTTON

Caption = "Button9"

Left = -369

Top = -268

TabOrder = 8

END CREATE

CREATE Button10 AS QBUTTON

Caption = ""

BMP = "C:\RapidQ\Help.bmp"

Left = 171

Top = 5

Width = 25

ShowHint = 1

Hint = "Invoke the Help File"

TabOrder = 9

OnClick = Button10Click

END CREATE

END CREATE

'Insert your initialization code here

Form.ShowModal

'--------- Subroutines ---------

SUB Button1Click (Sender AS QBUTTON)

'run control panel

WinExec "Control.exe" ,10

END SUB

SUB Button2Click (Sender AS QBUTTON)

'exit

Form.Close

END SUB

SUB Button3Click (Sender AS QBUTTON)

'run windows explorer

WinExec "Explorer.exe", 10

END SUB

SUB Button4Click (Sender AS QBUTTON)

'run calculator

WinExec "Calc.exe", 10

END SUB

SUB Button5Click (Sender AS QBUTTON)

'run character map

WinExec "CharMap.exe", 10

END SUB

SUB Button6Click (Sender AS QBUTTON)

'run internet explorer

WinExec "c:\Program Files\Internet Explorer\IExplore.exe", 10

END SUB

SUB Button7Click (Sender AS QBUTTON)

'about button bar

PlayWav "Trying to Think.wav",1

MessageDlg ("Button Bar v 1.0 , Danny Jackson", _

mtInformation, mbOK, 0)

END SUB

SUB Button8Click (Sender AS QBUTTON)

'invoke the dos prompt

WinExec "DOSPRMPT.pif" ,10

END SUB

SUB Button10Click (Sender AS QBUTTON)

'invoke the help file

WinExec "ButtonBar.chm" , 10

END SUB