A small piece of code related to message mapping

xiaoxiao2021-03-06  53

Here is specially there is a custom class, then there is a custom message in the CDialog dialog class. When this message is sent, it is called a function in the class defined, not the CDIALOG class. The function is. This requires the class you define to inherit CWnd. The specific code is as follows:

//Robot.cpp ----------------------------------------------------------------------------- ---------------------------------- //

#include "robot.h"

Lresult cspeech :: Recotive (WPARAM WPARAM, LPARAM LPARAM) {MessageBox ("Can send Message Now!"); Return true;

//Robot.h--------------------------------- -------------------------------------------------- -------------- / / # iFNDef Robot_H_ # define root_h_

#include "stdafx.h" // # include

Class cspeech: public cwnd {public: // method // cspeech (); // constructor // ~ cspeech ();

LResult Recognisition (WPARAM WPARAM, LPARAM LPARAM); Private: // Member};

#ENDIF

The above is the class defined.

The following code is to write in a dialog class file.

// tryclassdlg.cpp: Implement file ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------- //

BEGIN_MESSAGE_MAP (CtryClassDlg, CDialog) ON_WM_SYSCOMMAND () ON_WM_PAINT () ON_WM_QUERYDRAGICON () //}} AFX_MSG_MAP ON_MESSAGE (MYMESSAGE, CSpeech :: Recognisition) // this one is only added their own ON_BN_CLICKED (IDC_BUTTON1, OnBnClickedButton1)

Void CTRECLASSDLG :: OnbnclickedButton1 () {// Todo: Add control notification handler code sendMessage (MyMessage); // issued a message}

// tryclassdlg.h: header file ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------- //

#pragma overce

#define mymessage 1000 // If you don't conflict, you can have a macro, but I can't afford it.

#include "robot.h" is like this. :)

转载请注明原文地址:https://www.9cbs.com/read-73257.html

New Post(0)