def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
if lparam==win32con.WM_RBUTTONUP:
print "You right clicked me."
# display the menu at the cursor pos.
pos = GetCursorPos()
SetForegroundWindow(self.hwnd)
TrackPopupMenu(self.hmenu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
elif lparam==win32con.WM_LBUTTONDBLCLK:
print "You double-clicked me"
# find the default menu item and fire it.
cmd = GetMenuDefaultItem(self.hmenu, False, 0)
if cmd == -1:
print "Can't find a default!"
# and just pretend it came from the menu
self.OnCommand(hwnd, win32con.WM_COMMAND, cmd, 0)
return 1
python类WM_COMMAND的实例源码
def get_new_desktop_name(parent_hwnd):
""" Create a dialog box to ask the user for name of desktop to be created """
msgs={win32con.WM_COMMAND:desktop_name_dlgproc,
win32con.WM_CLOSE:desktop_name_dlgproc,
win32con.WM_DESTROY:desktop_name_dlgproc}
# dlg item [type, caption, id, (x,y,cx,cy), style, ex style
style=win32con.WS_BORDER|win32con.WS_VISIBLE|win32con.WS_CAPTION|win32con.WS_SYSMENU ## |win32con.DS_SYSMODAL
h=win32gui.CreateDialogIndirect(
win32api.GetModuleHandle(None),
[['One ugly dialog box !',(100,100,200,100),style,0],
['Button','Create', win32con.IDOK, (10,10,30,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW|win32con.BS_DEFPUSHBUTTON],
['Button','Never mind', win32con.IDCANCEL, (45,10,50,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW],
['Static','Desktop name:',71,(10,40,70,10),win32con.WS_VISIBLE],
['Edit','',72,(75,40,90,10),win32con.WS_VISIBLE]],
parent_hwnd, msgs) ## parent_hwnd, msgs)
win32gui.EnableWindow(h,True)
hcontrol=win32gui.GetDlgItem(h,72)
win32gui.EnableWindow(hcontrol,True)
win32gui.SetFocus(hcontrol)
def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):
if lparam==win32con.WM_RBUTTONUP:
print("You right clicked me.")
# display the menu at the cursor pos.
pos = GetCursorPos()
SetForegroundWindow(self.hwnd)
TrackPopupMenu(self.hmenu, win32con.TPM_LEFTALIGN, pos[0], pos[1], 0, self.hwnd, None)
PostMessage(self.hwnd, win32con.WM_NULL, 0, 0)
elif lparam==win32con.WM_LBUTTONDBLCLK:
print("You double-clicked me")
# find the default menu item and fire it.
cmd = GetMenuDefaultItem(self.hmenu, False, 0)
if cmd == -1:
print("Can't find a default!")
# and just pretend it came from the menu
self.OnCommand(hwnd, win32con.WM_COMMAND, cmd, 0)
return 1
def get_new_desktop_name(parent_hwnd):
""" Create a dialog box to ask the user for name of desktop to be created """
msgs={win32con.WM_COMMAND:desktop_name_dlgproc,
win32con.WM_CLOSE:desktop_name_dlgproc,
win32con.WM_DESTROY:desktop_name_dlgproc}
# dlg item [type, caption, id, (x,y,cx,cy), style, ex style
style=win32con.WS_BORDER|win32con.WS_VISIBLE|win32con.WS_CAPTION|win32con.WS_SYSMENU ## |win32con.DS_SYSMODAL
h=win32gui.CreateDialogIndirect(
win32api.GetModuleHandle(None),
[['One ugly dialog box !',(100,100,200,100),style,0],
['Button','Create', win32con.IDOK, (10,10,30,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW|win32con.BS_DEFPUSHBUTTON],
['Button','Never mind', win32con.IDCANCEL, (45,10,50,20),win32con.WS_VISIBLE|win32con.WS_TABSTOP|win32con.BS_HOLLOW],
['Static','Desktop name:',71,(10,40,70,10),win32con.WS_VISIBLE],
['Edit','',72,(75,40,90,10),win32con.WS_VISIBLE]],
parent_hwnd, msgs) ## parent_hwnd, msgs)
win32gui.EnableWindow(h,True)
hcontrol=win32gui.GetDlgItem(h,72)
win32gui.EnableWindow(hcontrol,True)
win32gui.SetFocus(hcontrol)
def __init__(self, netkeeper):
msg_TaskbarRestart = win32gui.RegisterWindowMessage("NKService")
message_map = {
msg_TaskbarRestart: self.OnRestart,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_USER + 20: self.OnTaskbarNotify,
}
# ?????
wndclass = win32gui.WNDCLASS()
hinst = wndclass.hInstance = win32api.GetModuleHandle(None)
wndclass.lpszClassName = "NetkeeperTrayIcon"
wndclass.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
wndclass.hCursor = win32api.LoadCursor(0, win32con.IDC_ARROW)
wndclass.hbrBackground = win32con.COLOR_WINDOW
wndclass.lpfnWndProc = message_map
try:
classAtom = win32gui.RegisterClass(wndclass)
except win32gui.error, err_info:
if err_info.winerror != winerror.ERROR_CLASS_ALREADY_EXISTS:
raise
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(wndclass.lpszClassName, 'NetKeeper Service', style, 0, 0,
win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, 0, 0, hinst, None)
win32gui.UpdateWindow(self.hwnd)
self.netkeeper = netkeeper
self._createIcon()
def _CreateMainWindow(self, prev, settings, browser, rect):
# Creates a parent window that hosts the view window. This window
# gets the control notifications etc sent from the child.
style = win32con.WS_CHILD | win32con.WS_VISIBLE #
wclass_name = "ShellViewDemo_DefView"
# Register the Window class.
wc = win32gui.WNDCLASS()
wc.hInstance = win32gui.dllhandle
wc.lpszClassName = wclass_name
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
try:
win32gui.RegisterClass(wc)
except win32gui.error, details:
# Should only happen when this module is reloaded
if details[0] != winerror.ERROR_CLASS_ALREADY_EXISTS:
raise
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_NOTIFY: self.OnNotify,
win32con.WM_CONTEXTMENU: self.OnContextMenu,
win32con.WM_SIZE: self.OnSize,
}
self.hwnd = win32gui.CreateWindow( wclass_name, "", style, \
rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1],
self.hwnd_parent, 0, win32gui.dllhandle, None)
win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map)
print "View 's hwnd is", self.hwnd
return self.hwnd
def __init__(self,
icon,
hover_text,
menu_options,
on_quit=None,
default_menu_index=None,
window_class_name=None, wnd=None,):
self.icon = icon
self.hover_text = hover_text
self.on_quit = on_quit
menu_options = menu_options + (('Quit', None, self.QUIT),)
self._next_action_id = self.FIRST_ID
self.menu_actions_by_id = set()
self.menu_options = self._add_ids_to_menu_options(list(menu_options))
self.menu_actions_by_id = dict(self.menu_actions_by_id)
del self._next_action_id
self.wnd = wnd
self.default_menu_index = (default_menu_index or 0)
self.window_class_name = window_class_name or "SysTrayIconPy"
message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
win32con.WM_DESTROY: self.destroy,
win32con.WM_COMMAND: self.command,
win32con.WM_USER+20 : self.notify,}
# Register the Window class.
window_class = win32gui.WNDCLASS()
hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
window_class.lpszClassName = self.window_class_name
window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
window_class.hbrBackground = win32con.COLOR_WINDOW
window_class.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = win32gui.RegisterClass(window_class)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(classAtom,
self.window_class_name,
style,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None)
win32gui.UpdateWindow(self.hwnd)
self.notify_id = None
self.refresh_icon()
win32gui.PumpMessages()
def _CreateMainWindow(self, prev, settings, browser, rect):
# Creates a parent window that hosts the view window. This window
# gets the control notifications etc sent from the child.
style = win32con.WS_CHILD | win32con.WS_VISIBLE #
wclass_name = "ShellViewDemo_DefView"
# Register the Window class.
wc = win32gui.WNDCLASS()
wc.hInstance = win32gui.dllhandle
wc.lpszClassName = wclass_name
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
try:
win32gui.RegisterClass(wc)
except win32gui.error, details:
# Should only happen when this module is reloaded
if details[0] != winerror.ERROR_CLASS_ALREADY_EXISTS:
raise
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_NOTIFY: self.OnNotify,
win32con.WM_CONTEXTMENU: self.OnContextMenu,
win32con.WM_SIZE: self.OnSize,
}
self.hwnd = win32gui.CreateWindow( wclass_name, "", style, \
rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1],
self.hwnd_parent, 0, win32gui.dllhandle, None)
win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map)
print "View 's hwnd is", self.hwnd
return self.hwnd
def __init__(self):
msg_TaskbarRestart = win32gui.RegisterWindowMessage("TaskbarCreated");
message_map = {
msg_TaskbarRestart: self.OnRestart,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_USER+20 : self.OnTaskbarNotify,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbarDemo"
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
wc.hCursor = win32api.LoadCursor( 0, win32con.IDC_ARROW )
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpfnWndProc = message_map # could also specify a wndproc.
# Don't blow up if class already registered to make testing easier
try:
classAtom = win32gui.RegisterClass(wc)
except win32gui.error, err_info:
if err_info.winerror!=winerror.ERROR_CLASS_ALREADY_EXISTS:
raise
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow( wc.lpszClassName, "Taskbar Demo", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
win32gui.UpdateWindow(self.hwnd)
self._DoCreateIcons()
def _DoCreate(self, fn):
message_map = {
win32con.WM_SIZE: self.OnSize,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_NOTIFY: self.OnNotify,
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
win32con.WM_DESTROY: self.OnDestroy,
WM_SEARCH_RESULT: self.OnSearchResult,
WM_SEARCH_FINISHED: self.OnSearchFinished,
}
dlgClassName = self._RegisterWndClass()
template = self._GetDialogTemplate(dlgClassName)
return fn(self.hinst, template, 0, message_map)
def _DoCreate(self, fn):
message_map = {
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
}
return fn(0, self.dlg_template, 0, message_map)
def __call__(self, *args):
win32ui.GetMainFrame().SendMessage(win32con.WM_COMMAND, self.cmd)
def _CreateMainWindow(self, prev, settings, browser, rect):
# Creates a parent window that hosts the view window. This window
# gets the control notifications etc sent from the child.
style = win32con.WS_CHILD | win32con.WS_VISIBLE #
wclass_name = "ShellViewDemo_DefView"
# Register the Window class.
wc = win32gui.WNDCLASS()
wc.hInstance = win32gui.dllhandle
wc.lpszClassName = wclass_name
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
try:
win32gui.RegisterClass(wc)
except win32gui.error as details:
# Should only happen when this module is reloaded
if details[0] != winerror.ERROR_CLASS_ALREADY_EXISTS:
raise
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_NOTIFY: self.OnNotify,
win32con.WM_CONTEXTMENU: self.OnContextMenu,
win32con.WM_SIZE: self.OnSize,
}
self.hwnd = win32gui.CreateWindow( wclass_name, "", style, \
rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1],
self.hwnd_parent, 0, win32gui.dllhandle, None)
win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, message_map)
print("View 's hwnd is", self.hwnd)
return self.hwnd
def __call__(self, *args):
win32ui.GetMainFrame().SendMessage(win32con.WM_COMMAND, self.cmd)
def desktop_name_dlgproc(hwnd,msg,wparam,lparam):
""" Handles messages from the desktop name dialog box """
if msg in (win32con.WM_CLOSE,win32con.WM_DESTROY):
win32gui.DestroyWindow(hwnd)
elif msg == win32con.WM_COMMAND:
if wparam == win32con.IDOK:
desktop_name=win32gui.GetDlgItemText(hwnd, 72)
print('new desktop name: ',desktop_name)
win32gui.DestroyWindow(hwnd)
create_desktop(desktop_name)
elif wparam == win32con.IDCANCEL:
win32gui.DestroyWindow(hwnd)
def _DoCreate(self, fn):
message_map = {
win32con.WM_SIZE: self.OnSize,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_NOTIFY: self.OnNotify,
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
win32con.WM_DESTROY: self.OnDestroy,
WM_SEARCH_RESULT: self.OnSearchResult,
WM_SEARCH_FINISHED: self.OnSearchFinished,
}
dlgClassName = self._RegisterWndClass()
template = self._GetDialogTemplate(dlgClassName)
return fn(self.hinst, template, 0, message_map)
def _DoCreate(self, fn):
message_map = {
win32con.WM_INITDIALOG: self.OnInitDialog,
win32con.WM_CLOSE: self.OnClose,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
}
return fn(0, self.dlg_template, 0, message_map)
def _sendNotifyMessage(hwnd, nofifyMessage):
"""Send a notify message to a control."""
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def __init__(self):
self.QUIT = 'QUIT'
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.command,
win32con.WM_USER+20 : self.notify,
}
# Register the Window class.
wc = WNDCLASS()
hinst = wc.hInstance = GetModuleHandle(None)
wc.lpszClassName = "PythonTaskbar"
wc.lpfnWndProc = message_map
classAtom = RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = CreateWindow( classAtom, "Taskbar", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
UpdateWindow(self.hwnd)
iconPathName = os.path.abspath(os.path.join( sys.path[0], 'systray.ico'))
icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE
try:
hicon = LoadImage(hinst, iconPathName, \
win32con.IMAGE_ICON, 0, 0, icon_flags)
except:
hicon = LoadIcon(0, win32con.IDI_APPLICATION)
flags = NIF_ICON | NIF_MESSAGE | NIF_TIP
nid = (self.hwnd, 0, flags, win32con.WM_USER+20, hicon, "SysTrayExample")
Shell_NotifyIcon(NIM_ADD, nid)
def upload_by_win32(self, files):
"""win32?? —— ????????????????????files????list?"""
self._window_open()
self._files(files)
self.logger.info('upload {0} by win32'.format(self.files))
upload = win32gui.FindWindow('#32770', self.window_name)
# find Edit
ComboBoxEx32 = win32gui.FindWindowEx(upload, 0, 'ComboBoxEx32', None)
ComboBox = win32gui.FindWindowEx(ComboBoxEx32, 0, 'ComboBox', None)
Edit = win32gui.FindWindowEx(ComboBox, 0, 'Edit', None)
# find confirm button
button = win32gui.FindWindowEx(upload, 0, 'Button', None)
# ????????
if upload and Edit and button:
self.window_open_flag = 1
else:
raise UploadWindowNotOpenError('???????????')
win32gui.SendMessage(Edit, win32con.WM_SETTEXT, 0, self.files)
win32gui.SendMessage(upload, win32con.WM_COMMAND, 1, button)
self.window_open_flag = 0
winGuiAuto_bak.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
winGuiAuto.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def _sendNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.SendMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def _postNotifyMessage(hwnd, nofifyMessage):
'''Send a notify message to a control.'''
win32gui.PostMessage(win32gui.GetParent(hwnd),
win32con.WM_COMMAND,
_buildWinLong(nofifyMessage,
win32api.GetWindowLong(hwnd,
win32con.GWL_ID)),
hwnd)
def __init__(self, iconPath=None):
self.iconPath = iconPath
self.status = []
msg_TaskbarRestart = \
win32api.RegisterWindowMessage('TaskbarCreated')
message_map = {
msg_TaskbarRestart: self.OnRestart,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_USER + 20: self.OnTaskbarNotify,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = 'web2pyTaskbar'
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = win32gui.RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(
classAtom,
'web2pyTaskbar',
style,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None,
)
win32gui.UpdateWindow(self.hwnd)
self.SetServerStopped()
def __init__(self,
icon,
hover_text,
menu_options,
on_quit=None,
default_menu_index=None,
window_class_name=None, ):
self.icon = icon
self.hover_text = hover_text
self.on_quit = on_quit
menu_options = menu_options + (('Quit', None, self.QUIT),)
self._next_action_id = self.FIRST_ID
self.menu_actions_by_id = set()
self.menu_options = self._add_ids_to_menu_options(list(menu_options))
self.menu_actions_by_id = dict(self.menu_actions_by_id)
del self._next_action_id
self.default_menu_index = (default_menu_index or 0)
self.window_class_name = window_class_name or "SysTrayIconPy"
message_map = {win32gui.RegisterWindowMessage("TaskbarCreated"): self.restart,
win32con.WM_DESTROY: self.destroy,
win32con.WM_COMMAND: self.command,
win32con.WM_USER + 20: self.notify, }
# Register the Window class.
window_class = win32gui.WNDCLASS()
hinst = window_class.hInstance = win32gui.GetModuleHandle(None)
window_class.lpszClassName = self.window_class_name
window_class.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW;
window_class.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
window_class.hbrBackground = win32con.COLOR_WINDOW
window_class.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = win32gui.RegisterClass(window_class)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(classAtom,
self.window_class_name,
style,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None)
win32gui.UpdateWindow(self.hwnd)
self.notify_id = None
self.refresh_icon()
win32gui.PumpMessages()
def __init__(self):
message_map = {
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_SIZE: self.OnSize,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = "test_explorer_browser"
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = win32gui.RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPEDWINDOW | win32con.WS_VISIBLE
self.hwnd = win32gui.CreateWindow( classAtom, "Python IExplorerBrowser demo", style, \
0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \
0, 0, hinst, None)
eb = pythoncom.CoCreateInstance(shellcon.CLSID_ExplorerBrowser, None, pythoncom.CLSCTX_ALL, shell.IID_IExplorerBrowser)
# as per MSDN docs, hook up events early
self.event_cookie = eb.Advise(wrap(EventHandler()))
eb.SetOptions(shellcon.EBO_SHOWFRAMES)
rect = win32gui.GetClientRect(self.hwnd)
# Set the flags such that the folders autoarrange and non web view is presented
flags = (shellcon.FVM_LIST, shellcon.FWF_AUTOARRANGE | shellcon.FWF_NOWEBVIEW)
eb.Initialize(self.hwnd, rect, (0, shellcon.FVM_DETAILS))
if len(sys.argv)==2:
# If an arg was specified, ask the desktop parse it.
# You can pass anything explorer accepts as its '/e' argument -
# eg, "::{guid}\::{guid}" etc.
# "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" is "My Computer"
pidl = shell.SHGetDesktopFolder().ParseDisplayName(0, None, sys.argv[1])[1]
else:
# And start browsing at the root of the namespace.
pidl = []
eb.BrowseToIDList(pidl, shellcon.SBSP_ABSOLUTE)
# and for some reason the "Folder" view in the navigator pane doesn't
# magically synchronize itself - so let's do that ourself.
# Get the tree control.
sp = eb.QueryInterface(pythoncom.IID_IServiceProvider)
try:
tree = sp.QueryService(shell.IID_INameSpaceTreeControl,
shell.IID_INameSpaceTreeControl)
except pythoncom.com_error, exc:
# this should really only fail if no "nav" frame exists...
print "Strange - failed to get the tree control even though " \
"we asked for a EBO_SHOWFRAMES"
print exc
else:
# get the IShellItem for the selection.
si = shell.SHCreateItemFromIDList(pidl, shell.IID_IShellItem)
# set it to selected.
tree.SetItemState(si, shellcon.NSTCIS_SELECTED, shellcon.NSTCIS_SELECTED)
#eb.FillFromObject(None, shellcon.EBF_NODROPTARGET);
#eb.SetEmptyText("No known folders yet...");
self.eb = eb
def SetSite(self,unknown):
if unknown:
# retrieve the parent window interface for this site
olewindow = unknown.QueryInterface(pythoncom.IID_IOleWindow)
# ask the window for its handle
hwndparent = olewindow.GetWindow()
# first get a command target
cmdtarget = unknown.QueryInterface(axcontrol.IID_IOleCommandTarget)
# then travel over to a service provider
serviceprovider = cmdtarget.QueryInterface(pythoncom.IID_IServiceProvider)
# finally ask for the internet explorer application, returned as a dispatch object
self.webbrowser = win32com.client.Dispatch(serviceprovider.QueryService('{0002DF05-0000-0000-C000-000000000046}',pythoncom.IID_IDispatch))
# now create and set up the toolbar
self.toolbar = IEToolbarCtrl(hwndparent)
buttons = [
('Visit PyWin32 Homepage',self.on_first_button),
('Another Button', self.on_second_button),
('Yet Another Button', self.on_third_button),
]
self._command_map = {}
# wrap our parent window so we can hook message handlers
window = win32ui.CreateWindowFromHandle(hwndparent)
# add the buttons
for i in range(len(buttons)):
button = TBBUTTON()
name,func = buttons[i]
id = 0x4444+i
button.iBitmap = -2
button.idCommand = id
button.fsState = commctrl.TBSTATE_ENABLED
button.fsStyle = commctrl.TBSTYLE_BUTTON
button.iString = name
self._command_map[0x4444+i] = func
self.toolbar.AddButtons(button)
window.HookMessage(self.toolbar_command_handler,win32con.WM_COMMAND)
else:
# lose all references
self.webbrowser = None
def __init__(self, iconPath=None):
self.iconPath = iconPath
self.status = []
msg_TaskbarRestart = \
win32api.RegisterWindowMessage('TaskbarCreated')
message_map = {
msg_TaskbarRestart: self.OnRestart,
win32con.WM_DESTROY: self.OnDestroy,
win32con.WM_COMMAND: self.OnCommand,
win32con.WM_USER + 20: self.OnTaskbarNotify,
}
# Register the Window class.
wc = win32gui.WNDCLASS()
hinst = wc.hInstance = win32api.GetModuleHandle(None)
wc.lpszClassName = 'web2pyTaskbar'
wc.style = win32con.CS_VREDRAW | win32con.CS_HREDRAW
wc.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
wc.hbrBackground = win32con.COLOR_WINDOW
wc.lpfnWndProc = message_map # could also specify a wndproc.
classAtom = win32gui.RegisterClass(wc)
# Create the Window.
style = win32con.WS_OVERLAPPED | win32con.WS_SYSMENU
self.hwnd = win32gui.CreateWindow(
classAtom,
'web2pyTaskbar',
style,
0,
0,
win32con.CW_USEDEFAULT,
win32con.CW_USEDEFAULT,
0,
0,
hinst,
None,
)
win32gui.UpdateWindow(self.hwnd)
self.SetServerStopped()
def SetSite(self,unknown):
if unknown:
# retrieve the parent window interface for this site
olewindow = unknown.QueryInterface(pythoncom.IID_IOleWindow)
# ask the window for its handle
hwndparent = olewindow.GetWindow()
# first get a command target
cmdtarget = unknown.QueryInterface(axcontrol.IID_IOleCommandTarget)
# then travel over to a service provider
serviceprovider = cmdtarget.QueryInterface(pythoncom.IID_IServiceProvider)
# finally ask for the internet explorer application, returned as a dispatch object
self.webbrowser = win32com.client.Dispatch(serviceprovider.QueryService('{0002DF05-0000-0000-C000-000000000046}',pythoncom.IID_IDispatch))
# now create and set up the toolbar
self.toolbar = IEToolbarCtrl(hwndparent)
buttons = [
('Visit PyWin32 Homepage',self.on_first_button),
('Another Button', self.on_second_button),
('Yet Another Button', self.on_third_button),
]
self._command_map = {}
# wrap our parent window so we can hook message handlers
window = win32ui.CreateWindowFromHandle(hwndparent)
# add the buttons
for i in range(len(buttons)):
button = TBBUTTON()
name,func = buttons[i]
id = 0x4444+i
button.iBitmap = -2
button.idCommand = id
button.fsState = commctrl.TBSTATE_ENABLED
button.fsStyle = commctrl.TBSTYLE_BUTTON
button.iString = name
self._command_map[0x4444+i] = func
self.toolbar.AddButtons(button)
window.HookMessage(self.toolbar_command_handler,win32con.WM_COMMAND)
else:
# lose all references
self.webbrowser = None