Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > API


Автор: Alex 22.4.2002, 07:45
Как с помощью API поместить Label на Form. Я пробовал сделать так
program Project1;

uses
 Windows,
 Messages;

const
myClassName= 'myWindow';

var
handleWnd, Label1 : THandle;
WndClass: TWndClass;
Msg: TMsg;

function WindowProc(Window: HWnd; AMessage, WParam,
                   LParam: Longint): Longint; stdcall;
begin
 WindowProc:= DefWindowProc(Window, AMessage, WParam, LParam);
 case AMessage of
   {WM_COMMAND: if lParam = Button1 then
                  MessageBox( 0, 'Вы нажали кнопку!', 'Информация',
                              MB_OK or MB_ICONINFORMATION);   }
   WM_DESTROY: Halt;
 end;
end;

begin
 with WndClass do
 begin
   hInstance    := hInstance;
   lpszClassName:= myClassName;
   style        := cs_hRedraw or cs_vRedraw;
   hbrBackground:= color_btnface +1;
   lpfnWndProc  := @WindowProc;
   hCursor      := LoadCursor(0, idc_Arrow);

   hIcon        := LoadIcon(0, IDI_EXCLAMATION);
   lpszMenuName := NIL;
   cbWndExtra   := 0;
   cbClsExtra   := 0;
 end;
 RegisterClass( WndClass );
 handleWnd:= CreateWindow(myClassName, 'Hажми кнопку', ws_OverlappedWindow,
  400, 300, 200, 100, 0, 0, hInstance , NIL);
 if handleWnd = 0 then
 begin
   MessageBox( 0, 'Error', NIL, MB_OK );
   Exit;
 end;
 Label1:= CreateWindow( 'Label', 'Text',

                         WS_VISIBLE or WS_CHILD or WM_SETTEXT,
                         20, 10, 60, 23, handleWnd, 0, hInstance, nil);

 ShowWindow(handleWnd, SW_SHOW);
 UpdateWindow(handleWnd);
 while GetMessage(Msg, handleWnd, 0, 0) do
 begin
   TranslateMessage(Msg) ;
   DispatchMessage(Msg) ;
 end;
end.

Автор: Baa 22.4.2002, 11:31
var
 hLabel : HWND ;
...
hLabel := CreateWindow ( 'STATIC', 'test', WS_CHILD or WS_VISIBLE,  0, 0, 200, 40, hWnd, NULL, hInstance, NULL );

Автор: Dexter 3.7.2002, 21:30
И это все что бы сделать Label :happy

Автор: Wowa 3.7.2002, 23:20
Цитата(Dexter @ 03.7.2002, 20:30)
И это все что бы сделать Label :happy

да нет. Там вроде еще всякие окна создаются.

Автор: Alex 4.7.2002, 08:06
Интерестно, а зачем создавать label, если у вас не создано окно.

Автор: RA 4.7.2002, 13:39
Вот тебе, кнопочка, окно, Лэйбл и едит:

Код
program YoNigers;

uses
 Windows,
 Messages;

var
 WinClass: TWndClassA;
 Inst, Handle, Button1, Label1, Edit1: Integer;
 Msg: TMsg;
 hFont: Integer;

function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;
begin
 Result := DefWindowProc(hWnd, uMsg, wParam, lParam);

 if uMsg = WM_DESTROY then
   Halt;
end;

begin
 Inst := hInstance;
 with WinClass do
 begin
   style              := CS_CLASSDC or CS_PARENTDC;
  lpfnWndProc        := @WindowProc;
   hInstance          := Inst;
   hbrBackground      := color_btnface + 1;
   lpszClassname      := 'AG_TESTWINDOW';
   hCursor            := LoadCursor(0, IDC_ARROW);
 end; { with }
 RegisterClass(WinClass);

 Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'You NigerS',
                          WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
                          363, 278, 305, 65, 0, 0, Inst, nil);

 Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
                          216, 8, 75, 25, handle, 0, Inst, nil);

 Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
              8, 12, 76, 13, Handle, 0, Inst, nil);


 Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
                         WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);


 hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
                     OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                     DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');


 if hFont <> 0 then
 begin
   SendMessage(Button1, WM_SETFONT, hFont, 0);
   SendMessage(Label1, WM_SETFONT, hFont, 0);
   SendMessage(Edit1, WM_SETFONT, hFont, 0);
 end;
 SetWindowText(Label1, 'Hello');
 SetFocus(Edit1);
 UpdateWindow(Handle);
 while(GetMessage(Msg, Handle, 0, 0)) do
 begin
   TranslateMessage(msg);
   DispatchMessage(msg);
 end;
end.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)