 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Thu Apr 19, 2007 1:59 pm Post subject: |
|
|
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. _________________
 |
|
| Back to top |
|
 |
Markus M.
Joined: 17 Apr 2007 Posts: 14 Location: Stuttgart (Ger)
|
Posted: Thu Apr 19, 2007 3:11 pm Post subject: |
|
|
| majkinetor wrote: | | 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
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Thu Apr 19, 2007 3:19 pm Post subject: |
|
|
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) _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 297 Location: Texas, USA
|
Posted: Thu Apr 19, 2007 8:50 pm Post subject: |
|
|
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?... |
|
| Back to top |
|
 |
freakkk
Joined: 29 Jul 2005 Posts: 114
|
Posted: Thu Apr 19, 2007 10:38 pm Post subject: |
|
|
| Quote: | 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.. | Code: | 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.  _________________ .o0[ corey ]0o. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Thu Apr 19, 2007 10:57 pm Post subject: |
|
|
I think in the archive is old version. Download using ChooseFont link on first page. _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 297 Location: Texas, USA
|
Posted: Fri Apr 20, 2007 4:27 am Post subject: |
|
|
| majkinetor wrote: | | 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. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Fri Apr 20, 2007 8:59 am Post subject: |
|
|
It works here, and it works in HexView.
This is the script. I downloaded it from here and included bellow.
| Code: | pFace := "Courier New", pStyle := "italic bold underline strikeout" ,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
}
|
_________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 297 Location: Texas, USA
|
Posted: Fri Apr 20, 2007 2:59 pm Post subject: |
|
|
| majkinetor wrote: | It works here, and it works in HexView.
This is the script. I downloaded it from here and included bellow.
...snip...
|
The initial (passed to) values appear to be set correctly but the return values, specifically the Style parameter, is not set correctly, at least not for me. In your example, without changing anything and clicking on the OK button, the pStyle variable is set to "s-1".
Thanks. |
|
| Back to top |
|
 |
TUFKABoBo Guest
|
Posted: Fri Apr 20, 2007 3:28 pm Post subject: |
|
|
This is the small bug I obviously made, and it appears when there is no s in initialization. Like this it works:
pStyle := "s12 italic bold underline strikeout"
This is the fixed function that doesn't require this:
| Code: | ;----------------------------------------------------------------------------------------------
; 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 "
if LogPixels =
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
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
}
|
Thx jballi |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Fri Apr 20, 2007 3:31 pm Post subject: |
|
|
Ah, sorry for TUFKABobo post... I was reserving nickname for BoBo and forgot to logout...
I think functions are pretty fine now.. small bugs have been fixed ... I just don't know if to implement custom colors in ChooseColor dialog. This can be done by passing Registry key or ini file where do you want user color to be saved and loaded afterwards... _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 297 Location: Texas, USA
|
Posted: Sat Apr 21, 2007 1:39 am Post subject: |
|
|
| majkinetor wrote: | This is the small bug I obviously made, and it appears when there is no s in initialization. Like this it works:
pStyle := "s12 italic bold underline strikeout"
snip
|
Font size is now returned but other style options (bold, underline, etc.) are not returned. |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Sat Apr 21, 2007 10:52 am Post subject: |
|
|
Omg, I must be insane.... I put := where . should be.... _________________
 |
|
| Back to top |
|
 |
majkinetor
Joined: 24 May 2006 Posts: 3544 Location: Belgrade
|
Posted: Sat Apr 21, 2007 12:06 pm Post subject: |
|
|
OK...
I today polished those 3 functions:
- Win 2K fix as noted by Markus
- Now all functions return false on failure as noted by toralf
- Bugs noted by jballi fixed and ChooseFont color bug fixed.
- Single include for all 3 commong dialogs and documentation made
If you don't see any further problems, I think that this should be linked to the help file instead:
| FileSelectFile/Folder wrote: | Related
FileSelectFolder, MsgBox, InputBox, ToolTip, GUI, CLSID List, parsing loop, SplitPath
Also, the operating system offers two standard dialogs that prompt the user to pick a font and/or color. These dialogs can be displayed via DllCall() as demonstrated in the forum topics ChooseFont and ChooseColor.
|
which link to the outdated script examples. _________________
 |
|
| Back to top |
|
 |
jballi
Joined: 01 Oct 2005 Posts: 297 Location: Texas, USA
|
Posted: Sun Apr 22, 2007 12:04 am Post subject: |
|
|
The ChooseFont is much impoved. Thanks. I'm only making a fuss about this function because I'm hoping to use it in the future.
One additional idiosyncrasy. The color value returned is sometimes correct but usually it's not.
Thanks. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|