home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!rsoft!mindlink!a4185
- From: Steve_Goyette@mindlink.bc.ca (Steve Goyette)
- Newsgroups: comp.os.ms-windows.programmer.misc
- Subject: Visual Basic Prof. Ext. Radio & Option Buttons
- Message-ID: <13791@mindlink.bc.ca>
- Date: 27 Jul 92 21:08:03 GMT
- Distribution: world
- Organization: MIND LINK! - British Columbia, Canada
- Lines: 71
-
- Hi,
-
- For a little while now, I have had a problem with the option and
- radio buttons in the Visual Basic Proffesional Extensions. When a
- form containing any of these controls was over-written with another form or
- dialog, the controls wouldn't get re-drawn. After wrestling
- with this problem (and tearing most of my remaining hair out) I came up with
- the following solution. I hope that this helps other people
- experiencing the same problem.
-
- In your Global file, declare the following windows API functions and
- constants.
-
- ------------------------------------------------------------------------
- Declare Function GetFocus% Lib "User" ()
- Declare Function SendMessage Lib "User" (ByVal hWnd As Integer,
- ByVal wMsg As Integer,
- ByVal wp As Integer,
- lp As Any) As Long
- Declare Function APISetFocus% Lib "User" Alias "SetFocus" (ByVal hWnd%)
- Global Const WM_PAINT = 15
- ------------------------------------------------------------------------
-
- Now, you need to declare a function either in a module or a form. I use
- it at a module level so that I can call it from ALL forms.
-
- ------------------------------------------------------------------------
- Sub Refresh_Control (Cntrl As Control)
-
- Dim OldHwnd As Integer
- Dim CtrlhWnd As Integer
-
- OldHwnd = GetFocus()
- Cntrl.SetFocus
- CtrlhWnd = GetFocus()
- Dummy% = SendMessage(CtrlhWnd, WM_PAINT, 0, 0)
- Dummy% = APISetFocus(OldHwnd)
-
- End Sub
- ------------------------------------------------------------------------
-
- The basis of this function is the fact that windows calls the Form_Paint
- sub everytime the window get's over-written. By calling Refresh_Control
- in your form paint (For all VB Prof. Ext. Radio and Option buttons) you
- can force Visual Basic to redraw them. The following is an example.
-
- ------------------------------------------------------------------------
- Sub Form_Paint ()
-
- For x = 0 To 6
- Call Refresh_Control(Days(x))
- Next x
- Call Refresh_Control(Course_Type(0))
- Call Refresh_Control(Course_Type(1))
-
- End Sub
- ------------------------------------------------------------------------
-
- Days(x) is a set of 7 option buttons with indexes from 0-6. Course_Type
- is a set of 2 Radio buttons with indexes from 0-1. You could also call
- this function for any Control used in VB but so far these two types of
- controls are they only ones that I have experienced problems with.
-
- I hope that this code can help out other users as it has helped me. If
- you have any comments, suggestions, or general banter please feel free to
- contact me.
-
-
-
- Steve Goyette
- (604) 421-8864
-