1. kankri
  2. pylaunchy

Commits

kshahar  committed 9af34ad

Fixed unicode encoding for window titles

  • Participants
  • Parent commits b42c775
  • Branches default

Comments (0)

Files changed (1)

File plugins/pygo-y.py

View file
  • Ignore whitespace
-# Copyright (c) 2008 Shahar Kosti <kshahar@users.sourceforge.net>
+# Copyright (c) 2008-2010 Shahar Kosti <kshahar@users.sourceforge.net>
 # Copyright (c) 2010 Risto Kankkunen <risto.kankkunen@iki.fi>
 #
 # This program is free software; you can redistribute it and/or modify it under
 import win32gui
 from win32con import SW_SHOW, SW_RESTORE, SW_SHOWMINIMIZED
 import ctypes
-from ctypes.wintypes import HWND, LPWSTR, UINT
-
-ACP = 'cp%d'%ctypes.windll.kernel32.GetACP()
+from ctypes.wintypes import HWND, LPWSTR, UINT, c_wchar
 
 GetWindowThreadProcessId = ctypes.windll.user32.GetWindowThreadProcessId
 def GetWindowProcess(hwnd):
 
 	return hIcon
 
+GetWindowTextW = ctypes.windll.user32.GetWindowTextW
+def GetWindowText(hwnd):
+	buffer_max_len = 1024
+	buffer = (c_wchar * buffer_max_len)()
+	length = GetWindowTextW(hwnd, byref(buffer), buffer_max_len)
+	if length>0:
+		return unicode(buffer.value)
+	else:
+		return u''
+
 from PyQt4 import QtCore, QtGui
 import hashlib
 
 		):
 			return
 		
-		title = unicode(win32gui.GetWindowText(hwnd), ACP)
+		title = GetWindowText(hwnd)
+		
 		path = GetProcessFilename(GetWindowProcess(hwnd))
 		descrs = getFileDescriptions(path)
 		if (is_match((title, os.path.basename(path)) + descrs)):