Python Win32API extract exe icons icon

Source: Internet
Author: User

Reprint Address: http://blog.csdn.net/gumanren/article/details/6129416

The code is as follows:

1 #-*-coding:utf-8-*-2 ImportSYS3 ImportWin32ui4 ImportWin32gui5  fromPyQt4ImportQtcore6  fromPyQt4ImportQtgui7 classTestwindow (Qtgui.qmainwindow):8     def __init__(self):9Super (Testwindow, self).__init__()TenSelf.setgeometry (180.0, 130.0, 280.0, 200.0) One self.setmousetracking (True) ALarge, small = Win32gui. Extracticonex (R"Netbeans.exe", 0) - Win32gui. DestroyIcon (small[0]) -Self.pixmap = QtGui.QPixmap.fromWinHBITMAP (Self.bitmapfromhicon (Large[0]), 2) the          -Self.pixmap.save ("A.ico","ico") -          -     defBitmapfromhicon (Self, hicon): +HDC =Win32ui. Createdcfromhandle (Win32gui. GetDC (0)) -hbmp =Win32ui. CreateBitmap () +Hbmp. CreateCompatibleBitmap (HDC, 32, 32) AHDC =HDC. CreateCompatibleDC () at HDC. SelectObject (hbmp) - HDC. DrawIcon ((0, 0), Hicon) - HDC. DeleteDC () -         returnhbmp. GetHandle () -     #PaintEvent Events -     defpaintevent (Self, event): in         #Palette palette Multiple pix display, -painter =Qtgui.qpainter () topalette =Qtgui.qpalette () +Palette.setbrush (Self.backgroundrole (), Qtgui.qbrush (Qtgui.qpixmap (SELF.PIXMAP)))#set a background picture - Self.setpalette (palette) the         #The painter Drawing class displays only one *         #Painter.begin (self) $         #painter.setrenderhint (QtGui.QPainter.Antialiasing)Panax Notoginseng         #Painter.setpen (QtCore.Qt.NoPen) -         #Painter.setbrush (Qtgui.qbrush (Qtgui.qcolor (255.0, 255.0, 255.0, 255.0), QtCore.Qt.SolidPattern)) the         #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) A         #painter.end () the if __name__=="__main__": +App =qtgui.qapplication (SYS.ARGV) -MainWindow =Testwindow () $ mainwindow.show () $APP.EXEC_ ()

Display effect:

Python Win32API extract exe icons icon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.