Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[module] Dlg 5.01


  • Please log in to reply
37 replies to this topic
majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Yeah, I love AHK too, don't know why though... i usualy hate it more then I love it..... maybe the community, maybe nothing at all, just fetish... who knows...


At least, there is nothing yet around that is better, and I define "better" on many plains.

About your VB i say you pwn it, and totaly switch to Delphi. Delphi is one of the best IDEs, IMO, you can find around.
Posted Image

Markus M.
  • Members
  • 14 posts
  • Last active: Dec 17 2007 01:14 PM
  • Joined: 17 Apr 2007

About your VB i say you pwn it, and totaly switch to Delphi. Delphi is one of the best IDEs, IMO, you can find around.


i have some little experience with borland pascal 7.0, which is simillar. but it was really a long time ago. i remember the really fast compiler that generated very optimized machine code :-)

Posted Image

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
Yes. Object Pascal is extremely fast, so fast, that it compiles entire code on every few keypresses.... (their implementation of intelisense relys on that, thats why Borland's CBuilder didn't have intelissense up to version 4, as C compiler is not fast at all due to its ugly syntax, so they had to do it differently)

However Borland Pascal 7.0 is far from Object Pascal. They share the basic syntax but everything else is new, there are even C like strings - P(Ansi/Wide)Char, contrary to pascal strings that are not zero terminated (AHK has acctually, the Pascal strings)
Posted Image

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
Using the example code, I just tried the ChooseIcon dialog. The font size doesn't appear to work correctly. I tried to select Courier New size 10 and the function returns size 13. Selecting size 20 returns size 27 and so on...

Any ideas?...

freakkk
  • Members
  • 182 posts
  • Last active: Dec 16 2014 06:23 PM
  • Joined: 29 Jul 2005

There is, sadly, no method to show modal windows in AHK. You can make only dialogs modal.

That is the reason why ChooseIconEx uses modality loop at the end of its function main function.

I was looking though the ChooseIcon script.. & I'm not sure where the modality loop was. I've always kept threads (or pseudo threads...) alive in gui's & functions..
MsgBox, % "The result of my input box is '" . CreateGUI1() . "'."
MsgBox, % "The result of my 2nd input box is '" . CreateGUI1() . "'."
ExitApp

;  (¯·._ (¯·._ Function: GUI1 _.·´¯) _.·´¯)
CreateGUI1()
{
  Global Gui1InputField
	Static Gui1HWND, Gui1Cancel, Gui1Okay

	Gui 1:+LastFoundExist
	IfWinExist
	  return  ;..gui1 already exists..

	Gui, 1:Default
	Gui, 1:+LabelGui1
	Gui, 1:+LastFound
	Gui1HWND := WinExist() ; Handle to the GUI

	Gui, Add, Text,   x6   y17  w30  h20                                 , Input:
	Gui, Add, Edit,   x36  y17  w180 h20 vGui1InputField,
	Gui, Add, Button, x96  y47  w60  h20 default vGui1Okay gGui1Okay     , &Okay
	Gui, Add, Button, x156 y47  w60  h20 vGui1Cancel gGui1Cancel         , C&ancel
	Gui, Show,        x319 y308 w227 h81                                 , Gui1Name

	Loop     ;--wait for return code..
	{
		if Gui1ReturnCode 
      break
	}
  Gui, 1:Destroy
Return Gui1ReturnCode
;-----------------
Gui1Cancel:
Gui1Escape:
Gui1Close:
	Gui1ReturnCode = -1
return
;-----------------
Gui1Okay:
GuiControlGet, Gui1ReturnCode, 1:, Gui1InputField
return
;--------- End of Function: GUI1 ------------
}
--but always wondered if there is a better way to do it. :?:

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
I think in the archive is old version. Download using ChooseFont link on first page.
Posted Image

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005

I think in the archive is old version. Download using ChooseFont link on first page.

I assume this was a reply to my post...

Per your instructions, I downloaded the the ChooseFont function directly from the first post. The font size problem appears to be fixed but now setting the font style (Bold, Italic, etc.) or Effects (Strikeout and Underline) don't do anything -- always returns regular font style and no effects.

Thanks for your help.

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
It works here, and it works in HexView.
This is the script. I downloaded it from here and included bellow.

pFace := "Courier New", [color=violet]pStyle := "italic bold underline strikeout"[/color] ,pColor := "0xFF"
ChooseFont(pFace, pStyle, pColor)
 


ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4)
; pSource is a string (buffer) whose memory area contains a raw/binary integer at pOffset.
; The caller should pass true for pSigned to interpret the result as signed vs. unsigned.
; pSize is the size of PSource's integer in bytes (e.g. 4 bytes for a DWORD or Int).
; pSource must be ByRef to avoid corruption during the formal-to-actual copying process
; (since pSource might contain valid data beyond its first binary zero).
{
    Loop %pSize%  ; Build the integer by adding up its bytes.
        result += *(&pSource + pOffset + A_Index-1) << 8*(A_Index-1)
    if (!pIsSigned OR pSize > 4 OR result < 0x80000000)
        return result  ; Signed vs. unsigned doesn't matter in these cases.
    ; Otherwise, convert the value (now known to be 32-bit) to its signed counterpart:
    return -(0xFFFFFFFF - result + 1)
}

InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
; only pSize number of bytes starting at pOffset are altered in it.
{
    Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
        DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
}

;----------------------------------------------------------------------------------------------
; Function:		ChooseFont
;				Display standard font dialog
;
; Parameters:
;				pFace	- Initial font,  output
;				pStyle	- Initial style, output 
;				pColor	- Initial text color, output
; 				hGui	- Parent's handle, affects modality and position
;
;  Returns:
;				False if user canceled the dialog or if error occured
;
ChooseFont(ByRef pFace, ByRef pStyle, ByRef pColor, hGui=0) {

	VarSetCapacity(SLogFont, 128, 0)

	;set initial name
	DllCall("RtlMoveMemory", "uint", &SLogFont+28, "Uint", &pFace, "Uint", 32)

	;set intial data
	if InStr(pStyle, "bold")
		InsertInteger(700, SLogFont, 16)

	if InStr(pStyle, "italic")
		InsertInteger(255, SLogFont, 20, 1	)

	if InStr(pStyle, "underline")
		InsertInteger(1, SLogFont, 21, 1)
	
	if InStr(pStyle, "strikeout")
		InsertInteger(1, SLogFont, 22, 1)

	if RegExMatch( pStyle, "s[1-9][0-9]*", s){
		StringTrimLeft, s, s, 1		

		RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels 
		s := -DllCall("MulDiv", "int", s, "int", LogPixels, "int", 72)
		InsertInteger(s, SLogFont, 0)				; set size
	}
	else  InsertInteger(16, SLogFont, 0)			; set size

    _rgb := pColor
    pColor := ((_rgb & 0xFF) << 16) + (_rgb & 0xFF00) + ((_rgb >> 16) & 0xFF) 

	VarSetCapacity(SChooseFont, 60, 0) 
	InsertInteger(60,		 SChooseFont, 0)		; DWORD lStructSize 
	InsertInteger(hGui,		 SChooseFont, 4)		; HWND hwndOwner (makes dialog "modal"). 
	InsertInteger(&SLogFont, SChooseFont, 12)		; LPLOGFONT lpLogFont 
	InsertInteger(0x141,	 SChooseFont, 20)		; CF_EFFECTS = 0x100, CF_SCREENFONTS = 1, CF_INITTOLOGFONTSTRUCT = 0x40
	InsertInteger(pColor,	 SChooseFont, 24)		; rgbColors

	r := DllCall("comdlg32\ChooseFontA", "uint", &SChooseFont)  ; Display the dialog. 
	if !r
		return 0

	;font name
	VarSetCapacity(pFace, 32)
	DllCall("RtlMoveMemory", "str", pFace, "Uint", &SLogFont + 28, "Uint", 32)
	pStyle := "s" ExtractInteger(SChooseFont, 16) // 10

	;color
	old := A_FormatInteger
	SetFormat, integer, hex							 ; Show RGB color extracted below in hex format.
	pColor := ExtractInteger(SChooseFont, 24)
	pColor := (pColor & 0xFF) << 16 | ((pColor >> 8) & 0xFF) | (pColor >> 16) 
	SetFormat, integer, %old%

	;styles
	pStyle =
	VarSetCapacity(s, 3)
	DllCall("RtlMoveMemory", "str", s, "Uint", &SLogFont + 20, "Uint", 3)

	if ExtractInteger(SLogFont, 16) >= 700
		pStyle .= "bold "

	if ExtractInteger(SLogFont, 20, false, 1)
		pStyle .= "italic "
	
	if ExtractInteger(SLogFont, 21, false, 1)
		pStyle .= "underline "

	if ExtractInteger(SLogFont, 22, false, 1)
		pStyle .= "strikeout "

	s := ExtractInteger(sLogFont, 0, true)
	pStyle := "s" DllCall("MulDiv", "int", abs(s), "int", 72, "int", LogPixels) . " "

	StringTrimRight, s, s, 1		;remove trailing space
	return 1
}


Posted Image