Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

How to send a specific windows message to all windows ?
[ All Languages » VB »  Windows]

Total Hit ( 3338)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Many times we need to send a specific message to other applications or windows itself to notify regarding some event. Windows provides a function called BroadcastSystemMessage. The BroadcastSystemMessage function sends a message to the specified recipients. The recipients can be applications, installable drivers, network drivers, system-level device drivers, or any combination of these system components. For example you can refresh explorer view, you can fire paint event for all applications and more using this function.

Here is the small example which will fire paint event for all application. To test this you can create another VB application and put breakpoint in form_paint event.

Step-By-Step example
- Create a standard exe project
- Add one command button
- Add the following code in form1 code window

Click here to copy the following block
Option Explicit

Private Declare Function BroadcastSystemMessage Lib "user32" ( _
    ByVal dw As Long, pdw As Long, ByVal un As Long, _
    ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const BSF_POSTMESSAGE As Long = &H10
Private Const BSM_ALLCOMPONENTS As Long = &H0
Private Const WM_PAINT As Long = &HF

Private Sub RefreshAll()
  Dim lRet As Long
  '
  ' See WinAPI Reference / MSDN for info on Broadcastsystemmessage
  '
  ' This example will cause WM_PAINT to be send (see FORM_PAINT in VB)
  lRet = BroadcastSystemMessage(BSF_POSTMESSAGE, BSM_ALLCOMPONENTS, WM_PAINT, 0&, 0&)
  If lRet > 0 Then  ' it Worked
  ElseIf lRet < 0 Then  ' it failed
  End If
End Sub

Private Sub Command1_Click()
  RefreshAll
End Sub

Private Sub Form_Paint()
  MsgBox "Paint event fired"
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.