你为什么要将wndTree的父窗口指定为m_Button呢?指定成Dlg不就得了?
解决方案 »
- cchildframe,cview的大小关联问题
- 一个Ping连续IP地址段的问题
- 超难的问题:使用ASP.NET URL重写后ISAPI不能执行
- 在EditBox中写入数行文字,要求将其中某一段文字变成红色,如何实现?
- 请大家帮忙阿:在CComboBox的DATA属性里写的值不能显示。
- 谁有<文件签名系统>的资料啊?
- 关于CEditView的解决方案
- 我的程序是否可以截获别的程序修改注册表?
- 请问如何得知当前是字符输入还是汉字输入状态,即汉字输入法有没有打开
- 代号 红心闪闪 4月19日晚8点攻击cnn网站
- prog_st(st)我如何更新VC,因为最新的有些函数它不认得
- 我下载了一个FC上的炸弹超人的世嘉版,他的文件名是M-BOMB.SMD???????
中的第一个参数 "ksjdk" 去掉试试,可能你的BUTTON没有创建成功2、你的消息映射可能你问题
让button 的OnSelchangedTree传递给dlg
to beni() 我怎样才能传递呢?
不错,是我看错了,我以前是类名呢!在自定义的BUTTON类中收到消息后,转发给父窗口就行了!
从CTreeXXX派生新类,在新类中添加消息,这时你会看到在VC的消息映射对话框中多了几个前面有“=”号的消息,其中有TVN_SELCHANGED,点中这个反射消息进行处理就行了
在你的button类的OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult) 里用SendMessage什么的发给dlg
是Julienjut(秋水) 所说
>_<
但在此我要解决的是如何让CDlg收到wndTree发出的消息。
wndTree.SetOwner(this);
SetOwner()的确不行。
那就试试SetParent()吧。
我试了一下,SetParent()也是不行的。不好意思!
// MyButton.cpp : implementation file
//#include "stdafx.h"
#include "testagain.h"
#include "MyButton.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyButtonCMyButton::CMyButton()
{
}CMyButton::~CMyButton()
{
}
BEGIN_MESSAGE_MAP(CMyButton, CButton)
//{{AFX_MSG_MAP(CMyButton)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyButton message handlersBOOL CMyButton::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
// TODO: Add your specialized code here and/or call the base class
int idCtrl = (int) wParam;
if (WM_USER+101==idCtrl)
{
LPNMHDR pnmh = (LPNMHDR) lParam;
if (TVN_SELCHANGED==pnmh->code)
{
int nRet=::SendMessage(GetParent()->m_hWnd,WM_USER+102,(WPARAM)wParam,(LPARAM)lParam);
}
}
return CButton::OnNotify(wParam, lParam, pResult);
}///////////////////////////////////////////////////
//下面是父窗口里的处理
BEGIN_MESSAGE_MAP(CTestagainDlg, CDialog)
//{{AFX_MSG_MAP(CTestagainDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_MESSAGE(WM_USER+102,OnNotifyMsg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CTestagainDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CMyButton *pButton=new CMyButton;
CRect rect(40,40,180,180);
CRect rect2(0,0,140,140);
pButton->Create("New",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect,this,WM_USER+100);
CTreeCtrl *pTree=new CTreeCtrl;
pTree->Create(WS_CHILD|WS_VISIBLE,rect2,pButton,WM_USER+101);
pTree->InsertItem("Second");
pTree->InsertItem("first");
m_nTreeCtrl.InsertItem("First");
m_nTreeCtrl.InsertItem("Second");
pButton->ShowWindow(SW_SHOWNORMAL);
pTree->ShowWindow(SW_SHOWNORMAL);
}
void CTestagainDlg::OnNotifyMsg(WPARAM wParam,LPARAM lParam)
{
AfxMessageBox("asdlfkjas;df");
}
在其中处理WM_NOFIFY()消息,如果是新建的TREECTRL的消息则转发给其父窗口。
(其中有一个问题,在消息映射中没有ON_MESSAGE(WM_NOTIFY)之类的语句,不知为什么)
在爷爷窗口的OnButton1()中创建一个BUTTON,一个TreeCtrl,并加入了一些数据
在OnNotifyMsg()进行想要的操作就可以了
#define IDC_TREE 1000
//之所以在Resource.h写,是使IDC_TREE在MyButton.cpp和Dlg.cpp中都起作用.//MyButton.cpp
#include "Resource.h"BEGIN_MESSAGE_MAP(CMyButton, CButton)
//{{AFX_MSG_MAP(CMyButton)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CGfxOutBarCtrl::OnSelchangedTree()
{
GetOwner()->SendMessage(TVN_SELCHANG,0,0);
}//MyButton.h
#define TVN_SELCHANG WM_USER + 10
protected:
//{{AFX_MSG(CGfxOutBarCtrl)
//}}AFX_MSG
afx_msg void OnSelchangedTree();
DECLARE_MESSAGE_MAP()// Dlg.cpp
#include "Resource.h"
BEGIN_MESSAGE_MAP(CDlg, CDialog)
ON_MESSAGE(TVN_SELCHANG, OnSelchangedTree)
END_MESSAGE_MAP()int CDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_Botton.Create("ksjdk",WS_CHILD|WS_VISIBLE,CRect(5,5,215,215),this,VIEW_BOTTON);
wndTree.Create(WS_CHILD|WS_VISIBLE, CRect(10,10,200,200), &m_botton, IDC_TREE);
return 0;
}
void CDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
AfxMessageBox("asdlfkjas;df");
}// Dlg.h
#define VIEW_BOTTON 3016
class CDlg: public CDialog
{
public:
CTreeCtrl wndTree;
CButton m_botton;
protected:
//{{AFX_MSG(CDlg)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//Resource.h
#define IDC_TREE 1000
//之所以在Resource.h写,是使IDC_TREE在MyButton.cpp和Dlg.cpp中都起作用.
//MyButton.cpp
#include "Resource.h"BEGIN_MESSAGE_MAP(CMyButton, CButton)
//{{AFX_MSG_MAP(CMyButton)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE, OnSelchangedTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CMyButton::OnSelchangedTree()
{
GetOwner()->SendMessage(TVN_SELCHANG,0,0);
}//MyButton.h
#define TVN_SELCHANG WM_USER + 10
protected:
//{{AFX_MSG(CMyButton)
//}}AFX_MSG
afx_msg void OnSelchangedTree();
DECLARE_MESSAGE_MAP()// Dlg.cpp
#include "Resource.h"
BEGIN_MESSAGE_MAP(CDlg, CDialog)
ON_MESSAGE(TVN_SELCHANG, OnSelchangedTree)
END_MESSAGE_MAP()int CDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_Botton.Create("ksjdk",WS_CHILD|WS_VISIBLE,CRect(5,5,215,215),this,VIEW_BOTTON);
wndTree.Create(WS_CHILD|WS_VISIBLE, CRect(10,10,200,200), &m_botton, IDC_TREE);
return 0;
}
void CDlg::OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
AfxMessageBox("asdlfkjas;df");
}// Dlg.h
#define VIEW_BOTTON 3016
class CDlg: public CDialog
{
public:
CTreeCtrl wndTree;
CButton m_botton;
protected:
//{{AFX_MSG(CDlg)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSelchangedTree(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};