Witam.
Chcę stworzyć sobie od zera kontrolkę, która będzie listą kontaktów mojego klienta gg.
Nigdy nie używam VCL, jedynie czystego WinAPI oraz Winsock.
Tworząc tą kontrolkę chciałbym ją "opakować" w klasę.
Jednak kod który zamieszczam poniżej nie działa.
Tzn. - kompiluje się, ale kontrolka nie zostaje utworzona - FHandle ma wartość 0.
Problem zapewne sprawia funkcja Contacts_Proc.
Co nalezy zrobić aby to zadziałało?
unit C_Contacts;
interface
uses
Windows, Messages;
type
TContacts = class
private
FHandle, FParentHandle: HWND;
FID: HMENU;
function Contacts_Proc(H: HWND; uMsg: UINT; wPar: WPARAM; lPar: LPARAM): LRESULT; stdcall;
procedure SetParentWnd(hParentWnd: HWND);
public
function RegisterContacts: Boolean;
procedure Create(hParentWnd: HWND; hMenu: Integer); overload;
property Handle: HWND read FHandle;
property ParentHandle: HWND read FParentHandle write SetParentWnd;
property ID: HMENU read FID;
end;
implementation
function TContacts.Contacts_Proc(H: HWND; uMsg: UINT; wPar: WPARAM; lPar: LPARAM): LRESULT; stdcall;
begin
case uMsg of
WM_CREATE: MessageBox(0, 'Dziala.', '', 0);
else Result := DefWindowProc(H, uMsg, wPar, lPar);
end;
end;
function TContacts.RegisterContacts: Boolean;
var
WndClass: TWndClass;
begin
Result := False;
WndClass.style := CS_HREDRAW or CS_VREDRAW;
WndClass.lpfnWndProc := @TContacts.Contacts_Proc;
WndClass.cbClsExtra := 0;
WndClass.cbWndExtra := 0;
WndClass.hInstance := hInstance;
WndClass.hIcon := 0;
WndClass.hCursor := LoadCursor(0, IDC_ARROW);
WndClass.hbrBackground := GetStockObject(NULL_BRUSH);
WndClass.lpszMenuName := nil;
WndClass.lpszClassName := 'Lista';
if (RegisterClass(WndClass) <> 0) then Result := True;
end;
procedure TContacts.Create(hParentWnd: HWND; hMenu: Integer);
begin
FParentHandle := hParentWnd;
FID := hMenu;
FHandle := CreateWindowEx(0, 'Lista', nil, WS_CHILD or WS_VISIBLE, 0, 0, 0, 0, FParentHandle, FID, hInstance, nil);
end;
procedure TContacts.SetParentWnd(hParentWnd : HWND);
begin
FParentHandle := hParentWnd;
SetParent(FHandle, FParentHandle);
end;
end.