Deutsches AutoHotkey Homepage AutoHotkey Community
Wir helfen uns gegenseitig aus der Patsche
 
 FAQFAQ   SuchenSuchen   MitgliederlisteMitgliederliste   RegistrierenRegistrieren 
 ProfilProfil   Einloggen, um private Nachrichten zu lesenEinloggen, um private Nachrichten zu lesen   LoginLogin 

Skripte, die wo von DerRaphael gemacht wurden :)
Gehe zu Seite Zurück  1, 2, 3, 4  Weiter
 
Neues Thema eröffnen   Neue Antwort erstellen    AutoHotkey Community Foren-Übersicht -> Smalltalk
Vorheriges Thema anzeigen :: Nächstes Thema anzeigen  
Autor Nachricht
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:14 am    Titel: Antworten mit Zitat

Frage: has anyone ever made a window a user can edit data in?
http://www.autohotkey.com/forum/viewtopic.php?p=171898#171898

Resultat
Code:

FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt)
if SelectedFile =
    MsgBox, The user didn't select anything.
else
{
    RO = 1
    Gui, Add, Edit, R20 +ReadOnly vMyEdit
    Gui, Add, Button, wp gtEdit, Toggle Edit
    FileRead, FileContents, %SelectedFile%
    GuiControl,, MyEdit, %FileContents%
    Gui, Show
}
return

tEdit:
  if (RO=1) {
    RO = 0
    GuiControl, -ReadOnly, MyEdit
  } else {
    RO = 1
    GuiControl, +ReadOnly, MyEdit
  } 
return

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:17 am    Titel: Antworten mit Zitat

Für alle, die sich schonmal gewundert haben, wie man den Anykey als Hotkey nutzen kann:

Resultat
Code:

; da AnyKey.ahk
; (c) 2k8 derRaphael / zLib License Style release

Gosub, Start
Gui, Add, Text,, % "You'll only see this GUI, "
                 . "when no Key was pressed while asked for`n`n"
                 . "You'd better press that anykey!"
Gui, Add, Button, gTest1 wp, Map any key to trigger hotkey CTRL+F12
Gui, Add, Button, gTest2 wp, Map any key to access label Testing
Gui, Add, Button, gTest3 wp, Map any key as at script's startup
Gui, Show,, DUH! AnyKey not found, uh`?
return

Testing:
 MsgBox This is label "Testing"
return

Test1:
 MsgBox,0,Test #1, % "This test maps our anykey to hardcoded`n"
                   . "Hotkey CTRL+F12 once with no Timeout`n"
                   . "and no PopupWindow"
 AnyKey("^f12",0,"")
return

Test2:
 MsgBox,0,Test #2, % "This test maps anykey to label Testing`n"
                   . "in source for 10 seconds and no PopupWindow"
 
 res := AnyKey("Testing",10,"")
 if (res=="Timeout") {
   MsgBox,0,Time's up,You didn't press the anykey in 10 seconds
 }
return

Test3:
 MsgBox,0,Test #3,% "This test is just repeating script's startup anykey:`n"
                  . "5 seconds Timeout and custom Popup"
Start:
 res := AnyKey("GuiClose",5,"Press any Key to exit this App")
 if (res=="Timeout") {
   MsgBox,0,Time's up,You didn't press the anykey in 5 seconds
 }
return

^f12::
MsgBox Hotkey CTRL+F12
return

GuiClose:
    ExitApp
return

AnyKey:
; Default Label for AnyKey Action
Return

AnyKey( Label="AnyKey", Duration=0, sText="Press the anykey..." ) {

    if (sText!="") {
      SplashTextOn,,, % sText
    }
    defReturnValue := 1

    If (Duration) AND ( (Duration is Integer) OR (Duration is Float) ) {
       D := "T" Duration
    }
    EndKeys := "{LControl}{RControl}{LShift}{RShift}{LAlt}{RAlt}"
             . "{LWin}{RWin}{LAlt}{RAlt}{AppsKey}"

    Input, AnyKey, L1 %D%, % EndKeys
    defReturnValue := AnyKey

    if (sText!="") {
      SplashTextOff
    }

    If (InStr(ErrorLevel,"Endkey")) {
      defReturnValue := SubStr(ErrorLevel,StrLen("EndKey:")+1)
    } else If (ErrorLevel=="Timeout") {
      defReturnValue := "Timeout"
    }

    If ( (Label) AND (defReturnValue!="Timeout") AND (Islabel(Label)) ) {
      Gosub, % Label
    } else {
      Return, % defReturnValue
    }
}

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:20 am    Titel: Antworten mit Zitat

Frage: RadioControl in einer Gruppe direkt anwählen?
http://www.autohotkey.com/forum/viewtopic.php?p=171275#171275

Resultat
Code:

gui, add, edit,x15 readonly,Highlight Value
gui, add, radio,x+5 hwndradio1 gHighlightValue vHighlightValue,1
gui, add, radio,x+1 hwndradio2 gHighlightValue ,2
gui, add, radio,x+1 hwndradio3 gHighlightValue ,3
gui, add, radio,x+1 hwndradio4 gHighlightValue ,4
gui, add, radio,x+1 hwndradio5 gHighlightValue ,5
gui,show
;guicontrol,,3,1
; use control instead
control, check,,,ahk_id %radio3%
highlightvalue:
return


maybe operating with the radiocontrol's hWnd and the control command will give you the desired reliability in your bigger script, since every control has an unique hWnd (as unique as classNN but easier to use)
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:22 am    Titel: Antworten mit Zitat

Frage: Hotkey um eine Loop zu verlassen
http://www.autohotkey.com/forum/viewtopic.php?p=171099#171099

Resultat:
this code loops and tooltips the round it loops untill f1 is pressed.

Code:
gosub, test1
return

test1:
loop
{
  tooltip, % a_index
  if (getkeystate("f1",p)) { ; checks for keystate of f1 different to 0 (= notpressed)
    break
  }
}
msgbox broken loop with f1
return


when you use a variable containing the keyname in it instead of "f1" NOT a combination as "!f1" you have your own primitive hotkey support
to use any altering keys such as control or alt or shift each must be checked seperately with getkeystate therefor the code gets more complex and is not too flexible

but why dont u simply use
Code:

setBatchLines, -1 ; fastest way to run scripts without critical command
a:=0
setTimer, myLabel, 1
return

f1::
setTimer, myLabel, OFF ; turns off timerloop
msgbox broken settimer
return

mylabel:
tooltip % a++
return



this way u'd buy comfort with a slower routine, but you can use hotkeys however u like 'em

depends on what you try to do and whether as much execution speed as possible is really neccessary
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:25 am    Titel: Antworten mit Zitat

Frage: Shutdown des Computers nach beendigung der downloads mit dTA!
http://www.autohotkey.com/forum/viewtopic.php?p=170027#170027

Resultat:

Code:

; dta! - chex and windows shutdown
; by derRaphael - distributed under zlib license style

; start check for %-sign in the title of dta! every 5 sec
#Persistent
setTimer, checkDTAWindowDLStat, 5000
return

checkDTAwindowDLStat:
 ToolTip, Checking dta! Download status...
 setTimer, ttoff, 1000
 oldSTMM := A_TitleMatchMode
 SetTitleMatchMode, 2
 WinGetTitle, dtaTitle, DownThemAll ahk_class MozillaUIWindowClass
 dtaTitleDLStats := SubStr(dtaTitle,1,InStr(dtaTitle," ")-1)
 if !(InStr(dtaTitleDLStats,"%")) {
    setTimer, checkDTAWindowDLStat, OFF
    ; ok - %-sign vanished from title
    ; start check for window to vanish - since it takes time to
    ; puzzle different dl fragments together and shutting down while
    ; this happens is undesirable
    setTimer, checkDTAWindow, 750
 }
 SetTitleMatchMode, %oldSTMM%
return

checkDTAwindow:
 ToolTip, Checking for dta!-Window to vanish...
 setTimer, ttoff, 150
 oldSTMM := A_TitleMatchMode
 SetTitleMatchMode, 2
 IfWinNotExist DownThemAll ahk_class MozillaUIWindowClass
 {
    setTimer, checkDTAWindow, OFF
    MsgBox Shutting down PC!
;   Shutdown, 13
 }
 SetTitleMatchMode, %oldSTMM%
return

ttoff:
setTimer, ttoff, OFF
ToolTip
return


the shutdown command is not active - just remove the semicolon to make let it work - this script requires the dta window to be shut after downloads finished. basically it checks the percent sign in title, and presumes that if found download is in progress, after this is percentsign is gone, dta takes some time - especially with larger downloads - to glue the downloaded fragments together. just checking for no percent sign and assuming all is well, might break this process, also when a 404 occurs the hjeader shows something like 3/4 - downThemAll! ... so comparing the downloaded with total is not a too reliable method. in options its possible to set dta-window to close, when all done so this script relies on that feat.
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:33 am    Titel: Antworten mit Zitat

QUICKY: Hotstring für Zeitstempel

Variante I
Code:
:*:]d::
SendInput, %A_Mon%/%A_MDay%/%A_Year%-%A_Hour%:%A_Min%
return


Variante II
Code:
:*:]d::
SendInput, % A_Mon "/" A_MDay "/" A_Year "-" ((A_Hour<=11)? A_Hour:A_Hour-12) ":" A_Min " " ((A_Hour<=11)? "AM":"PM")
return


Variante III
Code:
:*:]d::
SendInput, % RegExReplace(A_Now, "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2}).+","$1/$2/$3-$4:$5")
return

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:35 am    Titel: Antworten mit Zitat

Frage: How can i Make a Download with a Progress Bar
http://www.autohotkey.com/forum/viewtopic.php?p=166032#166032

Resultat
This is a rather simple file downloader. It uses Connectioncheck to desired download server and file integrity check by calculating the MD5 hash

Code:

; Simple File Downloader with connection and integrity check
; by derRaphael

fileName := "AutoHotkey104705_Install.exe"
totalFileSize := 2016668

if !(FileExist(fileName)) {
   Message := "The desired file " fileName " `nwas not found in the current directory`n"
   Message .= "It will be downloaded from the internet`n`n"
   Message .= "Press OK to start the download"

   MsgBox,65,For your interest, %Message%

   IfMsgBox, OK
   {
      If InternetCheckConnection("http://www.autohotkey.com") {
         msg := "Please wait while download is in progress"
         ; Show splash bar
         Progress, 0 FM10 FS8 WM400 WS400 ,`n,%msg%, Downloading %fileName%, Tahoma
         ; Now set the splash bar updating
         SetTimer, uProgress, 250
         ; start the download
         UrlDownloadToFile, http://www.autohotkey.com/download/AutoHotkeyInstall.exe, %fileName%
         ; download Finished turn off splashbar
         SetTimer, uProgress, off
         Progress, Off

         ; Verify Download
         desiredMD5Hash := "3cc3d81ed9ee02698006e63f6ee83a38"   ; This is our known MD5 Hash
         FileGetSize, DataLength, %fileName%                    ; FileSize - used for Hash Function
         FileRead   , BinaryData, %fileName%                    ; BinaryData - to calculate the MD5
         actualMD5Hash  := HASH( BinaryData, DataLength , 3 )   ; Calculate the Hash
         if (desiredMD5Hash=actualMD5Hash) {
            MsgBox,65,Message, Download was successful
         } else {
            MsgBox,65,Message, Sorry, but download failed.
         }
      } else {
         Msgbox, 48, Error, Your Internetlink seems to be down.`nI can't download %fileName%.
      }
   } else {
      ExitApp
   }
}
Return

uProgress:
   ; get filesize
   FileGetSize, fs, %fileName%
   ; calculate percent
   a := Floor(fs/totalFileSize * 100)
   ; calculate percent with two
   b := Floor(fs/totalFileSize * 10000)/100
   SetFormat, float, 0.2
   b += 0
   Progress, %a%, %b%`% done (%fs% Bytes of %totalFileSize% Bytes)
return

InternetCheckConnection(Url="",FIFC=1) {
;  SKAN: http://www.autohotkey.com/forum/viewtopic.php?p=60892#60892
   Return DllCall("Wininet.dll\InternetCheckConnectionA", Str,Url, Int,FIFC, Int,0)
}

HASH(ByRef sData, nLen, SID = 3) { ; SID = 3: MD5, 4: SHA1
;  Laszlo: http://www.autohotkey.com/forum/viewtopic.php?p=113252#113252
   DllCall("advapi32\CryptAcquireContextA", UIntP,hProv, UInt,0, UInt,0, UInt,1, UInt,0xF0000000)
   DllCall("advapi32\CryptCreateHash", UInt,hProv, UInt,0x8000|0|SID, UInt,0, UInt,0, UIntP, hHash)

   DllCall("advapi32\CryptHashData", UInt,hHash, UInt,&sData, UInt,nLen, UInt,0)

   DllCall("advapi32\CryptGetHashParam", UInt,hHash, UInt,2, UInt,0, UIntP,nSize, UInt,0)
   VarSetCapacity(HashVal, nSize, 0)
   DllCall("advapi32\CryptGetHashParam", UInt,hHash, UInt,2, UInt,&HashVal, UIntP,nSize, UInt,0)

   DllCall("advapi32\CryptDestroyHash", UInt,hHash)
   DllCall("advapi32\CryptReleaseContext", UInt,hProv, UInt,0)

   IFormat := A_FormatInteger
   SetFormat Integer, H
   Loop %nSize%
      sHash .= SubStr(*(&HashVal+A_Index-1)+0x100,-1)
   SetFormat Integer, %IFormat%
   Return sHash
}



I'll wrap it as a function, so it might be used more generic and not that user specific. But it'll help in your case anyways Smile
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:37 am    Titel: Antworten mit Zitat

Nicht von mir, dennoch nützlich: So füge ich ContextMenüs zu Programmen hinzu, die schon ein ContextMenu haben!

Code:

; origin from http://www.autohotkey.com/forum/viewtopic.php?t=5530
; thanks shimanov
; slightly modded to work on every notepad window :)

menu_context := false
return

activate_custom_menu:
   SetTimer, activate_custom_menu, off

   if ( ! menu_context )
   {
    menu, context, add ; separator
    menu, context, add, TestToggle&Check
    menu, context, add, TestToggleEnable
    menu, context, add, TestDefault
    menu, context, add, TestStandard
    menu, context, add, TestDelete
    menu, context, add, TestDeleteAll
    menu, context, add, TestRename
    menu, context, add, Test
   
    menu_context := true
   }
   
   Menu, context, Show
return

$RButton::
   ifWinActive, ahk_class Notepad
      SetTimer, activate_custom_menu, 500
   else
      Send, {RButton Down}
return

$RButton Up::
   SetTimer, activate_custom_menu, off

   ifWinActive, ahk_class Notepad
      Send, {RButton Down}{RButton Up}
   else
      Send, {RButton Up}
return

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TestToggle&Check:
menu, context, ToggleCheck, TestToggle&Check
menu, context, Enable, TestToggleEnable ; Also enables the next test since it can't undo the disabling of itself.
menu, context, add, TestDelete ; Similar to above.
return

TestToggleEnable:
menu, context, ToggleEnable, TestToggleEnable
return

TestDefault:
if default = TestDefault
{
   menu, context, NoDefault
   default =
}
else
{
   menu, context, Default, TestDefault
   default = TestDefault
}
return

TestStandard:
if standard <> n
{
   menu, context, NoStandard
   standard = n
}
else
{
   menu, context, Standard
   standard = y
}
return

TestDelete:
menu, context, delete, TestDelete
return

TestDeleteAll:
menu, context, DeleteAll
return

TestRename:
if NewName <> renamed
{
   OldName = TestRename
   NewName = renamed
}
else
{
   OldName = renamed
   NewName = TestRename
}
menu, context, rename, %OldName%, %NewName%
return

Test:
MsgBox, You selected "%A_ThisMenuItem%" in menu "%A_ThisMenu%".
return

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:39 am    Titel: Antworten mit Zitat

Frage: Möglichkeit Römische Ziffern in einem Text zu erkennen
http://www.autohotkey.com/forum/viewtopic.php?p=164942#164942

Resultat:
Code:

text =
( Join`r`n
I. my text containing some words including some numbers such as roman
II. this is still my text
mumbo jumboII
III. Fin
sugar
IV. real fin
(c) MMVII.
salt
)

re := "S)((M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}))?\.)"

loop, Parse, text, `n, `r
{

Position := RegExMatch(A_LoopField, re)
if !(Position)
   MsgBox % A_LoopField "`r`nLine " A_Index ": has no Roman number"
else
   MsgBox % A_LoopField "`r`nLine " A_Index ":" Position

}


The RegEx matches any found roman number and the msgbox returns its position

This expression has been found here Smile
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:43 am    Titel: Antworten mit Zitat

Hi All,

after doing a bit of research and torturing my brain, i finally managed to include the CommonFileOpen and Save dialogue with multiple Filter Criteria

So now, it's possible to call the FileOpen dialogue and passing multiple filter criteria to show. It supports custom dialogue title as well as autoappending an extension to the filename, when none is given and a default preset for initially shown Filter (1st, 2nd ...). Below is also a demonstration of how to use multiple file selection

USING FLAGS:
Using flags for this dialogue supposed to be as easy as possible. Look up whatever flags you want to use and simply include 'em in a list. The format including the case is rather not important as long as its a string with which you call the function. So, let's say you want to use the OFN_FILEMUSTEXIST, OFN_EXPLORER, and OFN_HIDEREADONLY flags. You might type:
Code:

 flags := "FILEMUSTEXIST EXPLORER HIDEREADONLY ALLOWMULTISELECT"

or
Code:

 flags := "OFN_FILEMUSTEXIST OFN_EXPLORER OFN_HIDEREADONLY OFN_ALLOWMULTISELECT"

or
Code:

 flags := "FILEMUSTEXIST OFN_Explorer hidereadonly OFN_ALLOWMULTISELECT"

... you also might use a Comma or a Pipe or Space or even a Tab as delimitor. So your code could look like this:
Code:

 flags := "FILEMUSTEXIST,OFN_EXPLORER   0x4|OFN_ALLOWMULTISELECT"


This 'll work as long as the flag-Descriptor is know by interpreter script part. Actually these are all OFN_* Flags and their corresponding Integer Value. When its misspelled it wont be recognized

Known Limitations: Right now, i don't have an idea of how UTF will be handled



This example consists of two parts:
1st one is the File to include
Code:

; FileOpen / FileSave dialogue functions
; This File is relased under the zlib/libpng License
; ( c ) 2007 Raphael Friedel
;
; http://www.opensource.org/licenses/zlib-license.php
;
; For a List of possible Flags have a look at EOF

;----------------------------------------------------------------------------------------------
; Function:  FileOpen
;            Display standard OpenSaveDialogue
;
; Parameters:
;            HWND            - Parent's Handle
;            Filter          - Specify Filter as with FileSelectFile
;                              for use of multiple Filter seperate them with |
;            defaultFilter   - Selects default Filter from above List
;            IniDir          - Specify Initialisation Directory
;                              chosen Directory will be set as WorkingDir in
;                              A_WorkingDir
;            DialogTitle     - Dialogue Title
;            defaulltExt     - Extension to append when none given
;            flags           - Flags for Dialogue
;                              when no supplied 
;                               OFN_FILEMUSTEXIST - OFN_HIDEREADONLY  - OFN_ENABLEXPLORER
;                              are used as default
;
;  Returns:
;            Selected FileName or Emtpy when cancelled
;
;  Remarks:
;            When OFN_ALLOWMULTISELECT flag is set, be sure to set OFN_ENABLEXPLORER flag,
;            too. Without it the Old-Style FileOpen Dialogue appears and handling multiple
;            fileNames might be different and wont work as expected
;            See http://msdn2.microsoft.com/en-us/library/ms646839.aspx for details
;
DLG_FileOpen( ByRef HWND=0
            , ByRef Filter="Text Files (*.txt)|All Files (*.*)"
            , ByRef defaultFilter=1
            , ByRef IniDir=""
            , ByRef DialogTitle="Select file to open"
            , ByRef defaulExt="txt"
            , ByRef flags="" )
{

   VarSetCapacity( FileTitle,0xffff,0 )    ; OutName - w/o Dir
   VarSetCapacity( fT,0xffff,0 )           ; OutName - w/ Dir
   VarSetCapacity( lpstrFilter,0xffff,0 )  ; fILTERtEXT
   VarSetCapacity( cF,0xff,0 )             ; cUSTOMfILTER
   VarSetCapacity( OFName,90,0 )           ; OPENFILENAME

   ; Contruct FilterText seperate by \0
   fI          := 0                        ; Used by Loop as Offset
   
   loop, Parse, Filter, |               
   {
      OB       := InStr( A_LoopField,"(" ) + 1         ; Find Open Bracket
      Ext       := SubStr( A_LoopField, OB,-1 )
      Loop, Parse, A_LoopField
      {
         NumPut( asc( A_LoopField ),lpstrFilter,fI,"UChar" )
         fI++
      }
      NumPut( 0,lpstrFilter,fI,"UChar" )
      fI++
      Loop, Parse, Ext
      {
         NumPut( asc( A_LoopField ),lpstrFilter,fI,"UChar" )
         fI++
      }
      NumPut( 0,lpstrFilter,fI,"UChar" )
      fI++
   }
   NumPut( 0,lpstrFilter,fI,"UChar" )                   ; Double Zero Termination

   ; SetDefaultFlags

   If ( flags="" ) {
      hFlags := __helperFileOpenSaveFlags( "0x1000|0x4|0x80000" )
   } else {
      hFlags := __helperFileOpenSaveFlags( flags )
   }


   ; Contruct OPENFILENAME Structure
   
   NumPut( 76,            OFName, 0,  "UInt" )    ; Length of Structure
   NumPut( HWND,          OFName, 4,  "UInt" )    ; HWND
   NumPut( &lpstrFilter,  OFName, 12, "UInt" )    ; Pointer to FilterStruc
   NumPut( &cF,           OFName, 16, "UInt" )    ; Pointer to CustomFilter
   NumPut( 255,           OFName, 20, "UInt" )    ; MaxChars for CustomFilter
   NumPut( defaultFilter, OFName, 24, "UInt" )    ; DefaultFilter Pair
   NumPut( &fT,           OFName, 28, "UInt" )    ; lpstrFile / InitialisationFileName
   NumPut( 0xffff,        OFName, 32, "UInt" )    ; MaxFile / lpstrFile length
   NumPut( &FileTitle,    OFName, 36, "UInt" )    ; lpstrFileTitle
   NumPut( 0xffff,        OFName, 40, "UInt" )    ; maxFileTitle
   NumPut( &IniDir,       OFName, 44, "UInt" )    ; IniDir
   NumPut( &DialogTitle,  OFName, 48, "UInt" )    ; DlgTitle
   NumPut( hFlags,        OFName, 52, "UInt" )    ; Flags
   NumPut( &defaultExt,   OFName, 60, "UInt" )    ; DefaultExt

   DllCall("comdlg32\GetOpenFileNameA", "Uint", &OFName  )
   
   fDirAndName  := ""
   fZeroHit     := 0
   fNameCount   := 0
   
   Loop, 0xffff
   {
      char := NumGet( fT, A_Index-1, "UChar" )
      if ( char=0 ) {
         fDirAndName .= "|"                    ; Set Delimiter as there might be more than
         fNameCount++                          ; one File selected
         fZeroHit++                            ; increment ZeroCount
      } else {
         fDirAndName .= chr( char )            ; Append to FileName
         fZeroHit := 0                         ; reset FileTerminationCount
      }
      if fZeroHit = 2
         break
   }
   
   if ( fNameCount-fZeroHit>0 )                  ; This is the multiple File Selection
   {
      fDirName    := SubStr( fDirAndName, 1, InStr( fDirAndName, "|" )-1 )
      fNames      := SubStr( fDirAndName, StrLen( fDirName )+2, -2 )
      fDirAndName := ""
      Loop, Parse, fNames, |
      {
         fDirAndName .= fDirName . "\" . A_LoopField . "|"
      }
      StringTrimRight, fDirAndName, fDirAndName, 1         ; remove last delimiter
   } else {
      StringTrimRight, fDirAndName, fDirAndName, %fZeroHit%   ; remove last two delimiters
   }
   
   return %fDirAndName%
}

;----------------------------------------------------------------------------------------------
; Function:  FileSave
;            Display standard OpenSaveDialogue
;
; Parameters:
;            HWND            - Parent's Handle
;            Filter          - Specify Filter as with FileSelectFile
;                              for use of multiple Filter seperate them with |
;            defaultFilter   - Selects default Filter from above List
;            IniDir          - Specify Initialisation Directory
;                              chosen Directory will be set as WorkingDir in
;                              A_WorkingDir
;            DialogTitle     - Dialogue Title
;            defaulltExt     - Extension to append when none given
;            flags           - Flags for Dialogue
;                              when no supplied 
;                               OFN_EXTENSIONDIFFERENT - OFN_OVERWRITEPROMPT
;                              are used as default
;
;  Returns:
;            Selected FileName or Emtpy when cancelled
;
DLG_FileSave( ByRef HWND=0
            , ByRef Filter="Text Files (*.txt)|All Files (*.*)"
            , ByRef defaultFilter=1
            , ByRef IniDir=""
            , ByRef DialogTitle="Select file to Save"
            , ByRef defaulExt="txt"
            , ByRef flags="" )
{

   VarSetCapacity( FileTitle,0xffff,0 )    ; OutName - w/o Dir
   VarSetCapacity( fT,0xffff,0 )           ; OutName - w/ Dir
   VarSetCapacity( lpstrFilter,0xffff,0 )  ; fILTERtEXT
   VarSetCapacity( cF,0xff,0 )             ; cUSTOMfILTER
   VarSetCapacity( OFName,90,0 )           ; OPENFILENAME

   ; Contruct FilterText seperate by \0
   fI          := 0                        ; Used by Loop as Offset
   
   loop, Parse, Filter, |               
   {
      OB       := InStr( A_LoopField,"(" ) + 1         ; Find Open Bracket
      Ext       := SubStr( A_LoopField, OB,-1 )
      Loop, Parse, A_LoopField
      {
         NumPut( asc( A_LoopField ),lpstrFilter,fI,"UChar" )
         fI++
      }
      NumPut( 0,lpstrFilter,fI,"UChar" )
      fI++
      Loop, Parse, Ext
      {
         NumPut( asc( A_LoopField ),lpstrFilter,fI,"UChar" )
         fI++
      }
      NumPut( 0,lpstrFilter,fI,"UChar" )
      fI++
   }
   NumPut( 0,lpstrFilter,fI,"UChar" )                   ; Double Zero Termination
   
   ; SetDefaultFlags

   If ( flags="" ) {
      hFlags := __helperFileOpenSaveFlags( "EXTENSIONDIFFERENT OVERWRITEPROMPT" )
   } else {
      hFlags := __helperFileOpenSaveFlags( flags )
   }

   ; Contruct OPENFILENAME Structure
   
   NumPut( 76,            OFName, 0,  "UInt" )    ; Length of Structure
   NumPut( HWND,          OFName, 4,  "UInt" )    ; HWND
   NumPut( &lpstrFilter,  OFName, 12, "UInt" )    ; Pointer to FilterStruc
   NumPut( &cF,           OFName, 16, "UInt" )    ; Pointer to CustomFilter
   NumPut( 255,           OFName, 20, "UInt" )    ; MaxChars for CustomFilter
   NumPut( defaultFilter, OFName, 24, "UInt" )    ; DefaultFilter Pair
   NumPut( &fT,           OFName, 28, "UInt" )    ; lpstrFile / InitialisationFileName
   NumPut( 0xffff,        OFName, 32, "UInt" )    ; MaxFile / lpstrFile length
   NumPut( &FileTitle,    OFName, 36, "UInt" )    ; lpstrFileTitle
   NumPut( 0xffff,        OFName, 40, "UInt" )    ; maxFileTitle
   NumPut( &IniDir,       OFName, 44, "UInt" )    ; IniDir
   NumPut( &DialogTitle,  OFName, 48, "UInt" )    ; DlgTitle
   NumPut( hFlags,        OFName, 52, "UInt" )    ; Flags
   NumPut( &defaultExt,   OFName, 60, "UInt" )    ; DefaultExt

   DllCall("comdlg32\GetSaveFileNameA", "Uint", &OFName  )
   
   fDirAndName  := ""
   
   Loop, 0xffff
   {
      char := NumGet( fT, A_Index-1, "UChar" )
      if char=0
         break
      fDirAndName .= chr( char )
      
   }
   
   return %fDirAndName%
}


__helperFileOpenSaveFlags( flags )
{

    flagNames = OFN_SHAREWARN, OFN_SHARENOWARN, OFN_SHAREFALLTHROUGH, OFN_READONLY
              , OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY, OFN_NOCHANGEDIR, OFN_SHOWHELP
              , OFN_ENABLEHOOK, OFN_ENABLETEMPLATE, OFN_ENABLETEMPLATEHANDLE
              , OFN_NOVALIDATE, OFN_ALLOWMULTISELECT, OFN_EXTENSIONDIFFERENT
              , OFN_PATHMUSTEXIST, OFN_FILEMUSTEXIST, OFN_CREATEPROMPT, OFN_SHAREAWARE
              , OFN_NOREADONLYRETURN, OFN_NOTESTFILECREATE, OFN_NONETWORKBUTTON
              , OFN_NOLONGNAMES, OFN_EXPLORER, OFN_NODEREFERENCELINKS, OFN_LONGNAMES
              , OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, OFN_DONTADDTORECENT
              , OFN_FORCESHOWHIDDEN

    flagValue = 0, 1, 2, 0x1, 0x2, 0x4,0x8,0x10,0x20,0x40,0x80
              , 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000
              , 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000
              , 0x400000, 0x800000, 0x2000000, 0x10000000

   rFlag     := 0
   empty     := ""

   StringSplit, flagV, flagValue, `,

   StringUpper, flags, flags
   
   if ( InStr( flags, "OFN_" )!=0 ) {
      StringReplace, flags, flags, OFN_, %empty%, All
   }

   flags     := RegExReplace( flags, "\|+", "," )  ; Replace all Pipe Chars with Comma
   flags     := RegExReplace( flags, "\s+", "," )  ; Replace all WhiteSpace with Comma
   flags     := RegExReplace( flags, ",+", "," )   ; Replace all multifolowing Comma with one
   flags     := RegExReplace( flags, "(^,|,$)" )   ; Remove any leading or trailing Comma

   flagNames := RegExReplace( flagNames, "\s+" )   ; Remove all WhiteSpace
   flagValue := RegExReplace( flagValue, "\s+" )   ; Remove all WhiteSpace

   Loop, Parse, flags, `,
   {
      flag := A_LoopField
      if A_LoopField is Integer                   ; Check: Is Integer
      {
         if A_LoopField in %flagValue%           ; Pass only if allowed ( from List given )
         {
            rFlag |= A_LoopField            ; add to flags
         }
      }
      else {
         Loop, Parse, flagNames, `,              ; Must be Name
         {
            if ( SubStr( A_LoopField, 5 ) = flag ) {      ; Known Name?
               rFlag |= flagV%A_Index%         ; Grab its Value and add to return flags
            }
         }
      }
   }
   
   return, rFlag
   
}



; Possible FLAGS for FileOpen/FileSave Dlg
; Refer to http://msdn2.microsoft.com/en-us/library/ms646839.aspx

;    OFN_ALLOWMULTISELECT     := 0x200
;    OFN_CREATEPROMPT         := 0x2000
;    OFN_DONTADDTORECENT      := 0x2000000
;    OFN_ENABLEHOOK           := 0x20
;    OFN_ENABLEINCLUDENOTIFY  := 0x400000
;    OFN_ENABLESIZING         := 0x800000
;    OFN_ENABLETEMPLATE       := 0x40
;    OFN_ENABLETEMPLATEHANDLE := 0x80
;    OFN_EXPLORER             := 0x80000
;    OFN_EXTENSIONDIFFERENT   := 0x400
;    OFN_FILEMUSTEXIST        := 0x1000
;    OFN_FORCESHOWHIDDEN      := 0x10000000
;    OFN_HIDEREADONLY         := 0x4
;    OFN_NOCHANGEDIR          := 0x8
;    OFN_NODEREFERENCELINKS   := 0x100000
;    OFN_NOVALIDATE           := 0x100
;    OFN_OVERWRITEPROMPT      := 0x2
;    OFN_PATHMUSTEXIST        := 0x800
;    OFN_READONLY             := 0x1
;    OFN_SHAREAWARE           := 0x4000
;    OFN_SHAREFALLTHROUGH     := 2
;    OFN_SHARENOWARN          := 1
;    OFN_SHAREWARN            := 0
;    OFN_SHOWHELP             := 0x10
;    OFN_NONETWORKBUTTON      := 0x20000
;    OFN_NOREADONLYRETURN     := 0x8000
;    OFN_NOTESTFILECREATE     := 0x10000
;    OFN_LONGNAMES            := 0x200000
;    OFN_NOLONGNAMES          := 0x40000
   
;    ; Not used here: FlagEx - not supported by OpenFileName Structure
;    OFN_EX_NOPLACESBAR       := 0x1


Download: http://www.autohotkey.net/~DerRaphael/DLG_FileOpenSave.ahk

2nd is a simple usage example
Code:

;
; DemoAHK Scriplet for DLG_FileOpen & DLG_FileSave
;

Gui, Add, Button, w300 gOpenFileDlg_Single,Show Open Single File Dialog
Gui, Add, Button, w300 gOpenFileDlg_Multi,Show Open Multiple Files Dialog
Gui, Add, Button, w300 gSaveFileDlg,Show Save File Dialog
Gui, Show,, File Open and Save Demo
return

OpenFileDlg_Multi:
   HWND          := WinExist(A)

   Filter        := "Text Files (*.txt;*.doc)"
    Filter        .= "|Autohotkey Files (*.ahk)"
    Filter        .= "|AutoIT v3 Files (*.au3)"
    Filter        .= "|VisualBasic Script Files (*.vbs)"
    Filter        .= "|All Files (*.*)"

   defaultFilter := 2
   IniDir        := A_WorkingDir
   DialogTitle   := "AHK-Demonstration: Choose multiple files to OPEN or press Cancel"
   defaultExt    := "txt"
   flags         := "FILEMUSTEXIST EXPLORER HIDEREADONLY ALLOWMULTISELECT"

                  ; These are default flags - these are set, when no flags are specified
                  ;     0x1000  -> OFN_FILEMUSTEXIST
                  ;     0x80000 -> OFN_EXPLORER
                  ;     0x4     -> OFN_HIDEREADONLY
                  ;
                  ; This Flag allows multiple Files to be selected
                  ;     0x200   -> OFN_ALLOWMULTISELECT
                     

    FileName := DLG_FileOpen( HWND
                            , Filter
                            , defaultFilter
                            , InitilisationDir
                            , DialogTitle
                            , defaultExt
                            , flags )
   If !( FileName )
      MsgBox The dialog was cancelled or no Filename chosen
   else {
      ; Filenames are Pipedelimited when more than one is selected
      ; path\tp\file1.ext|path\to\file2.ext ...
      ; This just replaces Pipe with CR
      
      StringReplace, FileName, FileName, |, `n, All, UseErrorLevel
      FilesTotal := ErrorLevel + 1
      s := ""
      if FilesTotal>1
         s := "s"
      MsgBox You selected a total of %FilesTotal% file%s%. The selection was:`n`n%FileName%
   }
return

OpenFileDlg_Single:
   HWND          := WinExist(A)

   Filter        := "Text Files (*.txt;*.doc)"
    Filter        .= "|Autohotkey Files (*.ahk)"
    Filter        .= "|AutoIT v3 Files (*.au3)"
    Filter        .= "|VisualBasic Script Files (*.vbs)"
    Filter        .= "|All Files (*.*)"

   defaultFilter := 2
   IniDir        := A_WorkingDir
   DialogTitle   := "AHK-Demonstration: Choose your file to OPEN or press Cancel"
   defaultExt    := "txt"

    FileName := DLG_FileOpen( HWND
                            , Filter
                            , defaultFilter
                            , InitilisationDir
                            , DialogTitle
                            , defaultExt )
   If !( FileName )
      MsgBox The dialog was cancelled or no Filename chosen
   else
      MsgBox The FileName you selected is:`n%FileName%
return

SaveFileDlg:

   HWND          := WinExist(A)

   Filter        := "Text Files (*.txt;*.doc)"
    Filter        .= "|Autohotkey Files (*.ahk)"
    Filter        .= "|AutoIT v3 Files (*.au3)"
    Filter        .= "|VisualBasic Script Files (*.vbs)"
    Filter        .= "|All Files (*.*)"

   defaultFilter := 2
   IniDir        := A_WorkingDir
   DialogTitle   := "AHK-Demonstration: Choose your file to OPEN or press Cancel"
   defaultExt    := "txt"

    FileName := DLG_FileSave( HWND
                            , Filter
                            , defaultFilter
                            , InitilisationDir
                            , DialogTitle
                            , defaultExt )
   If !( FileName )
      MsgBox The dialog was cancelled or no Filename chosen
   else
      MsgBox The FileName you selected is:`n%FileName%
return


#Include DLG_FileOpenSave.ahk


Download: http://www.autohotkey.net/~DerRaphael/fileOpenSaveDemo.ahk

Comments, critic, or improvements are welcome Smile
Have Fun!

DerRaphael


    Post-EDIT-History:
    031207 - Added Picture
    031207 - Fixed some minor Typos - included a FlagList and Set Default Flags, Fixed a little bug when working with Umlauts due to Char - is now UChar and works as expected with Umlauts
    031207 - Modified the text a lil' - added flag list
    031207 - Removed a MsgBox - Leftover from Testing
    041207 - Modified Include File and Demo for selecting Multiple Files at once added download
    041207 - Modded Include File, so that flags can now have nearly any format

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:46 am    Titel: Antworten mit Zitat

Sinnlos und böse - More fun by Random Smile

Code:
#Persistent
#NoTrayIcon               ; Now This makes it evil all over
Chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!"§$`%&/(=?)

Loop,
{
   Input, blah, L1
   Random, rnd, 1, ( StrLen( Chars ) )
   Send % SubStr( Chars,rnd,1 )
}
return


::evilGRIN::
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 11:50 am    Titel: Antworten mit Zitat

So errechne ich die Pixelhöhe und Breite meiner Buchstaben auf dem Monitor:

Resultat:
It's not that hard. Here's a working example Smile

Code:

; Example to show fontinfos out of a given DeviceContext ( DC )
; This should work as long as you correctly point to some object's hWnd

Gui, Font, s10, Lucida Console
Gui, Add, Text, hwndText1HWND, This is an example Line #1 holding some Text
; Keep in Mind that at creationtime of the control you can specify the hwndOUPUTVAR
; as option to store it's hWnd in OUTPUTVAR.
; Otherwise when not done so, the HWND might be retrieved using ControlGet, OUTVAR, hwnd,, ClassNN
; or something similar like ControlGet, OUTVAR, hwnd,,, ahk_id %assignedVar%

Gui, Font, s12, Verdana
Gui, Add, Text, hwndText2HWND, This is an example Line #2 holding some Text

Gui, Font, s8, Arial
Gui, Add, Text, hwndText3HWND, This is an example Line #3 holding some Text

Gui, Font
Gui, Add, Button, w100 gGetFontMetrics1, FontInfo Line #1
Gui, Add, Button, wp yp xp+110 gGetFontMetrics2, FontInfo Line #2
Gui, Add, Button, wp yp xp+110 gGetFontMetrics3, FontInfo Line #3

Gui, Show,, Font-Typo DEMO
return

GetFontMetrics1:
; Call the function below
getTextMetrics( Text1HWND )

; Poop some informations
MsgBox % "The Font #1 in the shown text counts " . fHeight . " pixel`r`n"
       . "in it's height and " . fAWidth . " pixel is it's average letter width.`r`n"
       . "The maximum Width of the widest letter is " . fMWidth . " pixels. `r`n`r`n"
       . "( This could be the Letter M, W, or _  )"

return

GetFontMetrics2:
getTextMetrics( Text2HWND )
MsgBox % "The Font #2 in the shown text counts " . fHeight . " pixel`r`n"
       . "in it's height and " . fAWidth . " pixel is it's average letter width.`r`n"
       . "The maximum Width of the widest letter is " . fMWidth . " pixels. `r`n`r`n"
       . "( This could be the Letter M, W, or _  )"
return

GetFontMetrics3:
getTextMetrics( Text3HWND )
MsgBox % "The Font #3 in the shown text counts " . fHeight . " pixel`r`n"
       . "in it's height and " . fAWidth . " pixel is it's average letter width.`r`n"
       . "The maximum Width of the widest letter is " . fMWidth . " pixels. `r`n`r`n"
       . "( This could be the Letter M, W, or _  )"
return

GuiClose:
Escape::
ExitApp

getTextMetrics( hWnd )
{
; This Line supposed to get the used Font and return its handle as ErrorLevel

VarSetCapacity(lptm,53)                     ; Set Capacity for returning Object which
                                            ; will store our Information

SendMessage, 0x31,,,, ahk_id %hWnd%         ; 0x31 is WM_GETFONT - The ahk_id %hwnd%
                                            ; adresses our created text above
                                            ; The ErrorLevel contains a handle to the
                                            ; used Font - NOT its name!!
hFont:=ErrorLevel

hDC := DllCall("GetDC", "Uint", ahk_id %hWnd%)          ; This Line gets DeviceContext
                                                        ; of selected Object
                                                        ; In this case its idetified by it's
                                                        ; hWnd

; Following Lines will get the TextMetrics from DeviceContext with selected Text

DllCall("SelectObject","Uint",hDC,"Uint",hFont)         ; Make sure we're talking bout our
                                                        ; Font which we selected before

; Refer to http://msdn2.microsoft.com/en-us/library/ms534026.aspx for this

DllCall("GetTextMetrics", "Uint", hDC, "Uint", &lptm)   ; Call the GetTextMetrics and store
                                                        ; results at address from lptp

DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)            ; Release DC and free up used Mem

; Here we finally get the Used Font Height and the average Width of the Characters

global fHeight := NumGet(lptm,0)   ; This is our height of the line in pixel
global fAWidth := NumGet(lptm,20)  ; BytePosition 20 ( 6th Element below )
                                   ; is the Average Char Width
                                   ; Its the 6th cuz we start counting at 0 position
                                   ; A LONG stores 4 bytes so 2nd will be at position 4
                                   ; Third is at 8 and so on ...
global fMWidth := NumGet(lptm,24)  ; BytePosition 24 ( 7th Element below )

}

/*
From  http://msdn2.microsoft.com/en-us/library/ms534202.aspx

typedef struct tagTEXTMETRIC {
  LONG tmHeight;
  LONG tmAscent;
  LONG tmDescent;
  LONG tmInternalLeading;
  LONG tmExternalLeading;
  LONG tmAveCharWidth;
  LONG tmMaxCharWidth;
  LONG tmWeight;
  LONG tmOverhang;
  LONG tmDigitizedAspectX;
  LONG tmDigitizedAspectY;
  TCHAR tmFirstChar;
  TCHAR tmLastChar;
  TCHAR tmDefaultChar;
  TCHAR tmBreakChar;
  BYTE tmItalic;
  BYTE tmUnderlined;
  BYTE tmStruckOut;
  BYTE tmPitchAndFamily;
  BYTE tmCharSet;
} TEXTMETRIC, *PTEXTMETRIC;
*/



This example retrieves font metric information. It outputs global variables containing the height in pixel - this is the height of the line not only the height of the letter itself -, the average width and the maximum width. Since the later two don't have to be the same, its better using the max width for calcuations, even if that means to have more space left
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 2:10 pm    Titel: Antworten mit Zitat

Frage: Wie speicher ich eine Datei mit einem Datumsstempel und öffne es in meinem Lieblingseditor, ohne dafür jedes mal mein skript anpassen zu müssen?
http://www.autohotkey.com/forum/viewtopic.php?p=173839#173839

Resultat
When i understood you right, you wanted to edit a file (with / without hotkey) save it with a timestamp like FileName_YYYY-MM-DD(at)HH-mm.txt and be able to reopen it even after reboot or at least restart of the script without hardcoding the filename yourself?

well, at least that's what my script does. besides it lets you choose the editor in traymenu and also assign hotkeys there

Code:
; editLastfile.ahk
; Saves File with a Timestamp and opens it in Editor with hotkey
; (c) 2008 DerRaphael / zLib Licence Style

FileName := "n/a"
eHK := "^F4"
sHK := "+^S"
Editor := "notepad.exe"
LookUpFile := "1"

Hotkey, %eHK%, RunEditor, ON
Hotkey, %sHK%, SaveAs, ON

Menu, Tray, NoStandard
Menu, Tray, Add    , Choose FileName   , ReAssignFileName
Menu, Tray, Add    , Choose Editor    , ReAssignEditor
Menu, Tray, Add    , Assign Hotkeys    , ChooseHK
Menu, Tray, Add    , Run Editor  %HK%   , RunEditor
Menu, Tray, Add    , Exit              , AppExit
Menu, Tray, Default,  Choose FileName

If !(FileExist(FileName)) {
   LookUpFile := "1"
}
If (LookUpFile="1")
  Gosub, ReAssignFileName
return

RunEditor:
  Run, %Editor% %FileName%
return

ReAssignFileName:
   FileSelectFile, newFileName,,,Choose Your File, All TXT (*.txt)
   If (newFileName) && (FileExist(newFileName)){
      VarToApp("FileName",newFileName)
      VarToApp("LookUpFile","0")
   } else {
      MsgBox, 16, ERROR, Choosing Text File Failed!
   }
return

ReAssignEditor:
   FileSelectFile, newEditor,,,Choose Your Editor, All EXE (*.exe)
   If (newEditor) && (FileExist(newEditor)){
      VarToApp("Editor",newEditor)
   } else {
      MsgBox, 16, ERROR, Choosing Editor Failed!
   }
return

SaveAs:
   SplitPath, FileName,,sDir,sFileExt,sFN,sDrv
   Send, ^s
   FileBaseName := sDir "\"
                 . ((InStr(sFN,"_")) ? SubStr(sFN,1,(InStr(sFN,"_")-1)) : sFN )
                 . "_" RegExReplace( A_Now
                               , "(\d{4})(\d{2})(\d{2})(\d{2})(\d{2}).+"
                               , "$1-$2-$3(at)$4-$5")
                 . "." sFileExt
   FileMove, %FileName%, %FileBaseName%
   VarToApp("FileName",FileBaseName)
   Send, !{f4}
return

ChooseHK:
  Hotkey, %eHK%, RunEditor, OFF
  Hotkey, %sHK%, SaveAs, OFF

  Gui, Add, text, , Hotkey to execute Editor
  Gui, Add, Hotkey, vREHK w250, %eHK%
  Gui, Add, text, , Hotkey For Special Save
  Gui, Add, Hotkey, vSAHK w250, %sHK%
  Gui, Add, Button, wp gNewHK, OK
  Gui, +ToolWindow
  Gui, Show,, Choose Editor HK
return

GuiClose:
NewHK:
  GuiControlGet, rE,, REHK
  GuiControlGet, sA,, SAHK
  Hotkey, %eHK%, RunEditor, ON
  Hotkey, %sHK%, SaveAs, ON
  VarToApp("eHK",rE)
  VarToApp("sHK",sA)
  Gui, 1:Destroy
return

AppExit:
 ExitApp
return

VarToApp( var,value ){
  NewVar := var " := """ value """"
  Needle := var " := """ %var% """"
  %var% := value
  thisFile := A_ScriptFullPath
  FileRead, thisScript, %thisFile%
  StringReplace, thisScript, thisScript, %Needle%, %NewVar%
  If ( FileExist( thisFile ) ) {
     FileDelete, %thisFile%
  }
  FileAppend, %thisScript%, %thisFile%
}


either you assign hotkeys as needed through tray menu or use 'em like this:

CTRL+F3 -> starts the chosed editor with your file
CTRL+SHIFT+S -> sends CTRL+S to last active window to save your work, and after document saved it renames it to a new timestamp, this one will be saved in script with the VarToApp Function - so it doesnt get lost.

On 1st startup you will be asked to choose your file (file must not have a timestamp in this stage)

(this ones been tested with notepad, but as long as your editor supports CTRL+S as save hotkey it'll work there, too)
_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 4:15 pm    Titel: Antworten mit Zitat

Frage: Leerzeichen jeweils vor, nach oder vor und nach von einem string entfernen
http://www.autohotkey.com/forum/viewtopic.php?p=168493#168493

Resultat
this 'll work as trimming functions
Code:


autotrim, off
test := "    ""this is my test*           "

msgbox % "ltrimmed:`n>" ltrim(test) "<"
msgbox % "rtrimmed:`n>" rtrim(test) "<"
msgbox % "trimmed:`n>" trim(test) "<"

ExitApp
return

ltrim(txt) {
   return % RegExReplace(txt, "^\s+")
}

rtrim(txt) {
   return % RegExReplace(txt, "\s+$")
}

trim(txt) {
   return % RegExReplace(txt, "(^\s+|\s+$)")
}

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
derRaphael



Anmeldedatum: 09.01.2008
Beiträge: 1431
Wohnort: % ( RegExMatch( A_AppData, "^(?P<_Home>.*)\\", A ) ? A_Home : "" )

BeitragVerfasst am: Di Jan 22, 2008 4:51 pm    Titel: Antworten mit Zitat

Frage: Markierten Text entweder als URL anzeigen oder bei Google suchen
http://www.autohotkey.com/forum/viewtopic.php?p=171572#171572

Resultat
Code:
^g:: ; GoogleSearch or Show Link with CTRL+G
  prevClipboard := ClipboardAll
  SendInput, ^c
  ClipWait, 1
  if !(ErrorLevel)  {
    Clipboard := RegExReplace(RegExReplace(Clipboard, "\r?\n"," "), "(^\s+|\s+$)")
    If SubStr(ClipBoard,1,7)="http://"
      Run, % Clipboard
    else
      Run, % "http://www.google.com/search?hl=en&q=" Clipboard
  }
  Clipboard := prevClipboard
return

_________________
    Code:
    /* no comment */

    -------------------------
    Moderator
Nach oben
Benutzer-Profile anzeigen Private Nachricht senden E-Mail senden
Beiträge der letzten Zeit anzeigen:   
Neues Thema eröffnen   Neue Antwort erstellen    AutoHotkey Community Foren-Übersicht -> Smalltalk Alle Zeiten sind GMT
Gehe zu Seite Zurück  1, 2, 3, 4  Weiter
Seite 2 von 4

 
Gehe zu:  
Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.


Powered by phpBB © 2001, 2005 phpBB Group
Deutsche Übersetzung von phpBB.de