• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 528
  • Last Modified:

Insert a VCL Control into a TWndClass

Hello, Experts?, I am from Dominican Republic, so sorry, I don't speak english at all. I would like to know how can I insert a VCL control into a TWndClass, I mean a WebBrowser component, a PageControl Component. I want to do a project that is going to display a WebPage and the only component that the form has is a WebBrowser and some others component that I have created with some specials functions, the problem is that the size of the application is over 350 Kb and is too big for only using a WebBrowser, so I Created a class from TWndClass but I don't know how can I insert the WebBrowser componet and my owns component to the class descendant from TWndClass.

Wishing you to answer me
Elvin L. Reyes
0
elvinluis29
Asked:
elvinluis29
1 Solution
 
odissey1Commented:
Hi elvinluis29,

ANY reference to VCL control in the application pulls ~250-280kb. I don't see how the size of the application (your final goal) could be reduced.

regards,
odissey1
0
 
elvinluis29Author Commented:
odissey1,

hello, thanks for answer.

The code that I using is this, this code reduce the size of the application a lot, but I can not insert a vcl control into the main form.

program ProgramName;
uses
  Windows,Messages,SysUtils,ExtCtrls;

var
 wClass: TWndClass;
 Msg: TMSG;
 Panel1:TPanel; //could be any other VCL component ie. TButton, TCalendar, TWebBrowser.
 hAppHandle: HWND;

function WndMessageProc(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT; stdcall;
begin

  case Msg of
    WM_CREATE:begin
                Panel1:=TPanel.Create(nil);
                // here is the problem, how do I insert this control to wClass?
              end;
    WM_DESTROY:
               begin
                 PostQuitMessage(0);
               end;
    WM_CLOSE:  begin
               end;
    WM_CHAR:   begin
               end;
    WM_COMMAND:begin

               end;
  end;

  Result := DefWindowProc(hWnd,Msg,wParam,lParam);
end;


BEGIN   // then MAIN Program Begin
  wClass.hInstance := hInstance;
  with wClass do
  begin
    style :=        0;
    hIcon :=        LoadIcon(0,'MAINICON');
    lpfnWndProc :=  @WndMessageProc;
    hbrBackground:= COLOR_BTNFACE+1;
    lpszClassName:= 'TForm';
    hCursor :=      LoadCursor(0,IDC_ARROW);
    cbClsExtra := 0;
    cbWndExtra := 0;
    lpszMenuName := '';
  end;

  RegisterClass(wClass);
  hAppHandle := CreateWindow(
    wClass.lpszClassName,
    'My program',
    WS_CAPTION or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX,
    Integer(CW_USEDEFAULT),
    Integer(CW_USEDEFAULT),
    178,
    210,
    0,
    0,
    hInstance,
    nil
   );
  if hAppHandle = 0 then
  begin
    UnRegisterClass(wClass.lpszClassName, hInstance);
    Exit;
  end;


  while GetMessage(Msg,0,0,0) do
  begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;
end.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Elvin,

Its the "dragging in" of the Foms unit that leads to the bloated size. Even testing your code, the resulting exe size is 288KB. (The ExtCtrls unit includes the Form unit). To answer your immediate question above though:

  case Msg of
    WM_CREATE:begin
                Panel1:=TPanel.Create(nil);
                Panel1.ParentWindow:=hWnd; // The key to making it work
                Panel1.SetBounds(10, 10, 100, 40); // Set bounds for the pane;
                Panel1.Visible:=True; // Display the panel
                result:=0;
   end;

The above code will make the panel a child of your base window. But still, with the WebBrowser control, your going to be dragging in ActiveX, ComObj, etc related units, so in the end, the size is still going to be 300KB plus. Not much you can do about it in the end though....

Regards,
Russell

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
elvinluis29Author Commented:
Russell,

Thank you for you answer, I thought I can reduce the size of the application this way.

Elvin.
0
 
Slick812Commented:
hello elvinluis29, you are right in thinking that the size of the program file will be smaller if you use the API windows program creation that you have coded above, however,  you can not effectively use ANY of the delphi  VCL visual components in this type of API programming, well maybe if you do alot of "Corrective" coding with it, and you may as well use the Forms unit, because the forms.pas  is in the VCL components somewhere anyway, if your main interrest is in a smaller program file size, and you do not have the time to learn the API nessariry to "Convert" the components you need to API, , , , then you might try the Key Objects Library at

http://bonanzas0.tripod.com/

this KOL is made to reduce the file size of delphi executables, and you will need to "Learn"  some of the KOL programming interface which is not too much different than the regular Delphi coding, ,, but it is much more easy than the work required to do pure API programming. . . If you are interested in the API programming you can visit my site at

http://www.angelfire.com/hi5/delphizeus/index.html
0
 
elvinluis29Author Commented:
Slick812,

Hello, Thanks for you answer, I went into your Site and it is so interesting, in the site http://bonanzas0.tripod.com/ is the answer  for making small program in delphi, I just want to do this program wth a small size because I got a friend that uses VB as language programming and this program are always in small size.}

Thanks for averyone who has answer to me.

Elvin L. Reyes.
0
 
Russell LibbySoftware Engineer, Advisory Commented:

Slick, I was going to mention KOL as well, but I didn't find a wrapper around the IE browser objects, so I didn't bring it up. An excellent library for making smaller programs though (without manual coding using straight win APIs)

Elvin,

Regarding the VB apps size...
The reason that the VB programs are so small in size is that they are most likely  using run time libraries. The benefit of this is the smaller exe size. The downside is having to make sure that they (the run time libraries) are always installed on the users system in order for the VB app to run. Delphi on the other hand, while making larger compiled exe's, requires nothing extra to be included....

Regards,
Russell

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now