Print Page | Close Window

TrackPopupMenu Markup

Printed From: Codejock Forums
Category: General
Forum Name: XAML Snippets
Forum Description: Post your XAML snippets here for everyone to enjoy :)
URL: http://forum.codejock.com/forum_posts.asp?TID=13645
Printed Date: 06 May 2024 at 9:30pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: TrackPopupMenu Markup
Posted By: BobWansink
Subject: TrackPopupMenu Markup
Date Posted: 11 March 2009 at 7:44am
Hi,

we've added a Contextmenu to our markupcode. Example:

<TextBlock MouseRightButtonDown="ShowMenu">bla</TextBlock>

with function ShowMenu:

CMenu men;
men.CreatePopupMenu();
  men.AppendMenu(MF_STRING, 100, "Bla");
men.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,this);

// x and y are fixed, not GetCursorPos(); I want the menu to display at a specific location.

If I click outside the menu with the left mousebutton, the menu disappears. Rightclicking outside the menu DOESN'T makes the menu disappear, but the ShowMenu function is immediately excecuted. This means the menu is .

What can i do to make the menu disappear on both buttons?

I think this has something to do with RightMouseButtonDown being excecuted again, even though the mouse has moved away from the element that called it. I've tried pArgs->SetHandled(), but that was to no avail.

I'd appreciate any help.

Thanks!


-------------
     Product: Xtreme ToolkitPro (MFC) version 13.0.0
     Platform: Windows (32bit) - XP - Vista
     Language: Visual C++



Replies:
Posted By: Oleg
Date Posted: 12 March 2009 at 2:27am
Hi,
 
Need to test. Show related code.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: BobWansink
Date Posted: 12 March 2009 at 3:47am
// XAML
            <Border Style="{StaticResource TabButtonBorder}">
            <Border Style="{StaticResource TabButton}">
                <StackPanel Orientation="Horizontal">
                    <Image Style="{StaticResource ImageStyle}" Source="file://images/nieuweversie.png"/>
                    <TextBlock MouseRightButtonDown="ShowContextMenu" Margin="5,7,16,0">Boe</TextBlock>
                </StackPanel>
            </Border>
            </Border>
//

// class ProjectCentrumXAMLPanel : public ZXAMLPanel
// class ZXAMLPanel : public ZPanel, public CXTPMarkupContext


void ProjectCentrumXAMLPanel::RightClickOnElement(CXTPMarkupObject * pSender, CXTPMarkupMouseButtonEventArgs* pArgs)
{
  CXTPMarkupBorder * pEl = (CXTPMarkupBorder *) pSender;
  pArgs->SetHandled();
  this->makeContextMenu(pEl);
}



void ZXAMLPanel::makeContextMenu(CXTPMarkupInputElement * pEl)
{

  CRect r1(0,0,0,0);
  this->GetWindowRect(r1);
  elementDatRechterMuisMenuOpriep = pEl;
  CRect r = this->GetClientBoundingRect(pEl);

  CPoint pt(r1.left+r.left, r1.top+r.bottom);
  CMenu menu;
  menu.CreatePopupMenu();
  UINT flags = MF_STRING;
  menu.AppendMenu(flags,1100,"Bob");
  menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,pt.x,pt.y,this);
}




BEGIN_MESSAGE_MAP(ZXAMLPanel, CWnd)
  ON_COMMAND_RANGE(1000, 2000, processContextMenu)
END_MESSAGE_MAP()

// ZXAMLPanel
virtual afx_msg void processContextMenu(UINT nID);

void ZXAMLPanel::processContextMenu(UINT nID)
{
  return;
}

void ProjectCentrumXAMLPanel::processContextMenu(UINT nID)
{
  if (nID == 1100) this->OpenBestand(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1101) this->VerwijderBestand(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1102) this->OpslaanVersie(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1103) this->NieuweVersie(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1104) this->HernoemBestand(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1105) this->ArchiveerBestand(elementDatRechterMuisMenuOpriep, 0);
  if (nID == 1106) this->BackupBestand(elementDatRechterMuisMenuOpriep, 0);
  this->elementDatRechterMuisMenuOpriep = NULL;
 
  return;
}






-------------
     Product: Xtreme ToolkitPro (MFC) version 13.0.0
     Platform: Windows (32bit) - XP - Vista
     Language: Visual C++


Posted By: BobWansink
Date Posted: 12 March 2009 at 6:51am
Hmm. I've managed to solve this problem via a work-around. Instead of using MouseLeftButtonDown or MouseRightButtonDown, I've started using MouseLeftButtonUp and MouseRightButtonUp. I'd still like to know what's wrong in the above code, in case I need something like this again. 

-------------
     Product: Xtreme ToolkitPro (MFC) version 13.0.0
     Platform: Windows (32bit) - XP - Vista
     Language: Visual C++


Posted By: Oleg
Date Posted: 13 March 2009 at 2:08am
Hi,
 
Guess its something in our code - your looks fine :)


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net