AutoHotkey Community

It is currently May 26th, 2012, 1:20 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 59 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: November 20th, 2008, 10:42 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
Thx, Chronos for that script.

toc's up to date.

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 3:31 am 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Layered Taskbar and StartMenu

Screenshot and blabla: http://thesmurth.deviantart.com/art/Layered-Taskbar-and-StartMenu-104058008

includes:
readini.ahk
gdip.ahk

SMU-Man.exe:
Code:
#NoEnv
#KeyHistory 0
#SingleInstance force
SetWorkingDir %A_ScriptDir%
SetBatchLines,-1
OnExit, Quit

   inifile = %1%

   ReadIni(inifile)

   Menu, Tray, NoStandard
   Menu, Tray, Add, %DlgAutoStart%, AutoStart
   Menu, Tray, Add, %DlgQuit%, Quit
   ; Menu, Tray, Icon, icon.ico, , 1
   Menu, Tray, Tip, SMU-D Manager
   RegRead,   AutoStart, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, SMUDaemon
   if AutoStart
      Menu, Tray,Check, %DlgAutoStart%

   pToken := Gdip_Startup()

   TaskbarCreate()
   TaskbarReDraw()

   SetTimer, Main, 100

Return



Main:

   WinSet, Bottom,, ahk_id %TaskbarBgID%
   WinA := WinExist("A")
   if (WinA = WinAl )
      Return
   if (WinA = StartMenuID )
      StartMenuReDraw()
   ifWinNotExist, Ahk_id %TaskbarID%
   {
      TaskbarCreate()
      TaskbarReDraw()
   }

   WinAl := WinA

Return



TaskbarCreate()
{
Global TaskbarID
   , TaskbarBgID
   , StartMenuID
   , StartMenuBgID


   Gui, 1: Destroy
   Gui, 2: Destroy
   WinWait, ahk_class Shell_TrayWnd
   WinGet, TaskbarID, ID
   Gui, 1: -Caption +LastFound +ToolWindow +E0x80020
   TaskbarBgID := WinExist()
   Gui, 1: Show, NA
   ; DllCall("SetParent", "uint", TaskbarBgID, "uint", WinExist("ahk_class Progman") )
   
   Gui, 2: -Caption +LastFound +ToolWindow +E0x80020 +AlwaysOnTop
   StartMenuBgID := WinExist()
   DetectHiddenWindows, On
   StartMenuID := WinExist("ahk_class DV2ControlHost")
   DetectHiddenWindows, Off
   ; Control, %TaskbarQuickLaunch%,, ToolbarWindow323, ahk_class Shell_TrayWnd
   ; Control, %TaskbarTasks%,, ReBarWindow321, ahk_class Shell_TrayWnd
   ; Control, %TaskbarClock%,, TrayClockWClass1, ahk_class Shell_TrayWnd
   ; Control, %TaskbarStartButton%,, Button1, ahk_class Shell_TrayWnd

}



TaskbarReDraw()
{
Global TaskbarID
   , TaskbarBgID
   , TaskbarTransColor
   , TaskbarBack
   , TaskbarFront
   , TaskbarStyle
   , TaskbarBorder
   , TaskbarBlur


   WinGetPos, x, y, w, h, ahk_id %TaskbarID%
   WinSet, Transcolor, %TaskbarTransColor%, ahk_id %TaskbarID%

   hbm := CreateDIBSection(w, h)
   hdc := CreateCompatibleDC()
   obm := SelectObject(hdc, hbm)
   G := Gdip_GraphicsFromHDC(hdc)

   if TaskbarBlur {
      pBitmap := Gdip_BitmapFromScreen(x . "|" . y . "|" . w . "|" . h+TaskbarBlur )
      Gdip_BlurBitmap(pBitmap, TaskbarBlur)
      Gdip_DrawImage(G, pBitmap, 0, 0, w, h, 0, 0, w, h)
   }
   pBrush := Gdip_BrushCreateHatch(TaskbarFront, TaskbarBack, TaskbarStyle)
   Gdip_FillRectangle(G, pBrush, 0, 0, w, h)
   Gdip_DeleteBrush(pBrush)
   if TaskbarBorder {

      if y
         y2 := 0
      else
         y2 := h-1

      pPen := Gdip_CreatePen( TaskbarBorder, 0 )
      Gdip_DrawRectangle( G, pPen, 0, y2, w, 1)
      Gdip_DeletePen(pPen)
   }

   UpdateLayeredWindow(TaskbarBgID, hdc, 0, y, w, h)

   SelectObject(hdc, obm)
   DeleteObject(hbm)
   DeleteDC(hdc)
   Gdip_DeleteGraphics(G)
   Gdip_DisposeImage(pBitmap)

}



StartMenuReDraw()
{
Global StartMenuID
   , StartMenuBgID
   , StartMenuTransColor
   , StartMenuBack1
   , StartMenuBack2
   , StartMenuFront1
   , StartMenuFront2
   , StartMenuStyle1
   , StartMenuStyle2
   , StartMenuBorder1
   , StartMenuBorder1Sick
   , StartMenuBorder2
   , StartMenuBorder2Sick
   , StartMenuBorder2Radius
   , StartMenuBlur
   , StartMenuPane
   , StartMenuTransColor

   WinSet, Transcolor, %StartMenuTransColor%, ahk_id %StartMenuID%

   WinGetPos, x, y, w, h, ahk_id %StartMenuID%
   hbm := CreateDIBSection(w, h)
   hdc := CreateCompatibleDC()
   obm := SelectObject(hdc, hbm)
   G := Gdip_GraphicsFromHDC(hdc)
   Gdip_SetSmoothingMode(G, 4)

   if StartMenuBlur {
      pBitmap := Gdip_BitmapFromScreen(x . "|" . y . "|" . w . "|" . h)
      Gdip_BlurBitmap(pBitmap, StartMenuBlur)
      Gdip_DrawImage(G, pBitmap, 0, 0, w, h, 0, 0, w, h)
   }
   pBrush := Gdip_BrushCreateHatch( StartMenuFront1, StartMenuBack1, StartMenuStyle1)
   Gdip_FillRectangle(G, pBrush, 0, 0, w, h)
   Gdip_DeleteBrush(pBrush)

   if StartMenuBorder1 {
      pPen := Gdip_CreatePen( StartMenuBorder1, StartMenuBorder1Sick )
      Gdip_DrawRectangle( G, pPen, 0, 0, w-1, h-1)
      Gdip_DeletePen(pPen)
   }

   StringSplit, s, StartMenuPane, `,
   s3 := w-s3-s1
   s4 := h-s4-s2
   r := StartMenuBorder2Radius

   Gdip_DrawImage(G, pBitmap, s1+r/4, s2+r/4, s3-r/2, s4-r/2, s1+r/4, s2+r/4, s3-r/2, s4-r/2)
   pBrush := Gdip_BrushCreateHatch( StartMenuFront2, StartMenuBack2, StartMenuStyle2)
   Gdip_FillRoundedRectangle(G, pBrush, s1, s2, s3, s4, r)
   Gdip_DeleteBrush(pBrush)
   if StartMenuBorder2 {
      pPen := Gdip_CreatePen( StartMenuBorder2, StartMenuBorder2Sick )
      Gdip_DrawRoundedRectangle( G, pPen, s1, s2, s3, s4, StartMenuBorder2Radius)
      Gdip_DeletePen(pPen)
   }
   UpdateLayeredWindow(StartMenuBgID, hdc, x, y, w, h)
   Gui, 2: Show, X%x% Y%y% W%w% H%h% NoActivate
   SelectObject(hdc, obm)
   DeleteObject(hbm)
   DeleteDC(hdc)
   Gdip_DeleteGraphics(G)
   Gdip_DisposeImage(pBitmap)
   WinWaitClose, ahk_id %StartMenuID%
   Gui, 2: Hide

}



Quit:

   Gdip_Shutdown(pToken)
   DetectHiddenWindows, On
   WinSet, Transcolor, Off, ahk_class Shell_TrayWnd
   WinSet, Transparent, Off, ahk_class Shell_TrayWnd
   WinSet, Transcolor, Off, ahk_class DV2ControlHost
   WinSet, Transparent, Off, ahk_class DV2ControlHost
   ExitApp

Return



AutoStart:

   Menu, Tray, ToggleCheck, %DlgAutoStart%
   if AutoStart {
      AutoStart :=
      RegDelete, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, SMUDaemon
   }
   else {
      AutoStart := true
      RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Run, SMUDaemon, "%A_ScriptFullPath%"
   }

Return




#Include, %A_ScriptDir%\Gdip.ahk
#Include, %A_ScriptDir%\readini.ahk





^#R::

   ReadIni(inifile)
   TaskbarRedraw()

Return


SMU-Man.ini:
Code:
[Taskbar]
TransColor=454647 144
Back=0x80000000
Front=0x80000000
Style=19
Border=0x80202020
Blur=4

[StartMenu]
TransColor=454647 192
Pane=4,5,5,36
Back1=0xF0000000
Front1=0xF0202020
Style1=2
Back2=0xA0202020
Front2=0x80000000
Style2=2
Border1=0x80000000
Border1Sick=2
Border2=0xC0202020
Border2Sick=2
Border2Radius=3
Blur=6

[Dlg]
AutoStart=Start with Windows
Quit=Quit


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 6:07 am 
Offline

Joined: April 18th, 2008, 7:57 am
Posts: 1390
Location: The Interwebs
Smurth wrote:
Layered Taskbar and StartMenu


Impressive. I would definitely use it if I wasn't using ObjectDock to replace the task bar.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 24th, 2008, 6:56 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Krogdor wrote:
Impressive. I would definitely use it if I wasn't using ObjectDock to replace the task bar.


Not so impressive, in fact. It works (most of the time) but it's tricky; very tricky.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 30th, 2008, 11:43 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
Layered GDIP usage without GUI commands

below is a lil example based on my clock code, which generates its own GUI and registers therefor a new window class named GDIP_canvas (can be seen with window spy). since i found the use of GUI commands to add a GDIP layer quite confusing this solution was only the next logical step

The neccessary functions are at the bottom of the code - the initialisation has to be modified a little bit to match the needs of GDIP init.

Image

Code:
; gdi+ ahk analogue clock example written by derRaphael

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

If !(pToken := Gdip_Startup()) {
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
} else {
   GDIP_RegisterClass()
   hwnd1 := GDIP_CreateWindow()
}
OnExit, Exit

SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop

ClockDiameter := 180
Width := Height := ClockDiameter + 2         ; make width and height slightly bigger to avoid cut away edges
CenterX := CenterY := floor(ClockDiameter/2) ; Center x

cBaseColor := "ff8000"  ; Hex of our Clock's Color
cSecHColor := "800000"  ; Hex of Second Hand
cPassColor := "00ff00"  ; Hex of Pie's passed Color

; Dont change unless u know what u're doin ;)
cAlpha_0   := "0xff", cAlpha_1   := "0xc0", cAlpha_2   := "0x66"
cAlpha_3   := "0x80", cAlpha_4   := "0xa0"

; Prepare our pGraphic so we have a 'canvas' to work upon
   hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC()
   obm := SelectObject(hdc, hbm), G := Gdip_GraphicsFromHDC(hdc)
   Gdip_SetSmoothingMode(G, 4)

; Draw outer circle
   Gdip_SetCompositingMode(G, 0)             ; switch off overdraw
   Diameter := ClockDiameter
   pBrush := Gdip_BrushCreateSolid(cAlpha_2 cBaseColor)
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)

; Draw inner circle
   Diameter := ceil(ClockDiameter - ClockDiameter*0.08)  ; inner circle is 8 % smaller than clock's diameter
   pBrush := Gdip_BrushCreateSolid(cAlpha_3 cBaseColor)
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)
   
   ; The OnMessage will let us drag the clock
   OnMessage(0x201, "WM_LBUTTONDOWN")
   UpdateLayeredWindow(hwnd1, hdc, WALeft+((WAWidth-Width)//2), WATop+((WAHeight-Height)//2), Width, Height)
   SetTimer, sec, 1000

sec:
; prepare to empty previously drawn stuff
   Gdip_SetSmoothingMode(G, 1)   ; turn off aliasing
   Gdip_SetCompositingMode(G, 1) ; set to overdraw
   
; delete previous graphic and redraw background
   Diameter := ceil(ClockDiameter - ClockDiameter*0.08)  ; inner circle is 8 % smaller than clock's diameter

;~    Diameter := ceil(ClockDiameter - ClockDiameter*0.18)  ; 18 % less than clock's outer diameter
   tDiameter := ceil(ClockDiameter*0.04)
   
   ; delete whatever has been drawn here
   pBrush := Gdip_BrushCreateSolid(0x00000000) ; fully transparent brush 'eraser'
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)
   
   Gdip_SetCompositingMode(G, 0) ; switch off overdraw
   pBrush := Gdip_BrushCreateSolid(cAlpha_2 cBaseColor)
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)
   pBrush := Gdip_BrushCreateSolid(cAlpha_3 cBaseColor)
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)
   
; If Pie Draw one
   Gdip_SetSmoothingMode(G, 4)   ; turn on antialiasing
   
; Draw HoursHand
   t := A_Hour*360//12 + (A_Min*360//60)//12 +90
   R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.5) ; outer position
   R2 := ClockDiameter//2-ceil((ClockDiameter//2)*0.90) ; inner position
   pPen := Gdip_CreatePen(cAlpha_4 cBaseColor, floor((ClockDiameter/100)*3.5))
   Gdip_DrawLine(G, pPen
      , ceil(CenterX - (R2 * Cos(t * Atan(1) * 4 / 180)))
      , ceil(CenterY - (R2 * Sin(t * Atan(1) * 4 / 180)))
      , ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
      , ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
   Gdip_DeletePen(pPen)
   
; Draw MinutesHand
   t := A_Min*360//60+90
   R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.25) ; outer position
   R2 := ClockDiameter//2-ceil((ClockDiameter//2)*0.92) ; inner position
   pPen := Gdip_CreatePen(cAlpha_4 cBaseColor, floor((ClockDiameter/100)*2.7))
   Gdip_DrawLine(G, pPen
      , ceil(CenterX - (R2 * Cos(t * Atan(1) * 4 / 180)))
      , ceil(CenterY - (R2 * Sin(t * Atan(1) * 4 / 180)))
      , ceil(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
      , ceil(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
   Gdip_DeletePen(pPen)

; Draw SecondsHand
   t := A_Sec*360//60+90
   R1 := ClockDiameter//2-ceil((ClockDiameter//2)*0.2) ; outer position
   pPen := Gdip_CreatePen(cAlpha_4 cSecHColor, floor((ClockDiameter/100)*1.2))
   Gdip_DrawLine(G, pPen, CenterX, CenterY
      , round(CenterX - (R1 * Cos(t * Atan(1) * 4 / 180)))
      , round(CenterY - (R1 * Sin(t * Atan(1) * 4 / 180))))
   Gdip_DeletePen(pPen)
   
   pBrush := Gdip_BrushCreateSolid(cAlpha_4 cSecHColor)
   Gdip_FillEllipse(G, pBrush, CenterX-(tDiameter//2), CenterY-(tDiameter//2),tDiameter, tDiameter)
   Gdip_DeleteBrush(pBrush)
   
   Gosub, DrawClockMarks2 ; do the funky seconds mark thingy
   
   UpdateLayeredWindow(hwnd1, hdc) ;, xPos, yPos, ClockDiameter, ClockDiameter)
return

DrawClockMarks:
   Loop, % Items
         Gdip_DrawLine(G, pPen
            , CenterX - ceil(R1 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
            , CenterY - ceil(R1 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
            , CenterX - ceil(R2 * Cos(((a_index-1)*360//Items) * Atan(1) * 4 / 180))
            , CenterY - ceil(R2 * Sin(((a_index-1)*360//Items) * Atan(1) * 4 / 180)) )
return

DrawClockMarks2:
   R1 := Diameter//2-1-ceil(Diameter//2*0.01) ; outer position
   R2 := Diameter//2-1-ceil(Diameter//2*0.05) ; inner position
   
   loop, 10 ; create neccessary pens for this (customizing alpha)
      pen%A_Index%  := Gdip_CreatePen( (0x19 cBaseColor)+(a_index-1)*0x19000000, floor((ClockDiameter/100)*1.2))
   
   Loop, 10 ; draw 10 passed seconds
      n := 10 - a_index, Gdip_DrawLine(G, pen%n%
            , CenterX - ceil(R1 * Cos((((a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterY - ceil(R1 * Sin((((a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterX - ceil(R2 * Cos((((a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterY - ceil(R2 * Sin((((a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180)) )
   Loop, 10 ; draw 10 next seconds
      Gdip_DrawLine(G, pen%A_index%
            , CenterX - ceil(R1 * Cos((((51+a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterY - ceil(R1 * Sin((((51+a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterX - ceil(R2 * Cos((((51+a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180))
            , CenterY - ceil(R2 * Sin((((51+a_sec+a_index-1)*360//60)+90) * Atan(1) * 4 / 180)) )

   Loop,10 ; delete pens
      Gdip_DeletePen(pen%A_Index%)
   
   ; redraw hour marks
   R1 := Diameter//2-1                       ; outer position
   R2 := Diameter//2-1-ceil(Diameter//2*0.1) ; inner position
   Items := 12                               ; we have 12 hours
   pPen := Gdip_CreatePen(cAlpha_1 cBaseColor, ceil((ClockDiameter//100)*2.3)) ; 2.3 % of total diameter is our pen width
   GoSub, DrawClockMarks
   Gdip_DeletePen(pPen)

return

WM_LBUTTONDOWN() {
   PostMessage, 0xA1, 2
   return
}

esc::
Exit:
   SelectObject(hdc, obm)
   DeleteObject(hbm)
   DeleteDC(hdc)
   Gdip_DeleteGraphics(G)
   Gdip_Shutdown(pToken)
   ExitApp
Return

^r::reload

; additional GDIP functions, to register a new GDIP Canvas class
; and work on a GUI which is NOT created by Gui* Commands
; initially written by derRaphael for tic's gdip library on nov 30, 2008
; licensed under the terms of gdip.ahk's license

; Inspiration to this came from this thread:
;    majkinetor's [tutorial] Creating windows without GUI commands
;    http://www.autohotkey.com/forum/viewtopic.php?t=22904

GDIP_CreateWindow(lpWindowName="dR's GDIP Canvas") {
   return DllCall("CreateWindowEx" ; This function actually creates the window and returns its hWnd
      , "uInt",dwExStyle:=0x80088, "Str", lpClassName:="GDIP_Canvas"
     , "Str", lpWindowName, "uInt", dwStyle:=0x940A0000
      , "Int", x, "Int", y, "Int", nWidth, "Int", nHeight, "uInt", hWndParent
      , "uInt",hMenu, "uInt", hInstance, "uInt", lpParam)
}

GDIP_RegisterClass(){ ; needs to be called only once, so it can register the class
   cName := "GDIP_Canvas", WndProc := RegisterCallback("GDIP_WndProc", "F")
   VarSetCapacity(WndClass, 40, 0)
   NumPut(WndProc, WndClass, 4) ; style / lpfnWndProc
   ; If below is NOT specified, the app must take care of assigning proper IDC_* Cursors
   ; the provoded method assigns standard cursor for the window
   NumPut((hCursor := DllCall( "LoadCursor", "Uint",0, "Int", IDC_ARROW:=32512 )), WndClass , 24)
   NumPut(&cName, WndClass, 36) ; lpszClassName
   return DllCall("RegisterClass", "uint", &WndClass )
}

/*
; Additional WndClass - http://msdn.microsoft.com/en-us/library/ms633576(VS.85).aspx
   NumPut(0, WndClass, 0)   ; style see http://msdn.microsoft.com/en-us/library/ms633574(VS.85).aspx
   NumPut(0, WndClass, 8)   ; cbClsExtra
   NumPut(0, WndClass, 12)  ; cbWndExtra
   NumPut(0, WndClass, 16)  ; hInstance
   NumPut(0, WndClass, 20)  ; hIcon
   NumPut(0, WndClass, 28)  ; hbrBackground (brush background)
   NumPut(0, WndClass, 32)  ; lpszMenuName
*/

; The callback for our new registered class
GDIP_WndProc(hwnd, uMsg, wParam, lParam) { ; This one can handle additional WndMsgs
   if (uMsg=0x111) {
      DllCall("DestroyWindow", "uint", hwnd)
   }
   return, DllCall("DefWindowProc", "uint", hwnd, "uint", umsg, "uint", wParam, "uint", lParam)
}



greets
dR

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2008, 10:22 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
DerRaphael wrote:
Layered GDIP usage without GUI commands

below is a lil example based on my clock code, which generates its own GUI and registers therefor a new window class named GDIP_canvas (can be seen with window spy)


Interesting; but, appart from overriding the 99 GUIs limit and allowing custom window classes, what are the real pro of this method ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2008, 10:58 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
this is a prep of showing how to use standard gui elements onto a layered window ... and by using this method, ppl wont get confused by having to handle multiple GUIs, but can focus on GDIP and on the GUI elements with standard GUI commands :)

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 1st, 2008, 11:24 pm 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Do you know how to do the same as "GuiDropFiles" ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 12:59 am 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
ahk_class GDIP_Canvas Drag'n'Drop Example

The code below shows the new introduced GDIP Variables, including Event's Coordinates, ItemCount and of course the FileNames.

Code:
; GDIP Class Drag n Drop Event
GDIPDropFiles:
   MsgBox % "GDIP_GuiEvent:`n" GDIP_GuiEvent "`n`n" ; The FileNames
         . "GDIP_GuiX: " GDIP_GuiX " / "           ; X Coordinate
         . "GDIP_GuiY: " GDIP_GuiY " / "           ; Y Coordinate
         . "GDIP_EventInfo: " GDIP_EventInfo       ; ItemCount
return


The code below is a fully working example showing how to use the above mentions new Global available variables - It uses a new modified GDIP_WndProc Callback function to pollute the new Global Variables.

Code:
; gdi+ ahk Drag n Drop w/ GDIP class example written by derRaphael

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

If !(pToken := Gdip_Startup()) {
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
} else {
   GDIP_RegisterClass()
   hwnd1 := GDIP_CreateWindow()
}
OnExit, Exit

SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop

Diameter := 80
Width := Height := Diameter + 2         ; make width and height slightly bigger to avoid cut away edges
CenterX := CenterY := floor(Diameter/2) ; Center x

; Dont change unless u know what u're doin ;)
   hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC()
   obm := SelectObject(hdc, hbm), G := Gdip_GraphicsFromHDC(hdc)
   Gdip_SetSmoothingMode(G, 4)
   pBrush := Gdip_BrushCreateSolid(0x660000ff)
   Gdip_FillEllipse(G, pBrush, CenterX-(Diameter//2), CenterY-(Diameter//2),Diameter, Diameter)
   Gdip_DeleteBrush(pBrush)
   nD := Diameter - 10
   pPen := Gdip_CreatePen(0xffff0000, 2)
   Loop, 3
      nD -= 20, Gdip_DrawEllipse(G, pPen, CenterX-(nD//2), CenterY-(nD//2),nD, nD)
   Gdip_DeletePen(pPen)
   

   OnMessage(0x201, "WM_LBUTTONDOWN")
   UpdateLayeredWindow(hwnd1, hdc, WALeft+((WAWidth-Width)//2), WATop+((WAHeight-Height)//2), Width, Height)
return

; GDIP Class Drag n Drop Event
GDIPDropFiles:
   MsgBox % "GDIP_GuiEvent:`n" GDIP_GuiEvent "`n`n" ; The FileNames
         . "GDIP_GuiX: " GDIP_GuiX " / "           ; X Coordinate
         . "GDIP_GuiY: " GDIP_GuiY " / "           ; Y Coordinate
         . "GDIP_EventInfo: " GDIP_EventInfo       ; ItemCount
return

esc::
Exit:
   SelectObject(hdc, obm)
   DeleteObject(hbm)
   DeleteDC(hdc)
   Gdip_DeleteGraphics(G)
   Gdip_Shutdown(pToken)
   ExitApp
Return

^r::reload

WM_LBUTTONDOWN() {
   PostMessage, 0xA1, 2
   return
}

; additional GDIP functions, to register a new GDIP Canvas class
; and work on a GUI which is NOT created by Gui* Commands
; initially written by derRaphael for tic's gdip library on nov 30, 2008
; licensed under the terms of gdip.ahk's license

; Inspiration to this came from this thread:
;    majkinetor's [tutorial] Creating windows without GUI commands
;    http://www.autohotkey.com/forum/viewtopic.php?t=22904

GDIP_CreateWindow(lpWindowName="dR's GDIP Canvas") {
   hwnd := DllCall("CreateWindowEx" ; This function actually creates the window and returns its hWnd
      , "uInt",dwExStyle:=0x80088, "Str", lpClassName:="GDIP_Canvas"
     , "Str", lpWindowName, "uInt", dwStyle:=0x940A0000
      , "Int", x, "Int", y, "Int", nWidth, "Int", nHeight, "uInt", hWndParent
      , "uInt",hMenu, "uInt", hInstance, "uInt", lpParam)
   DllCall("shell32.dll\DragAcceptFiles","uInt",hWnd,"uInt",True) ; Make the new Class Drag'n'Drop Capable
   return hwnd
}

GDIP_RegisterClass(){ ; needs to be called only once, so it can register the class
   cName := "GDIP_Canvas", WndProc := RegisterCallback("GDIP_WndProc", "F")
   VarSetCapacity(WndClass, 40, 0)
   NumPut(WndProc, WndClass, 4) ; style / lpfnWndProc
   ; If below is NOT specified, the app must take care of assigning proper IDC_* Cursors
   ; the provoded method assigns standard cursor for the window
   NumPut((hCursor := DllCall( "LoadCursor", "Uint",0, "Int", IDC_ARROW:=32512 )), WndClass , 24)
   NumPut(&cName, WndClass, 36) ; lpszClassName
   return DllCall("RegisterClass", "uint", &WndClass )
}

; The callback for our new registered class
GDIP_WndProc(hwnd, uMsg, wParam, lParam) { ; This one can handle additional WndMsgs
   if (uMsg=0x111) {
      DllCall("DestroyWindow", "uint", hwnd)
   }
   if (uMsg=0x233) { ; Drag n Drop event occured!
      Global GDIP_EventInfo := "", GDIP_GuiX := "", GDIP_GuiY := "" , GDIP_GuiEvent := ""
      ; Get FileNameStruct (maxpath is 4k)
      Loop,% GDIP_EventInfo := DllCall("shell32.dll\DragQueryFile","uInt",wParam,"uInt",0xFFFFFFFF,"uInt",0,"uInt",0)
      {
         VarSetCapacity(lpSzFile,4096,0)
         r := DllCall("shell32.dll\DragQueryFile","uInt",wParam,"uInt",A_index-1,"uInt",&lpSzFile,"uInt",4096)
         VarSetCapacity(lpSzFile,-1)
         GDIP_GuiEvent .= ((A_Index>1) ? "`n" : "") lpSzFile
      }
      ; Get Coordinates
      VarSetCapacity(lppt,8,0)
      DllCall("shell32.dll\DragQueryPoint","uInt",wParam,"uInt",&lppt)
      GDIP_GuiX := NumGet(lppt,0,"int"), GDIP_GuiY := NumGet(lppt,4,"int")
      ; Release Memory occupied from hDrop (wParam)
      DllCall("shell32.dll\DragFinish","uInt",wParam)
      ; If in Script: JumpThere
      If (IsLabel(Label := "GDIPDropFiles"))
         GoSub, % Label
      else If (IsLabel(Label := "GuiDropFiles"))
         GoSub, % Label
   }
   return, DllCall("DefWindowProc", "uint", hwnd, "uint", umsg, "uint", wParam, "uint", lParam)
}



dR

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 1:45 am 
Offline

Joined: December 13th, 2006, 7:10 am
Posts: 118
Very impressive :shock:
In fact, I really have no other word to say :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 1:48 am 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
ty :D

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 2nd, 2008, 12:52 pm 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
Hi Raph

I'm hope I dont come off as argumentative, but I still dont see the need for doing it this way. I think the same example looks cleaner just using standard gui commands:

Code:
#SingleInstance, Force
#NoEnv
SetBatchLines, -1

; Uncomment if Gdip.ahk is not in your standard library
;#Include, Gdip.ahk

If !(pToken := Gdip_Startup())
{
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop

Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs
Gui, 1: Show, NA
hwnd1 := WinExist()

Width := Height := WAWidth//20

hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm), G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetSmoothingMode(G, 4)

pBrush := Gdip_BrushCreateSolid(0x660000ff), pPen := Gdip_CreatePen(0xffff0000, 2)
Gdip_FillEllipse(G, pBrush, 0, 0, Width, Height)

j = 0.11|0.24|0.36
Loop, Parse, j, |
Gdip_DrawEllipse(G, pPen, A_LoopField*Width, A_LoopField*Height, Width-(2*A_LoopField*Height), Height-(2*A_LoopField*Height))

UpdateLayeredWindow(hwnd1, hdc, WALeft+((WAWidth-Width)//2), WATop+((WAHeight-Height)//2), Width, Height)

Gdip_DeleteBrush(pBrush), Gdip_DeletePen(pPen)
SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc), Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
Return

GuiDropFiles:
Gui, 1: +OwnDialogs
MsgBox, %A_GuiEvent%
Return


Please let me know if theres something Ive overlooked though


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 6th, 2008, 3:11 pm 
Offline

Joined: August 24th, 2005, 5:29 pm
Posts: 549
Location: Berlin / Germany
Coloured Buttons with GDI+

Image:

Image

Code:
Code:
#NoEnv

; Bitte auskommentieren, wenn sich Gdip.ahk im Standardverzeichnis befindet
#Include, Gdip.ahk

Gui, Margin, 50, 20
Gui, Color, 608080
Gui, Font, s8, Arial
CreateButtonImage("SetDefault", "FN", "Arial")
Gui, Add, Button, w100, s8!
Gui, Add, Button, y+10 w100 hwndBT1ID, s8!
hbmBT1 := CreateButtonImage(BT1ID, "00FF00", "000000", "", "", 1)
Gui, Font, s10
Gui, Add, Button, y+10 w100 h40 hwndBT2ID, s10!
hbmBT2 := CreateButtonImage(BT2ID, "D0E000", "800000", 10, "", 1)
Gui, Font, s12
Gui, Add, Button, y+10 w100 h71 hwndBT3ID, s12!
hbmBT3 := CreateButtonImage(BT3ID, "FF0000", "00FFFF", 12, "", 1)
Gui, Font, s48, Trebuchet MS
Gui, Add, Button, y+10 hwndBT4ID, S48 AUTOSIZE!
hbmBT4 := CreateButtonImage(BT4ID, "C0C0C0", "FF0000", 48, "Trebuchet MS", 2, 1)
Gui, Show, , Farbige Buttons
Msg := "Der Standardfont ist:`n`n`" CreateButtonImage("GetDefault", "FN")
MsgBox, 0, Farbige Buttons, %MSG%, 1
Return
;-------------------------------------------------------------------------------
GuiClose:
GuiEscape:
DllCall("DeleteObject", "UInt", hbmBT1)
DllCall("DeleteObject", "UInt", hbmBT2)
DllCall("DeleteObject", "UInt", hbmBT3)
DllCall("DeleteObject", "UInt", hbmBT4)
ExitApp
; ------------------------------------------------------------------------------
; ##############################################################################
; ------------------------------------------------------------------------------
CreateButtonImage(HWND
                , CB
                , CT = ""
                , FS = ""
                , FN = ""
                , 3D = ""
                , GC = "") {
   ; ---------------------------------------------------------------------------
   ; HWND   : HWND des Buttons
   ; CB     : Hintergrundfarbe (RGB: 6-stelliger Hexwert: RRGGBB )
   ; CT     : Textfarbe (RGB: 6-stelliger Hexwert: RRGGBB )
   ; FS     : Schriftgröße
   ; FN     : Zeichensatzname
   ; 3D     : 3D-Effekte (0 = ohne, 1 = erhaben, 2 = 3D)
   ; GC     : Gammakorrektur (0 = Nein, 1 = Ja)
   ; ---------------------------------------------------------------------------
   ; Für die meisten GDI+ Aufrufe wird das Skript GDIP.AHK von tic benötigt
   ; --> http://www.autohotkey.com/forum/post-198949.html
   ; Ohne dieses Skript gäbe es das hier nicht!!!
   ; Ergänzungen sind durch vorangestellte Kommentare und die Einleitung
   ; GpStatus WINGDIPAPI ...
   ; gekennzeichnet.
   ; ---------------------------------------------------------------------------
   ; Buttonkonstanten
   Static BS_BITMAP := 0x80
   Static BM_SETIMAGE := 0xF7
   Static IMAGE_BITMAP := 0x0
   ; Standardwerte für Parameter
   Static SETDEFAULT := "SetDefault"
   Static GETDEFAULT := "GetDefault"
   Static DEFAULTS := "FS,FN,CT,3D,GC"
   Static DEFFS := 8
   Static DEFFN := "Microsoft Sans Serif"
   Static DEFCT := 0x000000
   Static DEF3D := 0
   Static DEFGC := 1
   ; ---------------------------------------------------------------------------
   ; Standardwerte setzen?
   If (HWND = SETDEFAULT) {
      If InStr(DEFAULTS, CB) {
         DEF%CB% := CT
         Return True
      } Else {
         Return False
      }
   }
   ; ---------------------------------------------------------------------------
   ; Standardwerte ausgeben?
   If (HWND = GETDEFAULT) {
      If InStr(DEFAULTS, CB) {
         Return DEF%CB%
      } Else {
         Return "ERROR"
      }
   }
   ; ---------------------------------------------------------------------------
   ; Ggf. Standardparameterwerte setzen
   If (CT = "") {
      CT := DEFCT
   }
   If (FS = "") {
      FS := DEFFS
   }
   If (FN = "") {
      FN := DEFFN
   }
   If (3D = "") {
      3D := DEF3D
   }
   If (GC = "") {
      GC := DEFGC
   }
   ; ---------------------------------------------------------------------------
   ; Prüfen, ob GDIPlus verfügbar ist
   If (!pToken := Gdip_Startup()) {
      MsgBox, 48, GDIplus Fehler!
            , % "GDIplus konnte nicht gestartet werden!`n"
            . "Überprüfen Sie, ob GDIPlus auf Ihrem System vorhanden ist!"
      Return 0
   }
   ; ---------------------------------------------------------------------------
   ; Jetzt wird geprüft, ob der übergebene Font vorhanden ist
   If !(hFamily := Gdip_FontFamilyCreate(FN)) {
      MsgBox, 48, Font Fehler!
            , Der übergebene Font ist auf diesem System nicht vorhanden!
      Gdip_Shutdown(pToken)
      Return 0
   }
   ; ---------------------------------------------------------------------------
   ; Voreinstellung der Anzeige-DPI ermitteln
   ; Geklaut von http://www.autohotkey.com/forum/post-198727.html
   hDC := DllCall("GetDC")
   DPI := DllCall("GetDeviceCaps"
                , "UInt", hDC
                , "Int", 88)
   DllCall("ReleaseDC"
         , "Int", 0
         , "UInt", hDC)
   ; ---------------------------------------------------------------------------
   ; Clientbereich des Buttons ermitteln
   VarSetCapacity(RECT, 16, 0)
   DllCall("GetClientRect"
         , "UInt", HWND
         , "UInt", &RECT)
   W := NumGet(RECT, 8)
   H := NumGet(RECT, 12)
   ; ---------------------------------------------------------------------------
   ; Buttontext holen
   VarSetCapacity(TX, 255, 0)
   DllCall("GetWindowText"
         , "UInt", HWND
         , "Str", TX
         , "Int", 255)
   VarSetCapacity(TX, -1)
   ; ---------------------------------------------------------------------------
   ; GDI+ Bitmap erzeugen
   pBitmap := Gdip_CreateBitmap(W , H)
   ; ---------------------------------------------------------------------------
   ; Zeiger auf das zugehörige Grafikobjekt erzeugen
   pGraphics := Gdip_GraphicsFromImage(pBitmap)
   ; ---------------------------------------------------------------------------
   ; Kantenglättung auf Antializing = 4 setzen
   Gdip_SetSmoothingMode(pGraphics, 4)
   ; ---------------------------------------------------------------------------
   ; Buttonrechteck mit einem Verlauf füllen
   ; ---------------------------------------------------------------------------
   ; POINT Struktur für den Start füllen
   VarSetCapacity(Point1, 8, 0)
   NumPut(0, Point1, 0, "Float")
   NumPut(0, Point1, 4, "Float")
   ; ---------------------------------------------------------------------------
   ; POINT Struktur für das Ende füllen
   VarSetCapacity(Point2, 8, 0)
   NumPut(0, Point2, 0, "Float")
   NumPut(H, Point2, 4, "Float")
   ; ---------------------------------------------------------------------------
   ; Startfarbe: Schwarz
   Color1 := "0xFF000000"
   ; ---------------------------------------------------------------------------
   ; Endfarbe: Hintergrundfarbe
   Color2 := "0xFF" CB
   ; ---------------------------------------------------------------------------
   ; "linear gradient" Pinsel erstellen
   ; GpStatus WINGDIPAPI GdipCreateLineBrush(GDIPCONST GpPointF* point1
   ;                                       , GDIPCONST GpPointF* point2
   ;                                       , ARGB color1
   ;                                       , ARGB color2
   ;                                       , GpWrapMode wrapMode
   ;                                       , GpLineGradient **lineGradient)
   DllCall("gdiplus\GdipCreateLineBrush"
         , "UInt", &Point1
         , "UInt", &Point2
         , "Int", Color1
         , "Int", Color2
         , "Int", 0
         , "UInt*", pBrush)
   ; ---------------------------------------------------------------------------
   ; Array für relative Intensität versorgen
   VarSetCapacity(RELINT, 20, 0)
   I1 := (3D = 0 ? 1.0 : 3D = 1 ? 0.1 : 0.0)
   I2 := (3D = 0 ? 1.0 : 3D = 1 ? 1.0 : 0.4)
   I3 := (3D = 0 ? 1.0 : 3D = 1 ? 1.0 : 1.0)
   I4 := (3D = 0 ? 1.0 : 3D = 1 ? 1.0 : 0.4)
   I5 := (3D = 0 ? 1.0 : 3D = 1 ? 0.1 : 0.0)
   NumPut(I1, RELINT, 0, "Float")
   NumPut(I2, RELINT, 4, "Float")
   NumPut(I3, RELINT, 8, "Float")
   NumPut(I4, RELINT, 12, "Float")
   NumPut(I5, RELINT, 16, "Float")
   ; ---------------------------------------------------------------------------
   ; Array für relative Position versorgen
   I2 :=  (H * 0.2) < 6 ? 6 / H : 0.2
   I4 := 1.0 - I2
   VarSetCapacity(RELPOS, 20, 0)
   NumPut(0.0, RELPOS, 0, "Float")
   NumPut(I2, RELPOS, 4, "Float")
   NumPut(0.5, RELPOS, 8, "Float")
   NumPut(I4, RELPOS, 12, "Float")
   NumPut(1.0, RELPOS, 16, "Float")
   ; ---------------------------------------------------------------------------
   ; Überblendregeln setzen
   ; GpStatus WINGDIPAPI GdipSetLineBlend(GpLineGradient *brush
   ;                                    , GDIPCONST REAL *blend
   ;                                    , GDIPCONST REAL* positions
   ;                                    , INT count)
   DllCall("gdiplus\GdipSetLineBlend"
         , "UInt", pBrush
         , "UInt", &RELINT
         , "UInt", &RELPOS
         , "Int", 5)
   ; ---------------------------------------------------------------------------
   ; "gamma correction" setzen
   ; GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient *brush
   ;                                              , BOOL *useGammaCorrection)
   DllCall("gdiplus\GdipSetLineGammaCorrection"
         , "UInt", pBrush
         , "Int", GC)
   ; ---------------------------------------------------------------------------
   ; Buttonrechteck füllen
   Gdip_FillRectangle(pGraphics, pBrush, 0, 0, W, H)
   ; ---------------------------------------------------------------------------
   ; Pinsel wieder freigeben
   Gdip_DeleteBrush(pBrush)
   ; ---------------------------------------------------------------------------
   ; Fontobjekt mit Größe = S und Stil = Normal (0) erzeugen
   hFont := Gdip_FontCreate(hFamily, FS * (DPI/72), 0)
   ; ---------------------------------------------------------------------------
   ; Formatobjekt erzeugen
   hFormat := Gdip_StringFormatCreate(0x4000)
   ; ---------------------------------------------------------------------------
   ; Übergebene Textfarbe setzen
   pBrush := Gdip_BrushCreateSolid("0xFF" CT)
   ; ---------------------------------------------------------------------------
   ; Textausrichtung auf zentriert = 1 setzen
   Gdip_SetStringFormatAlign(hFormat, 1)
   ; ---------------------------------------------------------------------------
   ; Renderqualität auf AntiAliasGridFit = 3 setzen
   Gdip_SetTextRenderingHint(pGraphics, 3)
   ; ---------------------------------------------------------------------------
   ; Rechteck für den Text vorgeben
   CreateRectF(RECT, 0, 0, W, H)
   ; ---------------------------------------------------------------------------
   ; Benötigtes Rechteck für Text vermessen
   TR := Gdip_MeasureString(pGraphics, TX, hFont, hFormat, RECT)
   ; ---------------------------------------------------------------------------
   ; Rechteck für den Text dem Ergebnis der Messung anpassen
   StringSplit, TR, TR, |
   Y := (H / 2) - (TR4 / 2)
   CreateRectF(RECT, 0, Y, W, TR4)
   ; ---------------------------------------------------------------------------
   ; Text zeichnen
   Gdip_DrawString(pGraphics, TX, hFont, hFormat, pBrush, RECT)
   ; ---------------------------------------------------------------------------
   ; HBITMAP Objekt aus der Bitmap erzeugen
   hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap)
   ; ---------------------------------------------------------------------------
   ; Ressourcen freigeben
   ; Die Bitmap kann jetzt gelöscht werden
   Gdip_DisposeImage(pBitmap)
   ; Pinsel wieder freigeben
   Gdip_DeleteBrush(pBrush)
   ; Formatobjekt wieder freigeben
   Gdip_DeleteStringFormat(hFormat)
   ; Fontobjekt wieder freigeben
   Gdip_DeleteFont(hFont)
   ; Fontfamilyobjekt wieder freigeben
   Gdip_DeleteFontFamily(hFamily)
   ; Grafikobjekt wieder freigeben
   Gdip_DeleteGraphics(pGraphics)
   ; GDI+ beenden
   Gdip_Shutdown(pToken)
   ; ---------------------------------------------------------------------------
   ; Und jetzt den Button versorgen:
   WinSet, Style, +%BS_BITMAP%, ahk_id %HWND%
   SendMessage, BM_SETIMAGE, IMAGE_BITMAP, hBitmap, , ahk_id %HWND%
   ; HBITMAP wird zurückgegeben, damit das Objekt später freigegeben werden kann
   Return hBitmap
}

_________________
nick :wink:


Report this post
Top
 Profile  
Reply with quote  
PostPosted: December 6th, 2008, 3:44 pm 
nick wrote:
Coloured Buttons with GDI+

Or if you would like colored buttons (and most other controls like edit,text, checkbox, and radio) with much simpler (and smaller) code see this post by DerRaphael:Colored Controls (no bitmaps needed)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 6th, 2008, 6:05 pm 
Offline

Joined: November 23rd, 2007, 10:23 am
Posts: 841
Location: ~/.
Enhanced Mouseclick visualizer

This one has been written for screen recordings to help better stress which mousebutton was actually pressed. The video below has been recorded with camstudio and converted from avi to gif with super 2007.23

Image

greets
dR

Code:
; released under Terms of EUPL 1.0
; (w) by derRaphael Dec 01, 2008

CoordMode, Mouse, Screen
SetBatchLines,-1

If !(pToken := Gdip_Startup()) {
   MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system
   ExitApp
}

SysGet, MonitorPrimary, MonitorPrimary
SysGet, WA, MonitorWorkArea, %MonitorPrimary%
WAWidth := WARight-WALeft
WAHeight := WABottom-WATop

Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnmDialogs
Gui, 1: Show, NA
mhWnd := WinExist()

mWidth := mHeight := 80
mhbm := CreateDIBSection(mWidth, mHeight), mhdc := CreateCompatibleDC()
mobm := SelectObject(mhdc, mhbm), mG := Gdip_GraphicsFromHDC(mhdc)

Gdip_SetSmoothingMode(mG, 4)

mFadeMax    := 0xff
mDiaMax     := 60
mDiaMin     := 6
mDiaSteps   := 1
mDiameter   := mDiaMin

mAlphaSteps := mFadeMax//((mDiaMax-mDiaMin)/mDiaSteps)
mAlpha      := mFadeMax

return

*~lButton::
   mBaseColor  := 0xff0000
   Gosub, TriggerMouseRing
Return

*~rButton::
   mBaseColor  := 0x00a000
   Gosub, TriggerMouseRing
Return

TriggerMouseRing:
   SetTimer,mouseRing,OFF
   MouseGetPos,MX,MY
   mDiameter := mDiaMin
   mAlpha   := mFadeMax
   SetTimer,mouseRing,7
return

mouseRing:
   mDiameter += mDiaSteps         ; update Diameter
   GoSub, MouseRingErase          ; delete previous drawn ring
   mPen:=Gdip_CreatePen(((mAlpha-=mAlphaSteps)<<24)+mBaseColor, 2)
   Gdip_DrawEllipse(mG, mPen,1, 1,mDiameter-1,mDiameter-1)
   Gdip_DeletePen(mPen)
   UpdateLayeredWindow(mhWnd, mhdc, MX-mDiameter//2, MY-mDiameter//2, mDiameter+5, mDiameter+5)
   if (mDiameter>=mDiaMax) {
      GoSub, MouseRingDestroy
   }
return

mouseRingDestroy:
   SetTimer,mouseRing,Off
   GoSub, MouseRingErase
   mDiameter := mDiaMin, mAlpha := mFadeMax
   UpdateLayeredWindow(mhWnd, mhdc, MX-mDiameter//2, MY-mDiameter//2, mDiameter+5, mDiameter+5)
return

mouseRingErase:
   Gdip_SetCompositingMode(mG, 1)              ; set overdraw
   mBrush := Gdip_BrushCreateSolid(0x00000000) ; fully transparent brush 'eraser'
   Gdip_FillRectangle(mG, mBrush, 0, 0, mDiameter+10, mDiameter+10)
   Gdip_DeleteBrush(mBrush)
   Gdip_SetCompositingMode(mG, 0)              ; switch off overdraw
return

esc::exitapp
^r::reload

; uncomment if gdip is not in ur standard library
; #include gdip.ahk

_________________
Image
    All scripts, unless otherwise noted, are hereby released under CC-BY


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: maraskan_user and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group