Solved

Insert a VCL Control into a TWndClass

Posted on 2003-12-10
7
512 Views
Last Modified: 2010-04-05
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
Comment
Question by:elvinluis29
7 Comments
 
LVL 2

Expert Comment

by:odissey1
ID: 9914206
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
 

Author Comment

by:elvinluis29
ID: 9914812
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
 
LVL 26

Expert Comment

by:Russell Libby
ID: 9915359

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:elvinluis29
ID: 9916069
Russell,

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

Elvin.
0
 
LVL 33

Expert Comment

by:Slick812
ID: 9918179
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
 

Author Comment

by:elvinluis29
ID: 9919845
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
 
LVL 26

Accepted Solution

by:
Russell Libby earned 50 total points
ID: 9920202

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now