LRESULT CMainWindow::OnTVSelChanged(int, LPNMHDR pnmh, BOOL&) { // 如何解析参数 LPNMTREEVIEW pnmtv = reinterpret_cast<LPNMTREEVIEW>(pnmh); CTreeViewCtrlEx tree = pnmh->hwndFrom; if (tree.IsWindow()) { CTreeItem item = tree.GetSelectedItem(); std::string path; for (; !item.IsNull(); item = item.GetParent()) { std::string name(256, 0); item.GetText((LPTSTR)name.c_str(), 256); std::string temp = name.c_str(); if (!path.empty()) { path = temp + "/" + path; } else { path = temp; } } // m_wndStatusBar.SetPaneText(ID_DEFAULT_PANE, TEXT(path.c_str())); // mViewWindow.changeModelFile(path); } return 0L; }
LRESULT CMainFrame::OnTVSelChanged(int, LPNMHDR pnmh, BOOL&) { // 如何解析参数 LPNMTREEVIEW pnmtv = reinterpret_cast<LPNMTREEVIEW>(pnmh); CTreeViewCtrlEx tree = pnmh->hwndFrom; if (tree.IsWindow()) { CTreeItem item = tree.GetSelectedItem(); std::string path; for (; !item.IsNull() && !item.GetParent().IsNull(); item = item.GetParent()) { std::string name(256, 0); item.GetText((LPTSTR)name.c_str(), 256); std::string temp = name.c_str(); if (!path.empty()) { path = temp + "/" + path; } else { path = temp; } } // if (_canvas) { path = Buddha::FileSystem::getInstancePtr()->getDataDirectory() + path; _canvas->changeModelFile(standardFilePath(path)); } } return 0L; }
LRESULT CMainFrame::OnTVSelChanged(int, LPNMHDR pnmh, BOOL&) { // 如何解析参数 { LPNMTREEVIEW pnmtv = reinterpret_cast<LPNMTREEVIEW>(pnmh); CTreeViewCtrlEx tree = pnmh->hwndFrom; if (tree.IsWindow()) { CTreeItem item = tree.GetSelectedItem(); std::string name(256, 0); item.GetText((LPTSTR)name.c_str(), 256); // 如何插入列表 int r = rand(); m_wndListView.SetTextColor((DWORD)r); static int i = 0; if (0 == m_wndListView.GetItemCount()) { m_wndListView.InsertItem(i, "ok"); } m_wndListView.SetItemText(i, 0, name.c_str()); m_wndListView.SetItemText(i, 1, "1"); m_wndListView.SetItemText(i, 2, "2"); //++i; } } return 0L; }
LRESULT CRawFileListView::OnTvnSelchanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled) { CTreeViewCtrlEx* treeview = reinterpret_cast<CTreeViewCtrlEx*>(pnmh); CTreeItem treeitem = treeview->GetSelectedItem(); //fileView.SetCurFile((RawFile*)treeitem.GetData()); bHandled = false; return 0; }
LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { // Check if Common Controls 6.0 are used. If yes, use 32-bit (alpha) images // for the toolbar and command bar. If not, use the old, 4-bit images. UINT uResID = IDR_MAINFRAME_OLD; DWORD dwMajor = 0; DWORD dwMinor = 0; HRESULT hRet = AtlGetCommCtrlVersion(&dwMajor, &dwMinor); if(SUCCEEDED(hRet) && dwMajor >= 6) uResID = IDR_MAINFRAME; // Set values to be displayed in the view window m_view.m_dwCommCtrlMajor = dwMajor; m_view.m_dwCommCtrlMinor = dwMinor; m_view.m_bAlpha = (uResID == IDR_MAINFRAME); // create command bar window HWND hWndCmdBar = m_CmdBar.Create(m_hWnd, rcDefault, NULL, ATL_SIMPLE_CMDBAR_PANE_STYLE); // attach menu m_CmdBar.AttachMenu(GetMenu()); // load command bar images m_CmdBar.LoadImages(uResID); // remove old menu SetMenu(NULL); HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd, uResID, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE); CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE); AddSimpleReBarBand(hWndCmdBar); AddSimpleReBarBand(hWndToolBar, NULL, TRUE); CreateSimpleStatusBar(); m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE); UIAddToolBar(hWndToolBar); UISetCheck(ID_VIEW_TOOLBAR, 1); UISetCheck(ID_VIEW_STATUS_BAR, 1); // register object for message filtering and idle updates CMessageLoop* pLoop = _Module.GetMessageLoop(); ATLASSERT(pLoop != NULL); pLoop->AddMessageFilter(this); pLoop->AddIdleHandler(this); UIEnable(ID_EDIT_PASTE, FALSE); // CTreeViewCtrlEx tc; tc.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE); // _canvas = new Canvas(m_hWndClient); // return 0; }
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos) { int selectedItemData; // get selectedItemData CRect rect; CPoint posInView; HTREEITEM hItemSelected; // if clicked on tree, we need to change selection if (m_viewTreeList.GetWindowRect( rect ) && rect.PtInRect(pos) ) { CTreeViewCtrlEx ctrlTree = m_viewTreeList.GetTreeControl(); CHeaderCtrl ctrlHeader = m_viewTreeList.GetHeaderControl(); CRect rectHeader; ctrlHeader.GetClientRect(rectHeader); // clicked point is inside the tree control // Change screen coordinates to client coordinates posInView = pos - rect.TopLeft(); posInView.y -= rectHeader.Height(); if(hItemSelected = ctrlTree.HitTest(posInView, NULL)) { ctrlTree.SelectItem(hItemSelected); } } CNBDevice *pDevice = m_viewTreeList.GetSelectedDevice(); if(!pDevice) return; CMenu menu; CMenuHandle subMenu; menu.LoadMenu(IDR_MAINFRAME); subMenu = menu.GetSubMenu(1); // Tool subMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pos.x, pos.y, m_hWnd ); return; }
void TreeViewWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT rtUI = {0}; DWORD dwStyle = WS_CHILD | WS_VISIBLE |TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_INFOTIP | WS_BORDER | WS_HSCROLL | WS_TABSTOP |TVS_SHOWSELALWAYS; treeControl.Create(this->m_hWnd, &rtUI, _T(""), dwStyle, 0, IDC_TREEVIEWWND, NULL); assert(treeControl.m_hWnd); RECT rtParent = pOwner->GetPos(); // 由于treeControl作为子窗口存在,附着于父窗口的刷新,所以这里不用SetWinodwPos而用MoveWindow ::MoveWindow(treeControl.m_hWnd, rtParent.left, rtParent.top, rtParent.right - rtParent.left, rtParent.bottom - rtParent.top, TRUE); }
void CMainFrame::OnContextMenu(HWND /*hWnd*/, CPoint pos) { if(m_bRefreshing) return; ENTER_CRITICAL_SECTION(&m_csThreadRefreshStatus); int selectedItemData; // get selectedItemData CRect rect; CPoint posInView; HTREEITEM hItemSelected; // if clicked on tree, we need to change selection if (m_viewTreeList.GetWindowRect( rect ) && rect.PtInRect(pos) ) { CTreeViewCtrlEx ctrlTree = m_viewTreeList.GetTreeControl(); CHeaderCtrl ctrlHeader = m_viewTreeList.GetHeaderControl(); CRect rectHeader; ctrlHeader.GetClientRect(rectHeader); // clicked point is inside the tree control // Change screen coordinates to client coordinates posInView = pos - rect.TopLeft(); posInView.y -= rectHeader.Height(); if(NULL == (hItemSelected = ctrlTree.HitTest(posInView, NULL))) { LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); return; } ctrlTree.SelectItem(hItemSelected); } selectedItemData = m_viewTreeList.GetSelectedItemData(); // Display context menu CMenu menu; CMenuHandle subMenu; CDiskObjectPtr obj = m_mapObject[selectedItemData]; ATLASSERT( obj.get() != NULL ); menu.LoadMenu( MAKEINTRESOURCE(IDR_CONTEXT_MENU) ); subMenu = menu.GetSubMenu(0); CObjectUIHandler::GetUIHandler(obj)->InsertMenu(obj, subMenu); ATLTRACE(_T("Menu Count : %d"), subMenu.GetMenuItemCount()); subMenu.RemoveMenu(IDM_AGGR_PROPERTY, MF_BYCOMMAND); // subMenu.RemoveMenu(MF_BYPOSITION, subMenu.GetMenuItemCount()); subMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pos.x, pos.y, m_hWnd ); LEAVE_CRITICAL_SECTION(&m_csThreadRefreshStatus); return; }