N
nicolasr
Hi,
I'm trying to convert an application from C++ to CSharp.
Under C++ I used the SetLayeredWindowAttributes() API
to make parts of my form transparent. Now in CSharp, I
was trying the forms TransparencyKey property. However,
it doesn't work on my system with 32bit display and I found
this confirmed by other posts on this topic.
I asked myself if I could avoid this problem by dllimport-ing
the API function. I'm very new to CSharp and Dotnet and
could not get it working, yet. I would really appreciate if
anyone could tell me what is wrong in the following code:
//the original function signature
/*
BOOL SetLayeredWindowAttributes(HWND hwnd,
COLORREF crKey,
BYTE bAlpha,
DWORD dwFlags
);
*/
//define the key constant
private const int LWA_COLORKEY = 0x00000001;
[DllImport("user32.dll", SetLastError=true)]
public static extern int SetLayeredWindowAttributes(int hwnd,
int cKey, byte bAlpha, int dwFlags);
//in the forms constructor
int ret = SetLayeredWindowAttributes(this.Handle.ToInt32(), 0x00FFFFFF, 0,
LWA_COLORKEY);
if(ret == 0)
{
try
{
throw new Win32Exception();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
thanks for any ideas,
Nick
I'm trying to convert an application from C++ to CSharp.
Under C++ I used the SetLayeredWindowAttributes() API
to make parts of my form transparent. Now in CSharp, I
was trying the forms TransparencyKey property. However,
it doesn't work on my system with 32bit display and I found
this confirmed by other posts on this topic.
I asked myself if I could avoid this problem by dllimport-ing
the API function. I'm very new to CSharp and Dotnet and
could not get it working, yet. I would really appreciate if
anyone could tell me what is wrong in the following code:
//the original function signature
/*
BOOL SetLayeredWindowAttributes(HWND hwnd,
COLORREF crKey,
BYTE bAlpha,
DWORD dwFlags
);
*/
//define the key constant
private const int LWA_COLORKEY = 0x00000001;
[DllImport("user32.dll", SetLastError=true)]
public static extern int SetLayeredWindowAttributes(int hwnd,
int cKey, byte bAlpha, int dwFlags);
//in the forms constructor
int ret = SetLayeredWindowAttributes(this.Handle.ToInt32(), 0x00FFFFFF, 0,
LWA_COLORKEY);
if(ret == 0)
{
try
{
throw new Win32Exception();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
thanks for any ideas,
Nick