Python win32api 模块,SetWindowLong() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用win32api.SetWindowLong()

项目:code    作者:ActiveState    | 项目源码 | 文件源码
def __init__ (self):
        wx.Frame.__init__ (self, None, title="Clipboard viewer", size=(250,150))

        self.first   = True
        self.nextWnd = None

        # Get native window handle of this wxWidget Frame.
        self.hwnd    = self.GetHandle ()

        # Set the WndProc to our function.
        self.oldWndProc = win32gui.SetWindowLong (self.hwnd,
                                                  win32con.GWL_WNDPROC,
                                                  self.MyWndProc)

        try:
            self.nextWnd = win32clipboard.SetClipboardViewer (self.hwnd)
        except win32api.error:
            if win32api.GetLastError () == 0:
                # information that there is no other window in chain
                pass
            else:
                raise
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def MyWndProc (self, hWnd, msg, wParam, lParam):
        if msg == win32con.WM_CHANGECBCHAIN:
            self.OnChangeCBChain (msg, wParam, lParam)
        elif msg == win32con.WM_DRAWCLIPBOARD:
            self.OnDrawClipboard (msg, wParam, lParam)

        # Restore the old WndProc. Notice the use of win32api
        # instead of win32gui here. This is to avoid an error due to
        # not passing a callable object.
        if msg == win32con.WM_DESTROY:
            if self.nextWnd:
               win32clipboard.ChangeClipboardChain (self.hwnd, self.nextWnd)
            else:
               win32clipboard.ChangeClipboardChain (self.hwnd, 0)

            win32api.SetWindowLong (self.hwnd,
                                    win32con.GWL_WNDPROC,
                                    self.oldWndProc)

        # Pass all messages (in this case, yours may be different) on
        # to the original WndProc
        return win32gui.CallWindowProc (self.oldWndProc,
                                        hWnd, msg, wParam, lParam)
项目:grid    作者:russelg    | 项目源码 | 文件源码
def MakeTransparent(self, amount):
        if os.name == 'nt':  # could substitute: sys.platform == 'win32'
            hwnd = self.GetHandle()
            _winlib = win32api.LoadLibrary("user32")
            pSetLayeredWindowAttributes = win32api.GetProcAddress(
                _winlib, "SetLayeredWindowAttributes")
            if pSetLayeredWindowAttributes is None:
                return
            exstyle = win32api.GetWindowLong(hwnd, win32con.GWL_EXSTYLE)
            if 0 == (exstyle & 0x80000):
                exstyle |= win32con.WS_EX_LAYERED | win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_TRANSPARENT
                win32api.SetWindowLong(hwnd, win32con.GWL_EXSTYLE, exstyle)
            win32gui.SetLayeredWindowAttributes(hwnd, 0, amount, 2)
        else:
            print('####  OS Platform must be MS Windows')
            self.Destroy()
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def OnInitialUpdate(self):
        hwnd = self._obj_.GetSafeHwnd()
        style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
        win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style & ~commctrl.LVS_TYPEMASK) | commctrl.LVS_REPORT); 

        itemDetails = (commctrl.LVCFMT_LEFT, 100, "Name", 0)
        self.InsertColumn(0, itemDetails)
        itemDetails = (commctrl.LVCFMT_LEFT, 500, "Data", 0)
        self.InsertColumn(1, itemDetails)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def SetStyle(self, newStyle):
        hwnd = self.listControl.GetSafeHwnd()
        style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
        win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def OnInitialUpdate(self):
        hwnd = self._obj_.GetSafeHwnd()
        style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
        win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style & ~commctrl.LVS_TYPEMASK) | commctrl.LVS_REPORT); 

        itemDetails = (commctrl.LVCFMT_LEFT, 100, "Name", 0)
        self.InsertColumn(0, itemDetails)
        itemDetails = (commctrl.LVCFMT_LEFT, 500, "Data", 0)
        self.InsertColumn(1, itemDetails)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def SetStyle(self, newStyle):
        hwnd = self.listControl.GetSafeHwnd()
        style = win32api.GetWindowLong(hwnd, win32con.GWL_STYLE);
        win32api.SetWindowLong(hwnd, win32con.GWL_STYLE, (style | newStyle) )
项目:audio-visualizer-screenlet    作者:ninlith    | 项目源码 | 文件源码
def remove_taskbar_button(self):
        """Hide window from taskbar and ALT+TAB dialog."""
        win32gui.ShowWindow(self.hwnd, win32con.SW_HIDE)
        win32api.SetWindowLong(
            self.hwnd, win32con.GWL_EXSTYLE,
            win32api.GetWindowLong(self.hwnd, win32con.GWL_EXSTYLE)
            | win32con.WS_EX_NOACTIVATE
            | win32con.WS_EX_TOOLWINDOW)
        win32gui.ShowWindow(self.hwnd, win32con.SW_SHOW)
项目:fritzchecksum    作者:mementum    | 项目源码 | 文件源码
def WndProcManage(wnd):
        if not hasattr(wnd, 'GetHandle'):
            return False

        # Make a dictionary of message names to be used for printing below
        if PRINT_MESSAGES:
            msgdict = dict()
            for name in dir(win32con):
                if name.startswith('WM_'):
                    value = getattr(win32con, name)
                    msgdict[value] = name

        _oldWndProc = win32gui.GetWindowLong(wnd.GetHandle(),
                                             win32con.GWL_WNDPROC)

        def MyWndProc(self, hwnd, msg, wParam, lParam):
            # Display what we've got.
            if PRINT_MESSAGES:
                print (msgdict.get(msg), msg, wParam, lParam)

            # Restore the old WndProc.  Notice the use of win32api
            # instead of win32gui here.  This is to avoid an error due to
            # not passing a callable object.
            if msg == win32con.WM_DESTROY:
                win32api.SetWindowLong(self.GetHandle(),
                                       win32con.GWL_WNDPROC,
                                       _oldWndProc)

            stopproc = False
            for cb, cbtrigger in CALLBACKS[self]:
                if cbtrigger(self, msg, wParam, lParam):
                    if not cb(self, msg, wParam, lParam):
                        stopproc = True
                        break

            if stopproc:
                return
            # Pass all messages (in this case, yours may be different) on to
            # the original WndProc
            return win32gui.CallWindowProc(_oldWndProc,
                                           hwnd, msg,
                                           wParam,
                                           lParam)

        # Bind the function to the passed object
        _newWndProc = MyWndProc.__get__(wnd, wnd.__class__)

        # Set the WndProc to our function
        win32gui.SetWindowLong(wnd.GetHandle(),
                               win32con.GWL_WNDPROC,
                               _newWndProc)
        return True
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def EditValue(self, item):
        # Edit the current value
        class EditDialog(dialog.Dialog):
            def __init__(self, item):
                self.item = item
                dialog.Dialog.__init__(self, win32ui.IDD_LARGE_EDIT)
            def OnInitDialog(self):
                self.SetWindowText("Enter new value")
                self.GetDlgItem(win32con.IDCANCEL).ShowWindow(win32con.SW_SHOW)
                self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)
                # Modify the edit windows style
                style = win32api.GetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE)
                style = style & (~win32con.ES_WANTRETURN)
                win32api.SetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE, style)
                self.edit.SetWindowText(str(self.item))
                self.edit.SetSel(-1)
                return dialog.Dialog.OnInitDialog(self)
            def OnDestroy(self,msg):
                self.newvalue = self.edit.GetWindowText()

        try:
            index = self.GetNextItem(-1, commctrl.LVNI_SELECTED)
        except win32ui.error:
            return # No item selected.

        if index==0:
            keyVal = ""
        else:
            keyVal = self.GetItemText(index,0)
        # Query for a new value.
        try:
            newVal = self.GetItemsCurrentValue(item, keyVal)
        except TypeError, details:
            win32ui.MessageBox(details)
            return

        d = EditDialog(newVal)
        if d.DoModal()==win32con.IDOK:
            try:
                self.SetItemsCurrentValue(item, keyVal, d.newvalue)
            except win32api.error, exc:
                win32ui.MessageBox("Error setting value\r\n\n%s" % exc.strerror)
            self.UpdateForRegItem(item)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def EditValue(self, item):
        # Edit the current value
        class EditDialog(dialog.Dialog):
            def __init__(self, item):
                self.item = item
                dialog.Dialog.__init__(self, win32ui.IDD_LARGE_EDIT)
            def OnInitDialog(self):
                self.SetWindowText("Enter new value")
                self.GetDlgItem(win32con.IDCANCEL).ShowWindow(win32con.SW_SHOW)
                self.edit = self.GetDlgItem(win32ui.IDC_EDIT1)
                # Modify the edit windows style
                style = win32api.GetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE)
                style = style & (~win32con.ES_WANTRETURN)
                win32api.SetWindowLong(self.edit.GetSafeHwnd(), win32con.GWL_STYLE, style)
                self.edit.SetWindowText(str(self.item))
                self.edit.SetSel(-1)
                return dialog.Dialog.OnInitDialog(self)
            def OnDestroy(self,msg):
                self.newvalue = self.edit.GetWindowText()

        try:
            index = self.GetNextItem(-1, commctrl.LVNI_SELECTED)
        except win32ui.error:
            return # No item selected.

        if index==0:
            keyVal = ""
        else:
            keyVal = self.GetItemText(index,0)
        # Query for a new value.
        try:
            newVal = self.GetItemsCurrentValue(item, keyVal)
        except TypeError as details:
            win32ui.MessageBox(details)
            return

        d = EditDialog(newVal)
        if d.DoModal()==win32con.IDOK:
            try:
                self.SetItemsCurrentValue(item, keyVal, d.newvalue)
            except win32api.error as exc:
                win32ui.MessageBox("Error setting value\r\n\n%s" % exc.strerror)
            self.UpdateForRegItem(item)