Admin | Write | GuestBook
[공지] 해당 블로그에 용건이 있으신 분께서는 http://blog.fore.kr/ 의 방명록(Guestbook)으로 부탁드립니다.
[Python] 윈도우 다이어로그 생성

 

[やったぜ!]

 

파이썬으로 윈도우에서 윈도우(혹은 다이어로그)를 생성할 수 있을까 . . .

 

사용자가 만든 템플릿을 쓰면 매우 간단하게 풀리겠지만, 오기로 ctypes 에서 직접 함수를 불러와

 

직접 구현해보았다. (디짐 -_-...)

 

"""
Show Dialog in Python 2.7
Present by FORE
http://foreblog.tistory.com/
"""

 

from ctypes import *
from ctypes.wintypes import *
from msvcrt import *

 

# define win32 api function
DialogBoxIndirectParamW = windll.user32.DialogBoxIndirectParamW
PostQuitMessage = windll.user32.PostQuitMessage
DestroyWindow = windll.user32.DestroyWindow
EndDialog = windll.user32.EndDialog
CreateWindowExW = windll.user32.CreateWindowExW
SetWindowTextW = windll.user32.SetWindowTextW
GetClientRect = windll.user32.GetClientRect

GetModuleHandleW = windll.kernel32.GetModuleHandleW

 

# define callback function type
DLGPROC = WINFUNCTYPE(c_uint, HWND, c_uint, WPARAM, LPARAM)

 

# define window style
WS_VISIBLE = 0x10000000
WS_POPUP = 0x80000000
WS_CAPTION = 0x00C00000
WS_SYSMENU = 0x00080000
WS_CHILD = 0x40000000

 

# define window message
WM_INITDIALOG = 0x0110
WM_CLOSE = 0x0010
WM_DESTROY = 0x0002

 

# define structure
class DLGTEMPLATE(Structure):
 _fields_ = [
 ('style',c_uint),
 ('dwExtendedStyle',c_uint),
 ('cdit',c_ushort),
 ('x',c_short),
 ('y',c_short),
 ('cx',c_short),
 ('cy',c_short),
 ('id',c_uint)
 ]

 

# define callback function
def cb_wndproc(hwnd,msg,wparam,lparam):
 if msg == WM_INITDIALOG:
  SetWindowTextW(hwnd,u'Python Dialog')
  r = RECT()
  GetClientRect(hwnd,r)
  CreateWindowExW(0,u'Static',u'Show',WS_CHILD|WS_VISIBLE,(r.right-50)/2,(r.bottom-30)/2,50,30,hwnd,0,0,0)
  del r
 elif msg == WM_CLOSE:
  DestroyWindow(hwnd)
 elif msg == WM_DESTROY:
  EndDialog(hwnd,0)
 return 0

 

# Start
dtp = DLGTEMPLATE()
memset(byref(dtp),0,sizeof(DLGTEMPLATE))
dtp.style = WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU
dtp.cx = 100
dtp.cy = 100

hInstance = GetModuleHandleW(0);
DialogBoxIndirectParamW(hInstance,byref(dtp),0,DLGPROC(cb_wndproc),0)

 

 

Dialog.py

 

 

뭐 이건 . . . 하나하나 다 로딩해줘야함 -_- ;

 

※ 스크립트 복사해서 파이썬 스크립터 내에서 직접 돌리고자 할 경우

hInstance 부분을 직접 불러줘야 한다. ( 아직도 왜그런지 이유를 못찾고 있음... )

 

애니, 미연시, 프로그래밍 관련 블로그
Category
분류 전체보기 (605)
Notice (6)
About Me (1)
Programming (79)
Release Program (19)
Release Patch (14)
Programming Talk (46)
DISKER (1)
Release (1)
FSCH (7)
Core Release (1)
Plugin Release (6)
Dev. (0)
Caption (0)
러브 라이브 ! 1기 (0)
러브 라이브 ! 2기 (0)
B형 H계 (0)
프린세스 러버 ! (0)
etc... (0)
Rest Time ! (443)
Monologue (412)
Copy to Posting~ (31)
Hobby (64)
MYS-☆ (27)
Mahjong (12)
Animation (3)
Light Novel (0)
Blog skin (22)
Tour (5)
2013 Feb in Tokyo (5)
2014 Working Holiday JP (0)
2015 Aug in Tokyo (0)
2016 Dec in Osaka (0)
Blind Post (0)
Recent Post
Recent Comment
Link
Calender
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Total :
Today :
Yesterday :