First of all I've to say I'm a newbie in this kinda things. I'm pretty
good with delphi but this is the first time I try smothing at this
level.
Everything work in the main procedure.
procedure WinMain;
var
Wnd: hWnd;
Msg: TMsg;
Cls: TWndClass;
ClsNotify: TWndClass;
begin
if FindWindow(APPNAME, nil) <> 0 then ShutDown(APPNAME + ' gią
avviato!');
FillChar(Cls, sizeof(Cls), 0);
Cls.lpfnWndProc := @FaxWindowProc;
Cls.hInstance := hInstance;
Cls.lpszClassName := APPNAME;
RegisterClass(Cls);
//
FillChar(ClsNotify, sizeof(ClsNotify), 0);
ClsNotify.lpfnWndProc := @NotifyWindowProc;
ClsNotify.hInstance := hInstance;
ClsNotify.lpszClassName := NOTIFYWND;
RegisterClass(ClsNotify);
//
{ creazione finestra }
Wnd := CreateWindow(APPNAME, APPNAME, WS_OVERLAPPEDWINDOW,
cw_UseDefault, cw_UseDefault, cw_UseDefault,
cw_UseDefault,
0, 0, hInstance, nil);
gState := 0;
if (Wnd <> 0) then begin
ShowWindow(Wnd, SW_HIDE);
while GetMessage(Msg, 0, 0, 0) do begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
end;
As you can see I register two classes. Later in the program (when a
socket receive some information) I want to open a window (something
like MSN Messenger does when a new contact gets on-line).
To do that I write...
WndNotify := CreateWindow(NOTIFYWND, NOTIFYWND, WS_POPUP or WS_VISIBLE
or WS_CLIPSIBLINGS or WS_SYSMENU or WS_MINIMIZEBOX or WS_CAPTION, 10,
10, 250, 100, 0, 0, hInstance, nil);
if (WndNotify <> 0) then begin
ShowWindow(WndNotify, SW_SHOWNORMAL);
UpdateWindow(WndNotify);
//
dc := BeginPaint(WndNotify, lPaint);
try
TextOut(dc, 0, 0, PChar(lPacket.DataString),
length(lPacket.DataString));
finally
EndPaint(WndNotify, lPaint);
end;
end;
This draw a window (in the procedure that handles messages I paint the
background) but it freezes. The mouse pointer remain always the
hourglass. And it's just like if there's aloop somewhere. But there
isn't. After the line I wrote there nothing else.
If it can be helpful I'll write the window procedure for the one I'm
trying to open...
function NotifyWindowProc(Wnd: hWnd; Msg, wParam: Word; lParam:
LongInt): LongInt; stdcall;
var
dc: hDC;
lRect: TRect;
lPaint: PAINTSTRUCT;
begin
NotifyWindowProc := 0;
case Msg of
WM_PAINT:
begin
dc := BeginPaint(Wnd, lPaint);
try
GetClientRect(Wnd, lRect);
FillRect(dc, lRect, GetSysColorBrush($ffffff));
finally
EndPaint(Wnd, lPaint);
end;
end;
end;
NotifyWindowProc := DefWindowProc(Wnd, Msg, wParam, lParam);
end;
What's wrong? I dont' know what to try...
Thanks,
Enrico