WinForm什么时间启动消息循环?如何一步一步处理?消息处理机制是什么?谢谢!

解决方案 »

  1.   

    http://msdn2.microsoft.com/zh-cn/library/8zax2582.aspx
      

  2.   

    前段时间刚做了个测试消息的,详细代码给个邮箱可以发给你看看。
    Imports System.Runtime.InteropServicesModule Module1    Public Const MyMsgID As Integer = &H8FB    Public WithEvents MyTest As New clsRefresh    Public Structure StructMsg
            Dim MsgIndex As Integer
            Dim MsgInfo As String
            Dim MsgMemo As String
        End Structure    Private Sub MyTest_NowCount(ByVal i As Integer) Handles MyTest.NowCount
            Call SetOpenFormTitles(i.ToString)
        End Sub    Private Sub SetOpenFormTitles(ByVal Titles As String)
            Try
                For Each f As Form In My.Application.OpenForms
                    Call SetFormTitle(f, Titles)
                Next
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End Sub    Private Delegate Sub SetFormTitleDelegate(ByVal f As Form, ByVal Titles As String)    Private Sub SetFormTitle(ByVal f As Form, ByVal Titles As String)
            If Not f.InvokeRequired Then
                Call SendMsg(f, Titles)
            Else
                Dim del As SetFormTitleDelegate = AddressOf SetFormTitle
                Dim param As Object() = {f, Titles}            f.Invoke(del, param)
            End If
        End Sub    Private Sub SendMsg(ByVal f As Form, ByVal titles As String)
            Dim mMsg As New StructMsg
            With mMsg
                .MsgIndex = 1
                .MsgInfo = "12345678901234567890" + Space(2) + titles
                .MsgMemo = "none"
            End With        Dim hWnd As IntPtr
            Dim msg As Integer = MyMsgID
            Dim wparam As IntPtr
            Dim lparam As IntPtr = Marshal.AllocHGlobal(17) 'mMsg.MsgInfo.Length + mMsg.MsgMemo.Length + 4)        Marshal.StructureToPtr(mMsg, lparam, True)
            Dim WinMsg As System.Windows.Forms.Message= Message.Create(hWnd, msg, wparam, lparam)        f.PreProcessMessage(WinMsg)
            Marshal.FreeHGlobal(lparam)
        End SubEnd Module
      

  3.   

    我的Email:
    [email protected]
    谢谢!
      

  4.   

    一开始
        Public Sub main()
            While (...)
                Try
                    Application.DoEvents()
                Catch ex As Exception
                    'Throw ex
                End Try
            End While
        End Sub
      

  5.   

    winform的消息循环和传统的windows基本是一样的。