topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday May 19, 2022, 12:21 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - skrommel [ switch to compact view ]

Pages: prev1 2 3 4 5 [6] 7 8 9 10 11 ... 38next
126
 :) Nothing fancy, but try ThinTimer!

It shows a thin progress bar on the top edge of the screen.

Skrommel

;ThinTimer.ahk
; Shows a thin progress bar on the top edge of the screen
;Skrommel @ 2008

alarm=034500   ;Alarm time HHMMSS
height=2       ;Progress bar height >0
message=Timer!  ;Message to display when timer reached

#NoEnv
#SingleInstance,Force

range:=A_YYYY . A_MM . A_DD . alarm
EnvSub,range,%A_now%,seconds

Gui,+ToolWindow +AlwaysOnTop -Caption
Gui,Add,Progress,% "Vprogress X-2 Y-2 W" A_ScreenWidth+4 " H" height+5 " Range0-" range
Gui,Show,% "X0 Y0 W" A_ScreenWidth " H" height
Gui,+LastFound
guiid:=WinExist("A")
WinSet,Transparent,150,ahk_id %guiid%  ; Transparency
WinSet,ExStyle,+0x20,ahk_id %guiid%    ; Click-through

Loop,%range%
{
  Sleep,1000
  GuiControl,,progress,% range-A_Index
}
If message<>
  MsgBox,%message%
ExitApp

127
Coding Snacks / Re: IDEA: focus get (and keep, for a while)
« on: November 08, 2008, 12:09 PM »
 :) Try ReFocus!

- Refocuses a window after 5 seconds of inactivity.
- Press F1 to change the window to refocus.

Skrommel

;ReFocus.ahk
; Refocuses a window after 5 seconds of inactivity.
; Press F1 to change the window to refocus.
;Skrommel @ 2008

idletime=5000
focus:=WinExist("Notepad")

#SingleInstance,Force
#NoEnv
SetWinDelay,0

applicationname=ReFocus

SetTimer,TIMER,1000

TrayTip,%applicationname%,- Refocuses a window after 5 seconds of inactivity.`n- Press F1 to change the window to refocus.
Return

F1::
focus:=WinExist("A")
WinGetActiveTitle,title
TrayTip,%applicationname%,%title%
Return


TIMER:
IfWinNotActive,ahk_id %focus%
If (A_TimeIdlePhysical>idletime)
  WinActivate,ahk_id %focus%
Return

128
Post New Requests Here / Re: Auto Resize Taskbar
« on: November 06, 2008, 07:14 PM »
 :) Try TaskbarSize - it resizes the taskbar when it gets too crowded.

This is a very simple hack, I'll see if I can find a better way of sizing the taskbar.

Skrommel


;TaskbarSize.ahk
; Resizes the taskbar when it gets too crowded
;Skrommel @ 2008

#SingleInstance,Force
DetectHiddenWindows, On
SetWinDelay,0

WinMove,ahk_class Shell_TrayWnd,,100,0

buttonlimit=5

WinGetPos,tx,ty,tw,th,ahk_class Shell_TrayWnd

WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
idxTB:= GetTaskSwBar()
oldbuttons:=buttons
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
previous:=ErrorLevel

Loop
{
  Sleep,1000
  idxTB:= GetTaskSwBar()
  oldbuttons:=buttons
  SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
  buttons:=ErrorLevel
  If (oldbuttons=buttons)
    Continue
  If (buttons>previous+buttonlimit)
  {
    winid:=WinExist("A")
    WinActivate, ahk_class Shell_TrayWnd
    PostMessage, 0x112, 0xF000,,, ahk_class Shell_TrayWnd  ; SC_SIZE
    MouseGetPos,mx,my
    BlockInput,On
MouseClickDrag,L,1,1,1,-50,0
    BlockInput,Off
    MouseMove,% mx,% my,0
    WinActivate,ahk_id %winid%
  previous:=previous+buttonlimit
}
  If (buttons<previous-buttonlimit)
  {
    winid:=WinExist("A")
    WinActivate, ahk_class Shell_TrayWnd
    PostMessage, 0x112, 0xF000,,, ahk_class Shell_TrayWnd  ; SC_SIZE
    MouseGetPos,mx,my
    BlockInput,On
MouseClickDrag,L,1,1,1,50,0
    BlockInput,Off
    MouseMove,% mx,% my,0
    WinActivate,ahk_id %winid%
    previous:=previous-buttonlimit
  }
}
Return

;Stolen from Sean at http://www.autohotkey.com/forum/viewtopic.php?t=18652
TaskButtons(sExeName = "")
{
WinGet, pidTaskbar, PID, ahk_class Shell_TrayWnd
hProc:= DllCall("OpenProcess", "Uint", 0x38, "int", 0, "Uint", pidTaskbar)
pProc:= DllCall("VirtualAllocEx", "Uint", hProc, "Uint", 0, "Uint", 32, "Uint", 0x1000, "Uint", 0x4)
idxTB:= GetTaskSwBar()
SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_BUTTONCOUNT
Loop, %ErrorLevel%
{
SendMessage, 0x417, A_Index-1, pProc, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_GETBUTTON
VarSetCapacity(btn,32,0)
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", pProc, "Uint", &btn, "Uint", 32, "Uint", 0)
iBitmap := NumGet(btn, 0)
idn := NumGet(btn, 4)
Statyle := NumGet(btn, 8)
If dwData := NumGet(btn,12)
iString := NumGet(btn,16)
Else dwData := NumGet(btn,16,"int64"), iString:=NumGet(btn,24,"int64")
DllCall("ReadProcessMemory", "Uint", hProc, "Uint", dwData, "int64P", hWnd:=0, "Uint", NumGet(btn,12) ? 4:8, "Uint", 0)
If Not hWnd
Continue
WinGet, pid, PID,              ahk_id %hWnd%
WinGet, sProcess, ProcessName, ahk_id %hWnd%
WinGetClass, sClass,           ahk_id %hWnd%
If !sExeName || (sExeName = sProcess) || (sExeName = pid)
VarSetCapacity(sTooltip,128), VarSetCapacity(wTooltip,128*2)
, DllCall("ReadProcessMemory", "Uint", hProc, "Uint", iString, "Uint", &wTooltip, "Uint", 128*2, "Uint", 0)
, DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "str", wTooltip, "int", -1, "str", sTooltip, "int", 128, "Uint", 0, "Uint", 0)
, sTaskButtons .= "idx: " . A_Index-1 . " | idn: " . idn . " | pid: " . pid . " | hWnd: " . hWnd . " | Class: " . sClass . " | Process: " . sProcess . "`n" . "   | Tooltip: " . sTooltip . "`n"
}
DllCall("VirtualFreeEx", "Uint", hProc, "Uint", pProc, "Uint", 0, "Uint", 0x8000)
DllCall("CloseHandle", "Uint", hProc)
Return sTaskButtons
}

HideButton(idn, bHide = True)
{
idxTB := GetTaskSwBar()
SendMessage, 0x404, idn, bHide, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_HIDEBUTTON
}

DeleteButton(idx)
{
idxTB := GetTaskSwBar()
SendMessage, 0x416, idx, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd   ; TB_DELETEBUTTON
}

MoveButton(idxOld, idxNew)
{
idxTB := GetTaskSwBar()
SendMessage, 0x452, idxOld, idxNew, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd    ; TB_MOVEBUTTON
}

GetTaskSwBar()
{
ControlGet, hParent, hWnd,, MSTaskSwWClass1 , ahk_class Shell_TrayWnd
ControlGet, hChild , hWnd,, ToolbarWindow321, ahk_id %hParent%
Loop
{
ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd
If  Not hWnd
Break
Else If hWnd = %hChild%
{
idxTB := A_Index
Break
}
}
Return idxTB
}

129
 :) How about MaxMove?

Press F1 repeatedly to move a window to the next monitor.

Features:
- Moves maximized or restored windows to the same relative position on the other monitor
- Resizes resizable windows to the same relative size on the other monitor

Skrommel

;MaxMove.ahk
; Press a hotkey repeatedly to move a window to the next monitor
;Skrommel @ 2008

#SingleInstance,Force
#NoEnv
SetWinDelay,0

movekey=F1
Hotkey,%movekey%,MOVE
Return


MOVE:
  active:=WinExist("A")
  SysGet,monitors,MonitorCount
  Loop,% monitors
    SysGet,monitor%A_Index%,Monitor,%A_index%

  WinGet,minmax,MinMax,ahk_id %active%
  If minmax=1
    WinRestore,ahk_id %active%
  WinGetPos,resx,resy,resw,resh,ahk_id %active%
  Loop,% monitors
  {
    current:=A_Index
    If (resx+resw/2<monitor%current%Left Or resx+resw/2>monitor%current%Right)
      Continue
    If (resy+resh/2<monitor%current%Top Or resy+resh/2>monitor%current%Bottom)
      Continue
    next:=current+1
    If (next>monitors)
      next:=1
    WinGet,style,Style,ahk_id %active%
    If (style & 0x40000)  ; WS_SIZEBOX=0x40000
      WinMove,ahk_id %active%,,% monitor%next%Left+(resx-monitor%current%Left)/(monitor%current%Right-monitor%current%Left)*(monitor%next%Right-monitor%next%Left),% monitor%next%Top+(resy-monitor%current%Top)/(monitor%current%Bottom-monitor%current%Top)*(monitor%next%Bottom-monitor%next%Top),% resw/(monitor%current%Right-monitor%current%Left)*(monitor%next%Right-monitor%next%Left),% resh/(monitor%current%Bottom-monitor%current%Top)*(monitor%next%Bottom-monitor%next%Top)
    Else     
      WinMove,ahk_id %active%,,% monitor%next%Left+(resx-monitor%current%Left)/(monitor%current%Right-monitor%current%Left)*(monitor%next%Right-monitor%next%Left),% monitor%next%Top+(resy-monitor%current%Top)/(monitor%current%Bottom-monitor%current%Top)*(monitor%next%Bottom-monitor%next%Top)
    If minmax=1
      WinMaximize,ahk_id %active%
    Break
  }
Return

130
 :) Just uploaded GoneIn60s v1.4!

- Added option to ignore classes, closes windows when exiting.

Skrommel

131
Finished Programs / Re: IDEA: Photo Downloader Kiosk
« on: October 18, 2008, 05:02 PM »
 :) Download the pngs and place them beside the script.

Then replace the source code
Gui,Add, Button,W75 Xm Ym GREFRESH Default,&Refresh
Gui,Add, Button,W75 X+5 GSELECTALL,Select &All
Gui,Add, Button,W75 X+5 GINVERT,&Invert
Gui,Add, Button,W75 X+5 GUPLOAD,&Upload
width
Gui,Add,Picture,Xm Ym GREFRESH Default,reload.png
Gui,Add,Text,X+5 Ym+7 GREFRESH,&Reload
Gui,Add,Picture,X+5 Ym GSELECTALL,list-add.png
Gui,Add,Text,X+5 Ym+7 GSELECTALL,Select &All
Gui,Add,Picture,X+5 Ym GINVERT,list-remove.png
Gui,Add,Text,X+5 Ym+7 GINVERT,&Invert
Gui,Add,Picture,X+5 Ym GUPLOAD,filesave.png
Gui,Add,Text,X+5 Ym+7 GUPLOAD,&Upload

Skrommel

132
 :) Replace the CHECKCPULOAD procedure in IdleRun with the code below.

Skrommel

CHECKCPULOAD:
load:=GETCPULOAD(numberofprocessors)
icon:=load/100*9
Menu,Tray,Tip,%load% `%
IfExist,%icon%.ico
  Menu,Tray,Icon,%icon%.ico
If load>%cputhreshold%
If A_TimeIdlePhysical>=%idleduration%
{
  If program<>
  {
    Input,singlekey,L1,{LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
    Run,%program%
  }
  If message<>
    MsgBox,0,%applicationname%,%message%
  If exit=1
    Goto,EXIT
}
Return


133
Finished Programs / Re: IDEA: Photo Downloader Kiosk
« on: October 18, 2008, 12:54 PM »
 :) Updated the script above above to show a preview window.

Something's wrong with the icon-gz-archive, though.

Skrommel

134
Post New Requests Here / Re: REQUEST: Automated search and move tool
« on: October 18, 2008, 11:11 AM »
 :tellme: Maybe FileMoveDir,%A_LoopFileFullPath%,%outputvar%\%find%

Skrommel

135
Post New Requests Here / Re: REQUEST: Automated search and move tool
« on: October 13, 2008, 04:00 PM »
 :-[ Found two small errors and changed the script above...

Skrommel

136
Post New Requests Here / Re: IDEA: DropFolder
« on: October 13, 2008, 03:32 AM »
 :) Here's an early draft.

DropFolder - Drop files on a floating icon to move or copy files to user defined folders.

Press Ctrl while dropping to copy files

Skrommel

;DropFolder.ahk
; Drop files on a floating icon to move or copy files to user defined folders
; Press Ctrl while dropping to copy files
;Skrommel

#NoEnv
#SingleInstance,Force
SetWindelay,0

paths=C:\Archive\Work,C:\Archive\Games,C:\Archive\Photos
picture=C:\Windows\Web\Wallpaper\Wind.jpg
transparency=150
x=100
y=100
w=32
h=
location=AlwaysOnTop

Gosub,MENU
OnMessage(0x112,"WM_SYSCOMMAND")
If location=AlwaysOnTop
  guioptions:="+" location
If w<>
  pictureoptions:="H-1 W" w
Else
  pictureoptions:="W-1 H" h
Gui,Margin,0,0
Gui,% "-Caption +ToolWindow +LastFound -Resize " guioptions
guiid:=WinExist()
Gui,Add,Picture,% pictureoptions " GMOVEWINDOW",% picture
Gui,Show,% "X" x " Y" y
WinSet,Transparent,% transparency
Return


GuiDropFiles:
GetKeyState,ctrl,Control,P
where:=A_GuiControl
filecount:=A_EventInfo
guix:=A_GuiX
guiy:=A_GuiY
files:=A_GuiEvent
Menu,menu,Show
Return


MENU:
Loop,Parse,paths,`,
  Menu,menu,Add,% A_LoopField,COPY
Menu,menu,Add
Menu,menu,Add,&Browse...,BROWSE
Menu,menu,Add,&Cancel,CANCEL
Return


COPY:
FileCreateDir,%A_ThisMenuItem%
If ctrl=D
  Loop,Parse,files,`n
    FileCopy,%A_LoopField%,%A_ThisMenuItem%
Else
  Loop,Parse,files,`n
    FileMove,%A_LoopField%,%A_ThisMenuItem%
Return


BROWSE:
FileSelectFolder,target,,3
If target=
  Return
FileCreateDir,%target%
If ctrl=D
  Loop,Parse,files,`n
    FileCopy,%A_LoopField%,%target%
Else
  Loop,Parse,files,`n
    FileMove,%A_LoopField%,%target%
Return


CANCEL:
Return


;Stolen from SKAN at http://www.autohotkey.com/forum/topic32768.html
MOVEWINDOW:
  PostMessage,0xA1,2,,,A   ;WM_NCLBUTTONDOWN=0x00A1 HTCAPTION=2
Return


;Stolen from Lexicos at http://www.autohotkey.com/forum/topic18260.html
WM_SYSCOMMAND(wParam)
{
  Global guiid
  If (A_Gui && wParam = 0xF020) ; SC_MINIMIZE
    WinRestore,ahk_id %guiid%
}


GuiClose:
  ExitApp

137
Coding Snacks / Re: IDEA: micro macro
« on: October 10, 2008, 07:16 PM »
 :) If you have programmed your media button for something else...

Skrommel

;NextWmp.ahk
;Skrommel @ 2008

Loop
{
  PostMessage,0x111,18811,0,,ahk_class WMPlayerApp
  Sleep,20000
}

138
Post New Requests Here / Re: REQUEST: Automated search and move tool
« on: October 10, 2008, 12:13 PM »
 :) Here's an AutoHotkey script, almost untested.

If loops the local folder for dir names, searches the two san folders for a matching name, and moves it to the local folder.

Skrommel

localfolder=C:\PDFS                  ;local and target folder
sanfolder1=\\SAN\TIFS1            ;remote folder 1
sanfolder2=\\SAN\TIFS2            ;remote folder 2

Loop,%localfolder%\*,1            ;search through the local folder
{
  IfInString,A_LoopFileAttrib,D    ;look for folders
  {
    MOVE(A_LoopFileName,sanfolder1,A_LoopFileFullPath)  ;look for the folder in remote folder1
    MOVE(A_LoopFileName,sanfolder2,A_LoopFileFullPath)  ;look for the folder in remote folder2
  }
}
ExitAPP


MOVE(find,root,target)
{
  Loop,%root%\*,1            ;search through the remote folder
  {
    IfInString,A_LoopFileAttrib,D   ;look for folders
    If (A_LoopFileName=find)       ;if match
    {
      FileMoveDir,%A_LoopFileFullPath%,%target%\%find%   ;move the folder to the local folder
      Break
    }
  }
}

139
Finished Programs / Re: IDEA: Photo Downloader Kiosk
« on: October 10, 2008, 02:23 AM »
 :tellme: There must be something wrong with the icons-archive, a lot of the pngs are 0 bytes!

I thought I'd use the click on the thumbnails to show a preview, but maybe it isn't neccesary?

Skrommel

140
Post New Requests Here / Re: IDEA: Toggle Fullscreen of Control
« on: October 09, 2008, 05:56 AM »
 :tellme: No, I have FullScreen running at 0% CPU load in Vista on a quad core.

How it's done? I think they just grow and shrink the controls. The trick is deciding which controls to adjust.

Skrommel

141
Post New Requests Here / Re: IDEA: Toggle Fullscreen of Control
« on: October 09, 2008, 05:09 AM »
 :) I found it!

It's called FullScreen by Fanix Software, and it's just brilliant!

Just Alt-Leftclick in the control you want to maximize, and it fills the screen. But if you move the mouse outside of the control, it automatically shrinks back down to show what's hiding outside! Magic!

Example:
- In Internet Explorer, if you Alt-Leftclick in the main window, it is maximized.
- Now move the mouse to the top of the screen, and it shrinks to show the caption, menu, button bar and address bar!
- Move it to the bottom of the screen, and it shrinks to show the status bar!
- When you're done, just Alt-Leftclick to restore it again.

Video:
https://www.donationcoder.com/Software/Skrommel/AHK/FullScreen.swf

You really don't need that 48 inch monitor after all!

Skrommel

142
Coding Snacks / Re: codename: CopyCap - a tool to copy caption text
« on: October 09, 2008, 02:29 AM »
 :) I've just uploaded Captain v1.2.

Changes:

- Updates changing captions

Skrommel

143
Finished Programs / Re: IDEA: Photo Downloader Kiosk
« on: October 08, 2008, 10:47 PM »
 :) Updated PhotoKiosk above!

Got any icons in mind?

Skrommel

144
Post New Requests Here / Re: Vista style filename editing in XP
« on: October 08, 2008, 09:52 PM »
 :) Compiled and posted TheEnd above.

Skrommel

145
Finished Programs / Re: IDEA: Photo Downloader Kiosk
« on: October 08, 2008, 07:56 PM »
 :) Try PhotoKiosk!

It shows an always on top window with thumbnails from a disk of your choice, and a button to copy the selected files to a folder.

Just change the in and out-lines of the script to watch another folder.

I'll compile and clean it up if it's usable.

Skrommel

;PhotoKiosk.ahk
;Skrommel @ 2008

in:="N:,O:,P:,Q:"   ; Source folders separated by comma
out:="C:\Temp"      ; Targe folder
size:=120           ; Thumbnail size
space:=14           ; Thumbnail space
subfolders:=0       ; Traverse subfolders? 1=Yes 0=No
preview:=400        ; Width of preview window

applicationname=PhotoKiosk

#NoEnv
#SingleInstance,Force
SetBatchLines,-1
SetWinDelay,0
DetectHiddenWindows,On

OnExit,EXIT
pToken:=Gdip_Startup()

StringRight,right,out,1
If (right="\")
  StringTrimRight,out,out,1

START:
Gui,Destroy
Gui,Show,% "X Y W" A_ScreenWidth " H" A_ScreenHeight,%applicationname%
Gui,+Resize +0x300000 +AlwaysOnTop -Resize +OwnDialogs ;WS_VSCROLL | WS_HSCROLL
Gui,+LastFound
guiid:=WinExist()

WinSetUnMovable(guiid)
DllCall("RegisterShellHookWindow",UInt,guiid)
msgnum:=DllCall("RegisterWindowMessage",Str,"SHELLHOOK")
OnMessage(msgnum,"ShellMessage")
GroupAdd,MyGui,ahk_id %guiid%
WinSet,Top,,ahk_id %guiid%
WinSetTitle,ahk_id %guiid%,,% applicationname " - Reading pictures..."

subfolder:=A_Now
counter:=0
x:=space
y:=25+space
Loop,Parse,in,`,
{
  source:=A_LoopField
  StringRight,right,source,1
  If (right="\")
    StringTrimRight,source,source,1

  Loop,%source%\*.*,0,% subfolders
  {
    If A_LoopFileExt Not In GIF,JPG,JPEG,JPE,BMP,ICO,CUR,ANI,PNG,TIF,Exif,WMF,EMF
      Continue
    counter+=1
    path_%counter%:=A_LoopFileLongPath
    pBitmap := Gdip_CreateBitmapFromFile(A_LoopFileLongPath)
    w:=Gdip_GetImageWidth(pBitmap)
    h:=Gdip_GetImageHeight(pBitmap)
    Gdip_DisposeImage(pBitmap)
    If (w>h)
      Gui,Add,Picture,% "X" x " Y" y+(size-size*h/w)/2 " W" size " H-1 GPICTURE AltSubmit V" check%counter%,%A_LoopFileLongPath%
    Else
      Gui,Add,Picture,% "X" x+(size-size*w/h)/2 " Y" y " H" size " W-1 GPICTURE AltSubmit V" check%counter%,%A_LoopFileLongPath%
    Gui,Add,CheckBox,% "X" x-space " Y" y+size " W" space " H" space,% "" ; " W" size+space-1 " H" space*2,% "" ;% A_LoopFileName
    Gui,Add,Edit,% "X" x+1 " Y" y+size " W" size-2 " H" space*2 " -HScroll -VScroll",% A_LoopFileName

    x:=x+size+space*2
    If (x>A_ScreenWidth-size)
    {
      x:=space
      y:=y+size+space*2
    }
  }
}
Gui,Add, Button,W75 Xm Ym GREFRESH Default,&Refresh
Gui,Add, Button,W75 X+5 GSELECTALL,Select &All
Gui,Add, Button,W75 X+5 GINVERT,&Invert
Gui,Add, Button,W75 X+5 GUPLOAD,&Upload

OnMessage(0x115, "OnScroll") ; WM_VSCROLL
OnMessage(0x114, "OnScroll") ; WM_HSCROLL

WinMove,ahk_id %guiid%,,,,,% A_ScreenHeight-1
WinMove,ahk_id %guiid%,,,,,% A_ScreenHeight
WinSetTitle,ahk_id %guiid%,,% "Finished reading pictures"
Return


PICTURE:
MouseGetPos,mx,my,mwin,mctrl
StringTrimLeft,control,mctrl,6
Gui,2:Destroy
Gui,2:+Owner1
Gui,2:Margin,0,0
Gui,2:+AlwaysOnTop +ToolWindow
Gui,2:Add,Picture,% "X" 0 " Y" 0 " W" 400 " H-1 GPREVIEW",% path_%control%
Gui,2:Show
Return


PREVIEW:
Return


REFRESH:
subfolder:=A_Now
Gui,2:+AlwaysOnTop -Border -Resize
Gui,2:Show,X0 Y0 W%A_ScreenWidth% H%A_ScreenHeight%,PhotoKiosk
Gosub,START
Gui,2:Destroy
Return


SELECTALL:
WinGet,controls,ControlList,ahk_id %guiid%
Loop,Parse,controls,`n
{
  If A_LoopField Contains Button
    GuiControl,,% A_LoopField,1
  If (A_LoopField="Button" counter)
    Break
}
Return


INVERT:
WinGet,controls,ControlList,ahk_id %guiid%
Loop,Parse,controls,`n
{
  If A_LoopField Contains Button
  {
    GuiControlGet,checked,,% A_LoopField
    If checked=1
      GuiControl,,% A_LoopField,0
    Else
      GuiControl,,% A_LoopField,1
  }
  If (A_LoopField="Button" counter)
    Break
}
Return


UPLOAD:
FileCreateDir,% out "\" subfolder "\"
WinGet,controls,ControlList,ahk_id %guiid%
Loop,Parse,controls,`n
{
  If A_LoopField Contains Button
  {
    GuiControlGet,checked,,% A_LoopField
    If checked=1
    {
      StringTrimLeft,control,A_LoopField,6
     
      FileCopy,% path_%control%,% out "\" subfolder "\"
      WinSetTitle,ahk_id %guiid%,,% "Copying " path_%control% "..."
    }
  }
  If (A_LoopField="Button" counter)
    Break
}
WinSetTitle,ahk_id %guiid%,,% "Finished copying"
Return


GuiSize:
  UpdateScrollBars(A_Gui,A_GuiWidth,A_GuiHeight)
Return


GuiClose:
Return


^+!e::
EXIT:
Gdip_Shutdown(pToken)
DllCall("CloseHandle",UInt,hDir)
ExitApp
Return


ShellMessage(wParam,lParam)
{
  Global guiid
  If (lParam<>guiid)
  {
    WinSet,Top,,ahk_id %guiid%
    WinActivate,ahk_id %guiid%
  }
}
Return


WinSetUnMovable(hwnd)
{
  hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
  nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
  DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-6,"Uint","0x400")
  DllCall("DrawMenuBar","Int",hWnd)
}
Return


#IfWinActive ahk_group MyGui
WheelUp::
WheelDown::
+WheelUp::
+WheelDown::
  ; SB_LINEDOWN=1, SB_LINEUP=0, WM_HSCROLL=0x114, WM_VSCROLL=0x115
  OnScroll(InStr(A_ThisHotkey,"Down") ? 1 : 0, 0, GetKeyState("Shift") ? 0x114 : 0x115, WinExist())
Return
#IfWinActive


UpdateScrollBars(GuiNum, GuiWidth, GuiHeight)
{
  static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1
 
  Gui, %GuiNum%:Default
  Gui, +LastFound
 
  ; Calculate scrolling area.
  Left := Top := 9999
  Right := Bottom := 0
  WinGet, ControlList, ControlList
  Loop, Parse, ControlList, `n
  {
    GuiControlGet, c, Pos, %A_LoopField%
    if (cX < Left)
      Left := cX
    if (cY < Top)
      Top := cY
    if (cX + cW > Right)
      Right := cX + cW
    if (cY + cH > Bottom)
      Bottom := cY + cH
  }
  Left -= 8
  Top -= 8
  Right += 8
  Bottom += 8
  ScrollWidth := Right-Left
  ScrollHeight := Bottom-Top
 
  ; Initialize SCROLLINFO.
  VarSetCapacity(si, 28, 0)
  NumPut(28, si) ; cbSize
  NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
 
  ; Update horizontal scroll bar.
  NumPut(ScrollWidth, si, 12) ; nMax
  NumPut(GuiWidth, si, 16) ; nPage
  DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1)
 
  ; Update vertical scroll bar.
;     NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
  NumPut(ScrollHeight, si, 12) ; nMax
  NumPut(GuiHeight, si, 16) ; nPage
  DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &si, "int", 1)
 
  if (Left < 0 && Right < GuiWidth)
      x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left)
  if (Top < 0 && Bottom < GuiHeight)
      y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top)
  if (x || y)
      DllCall("ScrollWindow", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0)
}


OnScroll(wParam, lParam, msg, hwnd)
{
  static SIF_ALL=0x17, SCROLL_STEP=10
 
  bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
 
  VarSetCapacity(si, 28, 0)
  NumPut(28, si) ; cbSize
  NumPut(SIF_ALL, si, 4) ; fMask
  if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
    return
 
  VarSetCapacity(rect, 16)
  DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
 
  new_pos := NumGet(si, 20) ; nPos
 
  action := wParam & 0xFFFF
  if action = 0 ; SB_LINEUP
    new_pos -= SCROLL_STEP
  else if action = 1 ; SB_LINEDOWN
    new_pos += SCROLL_STEP
  else if action = 2 ; SB_PAGEUP
    new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP
  else if action = 3 ; SB_PAGEDOWN
    new_pos += NumGet(rect, 12, "int") - SCROLL_STEP
  else if action = 5 ; SB_THUMBTRACK
    new_pos := NumGet(si, 24, "int") ; nTrackPos
  else if action = 6 ; SB_TOP
    new_pos := NumGet(si, 8, "int") ; nMin
  else if action = 7 ; SB_BOTTOM
    new_pos := NumGet(si, 12, "int") ; nMax
  else
    return
 
  min := NumGet(si, 8, "int") ; nMin
  max := NumGet(si, 12, "int") - NumGet(si, 16) ; nMax-nPage
  new_pos := new_pos > max ? max : new_pos
  new_pos := new_pos < min ? min : new_pos
 
  old_pos := NumGet(si, 20, "int") ; nPos
 
  x := y := 0
  if bar = 0 ; SB_HORZ
    x := old_pos-new_pos
  else
    y := old_pos-new_pos
  ; Scroll contents of window and invalidate uncovered area.
  DllCall("ScrollWindow", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
 
  ; Update scroll bar.
  NumPut(new_pos, si, 20, "int") ; nPos
  DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
}


; Gdip standard library v1.22 by tic 09/09/08
;
;#####################################################################################
;#####################################################################################
; STATUS ENUMERATION
; Return values for functions specified to have status enumerated return type
;#####################################################################################
; Ok = 0
; GenericError = 1
; InvalidParameter = 2
; OutOfMemory = 3
; ObjectBusy = 4
; InsufficientBuffer = 5
; NotImplemented = 6
; Win32Error = 7
; WrongState = 8
; Aborted = 9
; FileNotFound = 10
; ValueOverflow = 11
; AccessDenied = 12
; UnknownImageFormat = 13
; FontFamilyNotFound = 14
; FontStyleNotFound = 15
; NotTrueTypeFont = 16
; UnsupportedGdiplusVersion = 17
; GdiplusNotInitialized = 18
; PropertyNotFound = 19
; PropertyNotSupported = 20
; ProfileNotFound = 21
;#####################################################################################
;#####################################################################################
; GDI and structure functions
; ########################
; UpdateLayeredWindow
; CreateRectF
; CreateSizeF
; CreateDIBSection

;#####################################################################################
;#####################################################################################
;
; GDI and structure functions
;
;#####################################################################################
;#####################################################################################

; Function:     UpdateLayeredWindow
; Description:  Updates a layered window with the handle to the DC of a gdi bitmap
;   
; hwnd        = Handle of the window to update
; hdc           = Handle to the DC of the GDI bitmap to update the window with
; Layeredx      = x position to place the window
; Layeredy      = x position to place the window
; Layeredw      = Width of the window
; Layeredh      = Height of the window
; Alpha         = Default = 255 : The transparency (0-255) to set the window transparency
;
; Return:      If the function succeeds, the return value is nonzero.
;
UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255)
{
   If ((x != "") && (y != ""))
   VarSetCapacity(pt, 8), NumPut(x, pt, 0), NumPut(y, pt, 4)
   
   If ((w = "") ||(h = ""))
   WinGetPos,,, w, h, ahk_id %hwnd%
   
   Return, DllCall("UpdateLayeredWindow"
   , "UInt", hwnd
   , "UInt", 0
   , "UInt", ((x = "") && (y = "")) ? 0 : &pt
   , "Int64*", w|h<<32
   , "UInt", hdc
   , "Int64*", 0
   , "UInt", 0
   , "UInt*", Alpha<<16|1<<24
   , "UInt", 2)
}
;#####################################################################################
BitBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, Raster="")
{
Return, DllCall("gdi32\BitBlt"
, "UInt", dDC ; handle to destination DC
, "Int", dx ; x-coord of destination upper-left corner
, "Int", dy ; y-coord of destination upper-left corner
, "Int", dw ; width of destination rectangle
, "Int", dh ; height of destination rectangle
, "UInt", sDC ; handle to source DC
, "Int", sx ; x-coordinate of source upper-left corner
, "Int", sy ; y-coordinate of source upper-left corner
, "UInt", Raster ? Raster : 0x00CC0020) ; raster operation code
}
;#####################################################################################
StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="")
{
Return, DllCall("gdi32\StretchBlt"
, "UInt", dDC ; handle to destination DC
, "Int", dx ; x-coord of destination upper-left corner
, "Int", dy ; y-coord of destination upper-left corner
, "Int", dw ; width of destination rectangle
, "Int", dh ; height of destination rectangle
, "UInt", sDC ; handle to source DC
, "Int", sx ; x-coordinate of source upper-left corner
, "Int", sy ; y-coordinate of source upper-left corner
, "Int", sw ; width of source rectangle
, "Int", sh ; height of source rectangle
, "UInt", Raster ? Raster : 0x00CC0020) ; raster operation code
}
;#####################################################################################
SetImage(hwnd, hBitmap)
{
SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd%
}
;#####################################################################################
Gdip_BitmapFromScreen(Screen=0)
{
If (Screen = 0)
{
Sysget, x, 76
Sysget, y, 77
Sysget, w, 78
Sysget, h, 79
}
Else If (Screen&1 != "")
{
Sysget, M, Monitor, %Screen%
x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop
}
Else
{
StringSplit, S, Screen, |
x := S1, y := S2, w := S3, h := S4
}

If (x = "") || (y = "") || (w = "") || (h = "")
Return, -1

chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := GetDC()
BitBlt(chdc, 0, 0, w, h, hhdc, x, y)
ReleaseDC(hhdc)

pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm)
SelectObject(hhdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc)
Return, pBitmap
}
;#####################################################################################

; Function:    CreateRectF
; Description: Creates a RectF object, containing a the coordinates and dimensions of a rectangle
;
; RectF        = Name to call the RectF object
; x            = x-coordinate of the upper left corner of the rectangle
; y            = y-coordinate of the upper left corner of the rectangle
; w            = Width of the rectangle
; h            = Height of the rectangle
;
; Return:      No return value
;
CreateRectF(ByRef RectF, x, y, w, h)
{
   VarSetCapacity(RectF, 16)
   NumPut(x, RectF, 0, "Float"), NumPut(y, RectF, 4, "Float"), NumPut(w, RectF, 8, "Float"), NumPut(h, RectF, 12, "Float")
}
;#####################################################################################

; Function:    CreateSizeF
; Description:   Creates a SizeF object, containing an 2 values
;
; SizeF         = Name to call the SizeF object
; w            = w-value for the SizeF object
; h            = h-value for the SizeF object
;
; Return:      No Return value
;
CreateSizeF(ByRef SizeF, w, h)
{
   VarSetCapacity(SizeF, 8)
   NumPut(w, SizeF, 0, "Float"), NumPut(h, SizeF, 4, "Float")     
}
;#####################################################################################

; Function:    CreateDIBSection
; Description:   Creates a SizeF object, containing an 2 values
;
; SizeF         = Name to call the SizeF object
; w            = w-value for the SizeF object
; h            = h-value for the SizeF object
;
CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0)
{
hdc2 := hdc ? hdc : GetDC(hwnd=0)

VarSetCapacity(bi, 40, 0)       ; BITMAPINFO(HEADER)
NumPut(40, bi,  0)              ; biSize
NumPut(1,  bi, 12, "UShort")    ; biPlanes
NumPut(0,  bi, 16)              ; biCompression = BI_RGB (none)
NumPut(w,  bi,  4)              ; biWidth
NumPut(h,  bi,  8)              ; biHeight
NumPut(bpp,bi, 14, "UShort")    ; biBitCount
       
hbm := DllCall("CreateDIBSection", "UInt" , hdc2, "UInt" , &bi, "UInt" , 0, "UInt*", ppvBits, "UInt" , 0, "UInt" , 0)
;If !hdc
;ReleaseDC(hdc2)
VarSetCapacity(bi, 0)
Return, hbm
}
;#####################################################################################

DestroyIcon(hIcon)
{
   Return, DllCall("DestroyIcon", "UInt", hIcon)
}

CreateCompatibleDC(hdc=0)
{
   Return, DllCall("CreateCompatibleDC", "UInt", hdc)
}     

SelectObject(hdc, hgdiobj)
{
   Return, DllCall("SelectObject", "UInt", hdc, "UInt", hgdiobj)
}

DeleteObject(hObject)
{
   Return, DllCall("DeleteObject", "UInt", hObject)
}

GetDC(hwnd=0)
{
Return, DllCall("GetDC", "UInt", hwnd)
}

ReleaseDC(hdc, hwnd=0)
{
   Return, DllCall("ReleaseDC", "UInt", hwnd, "UInt", hdc)
}

DeleteDC(hdc)
{
   Return, DllCall("DeleteDC", "UInt", hdc)
}
;#####################################################################################
;#####################################################################################
;
; Misc functions
;
;#####################################################################################

Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File)
{
   If (SubStr(File, 1, 4) = "File") && (SubStr(File, 5, StrLen(File)-4) & 1 != "")
   {
      RegExMatch(BRAFromMemIn, ":H:([0-9]+).*?:a:" SubStr(File, 5, StrLen(File)-4) ":b:(.*?):c:([0-9]+):d:([0-9]+)::", FileInfo)
      File := FileInfo2
   }
   Else
   RegExMatch(BRAFromMemIn, ":H:([0-9]+).*?:a:([0-9]+):b:\Q" File "\E:c:([0-9]+):d:([0-9]+)::", FileInfo)
   
   If !FileInfo
   Return, 0
   
   hData := DllCall("GlobalAlloc", "UInt", 2, "UInt", FileInfo3)
   pData := DllCall("GlobalLock", "UInt", hData)
   DllCall("RtlMoveMemory", "UInt", pData, "UInt", &BRAFromMemIn+FileInfo1+FileInfo4, "UInt", FileInfo3)
   DllCall("GlobalUnlock", "UInt", hData)
   DllCall("ole32\CreateStreamOnHGlobal", "UInt", hData, "Int", 1, "UInt*", pStream)
   DllCall("gdiplus\GdipCreateBitmapFromStream", "UInt", pStream, "UInt*", pBitmap)
   DllCall(NumGet(NumGet(1*pStream)+8), "UInt", pStream)
   Return, pBitmap
}

;#####################################################################################
;
; GDI+ functions
;
;#####################################################################################
;#####################################################################################
;#####################################################################################
; Draw shape/line
;#####################################################################################

Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
{
   Return, DllCall("gdiplus\GdipDrawRectangle", "UInt", pGraphics, "UInt", pPen
   , "Float", x, "Float", y, "Float", w, "Float", h)
}

Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r)
{
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h)
Gdip_ResetClip(pGraphics)
Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r)
Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
Gdip_ResetClip(pGraphics)
Return, E
}

Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h)
{
   Return, DllCall("gdiplus\GdipDrawEllipse", "UInt", pGraphics, "UInt", pPen
   , "Float", x, "Float", y, "Float", w, "Float", h)
}

Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4)
{
   Return, DllCall("gdiplus\GdipDrawBezier", "UInt", pgraphics, "UInt", pPen
   , "Float", x1, "Float", y1, "Float", x2, "Float", y2
   , "Float", x3, "Float", y3, "Float", x4, "Float", y4)
}

Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
{
   Return, DllCall("gdiplus\GdipDrawArc", "UInt", pGraphics, "UInt", pPen
   , "Float", x, "Float", y, "Float", w, "Float", h, "Float", StartAngle, "Float", SweepAngle)
}

Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle)
{
   Return, DllCall("gdiplus\GdipDrawPie", "UInt", pGraphics, "UInt", pPen, "Float", x, "Float", y, "Float", w, "Float", h, "Float", StartAngle, "Float", SweepAngle)
}

Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2)
{
   Return, DllCall("gdiplus\GdipDrawLine", "UInt", pGraphics, "UInt", pPen
   , "Float", x1, "Float", y1, "Float", x2, "Float", y2)
}

; Points passed as x1,y1|x2,y2|x3,y3.....
Gdip_DrawLines(pGraphics, pPen, Points)
{
   StringSplit, Points, Points, |
   VarSetCapacity(PointF, 8*Points0)   
   Loop, %Points0%
   {
      StringSplit, Coord, Points%A_Index%, `,
      NumPut(Coord1, PointF, 8*(A_Index-1), "Float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "Float")
   }
   Return, DllCall("gdiplus\GdipDrawLines", "UInt", pGraphics, "UInt", pPen, "UInt", &PointF, "Int", Points0)
}

;#####################################################################################
; Fill shape
;#####################################################################################

Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
{
   Return, DllCall("gdiplus\GdipFillRectangle", "UInt", pGraphics, "Int", pBrush
   , "Float", x, "Float", y, "Float", w, "Float", h)
}

Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r)
{
Region := Gdip_GetClipRegion(pGraphics)
Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4)
Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4)
E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4)
Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4)
Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r)
Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r)
Gdip_SetClipRegion(pGraphics, Region, 0)
Gdip_DeleteRegion(Region)
Return, E
}

; Points passed as x1,y1|x2,y2|x3,y3.....
Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0)
{
   StringSplit, Points, Points, |
   VarSetCapacity(PointF, 8*Points0)   
   Loop, %Points0%
   {
      StringSplit, Coord, Points%A_Index%, `,
      NumPut(Coord1, PointF, 8*(A_Index-1), "Float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "Float")
   }   
   Return, DllCall("gdiplus\GdipFillPolygon", "UInt", pGraphics, "UInt", pBrush, "UInt", &PointF, "Int", Points0, "Int", FillMode)
}

Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle)
{
   Return, DllCall("gdiplus\GdipFillPie", "UInt", pGraphics, "UInt", pBrush
   , "Float", x, "Float", y, "Float", w, "Float", h, "Float", StartAngle, "Float", SweepAngle)
}

Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h)
{
   Return, DllCall("gdiplus\GdipFillEllipse", "UInt", pGraphics, "UInt", pBrush
   , "Float", x, "Float", y, "Float", w, "Float", h, "Float")
}

Gdip_FillRegion(pGraphics, pBrush, Region)
{
   Return, DllCall("gdiplus\GdipFillRegion", "UInt", pGraphics, "UInt", pBrush, "UInt", Region)
}

Gdip_FillPath(pGraphics, pBrush, Path)
{
   Return, DllCall("gdiplus\GdipFillPath", "UInt", pGraphics, "UInt", pBrush, "UInt", Path)
}

;#####################################################################################
; Graphics functions
;#####################################################################################

; Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left)
Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", TransMatrix=1)
{
StringSplit, Points, Points, |
VarSetCapacity(PointF, 8*Points0)   
Loop, %Points0%
{
StringSplit, Coord, Points%A_Index%, `,
NumPut(Coord1, PointF, 8*(A_Index-1), "Float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "Float")
}

If (TransMatrix&1 = "")
ImageAttr := Gdip_SetImageAttributesColorMatrix(TransMatrix)
Else
ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" TransMatrix "|0|0|0|0|0|1")

E := DllCall("gdiplus\GdipDrawImagePointsRect", "UInt", pGraphics, "UInt", pBitmap
, "UInt", &PointF, "Int", Points0, "Float", sx, "Float", sy, "Float", sw, "Float", sh
, "Int", 2, "UInt", ImageAttr, "UInt", 0, "UInt", 0)
If ImageAttr
Gdip_DisposeImageAttributes(ImageAttr)
Return, E
}

Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx="", sy="", sw="", sh="", Matrix=1)
{
If (Matrix&1 = "")
ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix)
Else
ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1")

If (sx = "") && (sy = "") && (sw = "") && (sh = "")
sx := 0, sy := 0, sw := dw, sh := dh

E := DllCall("gdiplus\GdipDrawImageRectRect", "UInt", pGraphics, "UInt", pBitmap
, "Float", dx, "Float", dy, "Float", dw, "Float", dh
, "Float", sx, "Float", sy, "Float", sw, "Float", sh
, "Int", 2, "UInt", ImageAttr, "UInt", 0, "UInt", 0)
If ImageAttr
Gdip_DisposeImageAttributes(ImageAttr)
Return, E
}

;MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1
;MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1
;MatrixNegative = -1|0|0|0|0|0|1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1
Gdip_SetImageAttributesColorMatrix(Matrix)
{
VarSetCapacity(ColourMatrix, 100, 0)
Matrix := RegExReplace(RegExReplace(Matrix, "^[^0-9-\.]+([0-9\.])", "$1", "", 1), "[^0-9-\.]+", "|")
StringSplit, Matrix, Matrix, |
Loop, 25
{
Matrix := Matrix%A_Index% ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1
NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "Float")
}
DllCall("gdiplus\GdipCreateImageAttributes", "UInt*", ImageAttr)
DllCall("gdiplus\GdipSetImageAttributesColorMatrix", "UInt", ImageAttr, "Int", 1, "Int", 1, "UInt", &ColourMatrix, "Int", 0, "Int", 0)
VarSetCapacity(ColourMatrix, 0)
Return, ImageAttr
}

Gdip_GraphicsFromImage(pBitmap)
{
    DllCall("gdiplus\GdipGetImageGraphicsContext", "UInt", pBitmap, "UInt*", pGraphics)
    Return, pGraphics
}

Gdip_GraphicsFromHDC(hdc)
{
    DllCall("gdiplus\GdipCreateFromHDC", "UInt", hdc, "UInt*", pGraphics)
    Return, pGraphics
}

;#####################################################################################
; Bitmap functions
;#####################################################################################

Gdip_BlurBitmap(pBitmap, Blur)
{
If ((Blur > 100) || (Blur < 1))
Return, -1

sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap)
dWidth := sWidth//Blur, dHeight := sHeight//Blur

pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight)
G1 := Gdip_GraphicsFromImage(pBitmap1)
Gdip_SetInterpolationMode(G1, 7)
Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight)

Gdip_DeleteGraphics(G1)
Gdip_DisposeImage(pBitmap)

pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight)
G2 := Gdip_GraphicsFromImage(pBitmap2)
Gdip_SetInterpolationMode(G2, 7)
Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight)

Gdip_DeleteGraphics(G2)
Gdip_DisposeImage(pBitmap1)
Return, pBitmap2
}
;#####################################################################################

; Function:     Gdip_SaveBitmapToFile
; Description:  Saves a gdi+ bitmap to a file in any supported format onto disk
;   
; pBitmap      = Pointer to the gdi+ bitmap object
; sOutput      = The name of the file that the bitmap will eb saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
; Quality      = If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality
;
; Return:      If the function succeeds, the return value is zero, otherwise:
; -1: Extension supplied is not a supported file format
; -2: Could not get a list of encoders on system
; -3: Could not find matching encoder for specified file format
; -4: Could not get WideChar name of output file
; -5: Could not save file to disk
;

Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=100)
{
StringSplit, OutputArray, sOutput, .
    Extension := "." . OutputArray%OutputArray0%
If Extension not in .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG
Return, -1
   
DllCall("gdiplus\GdipGetImageEncodersSize", "UInt*", nCount, "UInt*", nSize)
VarSetCapacity(ci, nSize)
DllCall("gdiplus\GdipGetImageEncoders", "UInt", nCount, "UInt", nSize, "UInt", &ci)
If !(nCount && nSize)
Return, -2
   
Loop, %nCount%
{
nSize := DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", NumGet(ci, 76*(A_Index-1)+44), "Int", -1, "UInt", 0, "Int",  0, "UInt", 0, "UInt", 0)
VarSetCapacity(sString, nSize)
DllCall("WideCharToMultiByte", "UInt", 0, "UInt", 0, "UInt", NumGet(ci, 76*(A_Index-1)+44), "Int", -1, "Str", sString, "Int", nSize, "UInt", 0, "UInt", 0)

If !InStr(sString, Extension)
Continue
pCodec := &ci+76*(A_Index-1)
Break
    }
If !pCodec
Return, -3

If (Quality != 100)
{
If Extension in .JPG,.JPEG,.JPE,.JFIF
{
DllCall("gdiplus\GdipGetEncoderParameterListSize", "UInt", pBitmap, "UInt", pCodec, "UInt*", nSize)
VarSetCapacity(EncoderParameters, nSize, 0)
DllCall("gdiplus\GdipGetEncoderParameterList", "UInt", pBitmap, "UInt", pCodec, "UInt", nSize, "UInt", &EncoderParameters)
Loop, % NumGet(EncoderParameters) ;%
{
If (NumGet(EncoderParameters, (28*(A_Index-1))+20) = 1) && (NumGet(EncoderParameters, (28*(A_Index-1))+24) = 6)
{
p := (28*(A_Index-1))+&EncoderParameters
NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20)))
Break
}
}
}
}
   
nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sOutput, "Int", -1, "UInt", 0, "Int", 0)
VarSetCapacity(wOutput, nSize*2)
DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sOutput, "Int", -1, "UInt", &wOutput, "Int", nSize)
VarSetCapacity(wOutput, -1)
If !VarSetCapacity(wOutput)
Return, -4

E := DllCall("gdiplus\GdipSaveImageToFile", "UInt", pBitmap, "UInt", &wOutput, "UInt", pCodec, "UInt", p ? p : 0)
Return, E ? -5 : 0
}

Gdip_GetPixel(pBitmap, x, y)
{
DllCall("gdiplus\GdipBitmapGetPixel", "UInt", pBitmap, "Int", x, "Int", y, "UInt*", ARGB)
Return, ARGB
}

Gdip_SetPixel(pBitmap, x, y, ARGB)
{
   Return, DllCall("gdiplus\GdipBitmapSetPixel", "UInt", pBitmap, "Int", x, "Int", y, "Int", ARGB)
}

Gdip_GetImageWidth(pBitmap)
{
   DllCall("gdiplus\GdipGetImageWidth", "UInt", pBitmap, "UInt*", Width)
   Return, Width
}

Gdip_GetImageHeight(pBitmap)
{
   DllCall("gdiplus\GdipGetImageHeight", "UInt", pBitmap, "UInt*", Height)
   Return, Height
}

Gdip_GetDpiX(pGraphics)
{
DllCall("gdiplus\GdipGetDpiX", "UInt", pGraphics, "Float*", DPIx)
Return, DPIx
}

Gdip_GetDpiY(pGraphics)
{
DllCall("gdiplus\GdipGetDpiY", "UInt", pGraphics, "Float*", DPIy)
Return, DPIy
}

Gdip_CreateBitmapFromFile(sFile)
{
   VarSetCapacity(wFile, 1023)
   DllCall("kernel32\MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sFile, "Int", -1, "UInt", &wFile, "Int", 512)
   DllCall("gdiplus\GdipCreateBitmapFromFile", "UInt", &wFile, "UInt*", pBitmap)
   Return, pBitmap
}

Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0)
{
DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "UInt", hBitmap, "UInt", Palette, "UInt*", pBitmap)
Return, pBitmap
}

Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff)
{
DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "UInt", pBitmap, "UInt*", hbm, "Int", Background)
Return, hbm
}

Gdip_CreateBitmapFromHICON(hIcon)
{
DllCall("gdiplus\GdipCreateBitmapFromHICON", "UInt", hIcon, "UInt*", pBitmap)
Return, pBitmap
}

Gdip_CreateHICONFromBitmap(pBitmap)
{
DllCall("gdiplus\GdipCreateHICONFromBitmap", "UInt", pBitmap, "UInt*", hIcon)
Return, hIcon
}

Gdip_CreateBitmap(Width, Height, Format=0x26200A)
{
    DllCall("gdiplus\GdipCreateBitmapFromScan0", "Int", Width, "Int", Height, "Int", 0, "Int", Format, "UInt", 0, "UInt*", pBitmap)
    Return pBitmap
}

Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A)
{
DllCall("gdiplus\GdipCloneBitmapArea", "Float", x, "Float", y, "Float", w, "Float", h
, "Int", Format, "UInt", pBitmap, "UInt*", pBitmapDest)
Return, pBitmapDest
}

;#####################################################################################
; Create resources
;#####################################################################################

Gdip_CreatePen(ARGB, w)
{
   DllCall("gdiplus\GdipCreatePen1", "Int", ARGB, "Float", w, "Int", 2, "UInt*", pPen)
   Return, pPen
}

Gdip_BrushCreateSolid(ARGB=0xff000000)
{
   DllCall("gdiplus\GdipCreateSolidFill", "Int", ARGB, "UInt*", pBrush)
   Return, pBrush
}

; HatchStyleHorizontal = 0
; HatchStyleVertical = 1
; HatchStyleForwardDiagonal = 2
; HatchStyleBackwardDiagonal = 3
; HatchStyleCross = 4
; HatchStyleDiagonalCross = 5
; HatchStyle05Percent = 6
; HatchStyle10Percent = 7
; HatchStyle20Percent = 8
; HatchStyle25Percent = 9
; HatchStyle30Percent = 10
; HatchStyle40Percent = 11
; HatchStyle50Percent = 12
; HatchStyle60Percent = 13
; HatchStyle70Percent = 14
; HatchStyle75Percent = 15
; HatchStyle80Percent = 16
; HatchStyle90Percent = 17
; HatchStyleLightDownwardDiagonal = 18
; HatchStyleLightUpwardDiagonal = 19
; HatchStyleDarkDownwardDiagonal = 20
; HatchStyleDarkUpwardDiagonal = 21
; HatchStyleWideDownwardDiagonal = 22
; HatchStyleWideUpwardDiagonal = 23
; HatchStyleLightVertical = 24
; HatchStyleLightHorizontal = 25
; HatchStyleNarrowVertical = 26
; HatchStyleNarrowHorizontal = 27
; HatchStyleDarkVertical = 28
; HatchStyleDarkHorizontal = 29
; HatchStyleDashedDownwardDiagonal = 30
; HatchStyleDashedUpwardDiagonal = 31
; HatchStyleDashedHorizontal = 32
; HatchStyleDashedVertical = 33
; HatchStyleSmallConfetti = 34
; HatchStyleLargeConfetti = 35
; HatchStyleZigZag = 36
; HatchStyleWave = 37
; HatchStyleDiagonalBrick = 38
; HatchStyleHorizontalBrick = 39
; HatchStyleWeave = 40
; HatchStylePlaid = 41
; HatchStyleDivot = 42
; HatchStyleDottedGrid = 43
; HatchStyleDottedDiamond = 44
; HatchStyleShingle = 45
; HatchStyleTrellis = 46
; HatchStyleSphere = 47
; HatchStyleSmallGrid = 48
; HatchStyleSmallCheckerBoard = 49
; HatchStyleLargeCheckerBoard = 50
; HatchStyleOutlinedDiamond = 51
; HatchStyleSolidDiamond = 52
; HatchStyleTotal = 53
Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0)
{
   DllCall("gdiplus\GdipCreateHatchBrush", "Int", HatchStyle, "Int", ARGBfront, "Int", ARGBback, "UInt*", pBrush)
   Return, pBrush
}

;#####################################################################################
; Delete resources
;#####################################################################################

Gdip_DeletePen(pPen)
{
   Return, DllCall("gdiplus\GdipDeletePen", "UInt", pPen)
}

Gdip_DeleteBrush(pBrush)
{
   Return, DllCall("gdiplus\GdipDeleteBrush", "UInt", pBrush)
}

Gdip_DisposeImage(pBitmap)
{
   Return, DllCall("gdiplus\GdipDisposeImage", "UInt", pBitmap)
}

Gdip_DeleteGraphics(pGraphics)
{
   Return, DllCall("gdiplus\GdipDeleteGraphics", "UInt", pGraphics)
}

Gdip_DisposeImageAttributes(ImageAttr)
{
Return, DllCall("gdiplus\GdipDisposeImageAttributes", "UInt", ImageAttr)
}

Gdip_DeleteFont(hFont)
{
   Return, DllCall("gdiplus\GdipDeleteFont", "UInt", hFont)
}

Gdip_DeleteStringFormat(hFormat)
{
   Return, DllCall("gdiplus\GdipDeleteStringFormat", "UInt", hFormat)
}

Gdip_DeleteFontFamily(hFamily)
{
   Return, DllCall("gdiplus\GdipDeleteFontFamily", "UInt", hFamily)
}

Gdip_DeleteMatrix(Matrix)
{
   Return, DllCall("gdiplus\GdipDeleteMatrix", "UInt", Matrix)
}

;#####################################################################################
; Text functions
;#####################################################################################

Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="")
{
IWidth := Width, IHeight:= Height

RegExMatch(Options, "i)X([0-9]+)(p*)", xpos)
RegExMatch(Options, "i)Y([0-9]+)(p*)", ypos)
RegExMatch(Options, "i)W([0-9]+)(p*)", Width)
RegExMatch(Options, "i)H([0-9]+)(p*)", Height)
RegExMatch(Options, "i)C(?!(entre|enter))([a-f0-9]{8})", Colour)
RegExMatch(Options, "i)R([0-9])", Rendering)
RegExMatch(Options, "i)S([0-9]+)(p*)", Size)

If !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2)
Return, -1

Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout"
Loop, Parse, Styles, |
{
If InStr(Options, A_loopField)
Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8
}
   
Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right"
Loop, Parse, Alignments, |
{
If InStr(Options, A_loopField)
Align |= A_Index//2.1      ; 0|0|1|1|2|2
}

xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0
ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0
Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth
Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight
Colour := "0x" (Colour2 ? Colour2 : "ff000000")
Rendering := ((Rendering1 >= 0) && (Rendering1 <= 4)) ? Rendering1 : 4
Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12

hFamily := Gdip_FontFamilyCreate(Font)
hFont := Gdip_FontCreate(hFamily, Size, Style)
hFormat := Gdip_StringFormatCreate(0x4000)
pBrush := Gdip_BrushCreateSolid(Colour)
If !(hFamily && hFont && hFormat && pBrush && pGraphics)
Return, !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0
   
CreateRectF(RC, xpos, ypos, Width, Height)
Gdip_SetStringFormatAlign(hFormat, Align)
Gdip_SetTextRenderingHint(pGraphics, Rendering)
E1 := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC)
E2 := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC)
   
VarSetCapacity(RC, 0)
Gdip_DeleteBrush(pBrush)
Gdip_DeleteStringFormat(hFormat)   
Gdip_DeleteFont(hFont)
Gdip_DeleteFontFamily(hFamily)
Return, E1 ? E1 : E2
}

Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF)
{
   nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
   VarSetCapacity(wString, nSize*2)
   DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)
   Return, DllCall("gdiplus\GdipDrawString", "UInt", pGraphics, "UInt", &wString, "Int", -1, "UInt", hFont, "UInt", &RectF, "UInt", hFormat, "UInt", pBrush)
}

Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF)
{
   nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", 0, "Int", 0)
   VarSetCapacity(wString, nSize*2)   
   DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &sString, "Int", -1, "UInt", &wString, "Int", nSize)
   VarSetCapacity(RC, 16)   
   DllCall("gdiplus\GdipMeasureString", "UInt", pGraphics, "UInt", &wString, "Int", -1, "UInt", hFont, "UInt", &RectF, "UInt", hFormat, "UInt", &RC, "UInt*", Chars, "UInt*", Lines)
   Return, &RC ? NumGet(RC, 0, "Float") "|" NumGet(RC, 4, "Float") "|" NumGet(RC, 8, "Float") "|" NumGet(RC, 12, "Float") "|" Chars "|" Lines : 0
}

; Near = 0
; Center = 1
; Far = 2
Gdip_SetStringFormatAlign(hFormat, Align)
{
   Return, DllCall("gdiplus\GdipSetStringFormatAlign", "UInt", hFormat, "Int", Align)
}

Gdip_StringFormatCreate(Format=0, Lang=0)
{
   DllCall("gdiplus\GdipCreateStringFormat", "Int", Format, "Int", Lang, "UInt*", hFormat)
   Return, hFormat
}

; Regular = 0
; Bold = 1
; Italic = 2
; BoldItalic = 3
; Underline = 4
; Strikeout = 8
Gdip_FontCreate(hFamily, Size, Style=0)
{
   DllCall("gdiplus\GdipCreateFont", "UInt", hFamily, "Float", Size, "Int", Style, "Int", 0, "UInt*", hFont)
   Return, hFont
}

Gdip_FontFamilyCreate(Font)
{
   nSize := DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &Font, "Int", -1, "UInt", 0, "Int", 0)
   VarSetCapacity(wFont, nSize*2)
   DllCall("MultiByteToWideChar", "UInt", 0, "UInt", 0, "UInt", &Font, "Int", -1, "UInt", &wFont, "Int", nSize)

   DllCall("gdiplus\GdipCreateFontFamilyFromName", "UInt", &wFont, "UInt", 0, "UInt*", hFamily)
   Return, hFamily
}

;#####################################################################################
; Matrix functions
;#####################################################################################

Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y)
{
   DllCall("gdiplus\GdipCreateMatrix2", "Float", m11, "Float", m12, "Float", m21, "Float", m22, "Float", x, "Float", y, "UInt*", Matrix)
   Return, Matrix
}

Gdip_CreateMatrix()
{
   DllCall("gdiplus\GdipCreateMatrix", "UInt*", Matrix)
   Return, Matrix
}

;#####################################################################################
; GraphicsPath functions
;#####################################################################################

; Alternate = 0
; Winding = 1
Gdip_CreatePath(BrushMode=0)
{
DllCall("gdiplus\GdipCreatePath", "Int", BrushMode, "UInt*", Path)
Return, Path
}

Gdip_AddPathEllipse(Path, x, y, w, h)
{
   Return, DllCall("gdiplus\GdipAddPathEllipse", "UInt", Path, "Float", x, "Float", y, "Float", w, "Float", h)
}

Gdip_DeletePath(Path)
{
Return, DllCall("gdiplus\GdipDeletePath", "UInt", Path)
}

;#####################################################################################
; Quality functions
;#####################################################################################

; SystemDefault = 0
; SingleBitPerPixelGridFit = 1
; SingleBitPerPixel = 2
; AntiAliasGridFit = 3
; AntiAlias = 4
Gdip_SetTextRenderingHint(pGraphics, RenderingHint)
{
   Return, DllCall("gdiplus\GdipSetTextRenderingHint", "UInt", pGraphics, "Int", RenderingHint)
}

; Default = 0
; LowQuality = 1
; HighQuality = 2
; Bilinear = 3
; Bicubic = 4
; NearestNeighbor = 5
; HighQualityBilinear = 6
; HighQualityBicubic = 7
Gdip_SetInterpolationMode(pGraphics, InterpolationMode)
{
   Return, DllCall("gdiplus\GdipSetInterpolationMode", "UInt", pGraphics, "Int", InterpolationMode)
}

; Default = 0
; HighSpeed = 1
; HighQuality = 2
; None = 3
; AntiAlias = 4
Gdip_SetSmoothingMode(pGraphics, SmoothingMode)
{
   Return, DllCall("gdiplus\GdipSetSmoothingMode", "UInt", pGraphics, "Int", SmoothingMode)
}

;GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics, CompositingMode compositingMode)

; CompositingModeSourceOver = 0 (blended)
; CompositingModeSourceCopy = 1 (overwrite)
Gdip_SetCompositingMode(pGraphics, CompositingMode=0)
{
   Return, DllCall("gdiplus\GdipSetCompositingMode", "UInt", pGraphics, "Int", CompositingMode)
}

;#####################################################################################
; Extra functions
;#####################################################################################

Gdip_Startup()
{
   If !DllCall("GetModuleHandle", "Str", "gdiplus")
   DllCall("LoadLibrary", "Str", "gdiplus")
   VarSetCapacity(si, 16, 0), si := Chr(1)
   DllCall("gdiplus\GdiplusStartup", "UInt*", pToken, "UInt", &si, "UInt", 0)
   VarSetCapacity(si, 0)
   Return, pToken
}

Gdip_Shutdown(pToken)
{
   DllCall("gdiplus\GdiplusShutdown", "UInt", pToken)
   If hModule := DllCall("GetModuleHandle", "Str", "gdiplus")
   DllCall("FreeLibrary", "UInt", hModule)
   Return, 0
}

; Prepend = 0; The new operation is applied before the old operation.
; Append = 1; The new operation is applied after the old operation.
Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0)
{
Return, DllCall("gdiplus\GdipRotateWorldTransform", "UInt", pGraphics, "Float", Angle, "Int", MatrixOrder)
}

Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0)
{
Return, DllCall("gdiplus\GdipScaleWorldTransform", "UInt", pGraphics, "Float", x, "Float", y, "Int", MatrixOrder)
}

Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0)
{
Return, DllCall("gdiplus\GdipTranslateWorldTransform", "UInt", pGraphics, "Float", x, "Float", y, "Int", MatrixOrder)
}

Gdip_ResetWorldTransform(pGraphics)
{
Return, DllCall("gdiplus\GdipResetWorldTransform", "UInt", pGraphics)
}

Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation)
{
pi := 4*ATan(1), TAngle := Angle*(pi/180)

Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360)
If ((Bound >= 0) && (Bound <= 90))
xTranslation := Height*Sin(TAngle), yTranslation := 0
Else If ((Bound > 90) && (Bound <= 180))
xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle)
Else If ((Bound > 180) && (Bound <= 270))
xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle))
Else If ((Bound > 270) && (Bound <= 360))
xTranslation := 0, yTranslation := -Width*Sin(TAngle)
}

Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight)
{
pi := 4*ATan(1), TAngle := Angle*(pi/180)
If !(Width && Height)
Return, -1
RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle)))
RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle)))
}

; Replace = 0
; Intersect = 1
; Union = 2
; Xor = 3
; Exclude = 4
; Complement = 5
Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0)
{
   Return, DllCall("gdiplus\GdipSetClipRect", "UInt", pGraphics, "Float", x, "Float", y, "Float", w, "Float", h, "Int", CombineMode)
}

Gdip_SetClipPath(pGraphics, Path, CombineMode=0)
{
   Return, DllCall("gdiplus\GdipSetClipPath", "UInt", pGraphics, "UInt", Path, "Int", CombineMode)
}

Gdip_ResetClip(pGraphics)
{
   Return, DllCall("gdiplus\GdipResetClip", "UInt", pGraphics)
}

Gdip_GetClipRegion(pGraphics)
{
Region := Gdip_CreateRegion()
DllCall("gdiplus\GdipGetClip", "UInt" pGraphics, "UInt", Region)
Return, Region
}

Gdip_SetClipRegion(pGraphics, Region, CombineMode=0)
{
Return, DllCall("gdiplus\GdipSetClipRegion", "UInt", pGraphics, "UInt", Region, "Int", CombineMode)
}

Gdip_CreateRegion()
{
DllCall("gdiplus\GdipCreateRegion", "UInt*", Region)
Return, Region
}

Gdip_DeleteRegion(Region)
{
Return, DllCall("gdiplus\GdipDeleteRegion", "UInt", Region)
}

146
 :) Have you tried WinGroup WinStep ?

Step through groups of windows using hotkeys.

  Ctrl-0: Add a window to a Group0
  Ctrl-1: Add a window to a Group1
    ...

  Alt-0 : Show the next window of Group0
  Alt-1 : Show the next window of Group1
    ...

Features:
- User defined hotkeys and sounds.

Skrommel


147
Post New Requests Here / Re: IDEA: Click counter
« on: October 03, 2008, 01:18 PM »
 :) Try CliCount!

Rightclick the tray menu to change the title to watch and reset the counters.

Skrommel

;CliCount.ahk
; Count clicks in a user defined window
;Skrommel @ 2008

#NoEnv
#SingleInstance,Force
#Persistent,On
SetTitleMatchMode,2

applicationname=CliCount

OnExit,EXIT
Gosub,TRAYMENU
buttons=lrm
IniRead,title,%applicationname%.ini,Settings,title
If title=Error
  title=
Loop,Parse,buttons
{
  IniRead,%A_LoopField%button,%applicationname%.ini,Settings,%A_LoopField%button
  If %A_LoopField%button=ERROR
    %A_LoopField%button=0
}
Return


~*LButton::
~*RButton::
~*MButton::
StringTrimLeft,hotkey,A_ThisHotkey,2
MouseGetPos,,,mwin
WinGetTitle,mtitle,ahk_id %mwin%
IfInString,mtitle,%title%
  %hotkey%+=1
Return


TRAYMENU:
Menu,Tray,NoStandard
Menu,Tray,DeleteAll
Menu,Tray,Add,%applicationname%,SHOW
Menu,Tray,Add,
Menu,Tray,Default,%applicationname%
Menu,Tray,Add,E&xit,EXIT
Menu,Tray,Tip,%applicationname%
Return


SHOW:
InputBox,newtitle,%applicationname%,Left:`t%lbutton%`nRight:`t%rbutton%`nMiddle:`t%mbutton%`n`nPart of Window Caption:,,,,,,,,%title%
If ErrorLevel=1
  Return
title=%newtitle%
MsgBox,4,%applicationname%,Reset counters?
IfMsgBox,No
  Return
lbutton=0
rbutton=0
mbutton=0
Return


EXIT:
IniWrite,%title%,%applicationname%.ini,Settings,title
IniWrite,%lbutton%,%applicationname%.ini,Settings,lbutton
IniWrite,%rbutton%,%applicationname%.ini,Settings,rbutton
IniWrite,%mbutton%,%applicationname%.ini,Settings,mbutton
ExitApp


148
 :) @jdd: When you first run IdleRun, it creates an ini-file next to the program. This file is edited using the tray menu, but you have to restart IdleRun to invoke the changes (lazy, I know).

cputhreshold=5 is the max load of the CPU.
checkinterval=1 is how often to check tha CPU load.
idleduration=60 is how long the CPU load must be below the threshold.

To run a program using the screensaver, have you tried RunSaver?

Skrommel

149
Post New Requests Here / Re: Vista style filename editing in XP
« on: September 25, 2008, 03:13 AM »
 :-[ Thanks for clarifying things, lanux128!

Skrommel

150
Post New Requests Here / Re: IDEA: Desktop Bring to front
« on: September 25, 2008, 03:09 AM »
 :) I'll make a proper tool out of it in a couple of days, but wouldn't it be more useful to have the desktop behave like a proper window, and activate it via it's taskbar button? Is the ontop action really needed?

Skrommel

Pages: prev1 2 3 4 5 [6] 7 8 9 10 11 ... 38next