The MASM Forum

General => The Campus => Topic started by: jj2007 on September 17, 2012, 10:45:51 AM

Title: Really simple dialogs
Post by: jj2007 on September 17, 2012, 10:45:51 AM
Hutch has written great macros in dialogs.inc, see demos in \masm32\examples\dialogs_later.
The new MasmBasic macros are inspired by his work but even more "basic", in the sense: the Right ThingTM for beginners. Here is an example showing a prompt for entering data, on exit available in the Dlg$() array for further processing:

include \masm32\MasmBasic\MasmBasic.inc        ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  DlgDefine "Please enter your data, tab for next line:", 0, 0, 150, -4
  DlgControl dcEdit,   "First name", WS_BORDER or WS_TABSTOP, 1, -2              ; first control gets the focus
  DlgControl dcEdit,   "Family name", WS_BORDER or WS_TABSTOP, 1, -4           ; x, y only, the macro will assign width, height and ID
  DlgControl dcStatic,   "Type your first name:", SS_LEFT, 1, -1, 70.0           ; 70 means 70% - the buttons need space
  DlgControl dcButton,   "OK", BS_DEFPUSHBUTTON or WS_TABSTOP, 71.0, -1, 12.0, , IDOK        ; x=71%, y, width=14%, height, ID
  DlgControl dcButton,   "Quit", BS_PUSHBUTTON or WS_TABSTOP, 84.0, -1, 16.0, , IDCANCEL
  DlgControl dcStatic,   wCat$("Type your family name: (it's "+wTime$+" now)"), SS_LEFT, 1, -3
; DlgHandler MyHandler        ; optional - PM me for details
  DlgShow
  .if eax==IDOK
       wMsgBox 0, wCat$(Dlg$(0)+wCrLf$+Dlg$(1)), "Please confirm::", MB_OKCANCEL
  .endif
  Exit
end start

Another example showing how easy it is to code a Unicode dialog:

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  DlgDefine "Simpler than that is difficult:", 0, 0, 87, 82, DS_CENTER, 14   ; text, x, y, width, height [, style] [, font size] [, font face]
  DlgControl dcStatic, "... but why make it simple when you could code complicate stuff, too?", SS_LEFT, 2, 2, , 30
  DlgControl dcEdit, wCat$(wRes$(3)+wCrLf$+wRes$(403)+wCrLf$+wRes$(803)+wCrLf$+wRes$(1203)) , ES_MULTILINE or WS_BORDER, 3, 33, , 38
  DlgShow
  Exit
end start

I attach the sources and executables, plus a simple RTF viever coded in 54 lines. You need the MasmBasic version of today 17 September (http://masmforum.com/~masm32/board/index.php?topic=94) to assemble the examples.

Enjoy, jj
Title: Re: Really simple dialogs
Post by: hutch-- on September 17, 2012, 10:48:40 AM
These look good JJ, I don't suppose we could have a close button on the unicode dialog ?
Title: Re: Really simple dialogs
Post by: jj2007 on September 17, 2012, 10:57:08 AM
Hutch,

DS_CENTER or WS_OVERLAPPEDWINDOW would do the job, as we all know  :biggrin:

However, I find hitting Escape Really SimpleTM, that's why I left it with DS_CENTER ;-)
Title: Re: Really simple dialogs
Post by: hutch-- on September 17, 2012, 11:03:02 AM
JJ,

I was more thinking WS_SYSMENU so that you could click the system menu.
Title: Re: Really simple dialogs
Post by: jj2007 on September 17, 2012, 11:32:54 AM
Hutch,

Actually I think the style is pretty useless ;-)

Of course, you could be more explicit:

  DlgDefine "Simple?", 0, 0, 118, 69, DS_CENTER or WS_SYSMENU, 20, "Times New Roman"       ; x, y, width, height [, style] [, font size] [, font face]

But the simple solution does the job, too:

include \masm32\MasmBasic\MasmBasic.inc   ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  DlgDefine "Simpler than that is difficult:", 0, 0, 118, 69
  DlgControl dcStatic, "... but why make it simple when you could code complicate stuff, too?", SS_CENTER, 1, 0, , 20   ; x, y, ?, height
  DlgControl dcEdit, wCat$(wRes$(3)+wCrLf$+wRes$(403)+wCrLf$+wRes$(803)+wCrLf$+wRes$(1203)) , ES_MULTILINE, 2, 20, , 36
  DlgShow
  Exit
end start
Title: Re: Really simple dialogs
Post by: hutch-- on September 17, 2012, 12:37:23 PM
Elegant simplicity.
Title: Re: Really simple dialogs
Post by: jj2007 on September 19, 2012, 08:54:11 AM
Elegant simplicity.

9 files for a really simple dialog ::)

How do you define simplicity? My definition is here (http://masm32.com/board/index.php?topic=94.msg5880#msg5880) - with some mysteries ;-)
Title: Re: Really simple dialogs
Post by: hutch-- on September 19, 2012, 09:09:03 AM
 :biggrin:

I blame Microsoft for it, source file, mainfest file, RC file with version control block, an icon and a batch file to build it without needing an editor/IDE. The rest are binaries built by the assembler/linker and the resource compiler.
Title: Re: Really simple dialogs
Post by: Gunther on September 20, 2012, 02:01:39 AM
Hi Jochen,

How do you define simplicity? My definition is here (http://masm32.com/board/index.php?topic=94.msg5880#msg5880) - with some mysteries ;-)

That's real simplicity and very impressive.  :t

Gunther
Title: Re: Really simple dialogs
Post by: jj2007 on September 20, 2012, 02:50:32 AM
That's real simplicity and very impressive.  :t

Danke  :biggrin:
Title: Re: Really simple dialogs
Post by: Gunther on September 21, 2012, 05:17:50 AM
Jochen,

you're welcome. Great work.

Gunther
Title: Re: Really simple dialogs
Post by: kroz on September 21, 2012, 11:27:54 AM
very nice :)
Title: Re: Really simple dialogs
Post by: johnparker29 on September 30, 2012, 11:40:31 PM
I fault Microsoft for it, source computer file, mainfest computer file, RC computer file with edition control block, an symbol and a set computer file to build it without requiring an editor/IDE. The rest are binaries built by the assembler/linker and the resource compiler.