""" 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)
|