Question about skinned wxMessageBox

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Question about skinned wxMessageBox

Post 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
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Post 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.
Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Post by bertolino »

Great, I'll get right on it. Thanks!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Post 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 13715 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Post 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.
Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Post 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
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Post by doublemax »

wxMessageBox uses this to find a parent:

Code: Select all

wxWindow *wxDialogBase::GetParentForModalDialog() const
Use the source, Luke!
bertolino
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Post 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
Post Reply