今日は、DOSコマンドを調べていました。
動画の作成の為ですけど、途中で…
以前からの課題、ウインドウの巻き上げを調べて羽目になってしまった!
成果
本体を作る
大体できた(makiage.py)
方針!
方法1 グローバルフック タイトルバーのシステムメニューにハックして追加する
方法2 グローバルフック
https://www.google.com/search?q=python+dwmapi.h&sxsrf=ALeKk01azuNBKkDk_XuWNuQyS1SnEM3BZA:1612088907747&ei=S4YWYP2GLZr6-QbJhb2QBQ&start=10&sa=N&ved=2ahUKEwi92MSV-8XuAhUafd4KHclCD1IQ8NMDegQICBBI&biw=1005&bih=589
How can I paint an image in the caption bar?
http://answers.flyppdevportal.com/MVC/Post/Thread/0b4ce5c1-bb71-4641-bbef-c54d32e630c8?category=vcgeneral
※問題点
WPFでは、大丈夫なのか?
そんなこんなもあり(時間もあり)
タイトルバーには、自前でアイコンを表示する事にした
(これが安全で簡単)その検証が、(mainPin.py)
である。
マウスを動かすと小さなウインドウが追従する
これを利用して、以下を実現!
全てのウインドウにこの小さなウインドウ(アイコンを)付ける
(最小化アイコンの左側)
これをクリックすると巻き上げするというやり方だ!
どうかな~な!
でも、これが一番だと思ってやりますね
(mainPin.py)
# -*- coding: utf-8 -*-
# http://algomarket.wikidot.com/win32-api-in-python
# `Hello world in python using win32py'
# 手持ちのPython 3環境で動かしたらちょっと手直しが必要だったので、まずフォーク。
import mouse
import win32gui
import win32con
def mouseCallback( event ):
print('mouseCallback-Event:', event, type(event))
xx = event.x
yy = event.y
# //MoveWindow(hwnd, xx+10, yy, 20, 20, True)
win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,xx+10,yy, 20, 20,win32con.SWP_SHOWWINDOW)
# //mouse.on_click(mouse_callback)
mouse.hook( mouseCallback )
from win32api import (GetModuleHandle,)
from win32gui import (WNDCLASS,
GetStockObject,
RegisterClass,
CreateWindow,
ShowWindow,
MoveWindow,
UpdateWindow,
GetMessage,
TranslateMessage,
DispatchMessage,
PostQuitMessage,
BeginPaint,
GetClientRect,
DrawText,
EndPaint,
)
from win32con import (WHITE_BRUSH,
WS_OVERLAPPEDWINDOW,
WS_CAPTION,
WS_POPUP,
WS_VISIBLE,
CW_USEDEFAULT,
SW_SHOW,
WM_PAINT,
WM_DESTROY,
CS_VREDRAW,
CS_HREDRAW,
DT_SINGLELINE,
DT_CENTER,
DT_VCENTER,
)
def OnPaint(hwnd, message, wParam, lParam):
hdc, ps = BeginPaint(hwnd)
rect = GetClientRect(hwnd)
int, rect = DrawText(hdc, u"Hello, Windows 98!" , -1 , rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER)
EndPaint(hwnd, ps)
return 0
def OnDestroy(hwnd, message, wParam, lParam):
PostQuitMessage(0)
message_map = {
WM_PAINT: OnPaint,
WM_DESTROY: OnDestroy,
}
# have to create hInstance explicitly
hInst = GetModuleHandle()
# create window class structure
szAppName = u"HelloWin"
wndclass = WNDCLASS()
wndclass.style = CS_HREDRAW | CS_VREDRAW
wndclass.lpfnWndProc = message_map
wndclass.cbWndExtra = 0
wndclass.hInstance = hInst
wndclass.hIcon = 0
wndclass.hCursor = 0
wndclass.hbrBackground = GetStockObject(WHITE_BRUSH)
wndclass.lpszMenuName = ''
wndclass.lpszClassName = szAppName
# need encode!
# register window class
hr_registerclass = RegisterClass(wndclass)
# create window
# //hwnd = CreateWindow(szAppName,
# //u"The Hello Program",
# //WS_OVERLAPPEDWINDOW | WS_CAPTION,
# //CW_USEDEFAULT,
# //CW_USEDEFAULT,
# //CW_USEDEFAULT,
# //CW_USEDEFAULT,
# //0,
# //0,
# //hInst,
# //None) # must be None!
hwnd = CreateWindow(szAppName,
u"The Hello Program",
WS_POPUP | WS_VISIBLE,
# //WS_POPUP,
# //WS_OVERLAPPEDWINDOW | WS_CAPTION,
0, 0,
0, 0,
0, 0,
hInst,
None) # must be None!
MoveWindow(hwnd, 100, 100, 120, 120, True)
ShowWindow(hwnd, SW_SHOW)
UpdateWindow(hwnd)
# message loop
while True:
b, msg = GetMessage(hwnd, 0, 0)
if msg == 0:
break
TranslateMessage(msg)
DispatchMessage(msg)
(makiage.py)
import win32gui
import win32con
from pynput import mouse
hndTbl ={}
heightSV =0
def onlyTtl( X_Point,Y_Point ):
global heightSV
Handle = win32gui.WindowFromPoint((X_Point,Y_Point))
print(Handle)
(x01, y01, x02, y02) = win32gui.GetWindowRect(Handle)
width0 = x02 - x01
height0 = y02 - y01
(x1, y1, x2, y2) = win32gui.GetClientRect(Handle)
width = x2 - x1
height = height0 -y2
print( "height", height,y2)
if Handle in hndTbl:
print( "hndTbl 1=", hndTbl)
heightSV = hndTbl[Handle]
hndTbl.pop( Handle )
# //if y2 < heightSV:
print("dbg=",Handle, hndTbl)
win32gui.SetWindowPos(Handle,win32con.HWND_NOTOPMOST,x01,y01, width0, heightSV,win32con.SWP_SHOWWINDOW)
else:
win32gui.SetWindowPos(Handle,win32con.HWND_TOPMOST,x01,y01, width0, 25,win32con.SWP_SHOWWINDOW)
heightSV= y02 - y01
print("dbg=",Handle, hndTbl)
if not Handle in hndTbl:
hndTbl[ Handle ] = heightSV
print( "hndTbl 2=", hndTbl)
# //def Ttl( X_Point,Y_Point ):
# //global height0
# //Handle = win32gui.WindowFromPoint((X_Point,Y_Point))
# //print(Handle)
# //(x01, y01, x02, y02) = win32gui.GetWindowRect(Handle)
# //width0 = x02 - x01
# //height0 = y02 - y01
# //(x1, y1, x2, y2) = win32gui.GetClientRect(Handle)
# //width = x2 - x1
# //height = height0 -y2
# //print( "height", height,y2)
# //win32gui.SetWindowPos(Handle,win32con.HWND_TOPMOST,x01,y01, width0, height,win32con.SWP_SHOWWINDOW)
def on_move(x, y):
print('Pointer moved to {0}'.format(
(x, y)))
def on_click(x, y, button, pressed):
print('{0} at {1}'.format(
'Pressed' if pressed else 'Released',
(x, y)))
if not pressed:
Handle = win32gui.WindowFromPoint((x,y))
Handle2= win32gui.ChildWindowFromPoint( Handle, (x, y) )
print(Handle, Handle2)
deltaX = -200
deltaY = 30
(x01, y01, x02, y02) = win32gui.GetWindowRect(Handle)
print(x,x02,(x02 + deltaX) )
print(y,y01,(y01 + deltaY) )
if x02-90 >x and (x02 + deltaX) <x:
print("X OK")
if y01 <y and (y01 + deltaY) >y:
print("YY OK")
onlyTtl( x,y )
# //if not pressed:
# Stop listener
# //return False
def on_scroll(x, y, dx, dy):
print('Scrolled {0} at {1}'.format(
'down' if dy < 0 else 'up',
(x, y)))
# Collect events until released
with mouse.Listener(
on_move=on_move,
on_click=on_click,
on_scroll=on_scroll) as listener:
listener.join()
print("--------------------------------------------")
# //トップ画面のハンドル
Top_Handle = win32gui.FindWindow("hogegoge",None)
# //特定ハンドルの座標
X_Point = 50
Y_Point = 50
Handle = win32gui.WindowFromPoint((X_Point,Y_Point))
print(Handle)
(x01, y01, x02, y02) = win32gui.GetWindowRect(Handle)
width0 = x02 - x01
height0 = y02 - y01
(x1, y1, x2, y2) = win32gui.GetClientRect(Handle)
width = x2 - x1
height = height0 -y2
print( "height", height,y2)
win32gui.SetWindowPos(Handle,win32con.HWND_TOPMOST,x01,y01, width0, height,win32con.SWP_SHOWWINDOW)