Search Results

Search found 5 results on 1 pages for 'cmenu'.

Page 1/1 | 1 

  • Can I use MFC objects in STL containers?

    - by Jesse Stimpson
    The following code doesn't compile for me in MSVC2005: std::vector<CMenu> vec(10); CMenu is an MFC menu object (such as a context menu). Through some testing I learned that CMenu does not have a public copy constructor. To do what I wanted to do, I needed to use a dynamic array. CMenu* menus = new CMenu[10]; // ... delete [] menus; Of course, now I've lost all the benefits of using an STL container. Do I have any other options?

    Read the article

  • OnContextMenu() not working in view class

    - by Anu
    Hi, i have a popup menu for contextmenu.And i wrote the function for each menu in CMainframe. I have OnContextMenu() in each view class and in one dialog class.Its works fine in Dialog class.But not in View class.Codings are below: CMainframe funciton: void CMainFrame::OnUpdateFptrend(CCmdUI* pCmdUI) { ((CMainFrame *)AfxGetMainWnd())->SendMessage(WM_COMMAND,ID_TRENDVIEW,NULL); } void CMainFrame::OnUpdateFptuning(CCmdUI* pCmdUI) { ((CMainFrame *)AfxGetMainWnd())->SendMessageWM_COMMAND,ID_TUNINGVIEW,NULL); } Dialog class Contextmenu: void CFacePlate::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu mnuPopup; mnuPopup.LoadMenu(IDR_FPMENU); CRect rBarRect; rBarRect.left = rBarRect.top = 0; rBarRect.right = 1000;rBarRect.bottom = 300; CMenu *mnuPopupMenu = mnuPopup.GetSubMenu(0); ASSERT(mnuPopupMenu); if( rBarRect.PtInRect(point) ) mnuPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); } View class: void CGroupView::OnContextMenu(CWnd* pWnd, CPoint point) { CMenu mnuPopup; mnuPopup.LoadMenu(IDR_FPMENU); CRect rBarRect; rBarRect.left = rBarRect.top = 0; rBarRect.right = 1150;rBarRect.bottom = 390; CMenu *mnuPopupMenu = mnuPopup.GetSubMenu(0); ASSERT(mnuPopupMenu); if( rBarRect.PtInRect(point) ) mnuPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this); } When i press popup menu from Faceplate(Dialogclass),it goes to Mainframe function.At the same time when i press menu from any view class,it doesnot go to Mainframe function.Why its like that?

    Read the article

  • WPF - Redrawing a Context Menu when Items change?

    - by Rachel
    I have a ItemsControl in a ScrollViewer, and when the items exceed the width of the ScrollViewer they are put into a ContextMenu and shown as a DropDown instead. My problem is that when the Context Menu is first loaded, it saves the saves the size of the Menu and does not redraw when more commands get added/removed. For example, a panel has 3 commands. 1 is visible and 2 are in the Menu. Viewing the menu shows the 2 commands and draws the control, but then if you resize the panel so 2 are visible and only 1 command is in the menu, it doesn't redraw the menu to eliminate that second menu item. Or even worse, if you shrink the panel so that no commands are shown and all 3 are in the Menu, it will only show the top 2. Here's my code: <Button Click="DropDownMenu_Click" ContextMenuOpening="DropDownMenu_ContextMenuOpening"> <Button.ContextMenu> <ContextMenu ItemsSource="{Binding Path=MenuCommands}" Placement="Bottom"> <ContextMenu.Resources> <Style TargetType="{x:Type MenuItem}"> <Setter Property="Command" Value="{Binding Path=Command}" /> <Setter Property="Visibility" Value="{Binding Path=IsVisible, Converter={StaticResource ReverseBooleanToVisibilityConverter}}"/> </Style> </ContextMenu.Resources> <ContextMenu.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=DisplayName}" /> </DataTemplate> </ContextMenu.ItemTemplate> </ContextMenu> </Button.ContextMenu> </Button> Code Behind: void DropDownMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e) { Button b = sender as Button; b.ContextMenu.IsOpen = false; e.Handled = true; } private void DropDownMenu_Click(object sender, RoutedEventArgs e) { Button b = sender as Button; ContextMenu cMenu = b.ContextMenu; if (cMenu != null) { cMenu.PlacementTarget = b; cMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom; } } I have tried using InvalidateVisual and passing an empty delegate on Render to try and force a redraw, however neither works. I'm using .Net 4.0.

    Read the article

  • mfc tab control switch tabs

    - by MRM
    I created a simple tab control that has 2 tabs (each tab is a different dialog). The thing is that i don't have any idea how to switch between tabs (when the user presses Titlu Tab1 to show the dialog i made for the first tab, and when it presses Titlu Tab2 to show my other dialog). I added a handler for changing items, but i don't know how should i acces some kind of index or child for tabs. Tab1.h and Tab2.h are headers for dialogs that show only static texts with the name of the each tab. There may be an obvious answer to my question, but i am a real newbie in c++ and MFC. This is my header: // CTabControlDlg.h : header file // #pragma once #include "afxcmn.h" #include "Tab1.h" #include "Tab2.h" // CCTabControlDlg dialog class CCTabControlDlg : public CDialog { // Construction public: CCTabControlDlg(CWnd* pParent = NULL); // standard constructor // Dialog Data enum { IDD = IDD_CTABCONTROL_DIALOG }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: HICON m_hIcon; // Generated message map functions virtual BOOL OnInitDialog(); afx_msg void OnSysCommand(UINT nID, LPARAM lParam); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); DECLARE_MESSAGE_MAP() public: CTabCtrl m_tabcontrol1; CTab1 m_tab1; CTab2 m_tab2; afx_msg void OnTcnSelchangeTabcontrol(NMHDR *pNMHDR, LRESULT *pResult); }; And this is the .cpp: // CTabControlDlg.cpp : implementation file // #include "stdafx.h" #include "CTabControl.h" #include "CTabControlDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CCTabControlDlg dialog CCTabControlDlg::CCTabControlDlg(CWnd* pParent /*=NULL*/) : CDialog(CCTabControlDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CCTabControlDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_TABCONTROL, m_tabcontrol1); } BEGIN_MESSAGE_MAP(CCTabControlDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_NOTIFY(TCN_SELCHANGE, IDC_TABCONTROL, &CCTabControlDlg::OnTcnSelchangeTabcontrol) END_MESSAGE_MAP() // CCTabControlDlg message handlers BOOL CCTabControlDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(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 application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here CTabCtrl* pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TABCONTROL); m_tab1.Create(IDD_TAB1, pTabCtrl); TCITEM item1; item1.mask = TCIF_TEXT | TCIF_PARAM; item1.lParam = (LPARAM)& m_tab1; item1.pszText = _T("Titlu Tab1"); pTabCtrl->InsertItem(0, &item1); //Pozitionarea dialogului CRect rcItem; pTabCtrl->GetItemRect(0, &rcItem); m_tab1.SetWindowPos(NULL, rcItem.left, rcItem.bottom + 1, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); m_tab1.ShowWindow(SW_SHOW); // al doilea tab m_tab2.Create(IDD_TAB2, pTabCtrl); TCITEM item2; item2.mask = TCIF_TEXT | TCIF_PARAM; item2.lParam = (LPARAM)& m_tab1; item2.pszText = _T("Titlu Tab2"); pTabCtrl->InsertItem(0, &item2); //Pozitionarea dialogului //CRect rcItem; pTabCtrl->GetItemRect(0, &rcItem); m_tab2.SetWindowPos(NULL, rcItem.left, rcItem.bottom + 1, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); m_tab2.ShowWindow(SW_SHOW); return TRUE; // return TRUE unless you set the focus to a control } void CCTabControlDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == 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. void CCTabControlDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CCTabControlDlg::OnQueryDragIcon() { return static_cast<HCURSOR>(m_hIcon); } void CCTabControlDlg::OnTcnSelchangeTabcontrol(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: Add your control notification handler code here *pResult = 0; }

    Read the article

1