python獲取窗口句柄
① 如何用python實現窗口抖動
- 1. 獲取到當前窗口的句柄。可以使用GetForegroundWindow()函數來實現。
2. 獲取到當前窗口的坐標位置。可以使用GetWindowRect()函數來實現。此處不僅需要當前窗口的句柄,也需要我們定義一個結構體來實現坐標值得存儲。
3. 改變當前窗口的位置。可以使用SetWindowPos()函數來實現。函數原型為BOOL SetWindowPos(HWN hWnd,HWND hWndlnsertAfter,int X,int Y,int cx,int cy,UNIT.Flags),其中hWnd為窗口的句柄,hWndInsertAfter指在z序中的位於被置位的窗口前的窗口句柄,X指以客戶坐標指定窗口新位置的左邊界,Y指以客戶坐標指定窗口新位置的頂邊界,cx指以像素指定窗口的新的寬度,cy指以像素指定窗口的新的高度,uFlags:窗口尺寸和定位的標志。
② python中使用selenium獲取窗口句柄時,window_handles取值出錯
Form formPreview = new Form();
public Leaf(string name) : base(name) { }
public override void Add(Component c)
{
Console.WriteLine("Cannot add to a leaf");
}
public override void Remove(Component c)
{
Console.WriteLine("Cannot remove to a leaf");
}
public override void Display(int depth)
{
Console.WriteLine(new string('-',depth)+name);
}
}
③ python中獲取子窗口的句柄
可以使用win32gui 以及pyhook 庫來實現你的需求
④ python pywin32 裡面操作窗體,獲取窗體裡面的數據,在函數GetDlgItem函數中,怎麼獲取第二個參數的值
1.如何利用句柄操作windows窗體
首先,獲得窗體的句柄 win32api.FindWindows()
第二,獲得窗體中控制項的id號,spy++
第三,根據控制項的ID獲得控制項的句柄(hwnd) GetDlgItem(hwnd,loginID)
最後,利用控制項句柄進行操作
python可以通過win32api輕松獲取控制項的屬性值
通過標簽找到主窗口句柄,然後通過主句柄獲取下屬控制項句柄
#-*- coding: utf-8 -*- ##設置編碼方式
import win32api,win32gui,win32con
label = 'tt' #此處假設主窗口名為tt
hld = win32gui.FindWindow(None, label)
if hld > 0:
dlg = win32api.FindWindowEx(hld, None, 'Edit', None)#獲取hld下第一個為edit控制項的句柄
buffer = '0' *50
len = win32gui.SendMessage(dlg, win32con.WM_GETTEXTLENGTH)+1 #獲取edit控制項文本長度
win32gui.SendMessage(dlg, win32con.WM_GETTEXT, len, buffer) #讀取文本
print buffer[:len-1]
#虛擬滑鼠點擊按鈕(或者回車)
btnhld = win32api.FindWindowEx(hld, None,'Button', None)
# win32gui.PostMessage(btnhld, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
# win32gui.PostMessage(btnhld, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
win32gui.PostMessage(btnhld, win32con.WM_LBUTTONDOWN, win32con.MK_LBUTTON, 0)
win32gui.PostMessage(btnhld, win32con.WM_LBUTTONUP, win32con.MK_LBUTTON, 0)
#獲取顯示器屏幕大小
width = win32api.GetSystemMetrics(win32con.SM_CXSCREEN)
height = win32api.GetSystemMetrics(win32con.SM_CYSCREEN)
#點擊窗口button
w=win32ui.FindWindow(clsname,windowtitle)
b=w.GetDlgItem(窗口id)
b.postMessage(win32con.BM_CLICK)
#關閉窗體
import win32ui
import win32con
wnd=win32ui.FindWindow(classname,None)
wnd.SendMessage(win32con.WM_CLOSE) 成功!
import win32ui
w=win32ui.FindWindow(classname,窗體title)
print w.GetDlgItemText(0xFFFF) # 獲得彈窗里的消息文字
最小化窗體
w=win32gui.FindWindow()
win32gui.CloseWindow(w)
⑤ 如何用python控制windows彈出窗口
切換到新窗口,再定位元素
print browser.current_window_handle # 輸出當前窗口句柄(網路)
handles = browser.window_handles # 獲取當前窗口句柄集合(列表類型)
for handle in handles:# 切換窗口(切換到搜狗)
if handle!=browser.current_window_handle:
print 'switch to ',handle
browser.switch_to_window(handle)
print browser.current_window_handle # 輸出當前窗口句柄(搜狗)
break
⑥ 可以用python獲得別的進程的窗口句柄嗎
你拿到的是主窗口句柄,還需要搜索遍歷,找到子窗口或控制項。有些是自定義,只能通過位置定義。
⑦ python裡面,已經word和excle的窗口句柄,怎麼操作對應的excle和word
使用os.path.abspath()函數來獲取文件絕對路徑文件目錄結構如下: 解析假設app.py中想讀取config.ini文件的內容,首先app.py需要知道config.ini的文件路徑,從目錄結構上可以看出,config.ini與app.py的父目錄同級,也就是獲取到app.py父目錄(bin文件夾的路徑)的父目錄(config文件夾路徑)的絕對路徑再拼上config.ini文件名就能獲取到config.ini文件: 首先,在app.py中測試一下: import os def load_file(): # 獲取當前文件路徑 current_path = os.path.abspath(__file__) # 獲取當前文件的父目錄 father_path = os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".") # config.ini文件路徑,獲取當前目錄的父目錄的父目錄與congig.ini拼接 config_file_path=os.path.join(os.path.abspath(os.path.dirname(current_path) + os.path.sep + ".."),'config.ini') print('當前目錄:' + current_path) print('當前父目錄:' + father_path) print('config.ini路徑:' + config_file_path) load_file() 從結果中可以看到一切都正常,沒有什麼問題,假如現在需要從main.py中執行app.py的load_file()方法呢?來測試一下: main.py(處於同級目錄): from bin.app import load_file if __name__=='__main__': load_file() 可以看到,獲取的路徑是完全沒有問題的拓展內容 python os.path 常用模塊介紹
⑧ python如何抓取當前運行軟體的輸入框
算辦公自動化的一個應用。
先獲取窗口的句柄 >>遍歷窗口下的所有控制項>>通過輸入框的特徵,比如標識名稱,找到對應的輸入框>>操作輸入框屬性>>處理獲取新字元串>>通過sendpost返回給另一個輸入框
⑨ Python怎麼獲取不到子窗口的句柄呢,如圖,求指導,剛學習Python的小白吃,求指導
CSDN問答為您找到Python怎麼獲取不到子窗口的句柄呢,如圖,求指導相關問題答案,如果想了解更多關於Python怎麼獲取不到子窗口的句柄呢,如圖,求指導 python 技術問題等相關問答,請訪問CSDN問答。