Cannot access a child window's controls ( Created with CDialog::Create ) - visual-c++

I've been having some difficulties to understand and maybe you guys can help.
I have a project that uses CDialog and I've been trying to create a child window that retrieves some info from the main window ( the main/child windows have they're own classes), edits the content and sends the edited info back to the main window.
When I tried using CDialog::Create(), I wasn't able to use ANY of the controls on the child window. ( Example: Buttons are not responsive )
When I created the child window with DoModal() it backfired.. Buttons were responsive, and I had access to the child window's class functions, but when I tried to get the info from the main window class I was struck down with an appcrash.
I have tried passing the CWnd manually but it still crashed.. (Could not retrieve the main window handle )
Any ideas on how can I create the child window while still having access to the main app's variables and to the child window's event handlers ?
EDIT:
Ok, I finally found out what was the problem:
I was using
CDialog *eTest = new CDialog; // Pointing to .. ?? .. yeah I hate myself for this
eTest->Create(IDD_EDIT_DIALOG, NULL);
eTest->ShowWindow(SW_SHOW);
Instead, I should of created the window like this:
CDialog *eTest = new CEditDialog(); // Pointing to the dialog class
eTest->Create(IDD_EDIT_DIALOG, this);
eTest->ShowWindow(SW_SHOW);
Everything from the buttons to the data transfer seems to be working right now.
I hope it can help someone as dumb as me in the future.

Related

Programmatically changing tabs in a Monotouch app

Forgive me for my ignorance, as I'm new to Monotouch and I'm sure this is a simple thing but I can't find the answer anywhere.
I have an iPhone app in Monotouch that uses a UITabBarController for root navigation. It is defined in it's own class file. There is also a separate view controller class file for the content of each tab. So tab1 shows viewcontroller1, tab2 shows viewcontroller2, etc.
I want a user to be able to click on button1 inside of viewcontroller1 and have the app take them to tab2 and show viewcontroller2.
I have an event handled for the click of button1 and I can do things like pop up alerts when it's clicked, but I can't figure out how to get the tab bar to be accessible for me to call it. Please help!
Edit: I need to know not only how to make it accessible, but I also don't know what method to call to make it change.
When you create your "child" view controllers, pass in a reference to the "parent" tab controller. Then you child can call a method on it's parent to update the current tab index.
something like
btn1.TouchUpInside += (sender, args) => TabBarController.SelectedIndex = 0 ;

Creating UIElements outside Ui thread, Silverlight

In my silverlight 4.0 application, at one point, after user pushes a button, I have to create few UI objects that take some time (5-10seconds). During this time UI freezes of course. I decided to put creation of those objects in a background worker so UI could at least show progress bar.
But this solution does not work. To create UI object you have to be in UI thread.
If I put creation of those object inside Dispatcher.BeginInvoke() than again my UI freezes. In most cases without even showing progress bar. Is there a way around this?
Can I show progress bar while silverlight creates UI objects in the background?
Have a look at this forum post. It may help.
Instead of using:
System.Windows.Threading.Dispatcher.BeginInvoke(() => {});
They use:
System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() => {});
You can try displaying a custom message before creating UI objects inside BeginInvoke().
Example:
private void CreateObjects()
{
myMsg.Text = "Loading...";
Dispatcher.BeginInvoke(() => { AddObjects() });
}
Once all objects are created, disable the message.
You can try the similar thing with Progress Bar also.

Getting pyqt application focus for popup menu to disappear when clicking away from it

Let me quickly explain the background to this. I'm developing a custom menu system inside a 3D application called Softimage XSI. It has a PyQt application object created already and ProcessEvents is being called a certain number of times every second so that PyQt applications can exist in a non-modal state within XSI.
To implement the menu, I've got a webpage embedded in a toolbar which is calling a plugin for XSI that I've written to show a PyQt menu. This all works fine (albeit, slightly contrived!).
The issue is that when I show the menu, it won't disappear when I click away from it. If I move the mouse over the menu, and then click away from it, it will disappear. It's only when it first pops up.
I've tried everything I can think of. Here's a list:
Using QtGui.qApp.installEventFilter(menu) to try and catch the mousepressed signal. It never gets triggered. I suspect the application itself isn't receiving the click.
Using menu.raise_() makes no difference
Neither does QtGui.qApp.setActiveWindow(menu)
Or menu.setFocus()
I've also tried:
event = QtGui.QMouseEvent(QtCore.QEvent.MouseMove, pos, QtCore.Qt.NoButton, QtCore.Qt.NoButton, QtCore.Qt.NoModifier)
QtGui.qApp.sendEvent(menu, event)
I had a go writing my own QEventLoop, but it just crashed XSI. I suspect trying to run a modal loop inside the other one probably isn't a legal thing to do. Either that, or I really don't know what I'm doing (equally probable)
The only thing I have partial success with is using grabMouse(). This is what makes the menu close if I click away from the menu (only after the mouse has passed over the menu once), but I have to call it a couple of times for it to "stick".
So this is my code at the moment:
class MyMenu (QtGui.QMenu):
def __init__(self, parent = None):
QtGui.QMenu.__init__(self, parent)
self.grabbed=2
def getMouse(self):
if self.grabbed>0:
self.grabMouse()
self.grabbed-=1
def paintEvent(self, event):
QtGui.QMenu.paintEvent(self, event)
self.getMouse()
def hideEvent(self, event):
self.releaseMouse()
def ShowMenu():
menu = MyMenu()
menu.addAction("A")
menu.addAction("B")
menu.addAction("C")
submenu = MyMenu()
submenu.addAction("D")
submenu.addAction("E")
submenu.addAction("F")
menu.addMenu(submenu)
menu.setTearOffEnabled(True)
menu.setStyleSheet("font: 8pt \"Sans Serif\";")
submenu.setStyleSheet("font: 8pt \"Sans Serif\";")
submenu.setTitle("Window")
submenu.setTearOffEnabled(True)
pos = QtGui.QCursor.pos()
pos.setX(105)
menu.popup(pos)
#Prevent garbage collection
QtGui.XSIMenu=menu
QtGui.XSISubMenu=submenu
#Desperate acts!
menu.raise_()
QtGui.qApp.setActiveWindow(menu)
menu.setFocus()
Any thoughts or random suggestions would be very gratefully received as this is driving me nuts! Don't be afraid to suggest modifications to stuff I've already tried, as I'm relatively new to PyQt and I may well have missed something.
Many thanks,
Andy
Just before calling popup with self.trayMenu.popup(QtGui.QCursor.pos()), call self.trayMenu.activateWindow(). Putting activateWindow before popup makes the left-click menu work the same as the right-click menu and it goes away when you click elsewhere. :)

How to save the window state at wxWidgets?

I'm constructing a UI using wxWidgets.
In my GUI, I generate a window (wxFrame class) which is accessible through pushing a bitmap button. In that window, I also perform some tasks, again pushing some bitmap buttons and diabling them etc. But I can't close and reopen that window with the state saved. I always have to re-initialize it, and this is very impractical.
How can I save the state of my window? I checked the internet, it's suggested to use wxPersistent class but this class is missing in my wxWidgets.
Thank you for any help,
Best Regards.
Instead of destroying the window every time, you can just hide it with the wxWindow::Show() member function, passing false as the argument, when you receive a wxCloseEvent. You then veto the wxCloseEvent to prevent WxWidgets from destroying your window:
// In your close handler:
if(evt.CanVeto()) // Where evt is a wxCloseEvent
{
Show(false); // Hide window
evt.Veto(); // Prevent window destruction
}
This should remove it from the screen, but all the initialized parts should still be there. If you need to show it again, call the Show() method again with true.

How can I calculate the client area of an MFC CDialog without displaying it?

How can I obtain the Window Rect of a CDialog which is based on a dialog template. The dialog is not and can not be visible
It might be tricky with CDialog, because if you dont show the CDialog, the window handle is not created and you cant call GetClientRect.
Might i suggest calling CreateDialogIndirect instead to create the dialog, then you can get the client rect. You dont need to show the dialog. I think as long as the window handle is created, the GetClientRect should work. I am not an expert though and its been many years since i have written MFC code.
Well...
In Windows API-land, you could load the resource yourself (FindResourceEx, LoadResource), understand the binary structure of the dialog template resource (some clues at http://blogs.msdn.com/oldnewthing/archive/2004/06/22/162360.aspx), convert the size of the dialog in the dialog template from dialog units to pixels (check out http://msdn.microsoft.com/en-us/library/ms645475(VS.85).aspx).
I'd be curious why you'd want to do this, though.

Resources