2026/2/20 6:39:56
网站建设
项目流程
电商网站联盟平台,世界著名的设计公司,苏州保洁公司哪家比较好,网站引导页下载点击按钮将一个int数据用PostMessage消息投递给出去#xff0c;弹出MessagBox显示这个数据。核心代码如下。
头文件#define WM_MY_MESSAGE (WM_USER 200)afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);实现文件
ON_MESSAGE(WM_MY_MESSAGE, OnMyMessage)PostMes…点击按钮将一个int数据用PostMessage消息投递给出去弹出MessagBox显示这个数据。核心代码如下。头文件#defineWM_MY_MESSAGE(WM_USER200)afx_msg LRESULTOnMyMessage(WPARAM wParam,LPARAM lParam);实现文件ON_MESSAGE(WM_MY_MESSAGE,OnMyMessage)PostMessage(WM_MY_MESSAGE,60,0);LRESULTCMyDlg::OnMyMessage(WPARAM wParam,LPARAM lParam){intnValue(int)wParam;CString strInfo;strInfo.Format(%d,nValue);MessageBox(strInfo);return0;}完整代码Simple_PostMessageDlg.h// Simple_PostMessageDlg.h : header file//#defineWM_MY_MESSAGE(WM_USER200)#if!defined(AFX_SIMPLE_POSTMESSAGEDLG_H__F9AE712A_93C4_41DB_9DBF_3F981ECB8C6E__INCLUDED_)#defineAFX_SIMPLE_POSTMESSAGEDLG_H__F9AE712A_93C4_41DB_9DBF_3F981ECB8C6E__INCLUDED_#if_MSC_VER1000#pragmaonce#endif// _MSC_VER 1000/////////////////////////////////////////////////////////////////////////////// CSimple_PostMessageDlg dialogclassCSimple_PostMessageDlg:publicCDialog{// Constructionpublic:CSimple_PostMessageDlg(CWnd*pParentNULL);// standard constructor// Dialog Data//{{AFX_DATA(CSimple_PostMessageDlg)enum{IDDIDD_SIMPLE_POSTMESSAGE_DIALOG};// NOTE: the ClassWizard will add data members here//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CSimple_PostMessageDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);// DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected:HICON m_hIcon;// Generated message map functions//{{AFX_MSG(CSimple_PostMessageDlg)virtualBOOLOnInitDialog();afx_msgvoidOnSysCommand(UINT nID,LPARAM lParam);afx_msgvoidOnPaint();afx_msg HCURSOROnQueryDragIcon();afx_msgvoidOnButton1();afx_msg LRESULTOnMyMessage(WPARAM wParam,LPARAM lParam);//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C will insert additional declarations immediately before the previous line.#endif// !defined(AFX_SIMPLE_POSTMESSAGEDLG_H__F9AE712A_93C4_41DB_9DBF_3F981ECB8C6E__INCLUDED_)Simple_PostMessageDlg.cpp// Simple_PostMessageDlg.cpp : implementation file//#includestdafx.h#includeSimple_PostMessage.h#includeSimple_PostMessageDlg.h#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]__FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App AboutclassCAboutDlg:publicCDialog{public:CAboutDlg();// Dialog Data//{{AFX_DATA(CAboutDlg)enum{IDDIDD_ABOUTBOX};//}}AFX_DATA// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CAboutDlg)protected:virtualvoidDoDataExchange(CDataExchange*pDX);// DDX/DDV support//}}AFX_VIRTUAL// Implementationprotected://{{AFX_MSG(CAboutDlg)//}}AFX_MSGDECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){//{{AFX_DATA_INIT(CAboutDlg)//}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg)//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)//{{AFX_MSG_MAP(CAboutDlg)// No message handlers//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CSimple_PostMessageDlg dialogCSimple_PostMessageDlg::CSimple_PostMessageDlg(CWnd*pParent/*NULL*/):CDialog(CSimple_PostMessageDlg::IDD,pParent){//{{AFX_DATA_INIT(CSimple_PostMessageDlg)// NOTE: the ClassWizard will add member initialization here//}}AFX_DATA_INIT// Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIconAfxGetApp()-LoadIcon(IDR_MAINFRAME);}voidCSimple_PostMessageDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(CSimple_PostMessageDlg)// NOTE: the ClassWizard will add DDX and DDV calls here//}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CSimple_PostMessageDlg,CDialog)//{{AFX_MSG_MAP(CSimple_PostMessageDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON1,OnButton1)ON_MESSAGE(WM_MY_MESSAGE,OnMyMessage)//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CSimple_PostMessageDlg message handlersBOOLCSimple_PostMessageDlg::OnInitDialog(){CDialog::OnInitDialog();// Add About... menu item to system menu.// IDM_ABOUTBOX must be in the system command range.ASSERT((IDM_ABOUTBOX0xFFF0)IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX0xF000);CMenu*pSysMenuGetSystemMenu(FALSE);if(pSysMenu!NULL){CString strAboutMenu;strAboutMenu.LoadString(IDS_ABOUTBOX);if(!strAboutMenu.IsEmpty()){pSysMenu-AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);}}// Set the icon for this dialog. The framework does this automatically// when the applications main window is not a dialogSetIcon(m_hIcon,TRUE);// Set big iconSetIcon(m_hIcon,FALSE);// Set small icon// TODO: Add extra initialization herereturnTRUE;// return TRUE unless you set the focus to a control}voidCSimple_PostMessageDlg::OnSysCommand(UINT nID,LPARAM lParam){if((nID0xFFF0)IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialog::OnSysCommand(nID,lParam);}}// If you add a minimize button to your dialog, you will need the code below// to draw the icon. For MFC applications using the document/view model,// this is automatically done for you by the framework.voidCSimple_PostMessageDlg::OnPaint(){if(IsIconic()){CPaintDCdc(this);// device context for paintingSendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);// Center icon in client rectangleintcxIconGetSystemMetrics(SM_CXICON);intcyIconGetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(rect);intx(rect.Width()-cxIcon1)/2;inty(rect.Height()-cyIcon1)/2;// Draw the icondc.DrawIcon(x,y,m_hIcon);}else{CDialog::OnPaint();}}// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSORCSimple_PostMessageDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCSimple_PostMessageDlg::OnButton1(){PostMessage(WM_MY_MESSAGE,60,0);}LRESULTCSimple_PostMessageDlg::OnMyMessage(WPARAM wParam,LPARAM lParam){intnValue(int)wParam;CString strInfo;strInfo.Format(%d,nValue);MessageBox(strInfo);return0;}运行程序