G
Guest
Hello guys,
I am trying to create a transparent form using CreateWindowEx() by calling
the unmanaged code. But everytime after the call the returned handle is zero.
i could nto figure what is the problem in that...
Here is the code
--------------
[DllImport("User32", SetLastError=true)]
internal static extern int CreateWindowEx ( int dwExStyle, string
lpClassName,
string lpWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight,
int hWndParent, int hMenu, int hInstance, IntPtr lpParam);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WNDCLASSEX
{
public uint cbSize;
public uint style;
public long lpfnWndProc;
public int cbClsExtra;
public int cbWndExtra;
public long hInstance;
public long hIcon;
public long hCursor;
public long hbrBackGround;
public string lpszMenuName;
public string lpszClassName;
public long hIconSm;
}
[DllImport("User32.Dll")]
public static extern int RegisterClassEx(ref WNDCLASSEX wndcls);
[DllImport("user32.dll")]
public static extern int ShowWindow(long hwnd, int nCmdShow);
private string classname = "TestYetTransparency";
private void init()
{
// Let's create a window
IntPtr
hInst=Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModule("TestYetTransparency.exe"));
WNDCLASSEX wndclass=new WNDCLASSEX();
wndclass.cbSize = (uint) Marshal.SizeOf(typeof(WNDCLASSEX));
wndclass.style = 11; //CS_HREDRAW+CS_VREDRAW+CS_DBLCLKS;
wndclass.lpfnWndProc = 0;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst.ToInt32();
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackGround = 0;
wndclass.lpszMenuName = "TestYetTransparency";
wndclass.lpszClassName = classname;
wndclass.hIconSm = 0;
int mm = RegisterClassEx(ref wndclass);
int nativeHandle = CreateWindowEx(WS_EX_TRANSPARENT
,classname
,"transparent"
,WS_BORDER
,0
,0
,Screen.PrimaryScreen.Bounds.Width
,Screen.PrimaryScreen.Bounds.Height
,0
,0
,hInst.ToInt32()
,IntPtr.Zero);
ShowWindow(nativeHandle,5); //SW_SHOW
}
private int WS_EX_TRANSPARENT = 0x00000020;
private int WS_BORDER = 0x800000;
--------------
I am trying to create a transparent form using CreateWindowEx() by calling
the unmanaged code. But everytime after the call the returned handle is zero.
i could nto figure what is the problem in that...
Here is the code
--------------
[DllImport("User32", SetLastError=true)]
internal static extern int CreateWindowEx ( int dwExStyle, string
lpClassName,
string lpWindowName, int dwStyle, int X, int Y, int nWidth, int nHeight,
int hWndParent, int hMenu, int hInstance, IntPtr lpParam);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WNDCLASSEX
{
public uint cbSize;
public uint style;
public long lpfnWndProc;
public int cbClsExtra;
public int cbWndExtra;
public long hInstance;
public long hIcon;
public long hCursor;
public long hbrBackGround;
public string lpszMenuName;
public string lpszClassName;
public long hIconSm;
}
[DllImport("User32.Dll")]
public static extern int RegisterClassEx(ref WNDCLASSEX wndcls);
[DllImport("user32.dll")]
public static extern int ShowWindow(long hwnd, int nCmdShow);
private string classname = "TestYetTransparency";
private void init()
{
// Let's create a window
IntPtr
hInst=Marshal.GetHINSTANCE(System.Reflection.Assembly.GetExecutingAssembly().GetModule("TestYetTransparency.exe"));
WNDCLASSEX wndclass=new WNDCLASSEX();
wndclass.cbSize = (uint) Marshal.SizeOf(typeof(WNDCLASSEX));
wndclass.style = 11; //CS_HREDRAW+CS_VREDRAW+CS_DBLCLKS;
wndclass.lpfnWndProc = 0;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst.ToInt32();
wndclass.hIcon = 0;
wndclass.hCursor = 0;
wndclass.hbrBackGround = 0;
wndclass.lpszMenuName = "TestYetTransparency";
wndclass.lpszClassName = classname;
wndclass.hIconSm = 0;
int mm = RegisterClassEx(ref wndclass);
int nativeHandle = CreateWindowEx(WS_EX_TRANSPARENT
,classname
,"transparent"
,WS_BORDER
,0
,0
,Screen.PrimaryScreen.Bounds.Width
,Screen.PrimaryScreen.Bounds.Height
,0
,0
,hInst.ToInt32()
,IntPtr.Zero);
ShowWindow(nativeHandle,5); //SW_SHOW
}
private int WS_EX_TRANSPARENT = 0x00000020;
private int WS_BORDER = 0x800000;
--------------