Problem with a non-modal, self-closing dialog in combination with other dialogs - visual-c++

It is about a MFC-MDI application. I have added a popup window, which should be closed after some duration. Therefore, I create a non-modal dialog
CPopupDlg* pDlg = new CPopupDlg(this);
if (pDlg)
{
pDlg->Create(IDD, this);
pDlg->ShowWindow(SW_SHOW);
}
It will be closed by a Timer and destroyed in OnNcDestroy()
void CPopupDlg::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == m_CounterEventID)
{
KillTimer(nIDEvent);
EndDialog(IDCANCEL);
DestroyWindow();
}
}
void CPopupDlg::OnNcDestroy()
{
__super::OnNcDestroy();
delete this;
}
My problem are many other (modal) dialogs and message boxes, which may appear, while the CPopupDlg is open. These modal dialogs often does not specify a parent window in my project (CDialogconstructor with pParentWnd=NULL). Hence, the method CDialog::DoModal() use ::GetLastActivePopup() to determine its parent window. The CPopupDlg dialog is chosen as the parent window. As a consequence, DoModal() crashes, when the CPopupDlg window is closed by the timer.
How can I tackle this problem?
Is there a way to exclude the CPopupDlg dialog from the results of ::GetLastAcitvePopup()?
Sometimes I have seen, that non-modal dialogs uses RunModalLoop(). Would this be the solution?
popupDlg.Create(IDD, this);
popupDlg.RunModalLoop(MLF_SHOWONIDLE);
popupDlg.DestroyWindow();
What would happen, if the popup dialog would never be closed and destroyed, but only hidden. Would other modal dialog windows, which are undesired childs of the CPopupDlg wnd, also disappear, if popupDlg.ShowWindow(SW_HIDE) is called?

My solution is to create the popup window as a separate desktop child window. It is not a child window of the application and will not be chosen by ::GetLastActivePopup().
CPopupDlg* pDlg = new CPopupDlg(this);
if (pDlg)
{
pDlg->Create(IDD, GetDesktopWindow());
pDlg->ShowWindow(SW_SHOW);
}

Related

Menu - Focus onmouse

I have a menu that calls the above events at the main div.
mouseover
function() {
$('.box-content-category').addClass('active');
$(".box-content-category").show(1);
}
mouseout
function() {
$('.box-content-category').addClass('active');
$(".box-content-category").hide(1);
}
The problem. When the user sets the mouse (mouseover) to below div to explore the menu the menu dissapears.
How can i set the menu to stay open on mouseover and close when the mouseout at the above divs?
Thank you
Wish you the best

I want to avoid Mouse click event handled by both child and parent handlers in javafx 8

Currently in my javafx program I have structure like
AnchorPane[Parent] - > Group[Child] ... Both have setOnMouseClicked event code..
My problem is When click on child node, child node's setOnMouseClicked executed first and then Parent node's setOnMouseClicked gets executed ...
Now I have situation where I want to have functionality like
If child node's setOnMouseClicked is executed then
Parent node's setOnMouseClicked should not get executed ..
How do I achieve this ? For more information please check below image.
Now if I click on parent node - > selected child node should be deselected .. So I write parent Node.setOnMouseClicked -> de-select child node ..
But even when I click on child node to select it - > it also execute parent node's setOnMouseClicked - > And immediately deselect the child node ..
I find this problem as an architectural issue so as not posting code example.
Please let me know your valuable suggestions. Your help would be highly appreciated.
Here is a small example of consuming events - events that have been consumed will not bubble through to the next listeners:
#Override
public void start(Stage stage) throws Exception {
Canvas c = new Canvas(400, 400);
Pane p = new Pane(c);
p.setOnMouseClicked(me -> {
System.out.println("Pane mouse click: " + me.getX() + ", " + me.getY());
});
c.setOnMouseClicked(me -> {
System.out.println("Canvas mouse click: " + me.getX() + ", " + me.getY());
if (me.getX()>200) {
System.out.println("Consuming event");
me.consume();
}
});
stage.setScene(new Scene(p));
stage.show();
}
When clicking the left part and then the right part of the Canvas you will get something like this:
Canvas mouse click: 96.0, 174.0
Pane mouse click: 96.0, 174.0
Canvas mouse click: 373.0, 180.0
Consuming event
Notice how the second time the Pane event listener wasn't executed. Of course, you can use any logic to decide whether you consume the event.

Scroll to the selected tab if the selected tab is hidden in p:tabview on initial tabview load

Assume that there are many tabs are there in p:tabview and scroll is being shown to navigate to all the tabs.
If the active tab whose contents are shown is the right most tab then it is not visible to the user on initial p:tabview load. If we navigate to the right most using scroll button then we could see the active tab highlighted indicating it is selected tab.
How to scroll to the active tab on load so that user able to see the selected tab always.
This can be done in the following way by overriding initScrolling method in primefaces p:tabview component JavaScript file i.e. tabview.js file.
initScrolling: function() {
if(this.jq.is(':visible')) {
var overflown = (this.lastTab.position().left - this.firstTab.position().left) >
this.navscroller.innerWidth();
if(overflown) {
this.navscroller.css('padding-left', '18px');
this.navcrollerLeft.show();
this.navcrollerRight.show();
activeTab = this.navContainer.children('.ui-tabs-selected');
viewportWidth = this.navscroller.innerWidth();
activeTabPosition = activeTab.position().left + parseInt(activeTab.innerWidth());
if(activeTabPosition > viewportWidth) {
var scrollStep = activeTabPosition - viewportWidth;
scrollStep = Math.ceil(scrollStep/100) * -100;
this.scroll(scrollStep);
} else {
this.restoreScrollState();
}
}
return true;
}
else {
return false;
}
}
I would have wished to override this single method by extending tabview component widget but it is not supported. So we should have our own tabview.js file with the above method modified.
This is done in primefaces 4.0 version, more, or less the changes will be same higher versions also.

Selection type changes context menu using chrome extension

I am trying to build a chrome extension. In it I want the context menu to change according to the selected text on the page.
For example, if its a number I want a menu that says divisibility test for this numbr is ...
and if it is a string, it should have a something else, but not both at the same time.
I cant figure out how to do that.
You will have to set a listener for mouse down. There is no other way to get the selected text before the menu is created.
See this SO question:
chrome extension context menus, how to display a menu item only when there is no selection?
Here is part of the code the rest is at the link.
document.addEventListener("mousedown", function(event){
//right click
if(event.button == 2) {
if(window.getSelection().toString()) {
chrome.extension.sendRequest({cmd: "createSelectionMenu"});
} else {
chrome.extension.sendRequest({cmd: "createRegularMenu"});
}
}
}, true);

How to tell the difference between touchesBegan and touchesMoved

How can I ignore the touchesBegan method when the user is pinching an object and ignore the touchesMoved method when the user taps on the screen? I created a picture zoom in / zoom out effect and I want to be able to hide the navigation bar when the user taps on the screen once. Right now when the user starts pinching, the navigation bar gets displayed since the user touched once.
What would be the best way to do this?
It seems like the easiest thing to do for your show/hide navigation bar would be to add a UITapGestureRecognizer and set numberOfTouchesRequired and numberOfTapsRequired to 1.
Alternatively, you could use touchesEnded instead of touchesBegan. Then in your touchesEnded, you could check for the number of touches and only show/hide if it's 1:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *theTouch = [touches anyObject];
if (theTouch.tapCount == 1) {
// show/hide navigation here ...
} else {
// finish your zoom here ...
}
}

Resources