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.

Empfohlene Antworten

Veröffentlicht

Hallo,

ich möchte ein RichEdit-Feld mit einem Kontext-Menü versehen, und im RichEdit markierten Text herauskopieren können.

Wie mache ich das?

Gruß,

Technician

  • 1 Monat später...

Hallo,

dieser Thread ist schon etwas länger, aber ich hatte mich in der Zwischenzeit nicht mit dem Problem befasst.

Folgender Code funktioniert einwandfrei, um ein Kontextmenü über dem Button IDC_BUTTON1 anzeigen zu lassen:


	CMenu mnuPopupSubmit;

	mnuPopupSubmit.LoadMenu(IDR_CONSCONT);


	CButton *pButton;

	pButton = reinterpret_cast<CButton *>(GetDlgItem(IDC_BUTTON1));


	CRect rectSubmitButton;

	pButton->GetWindowRect(&rectSubmitButton);


	CMenu *mnuPopupMenu = mnuPopupSubmit.GetSubMenu(0);


	if( rectSubmitButton.PtInRect(point) ) // Since the user right-clicked the button, display the context menu

		mnuPopupSubmit.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

Nun will ich denselben Effekt natürlich bei einem RichEdit-Feld erreichen. Der Code lautet:

CMenu mnuPopupSubmit;

	mnuPopupSubmit.LoadMenu(IDR_CONSCONT);


	CRichEditCtrl* pCtrl;

	pCtrl = (CRichEditCtrl*)GetDlgItem(IDC_CONSOLE);


	CRect rectSubmitButton;

	pCtrl->GetWindowRect(&rectSubmitButton);


	CMenu *mnuPopupMenu = mnuPopupSubmit.GetSubMenu(0);

	//ASSERT(mnuPopupMenu);


	// Find out if the user right-clicked the button

	// because we are interested only in the button

	if( rectSubmitButton.PtInRect(point) ) // Since the user right-clicked the button, display the context menu

	{	mnuPopupSubmit.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);


	}

Mein Problem ist folgendes:

Wenn ich ins RichEdit-Feld klicke, wird dieses markiert (I-Cursor erscheint und ich kann etwas ins RichEdit-Feld eintippen) und wenn der I-Cursor im Feld ist, kann kein Kontextmenü angezeigt werden.

Denselben Effekt habe ich auch, wenn ich ein "programmweites Kontextmenü", also eines das nicht auf einen bestimmten Bereich beschränkt ist, habe: es funktioniert überall, nur nicht im RichEdit-Feld.

An der Event-Mask kann es nicht liegen:

pCtrl = (CRichEditCtrl*)GetDlgItem(IDC_CONSOLE);

lMask = pCtrl->GetEventMask();

lMask |= ENM_CHANGE;

lMask |= ENM_KEYEVENTS;

lMask |= ENM_MOUSEEVENTS;

pCtrl->SetEventMask(lMask);

Wie kann ich dieses Problem lösen?

(Nochmal zum Ausgangsproblem: Text in RichEdit-Feld markiert, Rechtsklick soll Kontextmenü anzeigen. Markierung darf also nicht verloren gehen. Soll genauso funktionieren wie man das z.B. von Textverarbeitungsprogrammen kennt.)

Viele Grüße,

Technician

*hoffend*

Nagut dann hab ich nen anderen Link der dir evtl. weiterhilft :D

Klick mich

Vielen Dank - das ging ja flott :)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

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.