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.
bertolino
Knows some wx things
Knows some wx things
Posts: 33
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Question about skinned wxMessageBox

Postby bertolino » Fri Jul 20, 2018 11:08 am

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: 12511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Postby doublemax » Fri Jul 20, 2018 11:28 am

- 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
Knows some wx things
Knows some wx things
Posts: 33
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Postby bertolino » Fri Jul 20, 2018 1:10 pm

Great, I'll get right on it. Thanks!

bertolino
Knows some wx things
Knows some wx things
Posts: 33
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Postby bertolino » Fri Jul 20, 2018 5:22 pm

Screen Shot 2018-07-20 at 19.17.49.png
Screen Shot 2018-07-20 at 19.17.49.png (16.18 KiB) Viewed 417 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: 12511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Postby doublemax » Fri Jul 20, 2018 5:31 pm

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
Knows some wx things
Knows some wx things
Posts: 33
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Postby bertolino » Fri Jul 20, 2018 5:59 pm

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: 12511
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about skinned wxMessageBox

Postby doublemax » Fri Jul 20, 2018 7:05 pm

wxMessageBox uses this to find a parent:

Code: Select all

wxWindow *wxDialogBase::GetParentForModalDialog() const
Use the source, Luke!

bertolino
Knows some wx things
Knows some wx things
Posts: 33
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Question about skinned wxMessageBox

Postby bertolino » Fri Jul 20, 2018 7:42 pm

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


Return to “Component Writing”

Who is online

Users browsing this forum: No registered users and 2 guests