December 9, 2000

VB IDE and ObjectContext

A myth that is still being spread in various VB and MTS/COM+ related newsgroups, is that an application can not obtain a reference to the MTS or COM+ ObjectContext in the Visual Basic Integrated Development Environment (VB IDE). Ever since VB 5 a VB ActiveX DLL project in the IDE

ListBoxFindString – Search an item in a ListBox or ComboBox control

Private Declare Function SendMessage Lib “user32” Alias “SendMessageA” (ByVal _ hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _ lParam As Any) As LongConst LB_FINDSTRING = &H18FConst LB_FINDSTRINGEXACT = &H1A2Const CB_FINDSTRING = &H14CConst CB_FINDSTRINGEXACT = &H158′ Find a string in a ListBox or ComboBox control’ Returns the

SetMenuBitmap – Add a bitmap to a menu item

Private Declare Function GetMenu Lib “user32” (ByVal hWnd As Long) As LongPrivate Declare Function GetSubMenu Lib “user32” (ByVal hMenu As Long, _ ByVal nPos As Long) As LongPrivate Declare Function SetMenuItemBitmaps Lib “user32” (ByVal hMenu As Long, _ ByVal nPosition As Long, ByVal wFlags As Long, ByVal hBitmapUnchecked As _

IsFormModal – Determines whether a form is modal

Private Declare Function GetWindowLong Lib “user32” Alias “GetWindowLongA” _ (ByVal hWnd As Long, ByVal nIndex As Long) As LongConst GWL_STYLE = (-16)Const WS_DISABLED = &H8000000′ Return True if the form is modal” Note: if an application has only one visible’ form, this function considers it as modalFunction IsFormModal(frm As Form)

Use a ListBox as a poor man’s grid

You can easily create columns of data in a ListBox control by setting its tab stop at appropriate positions. This way, you can use a ListBox control as a sort of grid control with (very) limited functionality, but without using third-party controls. You can set ListBox’s tab stop by sending

Quickly find which OptionButton is selected

Often OptionButton controls are arranged in control arrays. To quickly find the index of the only selected OptionButton control you can use the following code: ‘ assumes that the control array contains three OptionButton controlsintSelected = Option(0).Value * 0 – Option(1).Value * 1 – Option(2).Value * 2 Note that the

TileBitmap – Tile a bitmap using the PaintPicture method

‘ Tile a bitmap to a form or a Bitmap box” Target can be a Form or a BitmapBox control’ Bitmap can be the Bitmap property of a PictureBox or an Image control,’ or the return value of a LoadPicture function” Example: TileBitmap Form1, LoadPicture(“C:myimage.bmp”)Sub TileBitmap(Target As Object, Bitmap As