Back to index

python3.2  3.2.2
wintypes.py
Go to the documentation of this file.
00001 # The most useful windows datatypes
00002 import ctypes
00003 
00004 BYTE = ctypes.c_byte
00005 WORD = ctypes.c_ushort
00006 DWORD = ctypes.c_ulong
00007 
00008 #UCHAR = ctypes.c_uchar
00009 CHAR = ctypes.c_char
00010 WCHAR = ctypes.c_wchar
00011 UINT = ctypes.c_uint
00012 INT = ctypes.c_int
00013 
00014 DOUBLE = ctypes.c_double
00015 FLOAT = ctypes.c_float
00016 
00017 BOOLEAN = BYTE
00018 BOOL = ctypes.c_long
00019 
00020 class VARIANT_BOOL(ctypes._SimpleCData):
00021     _type_ = "v"
00022     def __repr__(self):
00023         return "%s(%r)" % (self.__class__.__name__, self.value)
00024 
00025 ULONG = ctypes.c_ulong
00026 LONG = ctypes.c_long
00027 
00028 USHORT = ctypes.c_ushort
00029 SHORT = ctypes.c_short
00030 
00031 # in the windows header files, these are structures.
00032 _LARGE_INTEGER = LARGE_INTEGER = ctypes.c_longlong
00033 _ULARGE_INTEGER = ULARGE_INTEGER = ctypes.c_ulonglong
00034 
00035 LPCOLESTR = LPOLESTR = OLESTR = ctypes.c_wchar_p
00036 LPCWSTR = LPWSTR = ctypes.c_wchar_p
00037 LPCSTR = LPSTR = ctypes.c_char_p
00038 LPCVOID = LPVOID = ctypes.c_void_p
00039 
00040 # WPARAM is defined as UINT_PTR (unsigned type)
00041 # LPARAM is defined as LONG_PTR (signed type)
00042 if ctypes.sizeof(ctypes.c_long) == ctypes.sizeof(ctypes.c_void_p):
00043     WPARAM = ctypes.c_ulong
00044     LPARAM = ctypes.c_long
00045 elif ctypes.sizeof(ctypes.c_longlong) == ctypes.sizeof(ctypes.c_void_p):
00046     WPARAM = ctypes.c_ulonglong
00047     LPARAM = ctypes.c_longlong
00048 
00049 ATOM = WORD
00050 LANGID = WORD
00051 
00052 COLORREF = DWORD
00053 LGRPID = DWORD
00054 LCTYPE = DWORD
00055 
00056 LCID = DWORD
00057 
00058 ################################################################
00059 # HANDLE types
00060 HANDLE = ctypes.c_void_p # in the header files: void *
00061 
00062 HACCEL = HANDLE
00063 HBITMAP = HANDLE
00064 HBRUSH = HANDLE
00065 HCOLORSPACE = HANDLE
00066 HDC = HANDLE
00067 HDESK = HANDLE
00068 HDWP = HANDLE
00069 HENHMETAFILE = HANDLE
00070 HFONT = HANDLE
00071 HGDIOBJ = HANDLE
00072 HGLOBAL = HANDLE
00073 HHOOK = HANDLE
00074 HICON = HANDLE
00075 HINSTANCE = HANDLE
00076 HKEY = HANDLE
00077 HKL = HANDLE
00078 HLOCAL = HANDLE
00079 HMENU = HANDLE
00080 HMETAFILE = HANDLE
00081 HMODULE = HANDLE
00082 HMONITOR = HANDLE
00083 HPALETTE = HANDLE
00084 HPEN = HANDLE
00085 HRGN = HANDLE
00086 HRSRC = HANDLE
00087 HSTR = HANDLE
00088 HTASK = HANDLE
00089 HWINSTA = HANDLE
00090 HWND = HANDLE
00091 SC_HANDLE = HANDLE
00092 SERVICE_STATUS_HANDLE = HANDLE
00093 
00094 ################################################################
00095 # Some important structure definitions
00096 
00097 class RECT(ctypes.Structure):
00098     _fields_ = [("left", LONG),
00099                 ("top", LONG),
00100                 ("right", LONG),
00101                 ("bottom", LONG)]
00102 tagRECT = _RECTL = RECTL = RECT
00103 
00104 class _SMALL_RECT(ctypes.Structure):
00105     _fields_ = [('Left', SHORT),
00106                 ('Top', SHORT),
00107                 ('Right', SHORT),
00108                 ('Bottom', SHORT)]
00109 SMALL_RECT = _SMALL_RECT
00110 
00111 class _COORD(ctypes.Structure):
00112     _fields_ = [('X', SHORT),
00113                 ('Y', SHORT)]
00114 
00115 class POINT(ctypes.Structure):
00116     _fields_ = [("x", LONG),
00117                 ("y", LONG)]
00118 tagPOINT = _POINTL = POINTL = POINT
00119 
00120 class SIZE(ctypes.Structure):
00121     _fields_ = [("cx", LONG),
00122                 ("cy", LONG)]
00123 tagSIZE = SIZEL = SIZE
00124 
00125 def RGB(red, green, blue):
00126     return red + (green << 8) + (blue << 16)
00127 
00128 class FILETIME(ctypes.Structure):
00129     _fields_ = [("dwLowDateTime", DWORD),
00130                 ("dwHighDateTime", DWORD)]
00131 _FILETIME = FILETIME
00132 
00133 class MSG(ctypes.Structure):
00134     _fields_ = [("hWnd", HWND),
00135                 ("message", UINT),
00136                 ("wParam", WPARAM),
00137                 ("lParam", LPARAM),
00138                 ("time", DWORD),
00139                 ("pt", POINT)]
00140 tagMSG = MSG
00141 MAX_PATH = 260
00142 
00143 class WIN32_FIND_DATAA(ctypes.Structure):
00144     _fields_ = [("dwFileAttributes", DWORD),
00145                 ("ftCreationTime", FILETIME),
00146                 ("ftLastAccessTime", FILETIME),
00147                 ("ftLastWriteTime", FILETIME),
00148                 ("nFileSizeHigh", DWORD),
00149                 ("nFileSizeLow", DWORD),
00150                 ("dwReserved0", DWORD),
00151                 ("dwReserved1", DWORD),
00152                 ("cFileName", CHAR * MAX_PATH),
00153                 ("cAlternateFileName", CHAR * 14)]
00154 
00155 class WIN32_FIND_DATAW(ctypes.Structure):
00156     _fields_ = [("dwFileAttributes", DWORD),
00157                 ("ftCreationTime", FILETIME),
00158                 ("ftLastAccessTime", FILETIME),
00159                 ("ftLastWriteTime", FILETIME),
00160                 ("nFileSizeHigh", DWORD),
00161                 ("nFileSizeLow", DWORD),
00162                 ("dwReserved0", DWORD),
00163                 ("dwReserved1", DWORD),
00164                 ("cFileName", WCHAR * MAX_PATH),
00165                 ("cAlternateFileName", WCHAR * 14)]
00166 
00167 ################################################################
00168 # Pointer types
00169 
00170 LPBOOL = PBOOL = ctypes.POINTER(BOOL)
00171 PBOOLEAN = ctypes.POINTER(BOOLEAN)
00172 LPBYTE = PBYTE = ctypes.POINTER(BYTE)
00173 PCHAR = ctypes.POINTER(CHAR)
00174 LPCOLORREF = ctypes.POINTER(COLORREF)
00175 LPDWORD = PDWORD = ctypes.POINTER(DWORD)
00176 LPFILETIME = PFILETIME = ctypes.POINTER(FILETIME)
00177 PFLOAT = ctypes.POINTER(FLOAT)
00178 LPHANDLE = PHANDLE = ctypes.POINTER(HANDLE)
00179 PHKEY = ctypes.POINTER(HKEY)
00180 LPHKL = ctypes.POINTER(HKL)
00181 LPINT = PINT = ctypes.POINTER(INT)
00182 PLARGE_INTEGER = ctypes.POINTER(LARGE_INTEGER)
00183 PLCID = ctypes.POINTER(LCID)
00184 LPLONG = PLONG = ctypes.POINTER(LONG)
00185 LPMSG = PMSG = ctypes.POINTER(MSG)
00186 LPPOINT = PPOINT = ctypes.POINTER(POINT)
00187 PPOINTL = ctypes.POINTER(POINTL)
00188 LPRECT = PRECT = ctypes.POINTER(RECT)
00189 LPRECTL = PRECTL = ctypes.POINTER(RECTL)
00190 LPSC_HANDLE = ctypes.POINTER(SC_HANDLE)
00191 PSHORT = ctypes.POINTER(SHORT)
00192 LPSIZE = PSIZE = ctypes.POINTER(SIZE)
00193 LPSIZEL = PSIZEL = ctypes.POINTER(SIZEL)
00194 PSMALL_RECT = ctypes.POINTER(SMALL_RECT)
00195 LPUINT = PUINT = ctypes.POINTER(UINT)
00196 PULARGE_INTEGER = ctypes.POINTER(ULARGE_INTEGER)
00197 PULONG = ctypes.POINTER(ULONG)
00198 PUSHORT = ctypes.POINTER(USHORT)
00199 PWCHAR = ctypes.POINTER(WCHAR)
00200 LPWIN32_FIND_DATAA = PWIN32_FIND_DATAA = ctypes.POINTER(WIN32_FIND_DATAA)
00201 LPWIN32_FIND_DATAW = PWIN32_FIND_DATAW = ctypes.POINTER(WIN32_FIND_DATAW)
00202 LPWORD = PWORD = ctypes.POINTER(WORD)