Created
October 12, 2017 08:09
-
-
Save dev001hajipro/89092284ab31a0db5933065ace397650 to your computer and use it in GitHub Desktop.
Python3.6でメモ帳起動して、移動とリサイズをするサンプルスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
メモ帳起動して、移動 | |
# インストール | |
pip install pywin32 | |
pip install win32gui | |
* 疑問点 | |
pywin32 バージョン220でWin32APIが動作している。ただし、win32gui(221.6)を入れないと | |
PyCharmのimport文がエラーになる。 | |
# 動作確認 | |
Python 3.6.2 64bit | |
""" | |
import subprocess | |
import time | |
import win32gui | |
def main(): | |
# サブプロセス(メモ帳)の起動 | |
child_process = subprocess.Popen(r'c:\windows\system32\notepad.exe') | |
# プロセスチェック | |
print(child_process.poll()) | |
# ウェイト | |
time.sleep(1) | |
# メモ帳がフォアグラウンドにあるので、Win32APIのMoveWindowで(100,100)に移動し、500x500にリサイズ。 | |
hwnd = win32gui.GetForegroundWindow() | |
win32gui.MoveWindow(hwnd, 100, 100, 500, 500, True) | |
child_process.wait() | |
print('done.') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment