우리의 응용 프로그램은 WinForms에서 "상대적으로"멋진 드래그 드롭 애니메이션을 사용할 수 있도록 커서 조작을합니다 (WPF는 옵션이 아닐 때). 그러나 RDP 세션을 통해 응용 프로그램을 사용하면 일반 GDI + 예외가 throw됩니다.Bitmap.FromHbitmap에서 RDP를 통해 호출 할 때 오류가 발생합니다.
는이 인 슬로우있어서
[DllImport("user32")]
private static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO pIconInfo);
[DllImport("user32.dll")]
private static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("gdi32.dll", SetLastError = true)]
private static extern bool DeleteObject(IntPtr hObject);
public static Bitmap BitmapFromCursor(Cursor cur)
{
ICONINFO iInfo;
GetIconInfo(cur.Handle, out iInfo);
Bitmap bmp = Bitmap.FromHbitmap(iInfo.hbmColor);
DeleteObject(iInfo.hbmColor);
DeleteObject(iInfo.hbmMask);
BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat);
Bitmap dstBitmap = new Bitmap(bmData.Width, bmData.Height, bmData.Stride, PixelFormat.Format32bppArgb, bmData.Scan0);
bmp.UnlockBits(bmData);
return new Bitmap(dstBitmap);
}
구체적 라인 :
Bitmap bmp = Bitmap.FromHbitmap(iInfo.hbmColor);
hbmColor
디버깅 0
이며, 반환하지 않는 RDP 위에 GetIconInfo
에 호출을 실행할 때 수단 필요한 정보.
0
을 확인하고 특별한 경우를 처리 할 수 있지만 정상적으로 수행 할 수있는 것처럼 RDP를 통해이 작업을 수행 할 수있는 방법이 있습니까? 나는 위의 구조에 호출/P의 의견을 추가 한 아래
[StructLayout(LayoutKind.Sequential)]
struct ICONINFO
{
public bool fIcon; // Specifies whether this structure defines an icon or a cursor. A value of TRUE specifies
// an icon; FALSE specifies a cursor.
public Int32 xHotspot; // Specifies the x-coordinate of a cursor's hot spot. If this structure defines an icon, the hot
// spot is always in the center of the icon, and this member is ignored.
public Int32 yHotspot; // Specifies the y-coordinate of the cursor's hot spot. If this structure defines an icon, the hot
// spot is always in the center of the icon, and this member is ignored.
public IntPtr hbmMask; // (HBITMAP) Specifies the icon bitmask bitmap. If this structure defines a black and white icon,
// this bitmask is formatted so that the upper half is the icon AND bitmask and the lower half is
// the icon XOR bitmask. Under this condition, the height should be an even multiple of two. If
// this structure defines a color icon, this mask only defines the AND bitmask of the icon.
public IntPtr hbmColor; // (HBITMAP) Handle to the icon color bitmap. This member can be optional if this
// structure defines a black and white icon. The AND bitmask of hbmMask is applied with the SRCAND
// flag to the destination; subsequently, the color bitmap is applied (using XOR) to the
// destination by using the SRCINVERT flag.
}
HABJAN의 대답에서 :
편집
다음은 ICONINFO
구조입니다. hbmMask
에 비트 맵 참조가 포함 된 것 같습니다.하지만 비트 조작 기술이 다소 녹슬 까봐 두렵습니다. p/Invoke가 상반부/하반부를 말할 때 - 그것은 무엇을 추론합니까?
여기에서 흑백 비트 맵을 얻을 수 있습니까?
'ICONINFO'구조 정의를 표시 할 수 있습니까? – HABJAN
winapi 함수의 반환 값을 무시하는 것은 일반적인 실수입니다. 그것은 선택 사항이 아니며 친숙한 .NET 예외가 없으므로 문제가 발생하지 않습니다. GetIconInfo()가 * false *를 반환하면 Win32Exception을 던져 실패 이유를 알 수 있습니다. 그리고 선언을 수정하여 SetLastError = true를 추가하십시오. –
건배 한스, p/Invoke에서 복사하여 붙여 넣기보다는 좀 더 익숙해지기 위해 필요한 것입니다. 나는 그 다음에 염두에 두었다. – Marlon