Author Topic: Taking full control over MessageBox API  (Read 207 times)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Taking full control over MessageBox API
« on: May 22, 2020, 11:41:51 PM »
The MessageBox API is one of the preferred APIs when it comes to simply displaying a message, but its simplicity comes at a cost.
Formatting options, size control and other drawing capabilities are missing. On the other hand, it has a well-designed behavior that most users are used to.

As you probably know, I recently designed a control that can draw formatted text based on a markup string. The idea behind this new advanced API is to combine the well-behaved MessageBox with new drawing features. This new API is simply called MsgBox and is parameter compatible the the original MessageBox. This way, you exchange the name of the API and add the markup string.

This approach is not limited to an OOP framework because the drawing code can easily be replaced with your own custom code.

Here are some details of the implementation:
  • Get access to the control using a system hook.
  • Pass additional information using a custom caption string.
  • Intercept WM_NCCALCSIZE, release the hook and replace the dialog WndProc.
  • Store the pointer to the additional information in a new window property.
  • Intercept WM_INITDLG and setup the control, get information of child controls and reposition them.
  • Intercept WM_NOTIFY and WM_HELP and forward them to the dialog parent window.
  • Intercept WM_PAINT to perform custom drawing.
  • Intercept WM_NCDESTROY to release allocated resources.
Notes:
  • Don’t use GWLP_USERDATA to store data. The original API uses it.
  • Don’t try to change the parent of the buttons. They will not work anymore.
  • Calling DefDlgProc after interception WM_PAINT will draw the grey band behind the buttons on the original position. This call is necessary to paint the remaining controls but make sure that the previous artwork don’t interfere with the actual drawing. In the demo code, the grey band in covered by the TextView control.
  • The Help dialog launched from the help button is also a MsgBox call.
  • The Tooltip information is obtained using a WM_NOTIFY that is forwarded to the main application.
  • I had to extend the TextView code and add some missing procedures in the ObjMem library. All those files are in the attachment.
  • The attached code is compiled for 32 bit and tested on Win10, Win8 and Win7. Still, the code may contain some bugs that I would like to hear about.
For this example, I used the following markup string:

Code: [Select]
"{S.X 420}{S.Y 195}{PADDING 20}", \
"[INDENT 55]",\
  "[B,H +6,C #FF4F4F]Warning![~]{P}", \
  "[H +2]Critical system failure   - ERRID 521 -  [~]", \
  "[Info 0, Font 'Webdings', H +1]{#69}[~]{P}", \
  "[C #5F4FFF]", \
    "[I]Read the instruction manual for more information  [~]", \
    "[Info 1, Font 'Webdings', H +1]{#69}[~]", \
  "[~]", \
"[~]"

Have fun,  :biggrin:

Biterider
« Last Edit: May 23, 2020, 04:59:47 AM by Biterider »

HSE

  • Member
  • *****
  • Posts: 1304
  • <AMD>< 7-32>
Re: Taking full control over MessageBox API
« Reply #1 on: May 23, 2020, 02:07:12 AM »
 :thumbsup:

Hi Biterider!

If you move the message out of screen, buttons disappear (except "anular").

Regards. HSE


Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Re: Taking full control over MessageBox API
« Reply #2 on: May 23, 2020, 05:00:55 AM »
Hi HSE
Thanks for your feedback.  :thumbsup:
I was able to fix this issue and uploaded the corrected version on the first post.


Biterider

HSE

  • Member
  • *****
  • Posts: 1304
  • <AMD>< 7-32>
Re: Taking full control over MessageBox API
« Reply #3 on: May 24, 2020, 04:59:47 AM »
Perfect  :thumbsup:

I have more feedback :biggrin:

Things  that were working in ObjAsmB are not working in ObjAsmC, for example this test

I can't see what it's different  :rolleyes: , "symbol not defined " is everywhere.

Code: [Select]
\masm32\ObjAsm\Code\Objects\Pixelmap.inc(251) : Error A2102: Symbol not defined : sIID_IPicture
 d:\masm32\ObjAsm\Code\Objects\Pixelmap.inc(251): Included by
  MacroLoop(7): iteration 1: Macro called from
   MakeObjects(9)[Objects.inc]: Macro called from
    TestPXM.asm(58): Main line code
Inheritance path: OA_Primer,OA_LinkedList
Inheritance path: OA_Primer,OA_Streamable,OA_Pixelmap,OA_Pixelmap2
TestPXM_Main.inc(85) : Error A2063: Symbol not defined : OA_TestPXM.Pxm1
 $GetInstance32(1)[Objects.inc]: Macro called from
  MethodInvoke(92)[Objects.inc]: Macro called from
   OCall(5)[Objects.inc]: Macro called from
    TestPXM_Main.inc(85): Included by
     TestPXM.asm(88): Main line code

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Re: Taking full control over MessageBox API
« Reply #4 on: May 24, 2020, 06:23:00 AM »
Hi HSE
This symbolic GUID is defined here \ObjAsm\Code\Inc\Windows\sGUID.inc
Try including this file at the beginning of your project.

I have a too here that helps me to quickly find such things. It is called "Windows Grep" (Version 2.3). Unfortunately, the original site is not available anymore, but it can be downloaded from other sites. I like the tool, because it shows the results immediately in addition to some lines before and after the match.

Biterider

HSE

  • Member
  • *****
  • Posts: 1304
  • <AMD>< 7-32>
Re: Taking full control over MessageBox API
« Reply #5 on: May 24, 2020, 07:26:34 AM »
Hi Biterider!

Ok.  :thumbsup:

Code: [Select]
TestPXM_Main.inc(85) : Error A2063: Symbol not defined : OA_TestPXM.Pxm1
 $GetInstance32(1)[Objects.inc]: Macro called from
Then, is new version failing to find includes?


Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Re: Taking full control over MessageBox API
« Reply #6 on: May 24, 2020, 08:24:31 AM »
Hi HSE
I got it working  :biggrin:
You have to do 2 things: adjust the inheritance and modify the OnSize declaration. That's all.

Code: [Select]
MakeObjects Primer, Stream
MakeObjects WinPrimer, Window, Dialog, DialogModal, DialogAbout
MakeObjects Button, ColorButton
MakeObjects WinApp, SdiApp

Code: [Select]
Object TestPXM , TestPXMID, SdiApp
  RedefineMethod    Init
  RedefineMethod    Done   
  RedefineMethod    OnSize,     WPARAM, LPARAM

  StaticMethod      Startup

  VirtualEvent      OnCreate,   WM_CREATE
  VirtualEvent      OnCommand,  WM_COMMAND
  VirtualEvent      OnPaint,    WM_PAINT

  ;Embed grid1, GridFixW
  DefineVariable cualquiera, dword, 0

  Embed     Pxm1,  Pixelmap2
ObjectEnd

Biterider

HSE

  • Member
  • *****
  • Posts: 1304
  • <AMD>< 7-32>
Re: Taking full control over MessageBox API
« Reply #7 on: May 24, 2020, 09:28:14 AM »
Hi Biterider

adjust the inheritance

That was the problem!! For some reason, 6 years ago I write objects in that order, and all projects ... are a copy of the same  :biggrin: :biggrin: :biggrin:

the OnSize declaration.
Yes, that was evident and solved previoulsy (erasing OnSize in Window.inc :biggrin:)

Thanks very much. HSE

Vortex

  • Member
  • *****
  • Posts: 2212
Re: Taking full control over MessageBox API
« Reply #8 on: May 24, 2020, 06:37:26 PM »

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Re: Taking full control over MessageBox API
« Reply #9 on: May 24, 2020, 07:01:07 PM »
Hi Vortex
Thanks for the link. I just tried it out.   :thup:
It seems that it is being actively developed (version 2.0.1.882 is dated 2020/05/21) and has many good features.

Biterider

daydreamer

  • Member
  • *****
  • Posts: 1217
  • I also want a stargate
Re: Taking full control over MessageBox API
« Reply #10 on: May 26, 2020, 01:38:24 AM »
thanks Biterider :thumbsup:
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

daydreamer

  • Member
  • *****
  • Posts: 1217
  • I also want a stargate
Re: Taking full control over MessageBox API
« Reply #11 on: May 27, 2020, 03:28:17 AM »
I let inventory list popup
Db "sayonara flute",13,10
...and list of other item
So It's need to be replaced by markup for blue text "sayonara flute"... Hexadecimal = RGB.. Followed by different colors for each item,preferably text color =same as object color? ( I have several different flutes in there)

Sayonara flute only works so far = exit dungeon, to ground floor
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
Gone serverside programming p:  :D
I love assembly,because its legal to write
princess:lea eax,luke
:)

Biterider

  • Moderator
  • Member
  • *****
  • Posts: 513
  • ObjAsm Developer
    • ObjAsm
Re: Taking full control over MessageBox API
« Reply #12 on: May 27, 2020, 06:01:29 AM »
Hi daydreamer
I posted a sort of reference on how to build the markup string here http://masm32.com/board/index.php?topic=8524.msg93250#msg93250
I also posted the the markup string used in the example. It should help you to build your own. It is not that hard.

Biterider
« Last Edit: May 27, 2020, 07:37:41 PM by Biterider »