c#中有没有和MFC中PeekMessage的函数啊

解决方案 »

  1.   

    不知道MFC中PeekMessage这个函数是干什么用的?
      

  2.   

    就是从系统消息队列里面取出需要的消息
    MSDN是这么说的:
    Many applications perform lengthy processing "in the background." Sometimes performance considerations dictate using multithreading for such work. Threads involve extra development overhead, so they are not recommended for simple tasks like the idle-time work that MFC does in the OnIdle function. This article focuses on idle processing. For more information about multithreading, see Multithreading Topics. Some kinds of background processing are appropriately done during intervals that the user is not otherwise interacting with the application. In an application developed for the Microsoft Windows operating system, an application can perform idle-time processing by splitting a lengthy process into many small fragments. After processing each fragment, the application yields execution control to Windows using a PeekMessage loop.This article explains two ways to do idle processing in your application: Using PeekMessage in MFC's main message loop.Embedding another PeekMessage loop somewhere else in the application.PeekMessage in the MFC Message Loop
    In an application developed with MFC, the main message loop in the CWinThread class contains a message loop that calls the PeekMessage Win32 API. This loop also calls the OnIdle member function of CWinThread between messages. An application can process messages in this idle time by overriding the OnIdle function. Note  
    Run, OnIdle, and certain other member functions are now members of class CWinThread rather than of class CWinApp. CWinApp is derived from CWinThread.
     
      

  3.   

    你可以这样/// <summary>Native methods</summary>
            public class NativeMethods
            {
                /**//// <summary>Windows Message</summary>
                [StructLayout(LayoutKind.Sequential)]
                public struct Message
                {
                    public IntPtr hWnd;
                    public uint msg;
                    public IntPtr wParam;
                    public IntPtr lParam;
                    public uint time;
                    public System.Drawing.Point p;
                }            [System.Security.SuppressUnmanagedCodeSecurity]
                [DllImport("User32.dll", CharSet = CharSet.Auto)]
                public static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);
            }
      

  4.   

    System.Windows.Forms.Application.DoEvents();