Reputation: 1368
I am trying to implement Windows Messaging in C# in order to communicate a HTML page with a regular exe. What I need to do is to create a new window with a specific class name and window name, so that other processes can send Windows Messages to my Activex application.
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr CreateWindowEx(
WindowStylesEx dwExStyle,
string lpClassName,
string lpWindowName,
WindowStyles dwStyle,
int x,
int y,
int nWidth,
int nHeight,
IntPtr hWndParent,
IntPtr hMenu,
IntPtr hInstance,
IntPtr lpParam);
IntPtr temp = CreateWindowEx(0, "privateclassname", "privatewindowname",
WindowStyles.WS_CHILD | WindowStyles.WS_VISIBLE, 0, 0, 1, 1,
IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
This is what I' ve been trying but temp always get 0 instead of a proper window handle. What is wrong with this piece of code? I suspect hWndParent parameter. A give it 0 because I don' t know the parent' s handle, or it even exists. Thanks in advance
Upvotes: 1
Views: 2461
Reputation: 104514
You are passing in WS_CHILD for a window style flag, but you are not passing a parent window handle (you are passing 0/NULL). Try removing the WS_CHILD style.
Also, see my comment about calling RegisterClass above (if that applies).
Upvotes: 1