AutoHotkey Community

It is currently May 27th, 2012, 3:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 79 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: July 12th, 2010, 10:10 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
HTML DialogBox v0.51

HtmDlg() works very much like MsgBox but with one difference and a couple of advantages.

The difference is that: HtmDlg() needs a HTM file/URL unlike MsgBox which accepts plain text.

The two advantages are:
1) HtmDlg() uses webcontrol to display message which offers vast text formatting capabilities.
2) HtmDlg() offers 9 user-definable, fully customizable buttons.

Example:

Code:
#SingleInstance, Force
SetWorkingDir %A_ScriptDir% 

bgcolor := GetSysColor(15)  ; Window Background color for the current desktop theme

FileDelete, demo.htm
FileAppend,
( Join
<html><body bgcolor="#%bgcolor%" leftmargin="10" topmargin="10"><div align="left"><p><font
 face="Arial" size="2">This area of this Dialogbox uses HTM which means you can format you
r message using <i>Italics, </i><b>Bold</b>, <font color="#3366CC"><b><font color="#FF0033
">Colors</font></b></font> and all other formatting HTML permits.<br><br>Please note that
 this webcontrol mimics a static control using these workarounds:<br><b>1)</b> Your comput
er system's window color is <b>%bgcolor%</b>, and is being used as the bgcolor of HTM so a
s to simulate transparency. <b><br>2)</b> This control has been disabled and so you cannot
 select/copy text.<b><br>3)</b> The vertical scrollbar is just outside the client-area of
 this dialog.<br><br>Do you like this MessageBox?</font><font face="Arial" size="2"></font
><font color="#3333CC" face="Arial" size="2"> </font></p></div></body></html>
)
, demo.htm


URL=file:///%A_ScriptDir%\demo.htm
Options := "Buttons=Yes/No/50-50, HtmW=360, HtmH=260, BEsc=3"

Sel := HtmDlg( URL, "", Options )

Return                                                 ; // end of auto-execute section //


GetSysColor( DisplayElement=1 ) {
 VarSetCapacity( HexClr,7,0 ), SClr := DllCall( "GetSysColor", UInt,DisplayElement )
 RGB := ( ( ( SClr & 0xFF) << 16 ) | ( SClr & 0xFF00 ) | ( ( SClr & 0xFF0000 ) >> 16 ) )
 DllCall( "msvcrt\sprintf", Str,HexClr, Str,"%06X", UInt,RGB )
Return HexClr
}

#Include HtmDlg.ahk ; You may copy/Paste HtmDlg() Instead


    Snapshot for above code:
    Image


HtmDlg()

Code:
;                                                      _     _            _____   _
;  HtmDlg() - HTML DialogBox v0.51                    | |   | |_         (____ \ | | v0.51
;                                                     | |__ | | |_  ____  _   \ \| | ____
;  Suresh Kumar A N (arian.suresh@gmail.com)          |  __)| |  _)|    \| |   | | |/ _  |
;                                                     | |   | | |__| | | | |__/ /| ( ( | |
;  Created  : 09-Jul-2010                             |_|   |_|\___)_|_|_|_____/ |_|\_|| |
;  Last Mod : 13-Jul-2010                                                          (_____|
;
;  Usage : HtmDlg( URL, hwndOwner, Options, OptionsDelimiter )
;        :  For Options, please refer the bottom of this script
;
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

HtmDlg( _URL="", _Owner=0, _Options="", _ODL="," ) {

; HTML DialogBox v0.50 - scripted by SKAN : www.autohotkey.com/forum/viewtopic.php?t=60215

 static _Ins, _hDLG, _DlgT, _DlgP, _STRU, _pIWEB, _pV,                      BDef=1, BEsc=0

 If ( A_EventInfo = 0xCBF ) {                                    ; nested CallBackFunction
 hWnd := _URL,  uMsg := _Owner,  wP := _Options,  lP := _ODL

 If ( uMsg=0x112 && wP=0xF060 )  ; WM_SYSCOMMAND && SC_ClOSE
  Return DllCall( "EndDialog", UInt,_hDLG, UInt,BDEf := BEsc )

 If ( uMsg=0x111 && (wP>>16)=0 ) ; WM_COMMAND && BN_CLICKED
  Return DllCall( "EndDialog", UInt,_hDLG, UInt,BDef := (wP=2) ? BEsc : wP-100  )

 Return False
 }

 If ! ( _Ins ) {

 _Ins := DllCall( "GetModuleHandle", Str,A_AhkPath )
 _DT=
 ( Ltrim Join
   61160CD3AFCDD0118A3EGC04FC9E26EZPCHC88OAZO8G4DG53G2H53G68G65G6CG6CG2H44G6CG67Q58ZHDG741
   G74G6CG41G78G57G69G6EK7BG38G38G35G36G46G39G36G31G2DG33G34G3H41G2DG31G31G44G3H2DG41G39G3
   6G42G2DG3H3H43G3H34G46G44G37G3H35G41G32G7DT14NFBFFQ65GFFFF8Y14NFBFFQ66GFFFF8Y14NFBFFQ67
   GFFFF8Y14NFBFFQ68GFFFF8Y14NFBFFQ69GFFFF8Y14NFBFFQ6AGFFFF8Y14NFBFFQ6BGFFFF8Y14NFBFFQ6CGF
   FFF8Y14NFBFFQ6DGFFFF8T
 )

 Loop 20  ;  Decompressing Nulls : www.autohotkey.com/forum/viewtopic.php?p=198560#198560
  StringReplace,_DT,_DT,% Chr(70+21-A_Index),% SubStr("000000000000000000000",A_Index),All

 VarSetCapacity( _STRU, ( _DTLEN := StrLen(_DT) // 2 ) + 256, 0 )
 Loop %_DTLEN%                                       ;  Creating Binary Structure from Hex
  NumPut( "0x" . SubStr(_DT, 2*A_Index-1,2),_STRU,A_Index-1,"Char" )

 _pIWEB := &_STRU, _pV := &_STRU+16, _DlgT := &_STRU+32

 If ! DllCall( "GetModuleHandle", Str,"atl.dll" )
      DllCall( "LoadLibrary", Str,"atl.dll" )
      DllCall( "atl\AtlAxWinInit" )
 _DlgP := RegisterCallback( A_ThisFunc,0,4,0xCBF )

 }

 _hDLG := DllCall( "CreateDialogIndirectParam", UInt,_Ins, UInt,_DlgT, UInt, ( _Owner="" )
         ? DllCall("FindWindowA", Str,"AutoHotkey", Str,A_ScriptFullPath " - AutoHotkey v"
         . A_AhkVersion ) : _Owner, UInt,_DlgP, UInt,0 )

 VarSetCapacity( _WU,StrLen(_URL)*2+2 ), sLen := StrLen(_URL)+1
 DllCall( "MultiByteToWideChar", UInt,0, UInt,0, UInt,&_URL, Int,-1, UInt,&_WU, Int,sLen )

 _hHTM := DllCall( "GetDlgItem", UInt,_hDLG, UInt,2000, UInt )

 ; www.autohotkey.com/forum/viewtopic.php?p=103987#103987  WebBrowser Control Demo by Sean
 ; ---------------------------------------------------------------------------------------
 DllCall( "atl\AtlAxGetControl", UInt,_hHTM, UIntP,_ppunk )
 DllCall( NumGet( NumGet( _ppunk+0 )+4*0 ), UInt,_ppunk, UInt,_pIWEB, UIntP,_ppwb )
 DllCall( NumGet( NumGet( _ppunk+0 )+4*2 ), UInt,_ppunk ), _pwb := NumGet( _ppwb+0 )
 DllCall( NumGet(_pwb+4*11),UInt,_ppwb, UInt,&_WU, UInt,_pV,UInt,_pV,UInt,_pV,UInt,_pV )
 ; ---------------------------------------------------------------------------------------

 Slee:=-1, HtmD:=1
 Butt:="OK", BWid:=75, BHei:=23, BSpH:=5, BSpV:=8, BAli:=1
 DlgX:="", DlgY:="", HtmW:=280, HtmH:=140, Left:=5, TopM:=5

 Loop, Parse, _Options, =%_ODL%, %A_Space%
   A_Index & 1  ? ( __ := (SubStr(A_LoopField,1,1)="_") ? "_" : SubStr(A_LoopField,1,4))
                : ( %__% := A_LoopField )

 If ( HtmD )
   DllCall( "MoveWindow", UInt,_hHTM, UInt,0, UInt,0, UInt,HtmW, UInt,HtmH, Int,1 )
 Else {
   DllCall( "MoveWindow", UInt,_hHTM, UInt,Left, UInt,TopM, UInt,HtmW, UInt,HtmH, Int,1 )
   Control, Enable,,, ahk_id %_hHTM%
 }

 Cap := DllCall( "GetSystemMetrics", UInt,4  ) ; SM_CYCAPTION    = Window Caption
 Frm := DllCall( "GetSystemMetrics", UInt,7  ) ; SM_CXFIXEDFRAME = Window Frame
 SBW := DllCall( "GetSystemMetrics", UInt,2  ) ; SM_CXVSCROLL    = VScrollbar Width

 DlgW := Frm + HtmW + Frm + ( HtmD ? 0-SBW : Left+Left )
 DlgH := Cap + Frm + HtmH + BSpV + BHei + BSpV + Frm + ( HtmD ? 0 : TopM )
 DlgX := ( DlgX <> "" ) ? DlgX : ( A_ScreenWidth - DlgW ) // 2
 DlgY := ( DlgY <> "" ) ? DlgY : ( A_ScreenHeight - DlgH ) // 2
 ClAW := DlgW - Frm - Frm                                               ; ClientArea Width

 DllCall( "MoveWindow", UInt,_hDLG, UInt,DlgX, UInt,DlgY, UInt,DlgW, UInt,DlgH, Int,1 )

 StringReplace, Butt,Butt, /,/, UseErrorLevel
 bCount := ErrorLevel+1

 If BAli = 0                                                       
 BX := ( BSpH * 2 ) + ( HtmD ? 0 : Left )
 Else If BAli = 1                                                   
 BX := ( ClAW - (BSpH*(bCount-1)) - (BWid*bCount) ) / 2
 Else
 BX := ClAW - (BSpH*(bCount+1)) - (BWid*bCount) - ( HtmD ? 0 : Left )

 BY := HtmH + BSpV + ( HtmD ? 0 : TopM )

 Loop, Parse, Butt, /
  {
    BHwnd := DllCall( "GetDlgItem", UInt,_hDLG, UInt,100+A_Index )
    DllCall( "MoveWindow", UInt,BHwnd, UInt,BX, UInt,BY, UInt,BWid, UInt,BHei, Int,1 )
    DllCall( "SetWindowTextA", UInt,BHwnd, Str,A_LoopField ), BX := BX+BSpH+BWid
    DllCall( "ShowWindow", UInt,BHwnd, Int,True )
  }
 BDef := ( BDef<1 || BDef>bCount ) ? 1 : BDef
 DllCall( "SendMessageA", UInt,_hDLG, UInt,0x401, UInt,100+BDef, UInt,0 )    ; DM_SETDEFID
 ControlFocus,, % "ahk_id " DllCall( "GetDlgItem", UInt,_hDLG, UInt,100+BDef )

 DllCall( "SetWindowTextA", UInt,_hDLG, Str,Titl ? Titl : A_ScriptName )
 Sleep, %Slee%

 WinShow, ahk_id %_hDLG%
 WinWaitClose, ahk_id %_hDLG%,, %Time%

 If ( TimedOut := Errorlevel ) {
  DllCall( "EndDialog", UInt,_hDLG, UInt,0 )
 }

 If ( AltR=1 && BDef ) {
   StringSplit, B, Butt, /
   BDef := B%BDef%
 }

 DllCall( NumGet(_pwb+4*2), UInt,_ppwb ), DllCall( "SetLastError", UInt,TimedOut ? 1 : 0 )
Return BDEf
}

/*

/- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>-  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  - O P T I O N S -
\- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Usage: HtmDlg( URL, hwndOwner, Options, OptionsDelimiter )

Parameters :

URL              - A valid URL supported by Internet Explorer including Res:// and File://

hWndOwner        - Handle to the parent window. If invalid handle or 0 ( zero ) is passed,
                   the dialog will have a taskbar button. Passing "" as a parameter will
                   definitely supress the Taskbar Button.

Options          - A series of 'variable overrides' delimited with character specified in
                   Options delimiter. Please refer 'VARIABLE OVERRIDES' below.

OptionsDelimiter - The delimiter used in seperating 'variable overrides'


;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;  * * *   V A R I A B L E   O V E R R I D E S   * * *
;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Important Note: leading 4 characters of a variable will be sufficient.
                for eg., Instead of 'AltReturn=1' you may use 'AltR=1'

Title         = Captionbar Text
                Default is A_ScriptName

DlgXpos       = X coordinate in pixels, relative to screen
                Dialog is horizontally centered by default

DlgYpos       = Y coordinate in pixels, relative to screen
                Dialog is vertically centered by default

AltReturn     = 1 will return Button-text
                0 is default and Button Instance will be returned

TimeOut       = Seconds
                No Default value
                Note: A_LastError will be true when a TimeOut occurs

Sleep         = MilliSeconds ( Will be used just before Dialog is shown )
                No Sleep by Default

LeftMargin    = Spacing in Pixels ( on the left/right sides of Htm Control )
                Default value is 5. Ignored if Htm control is disabled. See: HtmDisable

TopMargin     = Spacing in Pixels ( above the Htm Control )
                Default value is 5. Ignored if Htm control is disabled. See: HtmDisable

HtmDisable    = 0 to enable
                Htm Control is disabled by default.

HtmWidth      = Width of WebControl in Pixels
                Default value is 240

HtmHeight     = Height of WebControl in pixels
                Default value is 140

Buttons       = Button labels seperated with "/"  ( eg: Buttons=Yes/No/Cancel )
                Default is "OK"

BDefault      = Instance of Default Button ( eg: To make 3rd Button default, use BDef=3 )
                Default forced value is 1

BEscape       = Instance of Cancel Button ( Used when dialog is closed or Esc is pressed )
                Default is 0

BWidth        = Button Width in Pixels
                Default Value is 75

BHeight       = Button height Pixels
                Default value is 23

BSpHorizontal = Pixels ( affects the spacing on the sides of a button )

BSpVertical   = Pixels ( affects the spacing above/below a button )

BAlign        = 0 or 1 or 2  ( for Left, Center, Right alignment of Buttons )
                Default is 1

;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


Edit Log:

2010-07-13.v0.51 : Few important missing static variables now inserted.


Last edited by SKAN on July 13th, 2010, 9:10 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2010, 11:07 pm 
Offline

Joined: January 26th, 2009, 5:26 pm
Posts: 151
:shock: WOW :!: :!: :!:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 12:57 am 
Offline

Joined: September 15th, 2009, 1:14 am
Posts: 562
LiquidGravity wrote:
:shock: WOW :!: :!: :!:

I would have to agree.
Thanks a ton Skan!
I know I'm going to be rewriting all of my stuff to use this highly useful bit of code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 1:15 am 
Offline

Joined: April 8th, 2009, 8:23 pm
Posts: 3036
Location: Rio de Janeiro - RJ - Brasil
Impressive! :D

_________________
"Read the manual. Read it again. Search the forum.
Try something before asking. Show what you've tried.
"
Image
Antonio França
My stuff: Google Profile


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 1:31 am 
Online

Joined: June 7th, 2008, 6:00 am
Posts: 389
No matter what, SKAN, you never cease to amaze me. <3


Last edited by Wicked on July 13th, 2010, 1:34 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 6:27 am 
Offline

Joined: October 26th, 2009, 6:29 am
Posts: 362
Wicked wrote:
No matter what, SKAN, you never sees to amaze me. <3


The phrase is "cease" meaning you never stop amazing...
Not a grammar nazi but it's better to find out now than have it happen in a more embarrassing place.


And amen, I <3 this little tidbit. Hehe I said tidbit.

_________________
Check out the new AHK forum competition!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 7:58 am 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
Very cool SKAN! From now on there should be no more complaints about the limitation of message boxes!!!! The combination of ahk's ability to write HTML on the fly and incorporate a mini browser in a box is very powerful.

Interestingly I had found one trick myself: making the window wider so that the scroll bar is invisible. I just added 34 pixels to a_screenwidth for a full screen app. I haven't figured out yet how you're doing it , but I'll check it out!

It's also amazingly quick, certainly knowing that there is a little browser that you are opening in a box.

Your post inspired me to post my mortgage calculator which prints a payment schedule via HTML (http://www.autohotkey.com/forum/viewtopic.php?p=369069) .

I think this HTML msgbox is a significant contribution to AHK. Congratulations and thank you!

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 1:34 pm 
Online

Joined: June 7th, 2008, 6:00 am
Posts: 389
Ace Coder wrote:
Wicked wrote:
No matter what, SKAN, you never sees to amaze me. <3


The phrase is "cease" meaning you never stop amazing...
Not a grammar nazi but it's better to find out now than have it happen in a more embarrassing place.


And amen, I <3 this little tidbit. Hehe I said tidbit.

Hehe, was very late for me. :P. I've corrected it, thank you. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 3:04 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
This is exactly the type of code I've come to expect from Suresh!

Thank you.

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 8:22 pm 
Offline

Joined: October 1st, 2005, 9:55 pm
Posts: 775
Location: Texas, USA
Good stuff. Thanks for sharing. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 8:36 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thx.

As a related note,there is also Seans ShowHtmlDialog. It does require COM to be there tho, however it is AFAIK more powerful.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 13th, 2010, 11:53 pm 
Offline

Joined: September 15th, 2009, 1:14 am
Posts: 562
flyingDman wrote:
Interestingly I had found one trick myself: making the window wider so that the scroll bar is invisible. I just added 34 pixels to a_screenwidth for a full screen app. I haven't figured out yet how you're doing it , but I'll check it out!


Code:
<Style>
body {overflow-y:hidden; overflow-x:hidden}
</style>

Include that inside your html, preferably near the top or inside a header tag (<head></head>).
What that is doing is using CSS to hide the vertical and horizontal scroll-bars.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 1:05 am 
Offline

Joined: February 27th, 2009, 9:11 am
Posts: 693
Location: Burbank, California
Thank you! Was not aware of a CSS solution for that... Learn every day... I've already removed the ugly "a_screenwidth + 34" from one little app. The result looks the same but now I feel I am not cheating!...

_________________
"Data is not information, information is not knowledge, knowledge is not understanding, understanding is not wisdom" but let's start to get the data...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 2:09 am 
Offline

Joined: September 15th, 2009, 1:14 am
Posts: 562
flyingDman wrote:
Thank you! Was not aware of a CSS solution for that... Learn every day... I've already removed the ugly "a_screenwidth + 34" from one little app. The result looks the same but now I feel I am not cheating!...

No problem. I use to do a bunch of website coding with nothing but html and css. Mainly for the old profile layout for Myspace. If you have any more (this goes for anyone) html or css questions, feel free to PM* me and ask...



*It's best to PM me since I disappear and don't post much here in the forums.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 14th, 2010, 8:35 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Thanks to everybody for the nice words. :)
I thank Sean... if not for his IE webcontrol code, this function would never exist.

codybear wrote:
using CSS to hide the vertical and horizontal scroll-bars

:o Neat!. Thank you very much. :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 79 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: xXDarknessXx and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group