首页 > 编程语言 > 详细

Python中使用ctypes调用Windows API

时间:2014-11-27 01:29:42      阅读:684      评论:0      收藏:0      [点我收藏+]
# -*- coding: cp936 -*-

import ctypes
import ctypes.wintypes

#print(dir(ctypes))
#print(dir(ctypes.wintypes))

user32 = ctypes.WinDLL("user32.dll")
FindWindowA = user32.FindWindowA
GetWindowTextA = user32.GetWindowTextA
EnumWindows = user32.EnumWindows

#Windows回调函数
def EnumWindowProc(hWnd, lParam):
    text = ctypes.c_char_p()
    text.value = ""
    GetWindowTextA(hWnd, text, 200)
    print(text.value)
    return 1

#声明原型,注意需要首先要声明返回值类型
pFunc = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.wintypes.HWND, ctypes.wintypes.LPARAM)
pFuncHandle = pFunc(EnumWindowProc)

EnumWindows(pFuncHandle, None)

 

Python中使用ctypes调用Windows API

原文:http://www.cnblogs.com/sunlb/p/4125445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!