转载地址: http://blog.csdn.net/gumanren/article/details/6129416

代码如下:

 # -*- coding: utf-8 -*-
import sys
import win32ui
import win32gui
from PyQt4 import QtCore
from PyQt4 import QtGui
class testWindow(QtGui.QMainWindow):
def __init__(self):
super(testWindow, self).__init__()
self.setGeometry(180.0, 130.0, 280.0, 200.0)
self.setMouseTracking(True)
large, small = win32gui.ExtractIconEx(r"netbeans.exe", 0)
win32gui.DestroyIcon(small[0])
self.pixmap = QtGui.QPixmap.fromWinHBITMAP(self.bitmapFromHIcon(large[0]), 2) self.pixmap.save("a.ico","ico") def bitmapFromHIcon(self, hIcon):
hdc = win32ui.CreateDCFromHandle(win32gui.GetDC(0))
hbmp = win32ui.CreateBitmap()
hbmp.CreateCompatibleBitmap(hdc, 32, 32)
hdc = hdc.CreateCompatibleDC()
hdc.SelectObject(hbmp)
hdc.DrawIcon((0, 0), hIcon)
hdc.DeleteDC()
return hbmp.GetHandle()
# paintevent事件
def paintEvent(self, event):
# palette 调色板多个pix显示,
painter = QtGui.QPainter()
palette = QtGui.QPalette()
palette.setBrush(self.backgroundRole(), QtGui.QBrush(QtGui.QPixmap(self.pixmap))) # 设置背景图片
self.setPalette(palette)
#painter绘图类只显示一个
#painter.begin(self)
#painter.setRenderHint(QtGui.QPainter.Antialiasing)
#painter.setPen(QtCore.Qt.NoPen)
#painter.setBrush(QtGui.QBrush(QtGui.QColor(255.0, 255.0, 255.0, 255.0), QtCore.Qt.SolidPattern))
#painter.drawRect(QtCore.QRect(0.0, 0.0, 280.0, 400.0))
#painter.drawPixmap(QtCore.QRect(0.0, 0.0, 32.0, 32.0), self.pixmap)
#painter.end()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mainWindow = testWindow()
mainWindow.show()
app.exec_()

显示效果:

Python win32api提取exe图标icon的更多相关文章

  1. Delphi提取EXE,DLL文件图标

    //uses ShellAPIprocedure TForm1.Button1Click(Sender: TObject);var IconIndex:Word; h:hICON;begin Icon ...

  2. Python 获取 exe 的 icon 并且保存

    Python 获取 exe 的 icon 并且保存 参考链接:https://mail.python.org/pipermail/python-win32/2009-April/009078.html ...

  3. delphi编写提取exe文件的ICO图标

    http://www.duote.com/tech/4/11797.html delphi编写提取exe文件的ICO图标 7.0分 出处:天下网吧 时间:2011-08-05 人气:2390 核心提示 ...

  4. [工具-001]C++更换EXE的ICON图标

    我们都知道每个可执行文件EXE都会有自己的图标,它可以在项目生成的时候进行指认,但是有时候我们会遇到两种情况:1.没有源代码,2.我们的项目很多,一个个进行更换很耗时.本人就是因为接到这么一个需求,要 ...

  5. 关于python打包成exe的一点经验之谈

    我经常用python写些脚本什么的,有时候脚本写完以后,每次运行都得在IDE打开在运行,很麻烦,所以经常将python编译成exe.SO...有了一点经验,在这和大家分享一下.      python ...

  6. python:打包成exe程序

    1.需要安装 py2exe 2.示例代码: #exetest.py #创建一个gui界面,只用一个标签和按钮,无功能 from Tkinter import * win = Tk() label = ...

  7. 使用pyinstaller将Python打包为exe文件

    当我们完成一个Python项目或一个程序时,希望将Python的py文件打包成在Windows系统下直接可以运行的exe程序,那么pyInstaller就是一个很好的选择.pyInstaller可以将 ...

  8. Python打包成exe可执行文件

    Python打包成exe可执行文件 安装pyinstaller pyinstaller打包机制 Pyinstaller打包exe 总结命令 可能会碰到的一些常见问题 我们开发的脚本一般都会用到一些第三 ...

  9. 强行替换exe图标的方法

    说句实话,要想用普通的方法来替换图标,不是完全不可行,当然也不是完全可行.这个看似简单的问题并不是想象中那么容易解决,为什么有人修改exe的图标总是失败,其实他忽视了exe和图标的复杂性,用简单的方法 ...

随机推荐

  1. Linux的后台执行进程之nohup

    nohup 用途:LINUX命令用法,不挂断地运行命令.  语法:nohup Command [ Arg ... ] [ & ]  描述:nohup 命令运行由 Command 参数和任何相关 ...

  2. The Adapter of ListView: Just adapt data to view, don’t do anything else

    The design of SimpleAdapter is not good in my opinion. An adapter should just adapter the data to vi ...

  3. backbone调试

    有一个谷歌的扩展程序:https://chrome.google.com/webstore/detail/backbone-debugger/bhljhndlimiafopmmhjlgfpnnchjj ...

  4. phpcms分页用法简介

    PHPCMS分页的用法 前面需要有引用的list,代码如下: {pc:content action="lists" catid="11" order=" ...

  5. espcms列表页ajax获取内容 - 并初始化swiper

    <link rel="stylesheet" href="swiper.min.css" type="text/css" media= ...

  6. 《oracle每日一练》oracle截取字符的函数

    转载 在Oracle中 可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符. 在一个字符串中查找指定的字符,返回被查找到的指定的字符的位置. 语法: instr(sourceStri ...

  7. Unity3d《Shader篇》变胖

    变胖前 变胖后 //Shader Shader "Custom/NormalExt" { Properties { _MainTex("Base (RGB)", ...

  8. Semaphore(信号量)

    Semaphore msdn介绍: 限制可同时访问某一资源或资源池的线程数. 命名空间: System.Threading 程序集: System(在 System.dll 中) 通俗理解: 1:宾馆 ...

  9. 8.js模式-状态模式

    1. 状态模式 var offLightState = function(light){ this.light = light; } offLightState.prototype.buttonWas ...

  10. 禁止Linux用户登录方法

    我们在做系统维护的时候,希望个别用户或者所有用户不能登录系统,保证系统在维护期间正常运行.这个时候我们就要禁止用户登录. 1.禁止个别用户登录.比如禁止lynn用户登录. passwd -l lynn ...