×************************************* ON_COMMAND 响应菜单 按键 This macro is usually inserted in a message map by ClassWizard or manually. It indicates which function will handle a command message from a command user-interface object such as a menu item or toolbar button. When a command-target object receives a Windows WM_COMMAND message with the specified ID, ON_COMMAND will call the member function memberFxn to handle the message. ON_MESSAGE( message, memberFxn ) *************************************** ON_NOTIFY: Handling WM_NOTIFY Messages in MFC Applications ON_NOTIFY( wNotifyCode, id, memberFxn ) afx_msg void memberFxn( NMHDR * pNotifyStruct, LRESULT * result ); ************************** 响应自定义的消息 ON_MESSAGE( message, memberFxn ) **************************************** 2.消息的操作 ::SendMessage /*The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately. */
LRESULT SendMessage( HWND hWnd, // handle of destination window UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
SendDlgItemMessage The SendDlgItemMessage function sends a message to the specified control in a dialog box.
LONG SendDlgItemMessage( HWND hDlg, // handle of dialog box int nIDDlgItem, // identifier of control UINT Msg, // message to send WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );
DispatchMessage The DispatchMessage function dispatches a message to a window procedure. It is typically used to dispatch a message retrieved by the GetMessage function.
LONG DispatchMessage( CONST MSG *lpmsg // pointer to structure with message ); //////////////////////////////////////////////////////////////////////////// 三、消息解释 WM_CREATE 处理函数是OnCreate() 映射表ON_WM_CREATE() The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. 在该函数里面做一些初始化的时候,注意的是,如果处理消息,最好使用postmessage这样不至于影响,ONCREATE的 执行,一些依赖窗口处于完全激活状态的函数也不能在里面使用。视图类的OnIintUpdata是在窗口建立之后自动调用 可以在里面做一些初始化的工作
An application sends the WM_PAINT message when the system or another application makes a request to paint a portion of an application's window. The message is sent when the UpdateWindow or RedrawWindow function is called, or by theDispatchMessage function when the application obtains a WM_PAINT message by using theGetMessage orPeekMessage function 这个消息是WINDOWS发送最多的消息 Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.
文章评论(0条评论)
登录后参与讨论