Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Clickable Gdi picture ?


  • Please log in to reply
3 replies to this topic
Alexou
  • Members
  • 40 posts
  • Last active: Feb 02 2016 06:39 PM
  • Joined: 10 Aug 2015

Hi

 

I have multiple Gdi picture inside one GUI 

 

like this :

 

#include Gdip_All.ahk
Gui, Child: New, -Caption +LastFound +ToolWindow +OwnDialogs +HwndHChild +E0x80000 +LabelGui  
HwndHChild := WinExist()

File1 := "USB.png"
File2 := "eject.png"
pToken := Gdip_Startup()
pBitmap:=Gdip_CreateBitmapFromFile(File1)
pBitmap2:=Gdip_CreateBitmapFromFile(File2)

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

Gdip_DrawImage(G, pBitmap, 0, 10, 60, 60 )
Gdip_DrawImage(G, pBitmap2, 190, 10, 40, 40 )
UpdateLayeredWindow(HwndHChild, hdc, , , w, h)

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

Gui, Child: Show, w300 h300

How to do clickable gdi picture ?

 

I can do clickable GUI with this :

 

OnMessage(0x0201, "WM_LBUTTONDOWN")


return

WM_LBUTTONDOWN() {
   If (A_Gui = "Child")
   MsgBox hello
}
return

but i have two Gdi picture in my GUI and i need only one picture clickable.

so how to do this ?

 

Thanks

Sorry for my poor english

 



SkrillexAkaCraft
  • Members
  • 45 posts
  • Last active: Jan 04 2018 06:02 PM
  • Joined: 04 Feb 2015

for the images i would use this

Gui, Add, Picture, x1245 y4 gclose +BackgroundTrans gclose, Folder\Folder\YourImage.png

try that :)

 

 

 

EDIT:

Gui, Show, w500 h147, Image-Test
Gui, Add, Picture, x0 y40 +BackgroundTrans gImagePressed, ImagesTest\start.png
Gui, Add, Picture, x25 y115 w80 h30 +BackgroundTrans gImagePressed2, ImagesTest\stop.png
Gui, Add, Picture, x0 y0 w500 h147 +BackgroundTrans , ImagesTest\BG.png
return
 
ImagePressed:
{
MsgBox,64,,You did press Start.png
}
return
 
ImagePressed2:
{
MsgBox,64,,You did press Stop.png
}
return

 
 
 
ImagePressed:
{
msgbox,64,,You did press Start
}
return
 
 
Images used in attachment
 
Save this as BG.png in a folder called ImageTest
k1e1sj.png
Save this as start.png in the same folder
2sb7vj7.png
Save this as stop.png in the same folder
11lodht.png
 
 
 
 
now create a new folder on desktop then move the imagestest folder to that new folder create a new ahk script in the head folder where ImagesTest is located and start that script :)
 
 
hope this helped you out


noname
  • Members
  • 650 posts
  • Last active:
  • Joined: 12 Nov 2011

If you want to use GDIP and a layered window you can try this:


#include *i Gdip_All.ahk

File1 := "USB.png"
File2 := "eject.png"


Gui, Child: New, -Caption +LastFound +ToolWindow +OwnDialogs +HwndHChild +E0x80000 +LabelGui  
gui, show

pToken := Gdip_Startup()
pBitmap:=Gdip_CreateBitmapFromFile(File1)
pBitmap2:=Gdip_CreateBitmapFromFile(File2)

w = 300
h = 300
hbm := CreateDIBSection(w, h)
hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm)
G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7)
Gdip_SetSmoothingMode(G,4)

Gdip_GraphicsClear(G, 0x40000000)  ;just for testing to see position


Gdip_DrawImage(G, pBitmap, 0, 10, 60, 60 )
Gdip_DrawImage(G, pBitmap2, 190, 10, 40, 40 )
UpdateLayeredWindow(Hchild, hdc,(a_screenwidth-w)//2,(a_screenheight-h)//2,w,h)

;WinMove, ahk_id %HChild%,,100,100  ;move if needed 

OnMessage(0x0201, "WM_LBUTTONDOWN")

return

WM_LBUTTONDOWN(wParam,lParam,msg,hwnd){
 
    x := lParam & 0xFFFF
    y := lParam >> 16
    
    if (x<60 and y>10 and y<70)
    msgbox clicked usb
    else if (x>190 and x<230 and y>10 and y<50)
    msgbox clicked eject
    Else ;if needed for moving window 
    PostMessage, 0xA1, 2 ; move window with mouse
}
return

esc::
exit:
SelectObject(hdc, obm)
DeleteObject(hbm)
DeleteDC(hdc)
Gdip_DeleteGraphics(G)
Gdip_Shutdown(pToken)
exitapp



winXP  and ahk unicode


Alexou
  • Members
  • 40 posts
  • Last active: Feb 02 2016 06:39 PM
  • Joined: 10 Aug 2015

@SkrillexAkaCraft thanks but i need to use gdi.

 

@noname Thanks this is perfect !