Friday, July 28, 2006

ClipBoard

Five clipboard functions are provided. Two of them duplicate the action performed by the keyboard sequence PrtScr and Alt-PrtScr. Three of them deal with text data.

ActiveScreenToClipboard

Takes a snapshot of the current screen. Equivalent to tapping the PrtScr key.

You can use this in reporting errors or the status of a running program.

Once you have trapped the run-time error, issue a call to ActiveScreenToClipboard and at least have the user paste the results into Paintbrush. Better yet, use a routine to capture the clipboard image as a bitmap or other graphic file.

Sub TESTActiveScreenToClipboard()
Call ActiveScreenToClipboard
End Sub


ActiveWindowToClipboard

Takes a snapshot of the current window. Equivalent to tapping the Alt-PrtScr key combination.

You can use this in reporting errors or the status of a running program.

Once you have trapped the run-time error, issue a call to ActiveWindowToClipboard and at least have the user paste the results into Paintbrush. Better yet, use a routine to capture the clipboard image as a bitmap or other graphic file.

I have had little success with this function, the equivalent of Alt-PrtScr, under Windows XP

Sub TESTActiveWindowToClipboard()
Call ActiveWindowToClipboard
End Sub


ClearClipboard

Returns any text stored in the clipboard before emptying the clipboard.

Sub TESTstrClearClipboard()
MsgBox strClearClipboard
End Sub


StrAppendToClipboard

Returns any text stored in the clipboard before appending the supplied string to the clipboard.

Sub TESTstrAppendToClipboard()
MsgBox strAppendToClipboard("v")
MsgBox strAppendToClipboard("w")
MsgBox strAppendToClipboard("x")
MsgBox strClearClipboard
MsgBox strAppendToClipboard("y")
MsgBox strAppendToClipboard("z")
End Sub



strLoadToClipboard


Returns any text stored in the clipboard before loading the supplied string to the clipboard.

Sub TESTstrLoadToClipboard()
MsgBox strLoadToClipboard("b")
MsgBox strLoadToClipboard("c")
MsgBox strLoadToClipboard("d")
End Sub

Sunday, July 23, 2006

Fun 4 X

Also known as “Fun For All”.

I had reason to demonstrate my ability to switch languages (English, French, Spanish etc.) on the Control Tip Text on controls on a GUI form.

I decided to demonstrate by changing the established English-language tips to whimsical bumper stickers.

At the same time I was lecturing to classes in a sunny room, and students couldn’t see the GUI forms.

I decided to introduce random colour schemes.

Then I got carried away and decided that the fonts and mouse pointers could do with a touch-up.

The result is Fun4X.

To see how it works, introduce a new User Form and place four command controls on the form.

I haven’t bothered to rename or captioon them, for reasons which will appear below.

Set a refernce to UW.DOT.

Double-click on a command button and write the code for that button, close, double-click on the next, write, close and so on until all 4 command buttons have code and then write the userform initialization code, as set out below.

Private Sub CommandButton1_Click()
Call UW.cmdColoursClick(Me)
End Sub
Private Sub CommandButton2_Click()
Call UW.cmdFontsClick(Me)
End Sub
Private Sub CommandButton3_Click()
Call UW.cmdIconsClick(Me)
End Sub
Private Sub CommandButton4_Click()
Call UW.cmdCaptionsClick(Me)
End Sub
Private Sub UserForm_Initialize()
Call UW.UserFormInitialize(Me)
End Sub

Run the user form (F5 function key), and you’ll see this:

I had hooked the top-left control to “Colours”, and the bottom left control to “Captions”.

Click the Colours control repeatedly and watch the pretty random colours.

Click the Captions control once, then inspect your Control Tip Text.

If you have icon files (*.ICO) on your root drive C:, you can switch mouse pointers.

You can change font face and size, too.

Once I am sure the controls are working, I resize them to be 4-pixel square “rivets” in each corner of the GUI form.

That’s why I don’t need captions!

Friday, July 14, 2006

Using an INI file

Nothing complex about it.

We want to store data that reflects our run-time in a file quite separate from the program. INI files have been around for a long time. They are text files, and a reasonably competent user can edit them. A reasonably competent designer (like you!) can build a GUI form for a user interface.

Let us start by writing a small chunk of application code to demonstrate using an INI file.

References

Set a reference to the utility library UW.DOT from within your project.

Constants


In your constants module, declare two public constants:

Public Const strcDriveLetter As String = "DriveLetter"
Public Const strcDriveLetterDefault As String = "C"

Program code


In a module write a very simple test macro:

Sub test()
MsgBox UW.UT_ProfileStrings.strGPA(Publics.strcDriveLetter, Publics.strcDriveLetterDefault)
End Sub

You can, of course, omit the explicit module names:

Sub test()
MsgBox strGPA(strcDriveLetter, strcDriveLetterDefault)
End Sub

Testing the code


Run the little test macro.

You will observe a pop-up message box bearing the letter "C".
The INI file

In your Documents and settings folder locate the file Utils.INI.

Its contents should look like this:
[Utils]
DriveLetter=C

Changing the INI file

While you have the INI file open in Notepad, change the drive letter to be "D".

Re run the little test macro and observe the pop-up message box bearing the letter "D"
How it works

The procedure strGPA looks for a suitable INI file. If it doesn't find one, it builds one!

Within that file it looks for a key as stated in the first parameter of the call to strGPA; in our case the first parameter is "strcDriveLetter", so strGPA looks for a key "DriveLetter".

If the given parameter can not be found, strGPA creates a key and value using the second parameter of the call.; in our case the second parameter was "strcDriveLetterDefault" so the value defaults to "C", and that value is written to the INI file.

What is so good about all this?

I am glad you asked.

First off, you don't need to worry about the INI file. Just define your key names and default values, and strGPA does the rest.

Next, your user interface can include a ‘panic" button; resetting an INI file to default values is as simple as deleting the INI file. Your panic button merely KILLs the INI file, and each subsequent call will store and return the default values.

There's more – a strPPA function for Putting parameters to an INI file, section management, and the use of value strings much longer than the Microsoft limit of 255 characters.

As well the source code is switchable between registry, regular INI and long-value INI file methods.

More later