home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / mswindo / programm / misc / 1035 < prev    next >
Encoding:
Internet Message Format  |  1992-07-27  |  3.1 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!ames!agate!rsoft!mindlink!a4185
  2. From: Steve_Goyette@mindlink.bc.ca (Steve Goyette)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Visual Basic Prof. Ext. Radio & Option Buttons
  5. Message-ID: <13791@mindlink.bc.ca>
  6. Date: 27 Jul 92 21:08:03 GMT
  7. Distribution: world
  8. Organization: MIND LINK! - British Columbia, Canada
  9. Lines: 71
  10.  
  11. Hi,
  12.  
  13.    For a little while now, I have had a problem with the option and
  14. radio buttons in the Visual Basic Proffesional Extensions.  When a
  15. form containing any of these controls was over-written with another form or
  16. dialog, the controls wouldn't get re-drawn.  After wrestling
  17. with this problem (and tearing most of my remaining hair out) I came up with
  18. the following solution.  I hope that this helps other people
  19. experiencing the same problem.
  20.  
  21. In your Global file, declare the following windows API functions and
  22. constants.
  23.  
  24. ------------------------------------------------------------------------
  25. Declare Function GetFocus% Lib "User" ()
  26. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer,
  27.                                          ByVal wMsg As Integer,
  28.                                          ByVal wp As Integer,
  29.                                          lp As Any) As Long
  30. Declare Function APISetFocus% Lib "User" Alias "SetFocus" (ByVal hWnd%)
  31. Global Const WM_PAINT = 15
  32. ------------------------------------------------------------------------
  33.  
  34. Now, you need to declare a function either in a module or a form.  I use
  35. it at a module level so that I can call it from ALL forms.
  36.  
  37. ------------------------------------------------------------------------
  38. Sub Refresh_Control (Cntrl As Control)
  39.  
  40. Dim OldHwnd As Integer
  41. Dim CtrlhWnd As Integer
  42.  
  43.     OldHwnd = GetFocus()
  44.     Cntrl.SetFocus
  45.     CtrlhWnd = GetFocus()
  46.     Dummy% = SendMessage(CtrlhWnd, WM_PAINT, 0, 0)
  47.     Dummy% = APISetFocus(OldHwnd)
  48.  
  49. End Sub
  50. ------------------------------------------------------------------------
  51.  
  52. The basis of this function is the fact that windows calls the Form_Paint
  53. sub everytime the window get's over-written.  By calling Refresh_Control
  54. in your form paint (For all VB Prof. Ext. Radio and Option buttons) you
  55. can force Visual Basic to redraw them.  The following is an example.
  56.  
  57. ------------------------------------------------------------------------
  58. Sub Form_Paint ()
  59.  
  60.     For x = 0 To 6
  61.         Call Refresh_Control(Days(x))
  62.     Next x
  63.     Call Refresh_Control(Course_Type(0))
  64.     Call Refresh_Control(Course_Type(1))
  65.  
  66. End Sub
  67. ------------------------------------------------------------------------
  68.  
  69. Days(x) is a set of 7 option buttons with indexes from 0-6.  Course_Type
  70. is a set of 2 Radio buttons with indexes from 0-1.  You could also call
  71. this function for any Control used in VB but so far these two types of
  72. controls are they only ones that I have experienced problems with.
  73.  
  74. I hope that this code can help out other users as it has helped me.  If
  75. you have any comments, suggestions, or general banter please feel free to
  76. contact me.
  77.  
  78.  
  79.  
  80.                                              Steve Goyette
  81.                                              (604) 421-8864
  82.