|
马上注册登录,享用更多网站功能!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
前几天在网上看到一篇关于MFC树形控件在CATIA窗口上子例化的贴(https://bbs.csdn.net/topics/392061410?page=1)。根据原贴的提示,我在百度网盘的窗口也实现了一样的功能。现总结分享一下:
1.找到目标窗口的句柄:CWnd* pWnd= FindWindow(NULL, _T("欢迎使用百度网盘"));
2.在目标窗口上创建树形控件:m_TreeCtrl.Create(WS_VISIBLE | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES
| TVS_NOTOOLTIPS | TVS_EDITLABELS,
CRect(0, 100, 350, 600), pWnd, IDC_TREE1);
m_TreeCtrl.SetBkColor(RGB(230, 250, 250));
3.子例化树形控件:
3.1.设置树形控件窗口新的过程函数并保存原来的过程函数:oldProc = (WNDPROC)::SetWindowLong(g_pTreeCtrl->m_hWnd
, GWL_WNDPROC, (LONG)newProc);
3.2.把树形控件的原过程函数指针存储起来:SetProp(g_pTreeCtrl->m_hWnd, _T("MyProc"), oldProc);
3.3.定义树形控件新的过程函数体:
LRESULT CALLBACK newProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
// afxDump << Msg << "\r\n";
switch (Msg)
{
case WM_MOUSEMOVE://MN_MOUSEMOVE: not comes !
{
if (g_pWnd != NULL)
{
CString str;
CPoint point;
GetCursorPos(&point);//获得鼠标点击的位置
g_pWnd->ScreenToClient(&point);//转化为客户坐
int x = point.x;
int y = point.y;
str.Format(_T("当前坐标 x:%d,y:%d"), x, y);
//g_pWnd->SetWindowText(str);
HDC hDC = GetDC(g_pWnd->m_hWnd);
CDC *pDC = CDC::FromHandle(hDC);
pDC->Rectangle(0,0,300,30);
CRect rect = CRect(20,5,280,25);
pDC->DrawText(str, &rect,0);
//g_pTreeCtrl->Invalidate(TRUE);
//
}
//HWND hdlg = pWnd->GetSafeHwnd();
//
//afxDump << Msg << "\r\n";
break;
// only inside menu
}
case WM_LBUTTONDOWN://MN_BUTTONDOWN://
{
CString m_Lable;
CString str;
CPoint point;
GetCursorPos(&point);//获得鼠标点击的位置
g_pTreeCtrl->ScreenToClient(&point);//转化为客户坐标
UINT uFlags;
HTREEITEM CurrentItem;
CurrentItem = g_pTreeCtrl->HitTest(point, &uFlags);//获
m_Lable = g_pTreeCtrl->GetItemText(CurrentItem);
//AfxMessageBox(m_Lable);
int x = point.x;
int y = point.y;
HDC hDC = GetDC(g_pWnd->m_hWnd);
CDC *pDC = CDC::FromHandle(hDC);
pDC->Rectangle(0, 0, 280, 30);
CRect rect = CRect(20, 5, 270, 25);
pDC->DrawText(m_Lable, &rect, 0);
break;
}
case 0x01EF://MN_BUTTONUP://
//afxDump << Msg << "\r\n";
break;
case WM_DESTROY:
case WM_NCDESTROY:
oldProc = 0;
break;
}
return CallWindowProc((WNDPROC)::GetProp(hWnd, _T("MyProc")), hWnd, Msg, wParam, lParam);
}
4.实现的效果图片:F:\vs2013pro\MFC树形控件.PNG
|
|