Page 1 of 1

Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 11:08 am
by bertolino
I plan to make a skinned version of wxMessageBox. I wonder about some aspects:
- Should a class to do that be a good idea (since wxMessageBox is a function)?
- If so, which should be the best base class to derive?
- How to get the modal behavior?

Many thanks for any suggestion,

Pascal

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 11:28 am
by doublemax
- Should a class to do that be a good idea (since wxMessageBox is a function)?
Create a class and add another global function that wraps creating/showing the dialog.
- If so, which should be the best base class to derive?
- How to get the modal behavior?
wxDialog, maybe wxMessageDialog.

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 1:10 pm
by bertolino
Great, I'll get right on it. Thanks!

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 5:22 pm
by bertolino
Screen Shot 2018-07-20 at 19.17.49.png
Screen Shot 2018-07-20 at 19.17.49.png (16.18 KiB) Viewed 17604 times
Thanks to you Doublemax, the implementation was quite straightforward.
But I still have troubles with automatically centering the message box on the app frame:
Calling myMessageBox (my function that replaces wxMessageBox) does not mention the parent window.
On the other hand, I didn't manage to access the top level window from my MyMessageDialog.

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 5:31 pm
by doublemax
Calling myMessageBox (my function that replaces wxMessageBox) does not mention the parent window.
On the other hand, I didn't manage to access the top level window from my MyMessageDialog.
The "original" wxMessageBox has a "parent" parameter.
http://docs.wxwidgets.org/trunk/group__ ... 42de252647

You could use wxTheApp->GetTopWindow(), but i would consider it a bit "dirty". It's also not 100% reliable, as the "top" window is not necessarily the one myMessageBox was called from.

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 5:59 pm
by bertolino
Thanks for your advice that offers a solution but that doesn't fully answer my expectation:
Actually, until now I'm used to call wxMessageBox like this:
wxMessageBox(_("bla bla")), i.e, with just one parameter
and the message box is always well centered.

I'd like to keep on doing the same with myMessageBox, without the need to pass its
parent as a parameter...

Best regards,

Pascal

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 7:05 pm
by doublemax
wxMessageBox uses this to find a parent:

Code: Select all

wxWindow *wxDialogBase::GetParentForModalDialog() const

Re: Question about skinned wxMessageBox

Posted: Fri Jul 20, 2018 7:42 pm
by bertolino
Wow! I missed that (but you didn't!).
Only 2 lines to change and it works great!
Doublemax, you're the best and saved my evening.
I am very grateful for your valuable help.
Have a very good weekend!

Pascal