# - * - Coding: UTF-. 8 - * - Import Win32API Import win32gui, win32ui Import Time the while True: the time.sleep ( . 1) # Wait one second CI = win32gui.GetCursorInfo () # Get the cursor information Print ' comprises cursor type, handle coordinates ' + STR (CI) # comprising cursor type, handle, coordinate Print ' GetCursor Get handle ' + STR (win32gui.GetCursor ()) # win32gui.GetCursor () but also to obtain and obtaining cursor handle GetCursorInfo handle not the same, not sure why? IF (CI [1] == 0): # at some point the cursor will be hidden game or program, and therefore error Print " cursor disappears " the Continue # ----------------------------------------------- void # E = win32gui.SetCursor (CI [. 1]) # change the cursor back to the old cursor handle type # Print type (E) # IF (E == 0): # Print "cursor disappears" # Continue # ------ --------------------------------------- obsolete ii = win32gui.GetIconInfo (ci [1] ) # returns the cursor image information, Note: the parameter can not handle is win32gui.GetCursor () to get, otherwise hot read wrong, why? Print ' cursor parameter ' + STR (II) # cursor type, hot coordinates x, y, black and white bitmap, the bitmap color # I want to export a color bitmap bmp image is not successful, in c ++ bitmap into Cimg. Attach get there easily could save # then I do not know whether there are ways you can use in python, pil which is not found bm = win32gui.GetObject (ii [3]) #Returns the size of the cursor can be obtained PyBITMAP types, note that this is best placed to get black and white bitmap, the bitmap may cause color into monochrome cursor error Print ' high ' + STR (bm.bmHeight) Print ' width ' + STR ( bm.bmWidth) GDC = win32gui.GetDC (0) # the specified context 0 extracted a handle should also remember the release of 0 indicates that the entire screen HDC = win32ui.CreateDCFromHandle (GDC) # accordance with its handle to create a DC target hbmp = win32ui.CreateBitmap () # create a new bitmap hbmp.CreateCompatibleBitmap (HDC, bm.bmHeight, bm.bmWidth) # set bitmap context and make it compatible with the size of the picture HDC = hdc.CreateCompatibleDC () # set up a screen compatible DC # CreateCompatibleDC equivalent to open up a place in memory, copy come screen or window, and then its operation until the operation is complete # Then copied back to the screen to complete the refresh of the screen hdc.SelectObject (hBMP) # bitmap into context, you can edit a bitmap win32gui.DrawIconEx (hdc.GetHandleOutput (), 0, 0, ci [ . 1], bm.bmHeight, bm.bmWidth, 0, None, 2) # icon size # DrawIconEx to draw into the bitmap specified context # hdc.GetHandleOutput () returns the context handle # parameters (need to put a context handle , x coordinate, y coordinate, need to put the cursor handle, the cursor is high, the width of the cursor, animated cursors take the first few frames, background brush (which may be empty), drawing type int) bitmapbits hbmp.GetBitmapBits = (True) # the picture is converted to a string Print bitmapbits hbmp.SaveBitmapFile (HDC, ' scre99t.bmp ' ) # save the bitmap as a picture, note here only put DC # resource release win32gui.ReleaseDC (0, gdc)# Release context parameters (window handle, a context handle) hdc.DeleteDC () win32gui.DeleteObject (hbmp.GetHandle ())
Tiring python or c ++ is not suitable for live and online pywin32 example of too little, or go abroad pulls example, be vague understanding of the relationship between the context of the handle
But here are a few questions
1, win32gui.GetIconInfo contains black and white bitmap and color bitmaps, why they are constantly changing?
2, win32gui.GetCursor () and GetCursorInfo () Gets handle why not the same, and GetCursor () handle not show hotspots
3, win32gui.GetIconInfo whether the bitmap can be directly saved as bmp, in c ++ method in there, and can not find python