一个简单的示例(依赖gdip_all.ahk基础库),对于新手来说可以参考一下基础用法。
鼠标滚轮调节logo大小、鼠标右键呼出菜单列表
#Persistent
#Include gdip_all.ahk
OnMessage(0x201,"WM_LBUTTONDOWN")
;图片路径
ImagePath:=A_ScriptDir "\bagel.png"
;缩放比例
logosize:=50
xpos:=200,ypos:=100
;载入图片
load_logo_box(ImagePath,logosize,xpos,ypos)
;==================鼠标滚轮调节logo大小========================
IsModifyLogoSize:= Func("IsExistLogo")
Hotkey,if, % IsModifyLogoSize
Hotkey $WheelDown, ModifyLogoDownSize
Hotkey $WheelUp, ModifyLogoUpSize
;==================实时监测logo坐标位置========================
SetTimer,GetLogoClientPos,On
Return
;==========================================
GetLogoClientPos:
if WinExist("ahk_id " hlogo){
VarSetCapacity( size, 16, 0 )
DllCall( "GetClientRect", "Ptr", hlogo, "Ptr", &size )
DllCall( "ClientToScreen", "Ptr", hlogo, "Ptr", &size )
xpos := NumGet( size, 0, "Int"), ypos := NumGet( size, 4, "Int")
}
Return
ModifyLogoDownSize:
logosize--
load_logo_box(ImagePath,logosize,xpos,ypos)
Return
ModifyLogoUpSize:
logosize++
load_logo_box(ImagePath,logosize,xpos,ypos)
Return
IsExistLogo(){
Global hlogo
CoordMode,Mouse,Screen
MouseGetPos,,,MID
Return (MID&&MID=hlogo?True:False)
}
load_logo_box(ImagePath,logosize:=50,xpos:=100,ypos:=100,logoAlpha:=255){
Global hlogo
if !FileExist(ImagePath){
MsgBox,16,Error,图片文件不存在!
Return
}
pToken := Gdip_Startup()
pBitmap := Gdip_CreateBitmapFromFile(ImagePath)
if !pBitmap {
MsgBox,16,Error,图片载入失败!
Return
}
Gui, logo: -Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs +Hwndhlogo
Gui, logo: Show, NA
Ratio:=(logo_Width:=Gdip_GetImageWidth(pBitmap))/(logo_Height:=Gdip_GetImageHeight(pBitmap))
, DisplayWidth:=Round(logo_Width*logosize/100), DisplayHeight:=DisplayWidth//Ratio
pBitmap:=Gdip_ResizeBitmap(pBitmap, DisplayWidth, DisplayHeight, 0)
hbm := CreateDIBSection(DisplayWidth, DisplayHeight),hdc := CreateCompatibleDC()
obm := SelectObject(hdc, hbm),G := Gdip_GraphicsFromHDC(hdc)
Gdip_SetInterpolationMode(G, 7),Gdip_DrawImageFast(G, pBitmap, 0, 0)
UpdateLayeredWindow(hlogo, hdc,xpos , ypos, DisplayWidth, DisplayHeight,logoAlpha>0&&logoAlpha<=255?logoAlpha:255)
SelectObject(hdc, obh), DeleteObject(hbm), DeleteDC(hdc),Gdip_DeleteGraphics(G),Gdip_DisposeImage(pBitmap)
OnMessage(0x20, Func("WM_SETCURSOR").Bind(hlogo))
}
logoGuiContextMenu(GuiHwnd, CtrlHwnd, EventInfo, IsRightClick, X, Y){
if (IsRightClick){
if MenuGetHandle("logo")
Menu, logo, DeleteAll
Menu, logo, UseErrorLevel
Menu, logo,Add, 菜单项1,MenuItemLabel
Menu, logo,Add
Menu, logo,Add, 菜单项2,MenuItemLabel
Menu, logo,Add
Menu, logo,Add, 菜单项3,MenuItemLabel
Menu, logo,Add
Menu, logo,Add, 菜单项4,MenuItemLabel
Menu, logo,Show
Return
}
MenuItemLabel:
Switch A_ThisMenuItem
{
Case "菜单项1":
MsgBox % A_ThisMenuItemPos "-" A_ThisMenuItem
Case "菜单项2":
MsgBox % A_ThisMenuItemPos "-" A_ThisMenuItem
Case "菜单项3":
MsgBox % A_ThisMenuItemPos "-" A_ThisMenuItem
Case "菜单项4":
MsgBox % A_ThisMenuItemPos "-" A_ThisMenuItem
}
Return
}
WM_LBUTTONDOWN(wParam, lParam, uMsg, hWnd){
if (A_Gui="logo"&&HWND)
DllCall("user32.dll\PostMessage", "ptr", hWnd, "uint", 0x00A1, "ptr", 2, "ptr", 0)
}
WM_SETCURSOR(hPic, wp) {
static hCursor, flags := (LR_DEFAULTSIZE := 0x40) | (LR_SHARED := 0x8000)
, params := [ "Ptr", 0, "UInt", OCR_HAND := 32649
, "UInt", IMAGE_CURSOR := 2
, "Int", 0, "Int", 0, "UInt", flags, "Ptr" ]
(!hCursor && hCursor := DllCall("LoadImage", params*))
if (wp = hPic)
Return DllCall("SetCursor", "Ptr", hCursor)
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
学习!感谢分享