go-vgo / robotgo

RobotGo, Go Native cross-platform RPA and GUI automation @vcaesar
Apache License 2.0
9.57k stars 873 forks source link

Get the currently used icon in window. #300

Open EliosMax opened 3 years ago

EliosMax commented 3 years ago

Hello, I need to get the currently used icon(bitmap) in windows. Before, I used Pyhon and this function works:

Get cursor icon as bitmap, with ability to save it or get pixels from it

def get_icon_mouse(self):
    info = win32gui.GetCursorInfo()
    if info[1] != 0:
        gdc = win32gui.GetDC(0)
        hdc = win32ui.CreateDCFromHandle(gdc)
        hbmp = win32ui.CreateBitmap()
        hbmp.CreateCompatibleBitmap(hdc, self.ico_height, self.ico_width)
        hdc = hdc.CreateCompatibleDC()
        hdc.SelectObject(hbmp)
        hdc.DrawIcon((0, 0), info[1])
        signedIntsArray = hbmp.GetBitmapBits(True)
        img = np.fromstring(signedIntsArray, dtype='uint8')
        img.shape = (self.ico_height, self.ico_width, 4)

        # hbmp.SaveBitmapFile(ico, 'icon.bmp')
        # win32gui.DestroyIcon(info[1])

        win32gui.DeleteObject(hbmp.GetHandle())
        win32gui.ReleaseDC(0, gdc)
        hdc.DeleteDC()
        self.error_get_icon = 0
        return img
    else:
        return self.error_image

icon

Could someone help me write this code in Golang? Thank you

flyqie commented 1 year ago

It's 2023 and I have the same problem.

I am very happy, now there is a library that can realize this function, and supports windows/linux(x11)/macos at the same time!

Thanks to the authors of robotgo and rdesktop, their excellent work makes it easy to implement remote desktop control based on go 👏 .

https://github.com/lwch/rdesktop