Zostawiając to co najważniejsze:
type
TLinksWnd = class
private
FWndClassName: String;
FWndTitle: String;
FHandle: HWND;
FLinksEdit: HWND;
FStatic: HWND;
FDirEdit: HWND;
FChangeBtn: HWND;
FCancelBtn: HWND;
FAddBtn: HWND;
FThread_CheckLinks: DWORD;
function WndProc(uMsg: UINT; wPar: WPARAM; lPar: LPARAM): LRESULT; stdcall;
function Thread_CheckLinks(lpVoid: Pointer): DWORD; stdcall;
end;
function TLinksWnd.Thread_CheckLinks(lpVoid: Pointer): DWORD; stdcall;
var
hWindow: HWND;
iRet: Integer;
iLinksCount: Integer;
begin
hWindow := Integer(Self);
MessageBox(0, PChar(IntToStr(Integer(lpVoid))), 'lpVoid', 0); //Pokazuje zawsze liczbę 3
//if hWindow = LinksWnd.Handle then MessageBox(0, '', '', 0);
iRet := GetWindowLong(hWindow, GWL_USERDATA);
if (iRet <> 0) then Self := TLinksWnd(iRet)
else ExitThread(0);
iLinksCount := SendMessage(Self.FLinksEdit, EM_GETLINECOUNT, 0, 0);
ShowInt(iLinksCount); //MessageBox
end;
function TLinksWnd.WndProc(uMsg: UINT; wPar: WPARAM; lPar: LPARAM): LRESULT; stdcall;
var
hWindow: HWND;
iRet: Integer;
begin
Result := 0;
hWindow := Integer(Self);
iRet := GetWindowLong(hWindow, GWL_USERDATA);
if (iRet <> 0) then Self := TLinksWnd(iRet)
else Self := TLinksWnd(PCREATESTRUCT(lPar)^.lpCreateParams);
case uMsg of
WM_NCCREATE:
begin
SetWindowLong(hWindow, GWL_USERDATA, Integer(PCREATESTRUCT(lPar)^.lpCreateParams));
Result := 1;
end;
WM_COMMAND:
begin
case (LoWord(wPar)) of
ID_BUTTON_ADD:
begin
EnableWindow(FLinksEdit, False);
EnableWindow(FStatic, False);
EnableWindow(FDirEdit, False);
EnableWindow(FChangeBtn, False);
EnableWindow(FCancelBtn, False);
EnableWindow(FAddBtn, False);
MessageBox(0, PChar(IntToStr(Integer(Self))), 'Self', 0);
FThread_CheckLinks := CreateThread(nil, 0, @TLinksWnd.Thread_CheckLinks, Self, 0, PDWORD(nil)^);
end;
end;
end;
WM_CLOSE:
begin
ShowWindow(hWindow, SW_HIDE);
end;
else
Result := DefWindowProc(hWindow, uMsg, wPar, lPar);
end;
end;
Tak w ogóle to czym jest Self? Bo pasuje do Pointera i TLinksWnd, tak jakby był Variantem.
Przekazywać go powinno się jako:
Self
czy
@self
Czy jeszcze jakoś inaczej? (Np. deklarując nad klasą PLinksWnd = ^TLinksWnd i wykorzystując to)
Widzę, że nie da się niczego przekazać poprzez lpVoid, nawet zwykłego wskaźnika na rekord.
Zawsze jest 3, a 3 to chyba nil (bo jak dam nil to też MessageBox pokaże 3).