Jump to content
Tuts 4 You

Create Hidden Window With out VCL


StreamLine

Recommended Posts

Trying to create a hidden window in delphi or (message only window) I have read up on the msdn, and come up with


var
WClass :TWndClass;
TempClass :TWndClass;
ClassRegistered :Boolean;
begin
WClass.style := 0;
WClass.lpfnwndproc := @WndProc;
WClass.cbClsExtra := 0;
WClass.cbWndExtra := SizeOf(TWndClass);
WClass.hinstance := hInstance;
WClass.hIcon := 0;
WClass.hCursor := 0;
WClass.hbrbackground := 0;
WClass.lpszMenuName := nil;
WClass.lpszClassName := 'Server';
ClassRegistered := GetClassInfo(hInstance,WClass.lpszClassName,TempClass);
if ClassRegistered = True then UnregisterClass(TempClass.lpszClassName,hInstance);
Registerclass(Wclass);
Result := CreateWindowEx(WS_EX_NOACTIVATE, WClass.lpszClassName,WClass.lpszClassName, 0, 0, 0, 0, 0, 0, hInstance, nil);

which is in a formless application (console) once the console loses focus, if i take the console away and make it run with out any console or forms i am not able to recieve window messages. i read up and saw i could post HWND_MESSAGE to the handle, however the value of this is (-3) and delphi errors violate sub bound range for a handle :(

TIA

Link to comment

For a message-only Window, you should be passing HWND_MESSAGE as the window parent in the hWndParent param of CreateWindowEx.

HWND CreateWindowEx(      
DWORD dwExStyle,
LPCTSTR lpClassName,
LPCTSTR lpWindowName,
DWORD dwStyle,
int x,
int y,
int nWidth,
int nHeight,
HWND hWndParent, // <-- Pass HWND_MESSAGE in this param.
HMENU hMenu,
HINSTANCE hInstance,
LPVOID lpParam
);

HWND_MESSAGE is defined as -3, I'm not sure how Delphi handles this as I don't code in it so I cant really give a Delphi example.

After a few Google searches I'd try to to:

THandle(HWND_MESSAGE)

or

MsgHandle :HWND;
MsgHandle := HWND_MESSAGE;

And pass MsgHandle in CreateWindowEx.

I'm not really sure what falls under VCL in Delphi either, so sorry if this doesn't help. :(

Link to comment

var
WClass :TWndClass;
TempClass :TWndClass;
ClassRegistered :Boolean;
begin
WClass.style := 0;
WClass.lpfnwndproc := @WndProc;
WClass.cbClsExtra := 0;
WClass.cbWndExtra := SizeOf(TWndClass);
WClass.hinstance := HInstance;
WClass.hIcon := 0;
WClass.hCursor := 0;
WClass.hbrbackground := 0;
WClass.lpszMenuName := nil;
WClass.lpszClassName := 'Server';
ClassRegistered := GetClassInfo(hInstance,WClass.lpszClassName,TempClass);
if ClassRegistered = True then UnregisterClass(TempClass.lpszClassName,hInstance);
Registerclass(Wclass);
Result := CreateWindowEx(WS_EX_NOACTIVATE, WClass.lpszClassName,WClass.lpszClassName, 0, 0, 0, 0, 0, HWND(HWND_MESSAGE), 0, hInstance, nil);

for some reason doesnt work properly, if you post a C++ example i could have a go at converting it. thanks for your input :P

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...