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;

--------------

Re: problem creating transparent window... by Lloyd

Lloyd
Wed Jul 20 05:53:33 CDT 2005

alternatively you could use .NET transaparency option for Form.
there are 2 of them.

Form.Opacity
or
Form.TransparencyKey

"ve" <ve@discussions.microsoft.com> wrote in message
news:2BE6D67B-12F4-46A0-BFCE-0052B8D47A5F@microsoft.com...
> 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;
>
> --------------
>



Re: problem creating transparent window... by ve

ve
Wed Jul 20 09:47:05 CDT 2005

Hello Lloyd,

Actually i tried them before. But sme where in the newsgroups it was
mentioned that setting the WS_EX_transparency is not the same as setting the
opacity or transparentkey.

Well the reason why i want this window is that, i want to ink on it or
annotate on it. if i set the opacity the ink is becomign transparent and if i
set the transparent key i could not write on it.

thanks
vinod

"Lloyd Dupont" wrote:

> alternatively you could use .NET transaparency option for Form.
> there are 2 of them.
>
> Form.Opacityfore
> or
> Form.TransparencyKey
>
> "ve" <ve@discussions.microsoft.com> wrote in message
> news:2BE6D67B-12F4-46A0-BFCE-0052B8D47A5F@microsoft.com...
> > 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;
> >
> > --------------
> >
>
>
>

Re: problem creating transparent window... by ve

ve
Wed Jul 20 11:32:05 CDT 2005

is there anyway i can set the windo transparent with transparency key and as
well have a picture box which is set over it. And the picturebox should also
b transparent but when i cick it, the mouse events should not go to the
underlying windows?

vinod

"Lloyd Dupont" wrote:

> alternatively you could use .NET transaparency option for Form.
> there are 2 of them.
>
> Form.Opacity
> or
> Form.TransparencyKey
>
> "ve" <ve@discussions.microsoft.com> wrote in message
> news:2BE6D67B-12F4-46A0-BFCE-0052B8D47A5F@microsoft.com...
> > 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;
> >
> > --------------
> >
>
>
>