How to capture MS-Windows messages in wxPython?

Hi,
     I encounter a problem that wxPython does not mapping all MS
Windows messages into wxEvents. For example, WM_DEVICECHANGE is a
standard Win32 message, but there is no corresponding part in
wxWidget/wxPython, something maybe names with wx.EVT_DEVICECHANGE. My
question is how to capture this event in wxPython framework.
    Well, I tried hard to find a way. Here are two:

Solution #1: (Failed)
    I'm using pyEventBinder to create a EVT_DEVICECHANGE

EVT_DEVICECHANGE = pyEventBinder(win32con.WM_DEVICECHANGE)

self.Bind(EVT_DEVICECHANGE, self.OnDeviceChange)
It does not work...because wxPython seems to map the raw message value
into some other things. For example:

wx.EVT_PAINT.evtType == 10095
raw message value WM_PAINT == 15

So what is the value of WM_DEVICECHANGE after mapping in wxPython? As
far as I know, there is no such mapping in wxWidget.

Solution #2: (Works but ugly...)
    I use win32api to call raw API SetWindowLong & CallWindowProc, in
order to get raw message before wxPython. :slight_smile:
class MyFrame...
    def __init__(self, parent):
        self.oldwndproc = win32gui.SetWindowLong(self.GetHandle()

, win32con.GWL_WNDPROC

, self.MyWndProc)
        ....
    def MyWndProc(self, hwnd, msg, wparam, lparam):
        if msg == win32con.WM_DEVICECHANGE:
            self.OnDeviceChange(wparam, lparam)
            return True
        return win32gui.CallWindowProc(self.oldwndproc, hwnd, msg,
wparam, lparam)

Is there any better or standard way to do that?

Thank you!

···

---
ShenLei

甜瓜 wrote:

Hi,
     I encounter a problem that wxPython does not mapping all MS
Windows messages into wxEvents. For example, WM_DEVICECHANGE is a
standard Win32 message, but there is no corresponding part in
wxWidget/wxPython, something maybe names with wx.EVT_DEVICECHANGE. My
question is how to capture this event in wxPython framework.
    Well, I tried hard to find a way. Here are two:

Solution #1: (Failed)
    I'm using pyEventBinder to create a EVT_DEVICECHANGE

EVT_DEVICECHANGE = pyEventBinder(win32con.WM_DEVICECHANGE)

self.Bind(EVT_DEVICECHANGE, self.OnDeviceChange)
It does not work...because wxPython seems to map the raw message value
into some other things. For example:

wx.EVT_PAINT.evtType == 10095
raw message value WM_PAINT == 15

So what is the value of WM_DEVICECHANGE after mapping in wxPython? As
far as I know, there is no such mapping in wxWidget.

Solution #2: (Works but ugly...)
    I use win32api to call raw API SetWindowLong & CallWindowProc, in
order to get raw message before wxPython. :slight_smile:

Is there any better or standard way to do that?

That is the standard way to do it. See HookingTheWndProc - wxPyWiki (It even mentions WM_DEVICECHANGE)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Oh~ Thank you very much. This article is really helpful!!

···

---
ShenLei