Difference between revisions of "MSEide MSEgui Howto"

From Lazarus wiki
Jump to navigationJump to search
(Tips of Mirror to assign a visible frame)
(11 intermediate revisions by 6 users not shown)
Line 1: Line 1:
=Win32 Application Icon and Properties=
+
== Win32 Application Icon and Properties ==
  
 
1) Prepare the resource source files in the directory of your program:
 
1) Prepare the resource source files in the directory of your program:
Line 5: Line 5:
 
File "version_data.rc":
 
File "version_data.rc":
  
<pre>
+
1 VERSIONINFO
1 VERSIONINFO
+
FILEVERSION 4,0,3,17
FILEVERSION 4,0,3,17
+
PRODUCTVERSION 3,0,0,0
PRODUCTVERSION 3,0,0,0
+
FILEFLAGSMASK 0
FILEFLAGSMASK 0
+
FILEOS 0x40000
FILEOS 0x40000
+
FILETYPE 1
FILETYPE 1
 
{
 
BLOCK &rdquo;StringFileInfo&rdquo;
 
 
  {
 
  {
   BLOCK &rdquo;040904E4&rdquo;
+
   BLOCK "StringFileInfo"
 
   {
 
   {
  VALUE &rdquo;CompanyName&rdquo;,&rdquo;JSC TashkentP&rdquo;
+
  BLOCK "040904E4"
  VALUE &rdquo;FileDescription&rdquo;,&rdquo;The main program file&rdquo;
+
  {
  VALUE &rdquo;FileVersion&rdquo;,&rdquo;0.9a&rdquo;
+
  VALUE "CompanyName","JSC TashkentP"
  VALUE &rdquo;InternalName&rdquo;,&rdquo;ARM Podpiska&rdquo;
+
  VALUE "FileDescription","The main program file"
  VALUE &rdquo;LegalCopyright&rdquo;,&rdquo;JSC TashkentP&rsquo;s property&rdquo;
+
  VALUE "FileVersion","0.9a"
  VALUE &rdquo;OriginalFilename&rdquo;,&rdquo;podpiska.pas&rdquo;
+
  VALUE "InternalName","ARM Podpiska"
  VALUE &rdquo;ProductName&rdquo;,&rdquo;The program for ARM Podpiska&rdquo;
+
  VALUE "LegalCopyright","JSC TashkentP&rsquo;s property"
  VALUE &rdquo;ProductVersion&rdquo;,&rdquo;0.9a&rdquo;
+
  VALUE "OriginalFilename","podpiska.pas"
 +
  VALUE "ProductName","The program for ARM Podpiska"
 +
  VALUE "ProductVersion","0.9a"
 +
  }
 
   }
 
   }
 
  }
 
  }
}
 
</pre>
 
  
File &rdquo;icon_data.rc&rdquo;:
+
File "icon_data.rc":
  
<pre>
+
  AppIcon ICON "app_icon.ico"
AppIcon ICON &rdquo;app_icon.ico&rdquo;
 
</pre>
 
  
where &rdquo;app_icon.ico&rdquo; is 128x128 24bit ICO image. You may use any size at your favour ( usually depends on preferrable destop resilution/size ) commonly greater or equal to 24x24 pixels.
+
where "app_icon.ico" is 128x128 24bit ICO image. You may use any size at your favour (usually depends on preferable destop resolution/size) commonly greater or equal to 24x24 pixels.
  
My favorite editor to prepare such ( and any kind of image ) files is &rdquo;Embellish&rdquo;.
+
My favorite editor to prepare such (and any kind of image) files is "Embellish".
  
 +
2) From within Win-32 command shell, compile the prepared files with the supplied
 +
FPC resource compiler:
  
2) From within Win-32 command shell, complile the prepared files with the supplied
+
  # windres -O res -i version_data.rc -o version_data.res
FPC resource compiler :
+
  # windres -O res -i icon_data.rc -o icon_data.res
 
 
<code>
 
# windres -O res -i version_data.rc -o version_data.res
 
# windres -O res -i icon_data.rc -o icon_data.res
 
</code>
 
 
 
  
 
3) use the compiled resources in your application :
 
3) use the compiled resources in your application :
  
<delphi>
+
<syntaxhighlight lang=pascal>
 
program super_puper;
 
program super_puper;
  
Line 83: Line 75:
 
  application.run;
 
  application.run;
 
end.
 
end.
</delphi>
+
</syntaxhighlight>
  
 
That's all at the moment.
 
That's all at the moment.
 +
 +
== Dynamic widget creation ==
 +
 +
To dynamically create a new widget (without using IDE), you need to do the following steps:
 +
 +
* Instantiate a class with its <code>Create</code> constructor (passing the owner as the argument).
 +
* Create a <code>frame</code> for the component and set up its properties.
 +
* Optionally, create a <code>face</code> for the component and set up its properties.
 +
* Set up the component size with <code>bounds_cx</code> and <code>bounds_cy</code> properties.
 +
* Add the component to the window or other container by calling the container's <code>insertwidget</code>.
 +
* Show the component by calling its <code>show</code> method, or by setting <code>visible</code> to <code>true</code>.
 +
 +
Here is an example of dynamically creating a <code>tedit</code> (for this code to work, you need to add <code>dynedit: tedit;</code> property declaration):
 +
 +
<syntaxhighlight lang=pascal>
 +
procedure tmainfo.mainformcreated(const sender: TObject);
 +
begin
 +
  dynedit := tedit.Create(self);
 +
  dynedit.bounds_cx := 100;
 +
  dynedit.bounds_cy := 21;
 +
  dynedit.createframe;
 +
  dynedit.frame.levelo := -2;
 +
  insertwidget(dynedit, makepoint(300, 10));
 +
  dynedit.show;
 +
end;
 +
</syntaxhighlight>
 +
 +
If you need custom value for the <code>face</code> property, you can set it up as follows:
 +
 +
<syntaxhighlight lang=pascal>
 +
  dynedit.createface;
 +
  with dynedit.face do begin
 +
    fade_color.count := 2;
 +
    fade_color[0] := cl_ltgreen;
 +
    fade_color[1] := cl_dkgreen;
 +
    fade_direction := gd_down;
 +
  end;
 +
</syntaxhighlight>
 +
 +
[[Category:MSEide+MSEgui]]
 +
[[Category:Tutorials]]
 +
[[category:Windows]]

Revision as of 23:52, 30 March 2021

Win32 Application Icon and Properties

1) Prepare the resource source files in the directory of your program:

File "version_data.rc":

1 VERSIONINFO
FILEVERSION 4,0,3,17
PRODUCTVERSION 3,0,0,0
FILEFLAGSMASK 0
FILEOS 0x40000
FILETYPE 1
{
 BLOCK "StringFileInfo"
 {
  BLOCK "040904E4"
  {
  VALUE "CompanyName","JSC TashkentP"
  VALUE "FileDescription","The main program file"
  VALUE "FileVersion","0.9a"
  VALUE "InternalName","ARM Podpiska"
  VALUE "LegalCopyright","JSC TashkentP’s property"
  VALUE "OriginalFilename","podpiska.pas"
  VALUE "ProductName","The program for ARM Podpiska"
  VALUE "ProductVersion","0.9a"
  }
 }
}

File "icon_data.rc":

 AppIcon ICON "app_icon.ico"

where "app_icon.ico" is 128x128 24bit ICO image. You may use any size at your favour (usually depends on preferable destop resolution/size) commonly greater or equal to 24x24 pixels.

My favorite editor to prepare such (and any kind of image) files is "Embellish".

2) From within Win-32 command shell, compile the prepared files with the supplied FPC resource compiler:

 # windres -O res -i version_data.rc -o version_data.res
 # windres -O res -i icon_data.rc -o icon_data.res

3) use the compiled resources in your application :

program super_puper;

{$ifdef FPC}{$mode objfpc}{$h+}{$INTERFACES CORBA}{$endif}
{$ifdef FPC}
 {$ifdef mswindows}
  {$apptype console}
 {$endif}
{$endif}
uses
 {$ifdef FPC}{$ifdef linux}cthreads,{$endif}{$endif}msegui,mseforms,
 main,dmmain,dmprint, dmacnt1, dmf18,dmrefs,
 connsetupform,mseconsts,mseconsts_ru,mseconsts_uzcyr;

// importing the compiled resources

{$ifdef mswindows}
 {$R version_data.res}
 {$R icon_data.res}
{$endif}

begin
 setlangconsts('ru');
 application.createdatamodule(tdmmainmo,dmmainmo);
 application.createdatamodule(tdmprintmo, dmprintmo);
 application.createdatamodule(tdmacnt1mo, dmacnt1mo);
 application.createdatamodule(tdmf18mo, dmf18mo);
 application.createdatamodule(tdmrefsmo, dmrefsmo);
 application.createform(tmainfo,mainfo);
 application.run;
end.

That's all at the moment.

Dynamic widget creation

To dynamically create a new widget (without using IDE), you need to do the following steps:

  • Instantiate a class with its Create constructor (passing the owner as the argument).
  • Create a frame for the component and set up its properties.
  • Optionally, create a face for the component and set up its properties.
  • Set up the component size with bounds_cx and bounds_cy properties.
  • Add the component to the window or other container by calling the container's insertwidget.
  • Show the component by calling its show method, or by setting visible to true.

Here is an example of dynamically creating a tedit (for this code to work, you need to add dynedit: tedit; property declaration):

procedure tmainfo.mainformcreated(const sender: TObject);
begin
  dynedit := tedit.Create(self);
  dynedit.bounds_cx := 100;
  dynedit.bounds_cy := 21;
  dynedit.createframe;
  dynedit.frame.levelo := -2;
  insertwidget(dynedit, makepoint(300, 10));
  dynedit.show;
end;

If you need custom value for the face property, you can set it up as follows:

  dynedit.createface;
  with dynedit.face do begin
    fade_color.count := 2;
    fade_color[0] := cl_ltgreen;
    fade_color[1] := cl_dkgreen;
    fade_direction := gd_down;
  end;