AutoHotkey Community

It is currently May 27th, 2012, 8:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 166 posts ]  Go to page Previous  1, 2, 3, 4, 5 ... 12  Next
Author Message
 Post subject:
PostPosted: April 28th, 2006, 11:15 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Edited my first post so the first function follows more my coding rules (these functions will go in my function library) and to post the two others.
Of course, these are only one way to do this, there may be other tricks and al. Laszlo and toralf would remove some braces and pull out some obscure tricks. :-) But they seems to be a good compromise between readability (what is the logic behind the code) and optimization (strings are small, so over-optimizing may be fun, but quite useless).

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 11:38 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear PhiLho, :)

You wrote:
Edited my first post so the first function follows more my coding rules (these functions will go in my function library) and to post the two others.


Thanks again! :D

My version of CheckHexC() was dependent on the other two functions. Your version is just great!

This following function was posted by Rubberduck
@ http://www.autohotkey.com/forum/viewtopic.php?t=3401

I tried using it and had some errors (which I do not remember / not able to reproduce now).

Code:
;**** Function RGBtoHex(R,G,B)
;**** R,G and B are decimals. Returned is a hex e.g. 0xFFACBC
RGBtoHex(R,G,B)
{
   local Ret_Val
   SetFormat, Integer, Hex
   Ret_Val := (R << 16) | (G << 8) | B
   SetFormat, Integer, D
   return, Ret_Val
}


Do you see any error in it?

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on April 28th, 2006, 10:08 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 1:21 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
No, it is very close of my algorithm, without parsing and without removing the 0x prefix.
Of course, if any value is above 255, you get problems.
And it has a flaw, like my code (which I corrected and updated): for 0, 5, 0, it gives 0x500, no 0x000500.
Please, can you remove your quotes of my code, as I update my original post but the old code is still in your messages? Thank you.
Of course, you are free to post any variation of my code as you feel it.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 1:42 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear PhiLho, :)

You wrote:
it has a flaw, like my code (which I corrected and updated): for 0, 5, 0, it gives 0x500, no 0x000500.


Yes!.. I remember now.. This was it.. I am glad it has been rectified!

Thanks! :D

You wrote:
can you remove your quotes of my code, as I update my original post but the old code is still in your messages?


Sure & have done it ..

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 28th, 2006, 9:53 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
ownage (req. 1.0.46.x+) :
Code:
MsgBox, % "Example:`n`n" . rgbToHex("255,255,255") . "`n" . HexToRgb("#FFFFFF") . "`n" . CheckHexC("000000")

rgbToHex(s, d = "") {
   StringSplit, s, s, % d = "" ? "," : d
   SetFormat, Integer, % (f := A_FormatInteger) = "D" ? "H" : f
   h := s1 + 0 . s2 + 0 . s3 + 0
   SetFormat, Integer, %f%
   Return, "#" . RegExReplace(RegExReplace(h, "0x(.)(?=$|0x)", "0$1"), "0x")
}

hexToRgb(s, d = "") {
   SetFormat, Integer, % (f := A_FormatInteger) = "H" ? "D" : f
   Loop, % StrLen(s := RegExReplace(s, "^(?:0x|#)")) // 2
      c%A_Index% := 0 + (h := "0x" . SubStr(s, A_Index * 2 - 1, 2))
   SetFormat, Integer, %f%
   Return, c1 . (d := d = "" ? "," : d) . c2 . d . c3
}

CheckHexC(s, d = "") {
   If InStr(s, (d := d = "" ? "," : d))
      e := hexToRgb(rgbToHex(s, d), d) = s
   Else e := rgbToHex(hexToRgb(s)) = (InStr(s, "#") ? "" : "#"
      . RegExReplace(s, "^0x"))
   Return, e
}

_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on November 29th, 2006, 8:33 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 2nd, 2006, 12:51 pm 
@Goyyah:
Today your string manipulation functions have been very useful for me. Many thanks.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 30th, 2006, 8:07 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
GetBinaryType() - requires Windows NT/2000/XP or later

Usage : GetBinaryType(Filename)

GetBinaryType() determines whether a file is executable, and if so, what type of
executable file it is, and returns one of the following:

    32-Bit
    DOS
    16-Bit
    PIF
    POSIX
    OS2-16-Bit
    64-Bit


    ... and also

    File not found
    Not Executable

MSDN Reference : GetBinaryType function.

I have been using console based ExeType.exe bundled with the Windows 98 ResKit,
and now I have written GUI-ExeType - A Drag & Drop GUI Utility for similar functionality.

GetBinaryType() does not consider the file extension. You might have downloaded a .ZIP file
that does not Unzip. It could be an executable which you can find out by dropping it on GUI-ExeType!.
    Gui-ExeType.ahk - calls GetBinaryType()
Code:
/* ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;
*                                                                            *
*  Filename: Gui-ExeType.ahk                                                 *
*  Desc    : Drag and Drop GUI for finding the type of an Executable file.   *
*  Author  : A.N.Suresh Kumar aka "Goyyah"                                   *
*  Dated   : 30-Jun-2006 / Last Modifed: 30-Jun-2006                         *
*                                                                            *
*/ ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ;

If A_OSType <> WIN32_NT
   ExitApp

Gui, +AlwaysOnTop +ToolWindow
Gui +LastFound
ID:= WinExist()
Gui, Add, GroupBox, w285 h66, Drag `&& Drop File here %A_Space%
Gui, Font, S10, Verdana
Gui, Add, Text, x15 y27 w75 Right, File name:
Gui, Add, Text, x15 y+1 w75 Right, Exe. type:
Gui, Font, Bold
Gui, Add, Text, x93 y27 vFile w200
Gui, Add, Text, x93 y+1 vType w200
Gui, Show, AutoSize, GUI-ExeType
Return

GuiClose:
GuiEscape:
 ExitApp
Return

GuiDropFiles:
  FileType:=GetBinaryType(A_GuiControlEvent)
  SplitPath, A_GuiControlEvent, FileName
  GuiControl,,File, %FileName%
  GuiControl,,Type, %FileType%
Return

GetBinaryType(FileName) {
  IfNotExist, %FileName%, Return "File not found"
  Binary:=DllCall("GetBinaryType","Str", FileName, "UInt *", RetVal)
  IfEqual, Binary, 0, Return "Not Executable"
  BinaryTypes := "32-Bit|DOS|16-Bit|PIF|POSIX|OS2-16-Bit|64-Bit"
  StringSplit, BinaryType , BinaryTypes, |
  BinaryType:="BinaryType" . RetVal + 1
Return (%BinaryType%)
}




_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: GetSysColor()
PostPosted: July 2nd, 2006, 10:11 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
GetSysColor()

Usage : GetSysColor(DisplayElement)

GetSysColor() Retrieves the current color of the specified display element and returns it as RGB Hexcode.
Display elements are the parts of a window and the display that appear on the system display screen.

Edit: Function has been updated - Many thanks to Mr.Laszlo

Code:
GetSysColor(d_element) {
A_FI:=A_FormatInteger
SetFormat, Integer, Hex
BGR:=DllCall("GetSysColor"
 ,Int,d_element)+0x1000000
SetFormat,Integer,%A_FI%
StringMid,R,BGR,8,2
StringMid,G,BGR,6,2
StringMid,B,BGR,4,2
RGB := R G B
StringUpper,RGB,RGB
Return RGB
}


MSDN Reference : GetSysColor function.

Copy / Paste / Try example:

Code:
; Example to simulate a Tooltip Window

InfoText := GetSysColor(23) ; COLOR_INFOTEXT
InfoWind := GetSysColor(24) ; COLOR_INFOBK

Gui, 99:-Caption +ToolWindow +AlwaysOnTop +Border
Gui, 99:Margin, 2, 2
Gui, 99:Color, %InfoWind%
Gui, 99:Add, Text, c%InfoText%, This is a Simulated`nTooltip - Goyyah!

CoordMode, Mouse, Screen
MouseGetPos, X, Y
Gui, 99:Show, x%X% y%Y%, AHK.Simulated.Tooltip.Window

Sleep 4000
ExitApp
Return

GetSysColor(d_element) {
A_FI:=A_FormatInteger
SetFormat, Integer, Hex
BGR:=DllCall("GetSysColor"
 ,Int,d_element)+0x1000000
SetFormat,Integer,%A_FI%
StringMid,R,BGR,8,2
StringMid,G,BGR,6,2
StringMid,B,BGR,4,2
RGB := R G B
StringUpper,RGB,RGB
Return RGB
}




The following are the Parameters to be used with GetSysColor().

Code:

COLOR_3DDKSHADOW = 21       ; Dark shadow for three-dimensional display elements.

COLOR_3DFACE = 15           ; Face color for three-dimensional display elements
                            ; and for dialog box backgrounds.

COLOR_3DHIGHLIGHT = 20      ; Highlight color for three-dimensional display elements
                            ; (for edges facing the light source.)

COLOR_3DHILIGHT = 20        ; Highlight color for three-dimensional display elements
                            ; (for edges facing the light source.)

COLOR_3DLIGHT = 22          ; Light color for three-dimensional display elements
                            ; (for edges facing the light source.)

COLOR_3DSHADOW = 16         ; Shadow color for three-dimensional display elements
                            ; (for edges facing away from the light source).

COLOR_ACTIVEBORDER = 10     ; Active window border.

COLOR_ACTIVECAPTION = 2     ; Active window title bar. Specifies the left side color
                            ; in the color gradient of an active window's title bar
                            ; if the gradient effect is enabled.
                            ; Windows NT and Windows 95: This remark does not apply.

COLOR_APPWORKSPACE = 12     ; Background color of multiple document interface
                            ; (MDI) applications.

COLOR_BACKGROUND = 1        ; Desktop.

COLOR_BTNFACE = 15          ; Face color for three-dimensional display elements and
                            ; for dialog box backgrounds.

COLOR_BTNHIGHLIGHT = 20     ; Highlight color for three-dimensional display elements
                            ; (for edges facing the light source.)

COLOR_BTNHILIGHT = 20       ; Highlight color for three-dimensional display elements
                            ; (for edges facing the light source.)

COLOR_BTNSHADOW = 16        ; Shadow color for three-dimensional display elements
                            ; (for edges facing away from the light source).
COLOR_BTNTEXT = 18          ; Text on push buttons.

COLOR_CAPTIONTEXT = 9       ; Text in caption, size box, and scroll bar arrow box.

COLOR_DESKTOP =  1          ; Desktop.

COLOR_GRADIENTACTIVECAPTION = 27 ; See comment below.

/*
Right side color in the color gradient of an active window's title bar.
COLOR_ACTIVECAPTION specifies the left side color. Use SPI_GETGRADIENTCAPTIONS
with the SystemParametersInfo function to determine whether the gradient effect
is enabled.
Windows NT and Windows 95:  This value is not supported.
*/

COLOR_GRADIENTINACTIVECAPTION = 28 ; See comment below.

/*
Right side color in the color gradient of an inactive window's title bar.
COLOR_INACTIVECAPTION specifies the left side color.
Windows NT and Windows 95:  This value is not supported.
*/

COLOR_GRAYTEXT = 17         ; Grayed (disabled) text. This color is set to 0 if the
                            ; current display driver does not support a solid gray
                            ; color.

COLOR_HIGHLIGHT = 13        ; Item(s) selected in a control.

COLOR_HIGHLIGHTTEXT = 14    ; Text of item(s) selected in a control.

COLOR_HOTLIGHT = 26         ; Color for a hyperlink or hot-tracked item.
                            ; Windows NT & Windows 95: This value is not supported.

COLOR_INACTIVEBORDER = 11   ; Inactive window border.

COLOR_INACTIVECAPTION = 3   ; See comment below.

/*
Inactive window caption. Specifies the left side color in the color gradient
of an inactive window's title bar if the gradient effect is enabled.
Windows NT and Windows 95:  This remark does not apply.
*/
 
COLOR_INACTIVECAPTIONTEXT = 19 ; Color of text in an inactive caption.

COLOR_INFOBK = 24           ; Background color for tooltip controls.

COLOR_INFOTEXT = 23         ; Text color for tooltip controls.

COLOR_MENU = 4              ; Menu background.

COLOR_MENUHILIGHT = 29      ; See comment below.

/*
The color used to highlight menu items when the menu appears as a flat menu.
See SystemParametersInfo.The highlighted menu item is outlined with COLOR_HIGHLIGHT.
Windows 2000/NT & Windows Me/98/95:  This value is not supported.
*/

COLOR_MENUBAR = 30          ; See comment below.

/*
The background color for the menu bar when menus appear as flat menus.
See SystemParametersInfo. However, COLOR_MENU continues to specify the background
color of the menu popup.
Windows 2000/NT and Windows Me/98/95:  This value is not supported.
*/

COLOR_MENUTEXT = 7          ; Text in menus.

COLOR_SCROLLBAR = 0         ; Scroll bar gray area.

COLOR_WINDOW = 5            ; Window background.

COLOR_WINDOWFRAME = 6       ; Window frame.

COLOR_WINDOWTEXT = 8        ; Text in windows.



Edit: 2006-Jul-03 : Chris has already posted













Quote:
Short Version: 2007-Nov-20

Code:
GetSysColor( Dis=1, RGB=1, Pre="" ) {
  Static Hex := "123456789ABCDEF0"
  VarSetCapacity( TMV,4,0 ), NumPut(DllCall( "GetSysColor",Int,Dis), TMV ), Ptr:=&TMV-1
  Loop 3
    V%A_Index% := SubStr(Hex, (*++Ptr >> 4), 1) . SubStr(Hex, (*Ptr & 15), 1)
Return Pre . ( RGB ? V1 V2 V3 : V3 V2 V1 )
}


If RGB is false the returned hex will be BGR
Pre is prefix which maybe "0x" or "#"

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on February 21st, 2008, 3:30 pm, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 3:07 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Nice find, as always!
To handle leading 0's, this looks better
Code:
BGR:=DllCall("GetSysColor",Int,d_element)+0x1000000


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 5:15 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Dear Laszlo, :)

You wrote:
Nice find, as always!


Thanks ! :D

You wrote:
To handle leading 0's, this looks better
Code:
BGR:=DllCall("GetSysColor",Int,d_element)+0x1000000


Oops! :( . I did not test the function enough ... :(
Many thanks for noticing & pointing it out.

I request you to look into the updated code & let me know whether its logically correct.

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 5:42 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
"BGR=000000%BGR%" inserts 0's in the front. It is OK, but needs an extra instruction to remove 0x first. The easiest is to add 0x1000000 to the dll result (instead of +0). That makes the result always 7 hex digits, and you just cut the digits needed.
Code:
BGR:=DllCall("GetSysColor",Int,d_element)+0x1000000
SetFormat,Integer,%A_FI%
StringMid,R,BGR,8,2
StringMid,G,BGR,6,2
StringMid,B,BGR,4,2


Last edited by Laszlo on July 2nd, 2006, 5:49 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 5:47 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Laszlo wrote:
The easiest is to add 0x1000000 to the dll result (instead of +0). That makes the result always 7 hex digits, and you just cut the digits needed.


But the output color is slightly different ... or Am I wrong?

Please enlighten!

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on July 2nd, 2006, 6:11 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 5:53 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
(I sent my post too fast. See edit above. Both versions should be the same, because adding 0x1000000 does not cause a carry.)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 2nd, 2006, 5:53 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Laszlo wrote:
(Both versions should be the same, because adding 0x1000000 does not cause a carry.)


I did not change the string position for 3 StringMids and was getting bizarre results :oops:

Many thanks!

Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Report this post
Top
 Profile  
Reply with quote  
 Post subject: GetShortPathName()
PostPosted: July 25th, 2006, 10:38 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
Quote:
GetShortPathName()

Usage : GetShortPathName(LongPath)

GetShortPathName() is a wrapper for GetShortPathName function available in Kernel32.dll.
This function converts Folder & Filenames to DOS-Styled 8.3 naming convention.

Refer Topic : Reduce paths to dos terminology (like C:\docume~1\) started by Kerry

Edit: Function has been updated - Many thanks to Mr.PhiLho

The Wrapper:


Code:
GetShortPathName(LongPath) {
; http://www.autohotkey.com/forum/viewtopic.php?p=69366#69366
StringLen:=(StrLen(Longpath)+1)
VarSetCapacity(Shortpath,StringLen)
DllCall("GetShortPathName", Str,LongPath
       , Str,ShortPath, Int,StringLen)
Return Shortpath
}


Copy / Paste / Try Example :

Code:
MsgBox, 64, %A_ScriptName%     , % GetShortPathName(A_ScriptFullPath), 3
MsgBox, 64, Windows Directory  , % GetShortPathName(A_Windir)        , 3
MsgBox, 64, Temp Directory     , % GetShortPathName(A_Temp)          , 3
MsgBox, 64, Desktop            , % GetShortPathName(A_Desktop)       , 3
MsgBox, 64, Desktop (All Users), % GetShortPathName(A_DesktopCommon) , 3
MsgBox, 64, AutoHotkey.Exe     , % GetShortPathName(A_AhkPath)       , 3
Return

GetShortPathName(LongPath) {
; http://www.autohotkey.com/forum/viewtopic.php?p=69366#69366
StringLen:=(StrLen(Longpath)+1)
VarSetCapacity(Shortpath,StringLen)
DllCall("GetShortPathName", Str,LongPath
       , Str,ShortPath, Int,StringLen)
Return Shortpath
}



Regards, :)

_________________
URLGet - Internet Explorer based Downloader
StartEx - Portable Shortcut Link


Last edited by SKAN on July 25th, 2006, 11:41 am, edited 1 time in total.

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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], hyper_, tomoe_uehara, xXDarknessXx and 9 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