MsgBox Blaster, an easy way to create MessageRequester code

Share your advanced PureBasic knowledge/code with the community.
PBDragon
New User
New User
Posts: 4
Joined: Tue Jul 08, 2003 10:16 pm

MsgBox Blaster, an easy way to create MessageRequester code

Post by PBDragon »

Hello, new to PureBasic, very impressed with it so far.

Check out my first PureBasic program called MsgBox Blaster, which creates the MessageRequester code. (yeah I know the name is a throwback to VB, but MessageRequester Blaster just doesn't have the same ring to it). Thanks to all on this board, a large portion of the code came from some great posts!

I am pretty sure the "Test" feature to display a message is working correctly, but haven't been able to completely run through the "Copy" feature yet. The "copied" code works, but needs to be cleaned up.

I won't be able to work on it for a few days so am throwing it out in case any of you want to try it out. Just let me know if you find any bugs. I am sure there are a few obvious ones that I haven't come across yet.

All Windows standard msgbox features are available as well as the ability to customize the button text. Only thing that isn't straightforward is the Msg Length when you are customizing buttons. There has to be a cleaner way of doing it, I tried to automatically set the MsgLength, but it always ended up being too short. If you customize the buttons, play around with the MsgLength to find the optimum length for your message that doesn't truncate the message. Then take a look at the code that is copied, and let me know if there is a way to calc the msgspace length automatically.

Other then testing out the current features, I'll also be adding an option to add the Select code after the messagerequester. Down the road I may even try building custom Icons.

http://home.comcast.net/~akampmeier/Msgblast.zip

<IMG SRC="http://home.comcast.net/~akampmeier/Screenshotsmall.jpg">
Fred
Administrator
Administrator
Posts: 18220
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Welcome PBDragon ! Nice little tool. Would be nice if you could optimize the output code, so only needed one is generated :)
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

PBDragon,

Very nice tool! It makes the MessageRequester customization that I usually do much easier.

I have a suggestion for a new feature - setting the MessageRequester position. It's easy, just a few additions:

1) Add two Global variables: mbx.l and mby.l
2) Add X.l and Y.l parameters to the MessageBoxH() procedure, so it looks like this

Code: Select all

Procedure MessageBoxH (parentWindow, X.l, Y.l, title$, ...)
and is called like this

Code: Select all

MessageBoxH(0, 200, 200, "This is the Title", ...)
3) Add these statements to the MessageBoxH procedure

Code: Select all

mbx = X
mby = Y
4) Add a SetWindowPos_() API call in the MsgBoxHookProc() callback routine, after the SetWindowText_() call

Code: Select all

      SetWindowPos_(wParam, 0, mbx, mby, 0, 0, #SWP_NOSIZE|#SWP_NOZORDER)
Voila! A customized MessageRequester that you can position anywhere on the screen.

Regards,
Eric

Edit
Ooops, I forgot to give the value of the #SWP constants:

Code: Select all

; Window API Constants
  #SWP_NOSIZE = 1
  #SWP_NOMOVE = 2
  #SWP_NOZORDER = 4
  #SWP_NOACTIVATE = 16
  #SWP_SHOWWINDOW = 64
  #SWP_HIDEWINDOW = 128
ebs
Enthusiast
Enthusiast
Posts: 561
Joined: Fri Apr 25, 2003 11:08 pm

Post by ebs »

PBDragon,

I just took a closer look at the code generated by your MsgBox Blaster. You can eliminate all of the issues with the message length very easily - just get rid of it! :wink:

In the MessageBoxH() procedure, replace the last line

Code: Select all

ProcedureReturn MessageBox_ (parentWindow, Space (iMsgSpace), Space (iMsgSpace), ibuttontypes | icontype | idefaultbut)
with

Code: Select all

ProcedureReturn MessageBox_ (parentWindow, message$, title$, ibuttontypes | icontype | idefaultbut)
This sets the MessageRequester message and title text directly.

Now you can delete the

Code: Select all

SetWindowText_ (wParam, mbtitle$)
statement and all of the

Code: Select all

SetDlgItemText_ (wParam, #IDPROMPT, mbmsg$)
statements too. You can also remove the mbtitle$ and mbmsg$ variables and the code in MessageBoxH() that sets them.

Please let me know if this is what you had in mind, or if I misunderstood something.

Regards,
Eric
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Excellent program...

Very usefull !!! :lol:

Here's a little optimization for PB:

Code: Select all

Msg = Msg + Chr(13) + Chr(10)
can be

Code: Select all

Msg + Chr(13) + Chr(10)
PBDragon
New User
New User
Posts: 4
Joined: Tue Jul 08, 2003 10:16 pm

Fred, ebs, Num3 thanks for the feedback!

Post by PBDragon »

Fred, great idea. I'll probably add options something like

- All Procedures/Constants
- Optimized Procedures/Constants (which would copy only the procedures/constants used in that specific box)

Ebs, also great ideas. I'll play around with your code and let you know how it works.

Num3, didn't know you could do that, thanks for the tip!

Look for a new version which incorporates your ideas sometime late this weekend!

ps... This will always be a free tool, hope it comes in handy for everyone. My way of contributing to this great community!
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: Fred, ebs, Num3 thanks for the feedback!

Post by GPI »

>- All Procedures/Constants

Test your constants, some are already defined in PB

>- Optimized Procedures/Constants (which would copy only the
>procedures/constants used in that specific box)

I would add two options:
*Include all nedded Procedures and constants.
*Insert the call of the current Box

Some notes:
Cancel Try Again Continue don't work on Win9x don't work. When you do this, the programm hangs in a endless loop! Please make a OS-Version Check. ( PB-Function OSVersion() )
Help-> Is it possible to get a message? When not: Remove it, nobody can use it.

And finaly: Do you know jaPBe (when not, look in the announcment-forum). Would be nice, when you make a plugin for jaPBe, so you can kummunikate direct with the editor and you can insert your code direct. Also it is possible to find out, if you are called by jaPBe or not, so the plugin-feature would be optional.

GPI
weekend!

p.s.: Its always nice, when persons open there source-code.
Post Reply