def start(self): print("[log] start") wndproc = { # win32con.WM_PAINT: self.OnPaint, win32con.WM_CLOSE: self.OnClose, win32con.WM_CREATE: self.OnCreate, win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard, # copy # win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain, } wc = win32gui.WNDCLASS() wc.lpszClassName = 'app_clipboard' wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW + 1 wc.lpfnWndProc = wndproc class_atom = win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindowEx( 0, class_atom, u'分享链接', win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.WS_THICKFRAME | win32con.WS_SYSMENU, 100, 100, 600, 400, 0, 0, 0, None) win32clipboard.SetClipboardViewer(hwnd) win32gui.PumpMessages() win32gui.UnregisterClass(class_atom, None) win32clipboard.OpenClipboard() win32clipboard.EmptyClipboard() win32clipboard.CloseClipboard()
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
def go(self): wndproc = { win32con.WM_PAINT: self.OnPaint, win32con.WM_CLOSE: self.OnClose, win32con.WM_CREATE: self.OnCreate, win32con.WM_DRAWCLIPBOARD: self.OnDrawClipboard, win32con.WM_CHANGECBCHAIN: self.OnChangeCBChain, } wc = win32gui.WNDCLASS() wc.lpszClassName = "test_win32clipboard_bmp" wc.style = win32con.CS_GLOBALCLASS | win32con.CS_VREDRAW | win32con.CS_HREDRAW wc.hbrBackground = win32con.COLOR_WINDOW + 1 wc.lpfnWndProc = wndproc class_atom = win32gui.RegisterClass(wc) hwnd = win32gui.CreateWindowEx( 0, class_atom, "ClipboardViewer", win32con.WS_CAPTION | win32con.WS_VISIBLE | win32con.WS_THICKFRAME | win32con.WS_SYSMENU, 100, 100, 900, 900, 0, 0, 0, None, ) win32clipboard.SetClipboardViewer(hwnd) win32gui.PumpMessages() win32gui.UnregisterClass(class_atom, None)
def registerClipboardCallback( self ): self.hPrev = None self.window = win = win32ui.CreateFrame() win.CreateWindow( None, '', win32con.WS_OVERLAPPEDWINDOW ) win.HookMessage( self.onDrawClipboard, win32con.WM_DRAWCLIPBOARD ) win.HookMessage( self.onChangeClipboardChain, win32con.WM_CHANGECBCHAIN ) try: self.hPrev = win32clipboard.SetClipboardViewer( win.GetSafeHwnd() ) except win32api.error, err: if err.args[0]: raise
def StartListen(self): self.first = True self.text = None self.change = True try: self.hPrev = win32clipboard.SetClipboardViewer( self.win.GetSafeHwnd()) except win32api.error, err: if win32api.GetLastError() == 0: # information that there is no other window in chain pass else: raise
def __init__(self): wx.Frame.__init__(self, None, title="Clipboard viewer", size=(450, 150)) self.first = True self.nextWnd = None self.hwnd = self.GetHandle() self.oldWndProc = win32gui.SetWindowLong(self.hwnd, win32con.GWL_WNDPROC, self.MyWndProc) self.data_list = [] self.clipboard = wx.Clipboard() try: self.nextWnd = win32clipboard.SetClipboardViewer(self.hwnd) except win32api.error: if win32api.GetLastError() == 0: pass else: raise
# if btxt.find('http') != -1: # btxt = btxt[btxt.find('http'):] WCB.CloseClipboard() except Exception as e: print("error:", e) # finally: ok = False # 依次尝试打印Unicode和字节码,ok是打印成功标志位 if utxt: try: if utxt.find('http') != -1: utxt = utxt[utxt.find('http'):] print("UNICODE:", utxt) ok = True except Exception as e: print(u'UNICODE打印失败:', e) if btxt and not ok: try: print("GBK:", btxt.decode('gbk')) except Exception as e: print(u'GBK打印失败:', e) return win32gui.DefWindowProc(hwnd, msg, wParam, lParam) if __name__ == '__main__': mw = MyWindow() WCB.SetClipboardViewer(mw.hwnd) # 注册为剪切板监听窗口 win32gui.PumpMessages()
def SetClipboardViewer(hwnd): #------------------------------------------------------------------------------- try: return wcb.SetClipboardViewer(hwnd) except: return 0