Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Kontextmenü erstellen

Empfohlene Antworten

Hallo,

wie kann ich mittels MFC ein Kontextmenü erstellen, das erscheint, wenn mein RichEdit mit der rechten Maustaste angeklickt wird?

Gruß,

Technician


void CProgDlg::OnContextMenu(CWnd* pWnd, CPoint point)
{
// Lokale Variablen deklarieren
CMenu *m_lMenu; // Zeiger auf Menü
CPoint m_pPoint; // Kopie der Mausposition

// Mausposition in lokale Variable kopieren
m_pPoint = point;
// Zeiger auf Fenstermenü holen
m_lMenu = GetMenu();
// Zeiger auf erstes Untermenü holen
m_lMenu = m_lMenu->GetSubMenu(0);
// Popup-Menü anzeigen
m_lMenu->TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,
m_pPoint.x, m_pPoint.y, this, NULL);
}

[/PHP]

hast Du so versucht ?!?!?

Hallo,

ich habe IDR_KONTEXTMENUE als eigenes Menü angelegt (also nicht als Untermenü).



void CSandorfCode::OnContextMenu(CWnd* pWnd, CPoint point) 

{


    CMenu *m_lMenu; 

    CPoint m_pPoint;


     m_pPoint = point;


     // Zeiger auf anzuzeigendes Menü

    m_lMenu->LoadMenu(IDR_KONTEXTMENUE);

    // Popup-Menü anzeigen

    m_lMenu->TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,

 m_pPoint.x, m_pPoint.y, this, NULL);



}


Hier gibt es allerdings in der Zeile m_lMenu->LoadMenu(IDR_KONTEXTMENUE) einen Fehler, da ja m_lMenu nicht initialisiert ist.

aber mit welchem Wert soll der Zeiger initialisiert werden?! :confused:

Gruß,

Technician

... so funktioniert's zwar - aber das Kontextmenü wird nur als schmaler Streifen angezeigt. Genau so hoch, wie das Menü sein sollte - aber nur ca. 20 Pixel breit :(

Woran kann das liegen?!



void CSandorfCode::OnContextMenu(CWnd* pWnd, CPoint point) 

{

     CPoint m_pPoint; // Kopie der Mausposition

     Mausposition in lokale Variable kopieren

     m_pPoint = point;


     CMenu menu;

     menu.LoadMenu(IDR_KONTEXTMENUE);

     menu.TrackPopupMenu(TPM_CENTERALIGN + TPM_LEFTBUTTON,

     m_pPoint.x, m_pPoint.y, this, NULL);

}


Hi,

ich hab folgenden Code in der MSDN gefunden:


CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU1));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, x, y, AfxGetMainWnd());
[/PHP]

Probier`s mal damit aus.

Gruß

Guybrush

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Konto

Navigation

Suchen

Suchen

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.