Windows API
How can I pass an array to a API function?
Compatibility:VB3
VB4
VB5
Pass the first element(usually zero) of the array.
How can I undo the last action in a textbox?
Compatibility:VB3
VB4
VB5
Use this code:
Sendmessage(myHwnd, EM_UNDO, 0 , 0)
What is NULL?
Compatibility:VB3
VB4
VB5
NULL is a constant equal to zero.
How can I get a pointer to a string, object,
or variable?
Compatibility:VB3
VB4
VB5
For strings, use the undocumented function StrPtr.
If you need a pointer to a object, use ObjPtr. Finally,
if you need a pointer to a variable use VarPtr.
How can I put a toolbar in my application?
Compatibility:VB3
VB4
VB5
Create a new form with all your buttons on it.
Under VB5, you'll want to set the border property to "4 - ToolWindow".
Put the following declarations in a new module:
declare Function SetWindowWord Lib "User32" (ByVal hWnd as Long, ByVal _
nIndex as long, ByVal nNewWord as long) as long
Next, put the following code in the load event of the toolbar form.
SetWindowWord Me.hWnd, -8, Main.hWnd
Replace main with the name of your main form.
How can I make a form "Always on top"?
Compatibility:VB3
VB4
VB5
Put this code in a module:
Declare Function SetWindowPos Lib "user32" ( _
ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
public sub SetFormOnTop(myForm as object)
SetWindowPos myForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE
end sub
How can I find out the specifications for all those
neat Enum* functions?
Compatibility:VB3
VB4
VB5
If you have VC++ or the MSDN subscription, just
look up the Enum function and it will normally contain
a link to the arguments specs.
Egad! The SetFocus API won't work on
some hWnds. (Like America Online.) What
should I do?
Compatibility:VB3
VB4
VB5
Don't go crazy and use AppActivate, like
some(names have been removed to protect the
guilty) programmers.
Use the SetForegroundWindow API.
I'm writing a database system. How can I create a number that's is fairly unique,
and feasible to implement for ID strings?
Compatibility:VB3
VB4
VB5
GUIDs, which windows uses to OLE resources,
are farely random 128-bit numbers. Where I work we use them heavily
to track items in a database. GUID's
are great because the are unique.
Well, Visual Basic 5.0 comes with
a program that create them for you,
but what a pain. Wouldn't it be
nice to just do it via code? Well
now you can with the sample code
below.
Private Type GUID
Data1 As Long
Data2 As Long
Data3 As Long
Data4(8) As Byte
End Type
Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long
Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any,ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long
Public Function GetGUID() As String
Dim pudtGUID As GUID
Dim pstrGUID As String
Dim pbytGUID() As Byte
Dim plngRet As Long
Dim plngLen As Long plngLen = 40
pbytGUID = String(plngLen, 0)
CoCreateGuid pudtGUID
plngRet = StringFromGUID2(pudtGUID, VarPtr(pbytGUID(0)), plngLen)
pstrGUID = pbytGUID
If (Asc(Mid$(pstrGUID, plngRet, 1)) = 0) Then plngRet = plngRet - 1
GetGUID = Left(pstrGUID, plngRet)
End Function
Compliments of David McCarter/Woody Pewitt
I'm trying to find a way to browse folders, as opposed to files. I can use VB or Win32 to get at files no problem, but haven't yet found a way to look at folders. I'd like it to work both on drive letter and UNC.
Compatibility:VB3
VB4
VB5
Use the SHBrowseForFolder API function.
Copyright 2000, David J Berube<Form1@aol.com>. All Rights Reserved.