Saving the states of JavaFX controls on exit - javafx-2

I have a bunch of control objects (TextBoxes, to be precise) that get injected into my code using the #FXML annotation during the FXML load.
I would like to save the states of these controls, specifically the text values, when the user closes the Scene by clicking the close box on the title bar.
However, when I trap the CloseRequest event in an OnCloseRequest handler I find that the values of the control variables are null (the original injection works, so this is something that happens in between the loading of the FXML and the calling of OnCloseRequest).
Can anyone explain this behavior and/or suggest how I can get the functionality that I want?
TIA

onCloseRequest is
Called when there is an external request to close this Window. ...
(from Javadoc). One of the meanings of "external request" is when you close the window through OS native window close button. The closeRequest event is not triggered through the programmatic stage.close() or stage.hide() calls. So consider to handle onHiding or onHidden events.
Otherwise post your OnCloseRequest handler code.

Related

How to make backbutton work for a control, not just Page in UWP?

I followed this link http://www.wintellect.com/devcenter/jprosise/handling-the-back-button-in-windows-10-uwp-apps and "successfully" make my button work. I mean I can make my backbutton work between pages. However, if I navigate to a control which is inside this page and will cover the whole screen, then it would not allow me to back to the page. I will stuck in that control.
I'm wondering how to solve this problem. Currently I can think two possible ways (0) Override OnBackRequested() inside the control's code behind or viewmodel? (1) Override OnHardwareButtonsBackPressed() inside the control's code behind or viewmodel?. I don't know if these are correct way to do it or there is some better way to do it. Another reason for me to override is that I need to make some changes to the page navigation behavior.
As you have guessed, you simply need to hide the control again when the back button is pressed or back is requested in some other way. I would listen for the BackRequested event (not the HardwareButtons.BackPressed event) in the page's code-behind, and in the handling method you can check to see if the control is currently shown. The reason I recommend the BackRequested event is because it is universal, while HardwareButtons.BackPressed only works on a phone. Anyway, if the control is visible, then hide it, and set the Handled property of the event arguments to true. If the control is already hidden, don't do anything special to handle the event (because in that case you will want the navigation system to handle it by navigating to the previous page, if there is one). There are many aspects to navigation in Windows 10 -- please see these pages on Navigation and the SystemNavigationManager.

WM_PAINT not send when using WS_EX_COMPOSITE

I'm working in a legacy application using MFC.
We have a mechanism to enable/disable controls depending on some business logic.
This mechanism is implemented in the CView-derived class. The way it works is all the views in the application derived from a common CView-derived class (CBaseView) and on the PreTranslateMessage all controls of the view are enabled/disabled.
This worked fine so far because all controls send at least WM_PAINT message when they need to be painted. So the system worked without the user having to move the mouse or anything. I recently added some drawing features and I had to use WS_EX_COMPOSITE to get ride of some flickering. With this flag activated my CView-derived class is not getting any called to PreTranslateMessage when creating the view....so the controls are not disabled until the user moves the mouse over the control.
I understand there is no way to send WM_PAINT using WS_EX_COMPOSITE but is there other message I can use to get the same behaviour???
Edited:
I am currently using the OnIdle approach but it has a big drawback, the windows doesn't become idle until after drawing all the controls...so when you enter the screen al controls are enabled and inmediately they are disabled...this makes a quite ugly effect!
More solutions???
Thanks in advance...
The logical place to enable/disable controls would be CView::OnUpdate, it is called by the framework after the view's document has been modified and from OnInitialUpdate(); you can also call this function if there is some change that would trigger re-evaluation of your business logic.
EDIT
After reading the question a bit more closely, what you could also do is to post a private message at the end of OnInitialUpdate and "catch" it in your PreTranslateMessage:
PostMessage(WM_APP, 0, 0);
Calling InvalidateRect followed by UpdateWindow against the window in question will mark the entire client area as dirty and force an immediate repaint. Remember that WM_PAINT is not really a message, in the queue in the usual sense, it is pushed out after all other messages have been processed for that window, which would include any invalidations of the area being drawn. No message is generated at all if there are no invalid segments of the active window display.

Is it possible to Derive class from CWinThread Class in dialog based application

I am working with Dialog based application.
My Question is that, I want to show Waiting dialog, until some database operation carried out.
i Used Derived class from CWinThread, but problem is that, when this thread close, the background (Main application dialog) remains at deactivated means( it hide behind another window).
i am thinking that, this is happening because of WaitDialog used CWinThread class.
The problem is not unique to a dialog based application. Creating windows of any kind in more than one thread is difficult and not recommended. In your case it sounds like your wait dialog is modal, while its parent dialog is in another thread. That is even worse and can lead to deadlocks between threads.
The reliable solution is to put the wait dialog (and all other GUI) in the main thread, and the lengthy database processing in a secondary thread.
Another alternative would be to use a Modeless Dialogbox which can also optionally show the status and call the DestroyWindow function when the database operation is completed -- you may need to disable some operations of the main window while the Modeless Dialogbox is visible, though.
From the comments on my previous answer, it looks like that alternative is not viable in this situation.
Maybe a better way would be to create a normal modal "wait" dialog box, start the background thread in the dialog's InitDialog, periodically check the status of the thread using a timer and end the dialog when the thread completes?

Controls not receiving messages after parent change

In my application there are a lots of dialogs being opened and closed all the time. The dialogs are non-modal.
In order to save some performace, we are "recycling" some of the more complicated controls. When one dialog is closed, the controls are not destroyed, but their pointers are stored in an array so that they can be reused when another dialog is opened.
The problem is that after the control is positioned in the new dialog, it does not receive all the messages. For instance the message WM_DRAWITEM (the control is derived from CListCtrl) is not being sent anymore. The WM_LBUTTONDOWN on the other hand is still arriving. It is as if the control does not know its class anymore. The NC area (border and list header) is being painted correctly.
Did anyone have similar problems? What could be wrong? Can the controls be "detached" and "reattached" in this way at all?
For CListCtrl to respond to WM_DRAWITEM image it is needed it has the LVS_OWNERDRAWFIXED style. Are you sure you have it set?
And from http://msdn.microsoft.com/en-us/library/windows/desktop/bb774739(v=vs.85).aspx , it seems it only occurs if it is in Report view (Seems strange to me!).

Set message box from Message.Show() as a child of Wix installer window

In my custom actions, I've used MessageBox.Show() to show a dialog whether needed. For ex: during database installation, I'd like to show a message to user if any error. But the message box is not set as a child of Wix window by default, thus the end-user can leave the message box and touch the Back, Next button ...
Is there any way to set the message box as a child of the main Wix installer window?
Thanks in advance,
There are bad ways and good ways. The bad ways involve FindWindow calls so you can parent appropriately. The good ways involve calls to MsiProcessMessage, Session.Message, or whatever wrapper is available. However if this custom action is being invoked from a DoAction ControlEvent, the latter will not work.

Resources