- C -
CharLower Function
Declare Function CharLower Lib "user32.dll" Alias "CharLowerA" (ByVal lpsz As String) As String
CharLower converts the letters in a string to their lower-case equivalents. This function has the exact same purpose as Visual Basic's intrinsic LCase function. In fact, LCase is slightly faster and easier to use than CharLower, so use that instead. CharLower is in the API for programming languages that have no intrinsic function to do this. The converted string is returned.
lpsz | The string to convert.
|
Example:
'Both lines do the same thing.
Debug.Print LCase$("Hello, world!")
Debug.Print CharLower("Hello, world!")
Related Call: CharUpper
Category: String Manipulation
Back to the index.
CharUpper Function
Declare Function CharUpper Lib "user32.dll" Alias "CharUpperA" (ByVal lpsz As String) As String
CharUpper converts the letters in a string to their upper-case equivalents. This function has the exact same purpose as Visual Basic's intrinsic UCase function. In fact, UCase is slightly faster and easier to use than CharUpper, so use that instead. CharUpper is in the API for programming languages that have no intrinsic function to do this. The converted string is returned.
lpsz | The string to convert.
|
Example:
'Both lines do the same thing.
Debug.Print UCase$("Hello, world!")
Debug.Print CharUpper("Hello, world!")
Related Call: CharLower
Category: String Manipulation
Back to the index.
ChooseColor Function
Declare Function ChooseColor Lib "comdlg32.dll" Alias "ChooseColorA" (pChoosecolor As CHOOSECOLORS) As Long
ChooseColor displays the choose a color dialog box. While you can use the common dialog custom control to do this, you then have to include the large control file with your programs. This API call is both faster and uses fewer resources. All of the data you pass the function is a part of pChoosecolor
, as well as the values chosen. The custom colors of the box are stored in a Byte-sized array in your code, although it must be converted into a Unicode string via the StrConv function before it's passed (see the example for a better idea of how this is done). The function returns 0 if the user chooses Cancel.
pChoosecolor | Contains all of the arguments passed to the function. Also holds the chosen color and list of custom colors after the function is called.
|
Example:
'**Place this code in the (declarations) section of your code.**
Dim customcolors() As Byte 'dynamic (resizable) array
'**Place this code in the Form_Load Sub or other similar section.**
ReDim customcolors(0 To 16 * 4 - 1) As Byte
Dim i As Integer
For i = LBound(customcolors) To UBound(customcolors)
customcolors(i) = 0 'RGB value of a custom color
Next i
'**Code to actually create and use the dialog box.**
Dim cc As CHOOSECOLORS, x As Long
cc.hwndOwner = Form1.hWnd 'handle of calling form
cc.lpCustColors = StrConv(customcolors, vbUnicode) 'convert array to string
cc.flags = CC_ANYCOLOR 'allow any color to be chosen
cc.lStructSize = Len(cc) 'size of variable
x = ChooseColor(cc) 'call the dialog box
If x = 0 Then Exit Sub 'if user chose Cancel
Form1.BackColor = cc.rgbResult 'set form background to chosen color
customcolors = StrConv(cc.lpCustColors, vbFromUnicode) 'restore array
Category: Common Dialog
Back to the index.
ClipCursor Function
Declare Function ClipCursor Lib "user32.dll" (lpRect As RECT) As Long
ClipCursor confines the mouse cursor to a rectangular area of the screen. If the mouse starts outside of this rectangle or SetCursorPos tells it to go outside the area, the cursor will immediately be put back in. Nothing can get it out. The cursor will remain in the rectangle no matter what program you switch to, or even if you close the one that confined it. The only way to release it back into full-screen range is to confine it to a rectange the size of the screen (see example). It isn't usually a good idea to confine the cursor, because the user will expect to be able to move the cursor anywhere. The function returns a value which can be safely ignored.
lpRect | A RECT variable containing the upper-left and lower-right coordinates of the confinement rectangle.
|
Example:
Dim r As RECT
'This code confines the cursor to inside of Form1
x = GetWindowRect(Form1.hWnd, r) 'API call puts a window size into a RECT
x = ClipCursor(r) 'Confine the cursor
'This code releases the cursor
deskhWnd = GetDesktopWindow() 'API call gets the handle of the screen window
x = GetWindowRect(deskhWnd, r) 'API call puts a window size into a RECT
x = ClipCursor(r) 'Confine the cursor to the entire screen
Related Call: GetClipCursor
Category: Mouse
Back to the index.
CopyRect Function
Declare Function CopyRect Lib "user32.dll" (lpDestRect As RECT, lpSourceRect As RECT) As Long
CopyRect sets one RECT-type variable equal to another. This is done by duplicating all of the member values in the source rectangle to the corresponding values in the target rectangle. While you could do this manually in four commands setting each value equal, this is shorter to write and quicker to understand. You can safely ignore the value returned.
lpDestRect | The RECT to set the member values of.
|
lpSourceRect | The RECT to set the member values as.
|
Example:
'Set RECT target equal to RECT source
Dim target As RECT, source As RECT
x = GetWindowRect(Form1.hWnd, source) 'set source to size and shape of Form1
x = CopyRect(target, source) 'now target.Left = source.Left etc.
Related Call: EqualRect
Category: RECT Manipulation
Back to the index.

Paul Kuliniewicz
E-mail: Borg953@aol.com
All material presented on these pages is Copyright © Paul Kuliniewicz, except for other copyrighted material.
http://members.aol.com/Borg953/api/c.html