1.禁用窗口最小化、关闭按钮:
MF_GRAYED = 0x01 SC_MINIMIZE = 0xF020 #最小化 SC_CLOSE = 0xF060 #关闭 HWND = Win32API.new('user32.dll','GetActiveWindow',nil,'l').call GSM = Win32API.new('user32.dll','GetSystemMenu','ll','l').call(HWND,0) Win32API.new('user32.dll','RemoveMenu','lll','l').call(GSM,SC_MINIMIZE,MF_GRAYED) #禁用最小化 Win32API.new('user32.dll','RemoveMenu','lll','l').call(GSM,SC_CLOSE,MF_GRAYED) #禁用关闭
最小化按钮无法变灰,只会失效;关闭按钮可以正常变灰。
2.半透明窗口:
#设置不透明度(有效范围0~255) OPACITY = 150 #获取窗口句柄 HWND = Win32API.new('user32','GetActiveWindow',nil,'l').call #设置窗口风格WS_EX_LAYERED (0x00080000) Win32API.new('user32','SetWindowLong','lil','l').call(HWND,-20,0x00080000) Win32API.new('user32','SetLayeredWindowAttributes','llil','l').call(HWND,0,OPACITY,2)
3.窗口靠边
#使用到的API #获取屏幕宽度 Width = Win32API.new('user32','GetSystemMetrics','i','i').call(0) #获取屏幕高度 Height = Win32API.new('user32','GetSystemMetrics','i','i').call(1) #获取窗口句柄 HWND = Win32API.new('user32','GetActiveWindow',nil,'l').call #用来改变窗口位置 Set = Win32API.new("user32", "SetWindowPos",'lliiiii','l') class << Graphics alias_method :o_update, :update unless method_defined? :o_update def update pos = "\0"*16 Win32API.new('user32','GetWindowRect',['l','p'],'i').call(HWND,pos) left,top,right,bottom = pos.unpack('llll') if left <= 40 Set.call(HWND,0,0,top,0,0,0x0001) elsif right >= Width - 40 or right >= Width + 40 Set.call(HWND,0,Width - 640,top,0,0,0x0001) elsif top <= 40 Set.call(HWND,0,left,0,0,0,0x0001) end o_update end end
纯属娱乐,插入该段脚本后,可将窗口拖至离屏幕边缘40像素以内后松开左键,窗口会自动靠边。
在拖曳窗口的过程中,Graphics.update 会停止,必须松开鼠标键后才会进行刷新,目前暂无解决办法。
以上脚本中,获取窗口句柄的部分有更严谨的写法,这里为方便起见就从简,直接用GetActiveWindow 函数获取当前活动窗口句柄