Gui窗口实用的一些基础操作实例

/*
	https://github.com/jNizM/AHK_Scripts/tree/master/src/gui
	禁用/启用窗口关闭按钮
	启用/禁用移动窗口
	开启窗口边框阴影效果
*/

Gui,test:Destroy
Gui,test:+AlwaysOnTop +HWNDGuiTest
SetWindowsFrameShadow(GuiTest)
ToggleGuiCloseButton(GuiTest,OnOff:=False)
ToggleGuiMove(GuiTest,EnableMove:=False)
Gui,test:Add,Edit,w200 HWNDEditBox,
EM_SETCUEBANNER(EditBox, "Edit输入框")
Gui,test:Add,ComboBox,w200 HWNDCBoxTest,1|2|3
CB_SETCUEBANNER(CBoxTest, "ComboBox选择框")
Gui,test:Add,Button,w200 gbuttonTest vIsClose,% "启用/禁用关闭按钮"
Gui,test:Add,Button,w200 gbuttonTest vIsMove,% "启用/禁用移动窗口"
Gui,test:Show,w250 h200
Return

testGuiClose:
	ExitApp
Return

buttonTest:
	Switch A_GuiControl
	{
		Case "IsClose":
			OnOff:=!OnOff
			ToggleGuiCloseButton(GuiTest,OnOff)
		Case "IsMove":
			EnableMove:=!EnableMove
			ToggleGuiMove(GuiTest,EnableMove)
	}
Return

;;无边框窗口加阴影效果
SetWindowsFrameShadow(handle){
	DllCall("dwmapi.dll\DwmIsCompositionEnabled", "int*", DwmEnabled)
	if !(DwmEnabled)
		DllCall("user32.dll\SetClassLongPtr", "ptr", handle, "int", -26, "ptr", DllCall("user32.dll\GetClassLongPtr", "ptr", handle, "int", -26) | 0x20000)
	else {
		VarSetCapacity(MARGINS, 16, 0) && NumPut(1, NumPut(1, NumPut(1, NumPut(1, MARGINS, "int"), "int"), "int"), "int")
		DllCall("dwmapi.dll\DwmSetWindowAttribute", "ptr", handle, "uint", 2, "ptr*", 2, "uint", 4)
		DllCall("dwmapi.dll\DwmExtendFrameIntoClientArea", "ptr", handle, "ptr", &MARGINS)
	}
}


;;启用/禁用移动窗口
ToggleGuiMove(handle,Enable:=True){
	hMenu := DllCall("user32\GetSystemMenu", "ptr", handle, "int", Enable, "ptr")
	DllCall("user32\RemoveMenu", "ptr", hMenu, "uint", 0xf010, "uint", 0x0)
	return DllCall("user32\DrawMenuBar", "ptr", handle)
}

;;禁用/启用窗口关闭按钮
ToggleGuiCloseButton(handle,Enable:=True){
	hMenu := DllCall("user32\GetSystemMenu", "ptr", handle, "int", Enable, "ptr")
	DllCall("user32\EnableMenuItem", "ptr", hMenu, "uint", 0xf060, "uint", 0x3)
	return DllCall("user32\DrawMenuBar", "ptr", handle)
}

;;设置Edit控件默认提示文本
EM_SETCUEBANNER(handle, string, hideonfocus := true){
	static EM_SETCUEBANNER := 0x1501
	return DllCall("user32\SendMessage", "ptr", handle, "uint", EM_SETCUEBANNER, "int", hideonfocus, "str", string, "int")
}

;;设置Combobox控件默认提示文本
CB_SETCUEBANNER(handle, string){
	static CB_SETCUEBANNER := 0x1703
	return DllCall("user32\SendMessage", "ptr", handle, "uint", CB_SETCUEBANNER, "int", 0, "str", string, "int")
}

给TA捐赠
共{{data.count}}人
人已捐赠
AHKV1代码示例近期更新

MsgBox显示字体调整

2022-1-23 21:23:26

AHKV1工具社区推荐近期更新

《右键清单式工具》提高学习效率的快捷搜索翻译工具

2022-1-24 19:57:04

2 条回复 A文章作者 M管理员
  1. yukingzou

    认真学习中,谢谢分享

  2. 〇〇13092

    👍

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索