Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Crear formulario,botones y edit con apis de windows sin vcl (https://www.clubdelphi.com/foros/showthread.php?t=83858)

force1758 07-08-2013 00:21:31

Crear formulario,botones y edit con apis de windows sin vcl
 
Hola a todos de nuevo de esta comunidad tan respetada en la web vengo a preguntar si es posible crear un formulario, botón, edit etc. solo con apis de windows sin el componente vcl que trae el delphi sino puro codigo.

Gracias Saludos

ecfisa 07-08-2013 00:31:29

Cita:

Empezado por force1758 (Mensaje 465129)
Hola a todos de nuevo de esta comunidad tan respetada en la web vengo a preguntar si es posible crear un formulario, botón, edit etc. solo con apis de windows sin el componente vcl que trae el delphi sino puro codigo.

Hola force1758.

Por supuesto que sí.

Hay muchos ejemplos en la web, aquí tenes uno que se corresponde significativamente con tu consulta: Creating forms without using VCL

Saludos. :)

movorack 07-08-2013 04:35:34

Aunque no entiendo porque reinventar la rueda cuando tienes un ferrari disponible.

FGarcia 07-08-2013 04:36:47

Interesante ejemplo eficsa, sin embargo como ejemplo didáctico esta muy bien ya que precisamente el éxito de Delphi es la VCL, la cual evita al programador entrar en esas "profundidades" o ¿porque algún programador querría desarrollar en delphi así? ¿Alguien con alma de mártir por ejemplo?

Saludos!

nlsgarcia 07-08-2013 08:55:29

force1758,

Cita:

...es posible crear un formulario, botón, edit etc. solo con APIs de Windows sin el componente VCL que trae el Delphi...
Revisa este link:
Cita:

A guide to developing Delphi programs in Windows API (without the use of the VCL) : http://delphi.about.com/od/windowssh.../apicourse.htm
Espero sea útil :)

Nelson.

ecfisa 07-08-2013 16:45:08

Cita:

Empezado por movorack (Mensaje 465136)
Aunque no entiendo porque reinventar la rueda cuando tienes un ferrari disponible.

Cita:

Empezado por FGarcia (Mensaje 465137)
Interesante ejemplo eficsa, sin embargo como ejemplo didáctico esta muy bien ya que precisamente el éxito de Delphi es la VCL, la cual evita al programador entrar en esas "profundidades" o ¿porque algún programador querría desarrollar en delphi así? ¿Alguien con alma de mártir por ejemplo?

Hola amigos.

Sin dudas que estoy de acuerdo con ustedes, sólo es un ejemplo de como Delphi puede hacerlo.

Saludos :)

force1758 07-08-2013 23:06:01

Gracias a todos por responder a este tema que para mi es muy importante bueno con el ejemplo que me dieron quiesiera saber si lo puedo utilizar en una librería o en dll es tratado pero no logro ningun resultado espero q me puedan ayudar xD

Código Delphi [-]
library Project1;

uses
  Windows,
  Messages,
  SysUtils;

var
  Msg        : TMSG;
  LWndClass  : TWndClass;
  hMainHandle: HWND;
  hButton    : HWND;
  hStatic    : HWND;
  hEdit      : HWND;
  hFontText  : HWND;
  hFontButton: HWND;


procedure ReleaseResources;
begin
  DestroyWindow(hButton);
  DestroyWindow(hStatic);
  DestroyWindow(hEdit);
  DeleteObject(hFontText);
  DeleteObject(hFontButton);
  PostQuitMessage(0);
end;

function WindowProc(hWnd,Msg:Longint; wParam : WPARAM; lParam: LPARAM):Longint; stdcall;
begin
  case Msg of
      WM_COMMAND: if lParam = hButton then
                    MessageBox(hMainHandle,'You pressed the button Hello', 'Hello',MB_OK or MB_ICONINFORMATION);
      WM_DESTROY: ReleaseResources;
  end;
  Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
end;

begin
  //create the window
  LWndClass.hInstance := hInstance;
  with LWndClass do
    begin
      lpszClassName := 'MyWinApiWnd';
      Style         := CS_PARENTDC or CS_BYTEALIGNCLIENT;
      hIcon         := LoadIcon(hInstance,'MAINICON');
      lpfnWndProc   := @WindowProc;
      hbrBackground := COLOR_BTNFACE+1;
      hCursor       := LoadCursor(0,IDC_ARROW);
    end;

  RegisterClass(LWndClass);
  hMainHandle := CreateWindow(LWndClass.lpszClassName,'Window Title', WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE, (GetSystemMetrics(SM_CXSCREEN) div 2)-190,
      (GetSystemMetrics(SM_CYSCREEN) div 2)-170, 386,200,0,0,hInstance,nil);

  //Create the fonts to use
  hFontText := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PIT  CH or FF_SWISS,'Tahoma');
  hFontButton := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');

  //create the static
  hStatic:=CreateWindow('Static','This is static text, like a TLabel',WS_VISIBLE or WS_CHILD or SS_LEFT, 10,10,360,44,hMainHandle,0,hInstance,nil);
  SendMessage(hStatic,WM_SETFONT,hFontText,0);

  //create the edit
  hEdit:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit','This a Edit like and TEdit', WS_VISIBLE or WS_CHILD or ES_LEFT or ES_AUTOHSCROLL,10,35,360,23,hMainHandle,0,hInstance,nil);
  SendMessage(hEdit,WM_SETFONT,hFontText,0);

  //create the button
  hButton:=CreateWindow('Button','Hello', WS_VISIBLE or WS_CHILD or BS_PUSHBUTTON or BS_TEXT, 10,130,100,28,hMainHandle,0,hInstance,nil);
  SendMessage(hButton,WM_SETFONT,hFontButton,0);

  //message loop
  while GetMessage(Msg,0,0,0) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;

end.



procedure DllMain(reason: integer);
begin 
   case reason of 
     DLL_PROCESS_ATTACH: 
     begin
  CreateThread(nil, 0, @WindowProc, nil, 0, 0);

     end;
     DLL_PROCESS_DETACH:
     begin
       // Unload Library 
     end; 
   end; 
end; (*DllMain*)

Gracias saludo

MAXIUM 08-08-2013 03:42:43

Hace años me interese por este tema. La idea era crear un ejecutable lo más reducido posible.

Por otra parte, fue una buena experiencia.

Hay unos "componentes" que también sirven bastante. Los publico en cuanto vuelva a casa.

force1758 08-08-2013 20:23:58

hola de nuevo espero que me ayuden con el src de arriba ya que muestra bien la form pero se me congela la aplicación donde la inyecto por eso no me trabaja como yo quisiera ya que tendría que cerrarla para que siga andando el programa que estoy invadiendo espero que me puedan ayudar
saludos

MAXIUM 09-08-2013 03:33:08

Lo encontré!!! http://kolmck.net

Cita:

KOL - Key Objects Library is a set of objects to develop power (but small) 32 bit Windows GUI applications using Delphi but without VCL (or Free Pascal). It is distributed free of charge, with source code.

force1758 12-08-2013 20:59:30

Cita:

Empezado por MAXIUM (Mensaje 465236)
Lo encontré!!! http://kolmck.net

Gracias por el enlace, pero todavía no me responde lo que pregunte como lo aria para hacerlo funcionar ya que cuando hice la dll con las funciones de arriba se me congela la aplicación donde la inyecto tengo que cerrar la form que hice en la dll para que siga trabajando la aplicación que había inyectado. espero que me respondan si puedes para no dejar este post en el olvido de todas forma gracias por su ayuda y espero su pronta respuestas

José Luis Garcí 12-08-2013 21:46:19

hola force1758 si lo que quieres no es muy complicado e incluso repetitivo, puedes optar por crear una función, con lo que la llamas cada vez que la necesitas, como ejemplo te pongo la siguiente

Código Delphi [-]
//------------------------------------------------------------------------------
//*************************************************************[ Imputdate ]****
//  Parte de la idea original de   Felipe Monteiro  del 25/05/2006
// bajada de http://www.planetadelphi.com.br/dica...tbox-com-combo)
//------------------------------------------------------------------------------
// J.L.G.T. 05/08/2012 Basando me en el código de Felipe Monteiro , lo adapte a
// mis necesidades, creando un imput de doble entrada en mi caso para insertar
// Comentarios Con fecha
//------------------------------------------------------------------------------
//  [Acaption]       String     Texto en la barra del caption
//  [Aprompt]        String     Texto aclaratorio para elmensaje o petición
//  [Separadores]   Boolean    Muestra la fecha entre separadores []
//------------------------------------------------------------------------------
//---EJEMPLO--------------------------------------------------------------------
//  procedure TForm1.Button1Click(Sender: TObject);
//  begin
//     Label1.Caption:=Inputdate('Comentario con fecha','Comentario');
//  end;
//------------------------------------------------------------------------------
function Inputdate(const ACaption, APrompt: string; Separadores:Boolean =true): string;
  function GetCharSize(Canvas: TCanvas): TPoint;
  var
    I: Integer;
    Buffer: array[0..51] of Char;
  begin
    for I := 0 to 25 do Buffer[i] := Chr(I + Ord('A'));
    for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
    GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
    Result.X := Result.X div 52;
  end;

var
  Form: TForm;
  Prompt: TLabel;
  Combo: TDateTimePicker;
  Ed:  TEdit;
  Labelfec2: TLabel;
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  R: TRect;
begin
  Result := '';
  Form   := TForm.Create(Application);
  with Form do
    try
      Canvas.Font     := Font;
      DialogUnits     := GetCharSize(Canvas);
      BorderStyle     := bsDialog;
      FormStyle        :=fsStayOnTop;
      Caption         := ACaption;
      ClientWidth     := MulDiv(195, DialogUnits.X, 4);
      Position        := poScreenCenter;
      Prompt          := TLabel.Create(Form);
      with Prompt do
      begin
        Parent   := Form;
        Caption  := APrompt;
        Left     := MulDiv(8, DialogUnits.X, 4);
        Top      := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(180, DialogUnits.X, 4);
        WordWrap := True;
      end;
      Ed:=TEdit.Create(Form);
      with Ed do
      begin
        Parent     := Form;
        Left      := Prompt.Left;
        Top       := Prompt.top+Prompt.Height+5;
        Width     := MulDiv(180, DialogUnits.X, 4);
        Text      :='';
      end;
      Labelfec2   := TLabel.Create(Form);
      with Labelfec2 do
      begin
        Parent   := Form;
        Caption  := 'Fecha';
        Left     := Prompt.Left;
        Top      := ED.top+ED.Height+5;
        WordWrap := True;
      end;
      Combo := TDateTimePicker.Create(Form);
      with Combo do
      begin
        Parent     := Form;
        Left      := Prompt.Left;
        Top       := Labelfec2.top+Labelfec2.Height+5;
        Width     := MulDiv(178, DialogUnits.X, 4);
      end;
      ButtonTop    := combo.top+Combo.Height+10;;
      ButtonWidth  := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
      with TButton.Create(Form) do
      begin
        Parent      := Form;
        Caption     := 'OK';
        ModalResult := mrOk;
        default     := True;
        SetBounds(MulDiv(Prompt.Left-2, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;
      with TButton.Create(Form) do
      begin
        Parent      := Form;
        Caption     := 'Cancelar';
        ModalResult := mrCancel;
        Cancel      := True;
        SetBounds(MulDiv(137, DialogUnits.X, 4), ButtonTop,ButtonWidth, ButtonHeight);
        Form.ClientHeight := 140;
      end;
      if ShowModal = mrOk then
      begin
        if Separadores then Result:=Ed.Text+' [ '+DateToStr(Combo.Date)+' ]'
                       else Result:=Ed.Text+' '+DateToStr(Combo.Date);
      end;
    finally
      Form.Free;
    end;
end;

y otro ejemplo

Código Delphi [-]
//------------------------------------------------------------------------------
//*************************************************************[ ImputMemo ]****
//  Parte de la idea original de   Felipe Monteiro  del 25/05/2006
// bajada de http://www.planetadelphi.com.br/dica...tbox-com-combo)
//------------------------------------------------------------------------------
// J.L.G.T. 06/08/2012 Basando me en el código de Felipe Monteiro , lo adapte a
// mis necesidades, creando un imput para entradas en memo
//------------------------------------------------------------------------------
//  [Acaption]       String     Texto en la barra del caption
//  [Aprompt]        String     Texto aclaratorio para elmensaje o petición
//  [Text]           String     Texto del MEmo
//------------------------------------------------------------------------------
//---EJEMPLO--------------------------------------------------------------------
//  procedure TForm1.Button1Click(Sender: TObject);
//  begin
//     DBMEMO1.lines.text:=InputMemo('Comentario con fecha','Comentario');
//  end;
//------------------------------------------------------------------------------
function InputMemo(const ACaption, APrompt: string; Text:String =''): string;
  function GetCharSize(Canvas: TCanvas): TPoint;
  var
    I: Integer;
    Buffer: array[0..51] of Char;
  begin
    for I := 0 to 25 do Buffer[i] := Chr(I + Ord('A'));
    for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
    GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
    Result.X := Result.X div 52;
  end;

var
  Form: TForm;
  Prompt: TLabel;
  MEM: TMemo;
  DialogUnits: TPoint;
  ButtonTop, ButtonWidth, ButtonHeight: Integer;
  R: TRect;
begin
  Result := '';
  Form   := TForm.Create(Application);
  with Form do
    try
      Canvas.Font     := Font;
      DialogUnits     := GetCharSize(Canvas);
      BorderStyle     := bsDialog;
      FormStyle        :=fsStayOnTop;
      Caption         := ACaption;
      ClientWidth     := MulDiv(396, DialogUnits.X, 4);
      Position        := poScreenCenter;
      Prompt          := TLabel.Create(Form);
      with Prompt do
      begin
        Parent   := Form;
        Caption  := APrompt;
        Left     := MulDiv(8, DialogUnits.X, 4);
        Top      := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(180, DialogUnits.X, 4);
        WordWrap := True;
      end;
      MEM := TMemo.Create(Form);
      with MEM do
      begin
        Parent         := Form;
        Left          := Prompt.Left;
        Top           := Prompt.top+Prompt.Height+5;
        Height        := 150;
        Width         := MulDiv(380, DialogUnits.X, 4);
        Lines.Text    := Text;
      end;
      ButtonTop    := MEM.top+MEM.Height+10;;
      ButtonWidth  := MulDiv(50, DialogUnits.X, 4);
      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
      with TButton.Create(Form) do
      begin
        Parent      := Form;
        Caption     := 'OK';
        ModalResult := mrOk;
        default     := True;
        SetBounds(MulDiv(Prompt.Left-2, DialogUnits.X, 4), ButtonTop, ButtonWidth,
          ButtonHeight);
      end;
      with TButton.Create(Form) do
      begin
        Parent      := Form;
        Caption     := 'Cancelar';
        ModalResult := mrCancel;
        Cancel      := True;
        SetBounds(MulDiv(340, DialogUnits.X, 4), ButtonTop,ButtonWidth, ButtonHeight);
        Form.ClientHeight := 220;
      end;
      MEM.Lines.Clear;
      MEM.Lines.Add(Text);
      if ShowModal = mrOk then Result:=MEM.Lines.Text
                          else Result:=Text;   //Devuelve el original
    finally
      Form.Free;
    end;
end;


La franja horaria es GMT +2. Ahora son las 20:40:54.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi