Skip to content

Instantly share code, notes, and snippets.

@dev001hajipro
Created October 12, 2017 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev001hajipro/89092284ab31a0db5933065ace397650 to your computer and use it in GitHub Desktop.
Save dev001hajipro/89092284ab31a0db5933065ace397650 to your computer and use it in GitHub Desktop.
Python3.6でメモ帳起動して、移動とリサイズをするサンプルスクリプト
#!/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