AutoHotkey Community

It is currently May 26th, 2012, 5:03 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: February 24th, 2009, 11:27 am 
Hi,

I'm really noob on GUI so be patient plz...

. I need to link my AHK macro to a button (png transparent) that need to stay ALWAYS on top
. Using a special key (ie. ctrl + LMouse) i need to move it.
. Need to execute specific actions/external macros click, double-click, etc... ON IT
. Need to show/hide it on specific button (i.e. CTRL+M or MButton)

Someone can help me or forward me to right posts?

Thanks


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2009, 11:56 am 
Offline

Joined: October 13th, 2008, 4:14 pm
Posts: 60
Location: South Park, Colorado
Start here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2009, 2:28 pm 
How make it Always ON Top?


Code:
sFile   := "button.png"

mDC_Scr   := Gdi_CreateCompatibleDC(0)
pToken   := Gdip_Startup()
pBitmap   := !hIcon ? Gdip_CreateBitmapFromFile(sFile) : Gdip_CreateBitmapFromHICON(hIcon)
nWidth   := Gdip_GetImageWidth( pBitmap)
nHeight   := Gdip_GetImageHeight(pBitmap)
hBitmap   := !hIcon ? Gdip_CreateHBITMAPFromBitmap(pBitmap) : Gdi_CreateDIBSection(mDC_Scr, nWidth, nHeight)
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
oBitmap   := Gdi_SelectObject(mDC_Scr, hBitmap)

If   hIcon
   DllCall("DrawIconEx", "Uint", mDC_Scr, "int", 0, "int", 0, "Uint", hIcon, "int", nWidth, "int", nHeight, "Uint", 0, "Uint", 0, "Uint", 1|2)

Gui, +LastFound -Caption +E0x80000
DllCall("UpdateLayeredWindow", "Uint", WinExist(), "Uint", 0, "Uint", 0, "int64P", nWidth|nHeight<<32, "Uint", mDC_Scr, "int64P", 0, "Uint", 0, "UintP", 255<<16|1<<24, "Uint", 2)
Gui, Show, Center W%nWidth% H%nHeight%
OnMessage(0x0201, "WM_LBUTTONDOWN")
OnMessage(0x0003, "WM_MOVE")

Gdi_SelectObject(mDC_Scr, oBitmap)
Gdi_DeleteObject(hBitmap)
Gdi_DeleteDC(mDC_Scr)
Return

GuiClose:
GuiEscape:
Gui, Destroy
ExitApp

WM_LBUTTONDOWN()
{
   If   A_Gui
      PostMessage, 0xA1, 2   ; WM_NCLBUTTONDOWN
}

WM_MOVE(wParam, lParam, nMsg, hWnd)
{
   If   A_Gui
   &&   DllCall("UpdateLayeredWindow", "Uint", hWnd, "Uint", 0, "int64P", (lParam<<48>>48)&0xFFFFFFFF|(lParam&0xFFFF0000)<<32>>16, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0)
   Return   0
}


Gdi_CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
   NumPut(VarSetCapacity(bi, 40, 0), bi)
   NumPut(nW, bi, 4)
   NumPut(nH, bi, 8)
   NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
 
   Return   DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}

Gdi_CreateCompatibleDC(hDC = 0)
{
   Return   DllCall("gdi32\CreateCompatibleDC", "Uint", hDC)
}

Gdi_SelectObject(hDC, hGdiObj)
{
   Return   DllCall("gdi32\SelectObject", "Uint", hDC, "Uint", hGdiObj)
}

Gdi_DeleteObject(hGdiObj)
{
   Return   DllCall("gdi32\DeleteObject", "Uint", hGdiObj)
}

Gdi_DeleteDC(hDC)
{
   Return   DllCall("gdi32\DeleteDC", "Uint", hDC)
}

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, "UintP", pBitmap)
   Return   pBitmap
}

Gdip_CreateBitmapFromHICON(hIcon)
{
   DllCall("gdiplus\GdipCreateBitmapFromHICON", "Uint", hIcon, "UintP", pBitmap)
   Return   pBitmap
}

Gdip_CreateHBITMAPFromBitmap(pBitmap, ARGB = 0)
{
   DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pBitmap, "UintP", hBitmap, "Uint", ARGB)
   Return   hBitmap
}

Gdip_DisposeImage(pImage)
{
   Return   DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)
}

Gdip_GetImageWidth(pImage)
{
   DllCall("gdiplus\GdipGetImageWidth", "Uint", pImage, "UintP", nW)
   Return   nW
}

Gdip_GetImageHeight(pImage)
{
   DllCall("gdiplus\GdipGetImageHeight", "Uint", pImage, "UintP", nH)
   Return   nH
}

Gdip_Startup()
{
   If Not   DllCall("GetModuleHandle", "str", "gdiplus")
   DllCall("LoadLibrary"    , "str", "gdiplus")
   VarSetCapacity(si, 16, 0), si := Chr(1)
   DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)
   Return   pToken
}

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




Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2009, 2:40 pm 
How can I change the Image on LMouse Click & launch my command?
And .. how to make it Always On TOP?

Tnx


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 24th, 2009, 3:37 pm 
to make it always on top change


Gui, +LastFound -Caption +E0x80000
in
Gui, +LastFound -Caption +E0x80000 +ToolWindow +OwnDialogs +AlwaysOnTop

but how change image onfly ?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2009, 11:46 am 
Offline

Joined: April 22nd, 2007, 6:33 pm
Posts: 1833
EricCartman wrote:
Start here.


I dont think its a good idea to point people to that topic EricCartman. Nearly everything in there is fully covered and explained in the gdi+ library


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2009, 3:52 pm 
Hi,

using ; gdi+ ahk tutorial 3 written by tic (Tariq Porter) i do the following code:
Code:
; gdi+ ahk tutorial 3 written by tic (Tariq Porter)
; Requires Gdip.ahk either in your Lib folder as standard library or using #Include
;
; Tutorial to take make a gui from an existing image on disk
; For the example we will use png as it can handle transparencies. The image will also be halved in size

#SingleInstance, Force
#NoEnv
SetBatchLines, -1

resize_img := 4

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

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

;
; Image 1
;

; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
Gui, 1: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs

; Show the window
Gui, 1: Show, NA

; Get a handle to this window we have created in order to update it later
hwnd1 := WinExist()

; If the image we want to work with does not exist on disk, then download it...
;If !FileExist("background.png")
;UrlDownloadToFile, http://www.autohotkey.net/~tic/background.png, background.png

; Get a bitmap from the image
pBitmap := Gdip_CreateBitmapFromFile("button1.png")

; Check to ensure we actually got a bitmap from the file, in case the file was corrupt or some other error occured
If !pBitmap
{
   MsgBox, 48, File loading error!, Could not load the image specified
   ExitApp
}

; Get the width and height of the bitmap we have just created from the file
; This will be the dimensions that the file is
Width := Gdip_GetImageWidth(pBitmap), Height := Gdip_GetImageHeight(pBitmap)

; Create a gdi bitmap with width and height of what we are going to draw into it. This is the entire drawing area for everything
; We are creating this "canvas" at half the size of the actual image
; We are halving it because we want the image to show in a gui on the screen at half its dimensions
hbm := CreateDIBSection(Width//resize_img, Height//resize_img)

; Get a device context compatible with the screen
hdc := CreateCompatibleDC()

; Select the bitmap into the device context
obm := SelectObject(hdc, hbm)

; Get a pointer to the graphics of the bitmap, for use with drawing functions
G := Gdip_GraphicsFromHDC(hdc)

; We do not need SmoothingMode as we did in previous examples for drawing an image
; Instead we must set InterpolationMode. This specifies how a file will be resized (the quality of the resize)
; Interpolation mode has been set to HighQualityBicubic = 7
Gdip_SetInterpolationMode(G, 7)

; DrawImage will draw the bitmap we took from the file into the graphics of the bitmap we created
; We are wanting to draw the entire image, but at half its size
; Coordinates are therefore taken from (0,0) of the source bitmap and also into the destination bitmap
; The source height and width are specified, and also the destination width and height (half the original)
; Gdip_DrawImage(pGraphics, pBitmap, dx, dy, dw, dh, sx, sy, sw, sh, Matrix)
; d is for destination and s is for source. We will not talk about the matrix yet (this is for changing colours when drawing)
Gdip_DrawImage(G, pBitmap, 0, 0, Width//resize_img, Height//resize_img, 0, 0, Width, Height)


; Update the specified window we have created (hwnd1) with a handle to our bitmap (hdc), specifying the x,y,w,h we want it positioned on our screen
; So this will position our gui at (0,0) with the Width and Height specified earlier (half of the original image)
UpdateLayeredWindow(hwnd1, hdc, 0, 0, Width//resize_img, Height//resize_img)

; Select the object back into the hdc
SelectObject(hdc, obm)

; Now the bitmap may be deleted
DeleteObject(hbm)

; Also the device context related to the bitmap may be deleted
DeleteDC(hdc)

; The graphics may now be deleted
Gdip_DeleteGraphics(G)

; The bitmap we made from the image may be deleted
Gdip_DisposeImage(pBitmap)


; Assign Actions

OnMessage(0x0201, "WM_LBUTTONDOWN")

Return


;#######################################################################

Exit:
; gdi+ may now be shutdown on exiting the program
Gdip_Shutdown(pToken)
ExitApp
Return

;#######################################################################
; Actions
;#######################################################################

;
; Left click Mouse
;------------------

WM_LBUTTONDOWN()
{
   If    A_Gui       
   {
   GetKeyState, state, LShift, P
   if state = D
      {
                   ;
         ; if LEFT SHIFT IS ON MOVE THE IMAGE
         ;------------------------------------

         PostMessage, 0xA1, 2   ; WM_NCLBUTTONDOWN 

      } else {
         msgbox Left Click
      }
   }
}



Using LSHIFT+CLIC i can move the image

I need to CHANGE image if i click on it like do the post http://www.autohotkey.com/forum/topic40234.html&highlight=gdi+button

How can I realize this ?

Thanks Mutch!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 25th, 2009, 5:02 pm 
I do the "swap" function clicking on image ..but repositioning the new one image on old one position does not work.

Look here:
http://www.autohotkey.com/forum/post-252281.html#252281

Plz help


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, gamax92, Miguel, rbrtryn, SifJar, SKAN and 54 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