MSEide MSEgui Howto: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: MSEide MSEgui Howto
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Demos and examples | |
| 2 | + | ||
| 3 | + | <https://github.com/mse-org/mseuniverse/> | |
| 4 | + | ||
| 5 | + | ## Win32 Application Icon and Properties | |
| 6 | + | ||
| 7 | + | 1\) Prepare the resource source files in the directory of your program: | |
| 8 | + | ||
| 9 | + | File "version_data.rc": | |
| 10 | + | ||
| 11 | + | `1 VERSIONINFO`\ | |
| 12 | + | `FILEVERSION 4,0,3,17`\ | |
| 13 | + | `PRODUCTVERSION 3,0,0,0`\ | |
| 14 | + | `FILEFLAGSMASK 0`\ | |
| 15 | + | `FILEOS 0x40000`\ | |
| 16 | + | `FILETYPE 1`\ | |
| 17 | + | `{`\ | |
| 18 | + | ` BLOCK "StringFileInfo"`\ | |
| 19 | + | ` {`\ | |
| 20 | + | ` BLOCK "040904E4"`\ | |
| 21 | + | ` {`\ | |
| 22 | + | ` VALUE "CompanyName","JSC TashkentP"`\ | |
| 23 | + | ` VALUE "FileDescription","The main program file"`\ | |
| 24 | + | ` VALUE "FileVersion","0.9a"`\ | |
| 25 | + | ` VALUE "InternalName","ARM Podpiska"`\ | |
| 26 | + | ` VALUE "LegalCopyright","JSC TashkentP’s property"`\ | |
| 27 | + | ` VALUE "OriginalFilename","podpiska.pas"`\ | |
| 28 | + | ` VALUE "ProductName","The program for ARM Podpiska"`\ | |
| 29 | + | ` VALUE "ProductVersion","0.9a"`\ | |
| 30 | + | ` }`\ | |
| 31 | + | ` }`\ | |
| 32 | + | `}` | |
| 33 | + | ||
| 34 | + | File "icon_data.rc": | |
| 35 | + | ||
| 36 | + | ` AppIcon ICON "app_icon.ico"` | |
| 37 | + | ||
| 38 | + | 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. | |
| 39 | + | ||
| 40 | + | My favorite editor to prepare such (and any kind of image) files is "Embellish". | |
| 41 | + | ||
| 42 | + | 2\) From within Win-32 command shell, compile the prepared files with the supplied FPC resource compiler: | |
| 43 | + | ||
| 44 | + | ` # windres -O res -i version_data.rc -o version_data.res`\ | |
| 45 | + | ` # windres -O res -i icon_data.rc -o icon_data.res` | |
| 46 | + | ||
| 47 | + | 3\) use the compiled resources in your application : | |
| 48 | + | ||
| 49 | + | ``` pascal | |
| 50 | + | program super_puper; | |
| 51 | + | ||
| 52 | + | {$ifdef FPC}{$mode objfpc}{$h+}{$INTERFACES CORBA}{$endif} | |
| 53 | + | {$ifdef FPC} | |
| 54 | + | {$ifdef mswindows} | |
| 55 | + | {$apptype console} | |
| 56 | + | {$endif} | |
| 57 | + | {$endif} | |
| 58 | + | uses | |
| 59 | + | {$ifdef FPC}{$ifdef linux}cthreads,{$endif}{$endif}msegui,mseforms, | |
| 60 | + | main,dmmain,dmprint, dmacnt1, dmf18,dmrefs, | |
| 61 | + | connsetupform,mseconsts,mseconsts_ru,mseconsts_uzcyr; | |
| 62 | + | ||
| 63 | + | // importing the compiled resources | |
| 64 | + | ||
| 65 | + | {$ifdef mswindows} | |
| 66 | + | {$R version_data.res} | |
| 67 | + | {$R icon_data.res} | |
| 68 | + | {$endif} | |
| 69 | + | ||
| 70 | + | begin | |
| 71 | + | setlangconsts('ru'); | |
| 72 | + | application.createdatamodule(tdmmainmo,dmmainmo); | |
| 73 | + | application.createdatamodule(tdmprintmo, dmprintmo); | |
| 74 | + | application.createdatamodule(tdmacnt1mo, dmacnt1mo); | |
| 75 | + | application.createdatamodule(tdmf18mo, dmf18mo); | |
| 76 | + | application.createdatamodule(tdmrefsmo, dmrefsmo); | |
| 77 | + | application.createform(tmainfo,mainfo); | |
| 78 | + | application.run; | |
| 79 | + | end. | |
| 80 | + | ``` | |
| 81 | + | ||
| 82 | + | That's all at the moment. | |
| 83 | + | ||
| 84 | + | ## Dynamic widget creation | |
| 85 | + | ||
| 86 | + | To dynamically create a new widget (without using IDE), you need to do the following steps: | |
| 87 | + | ||
| 88 | + | - Instantiate a class with its `Create` constructor (passing the owner as the argument). | |
| 89 | + | - Create a `frame` for the component and set up its properties. | |
| 90 | + | - Optionally, create a `face` for the component and set up its properties. | |
| 91 | + | - Set up the component size with `bounds_cx` and `bounds_cy` properties. | |
| 92 | + | - Add the component to the window or other container by calling the container's `insertwidget`. | |
| 93 | + | - Show the component by calling its `show` method, or by setting `visible` to `true`. | |
| 94 | + | ||
| 95 | + | Here is an example of dynamically creating a `tedit` (for this code to work, you need to add `dynedit: tedit;` property declaration): | |
| 96 | + | ||
| 97 | + | ``` pascal | |
| 98 | + | procedure tmainfo.mainformcreated(const sender: TObject); | |
| 99 | + | begin | |
| 100 | + | dynedit := tedit.Create(self); | |
| 101 | + | dynedit.bounds_cx := 100; | |
| 102 | + | dynedit.bounds_cy := 21; | |
| 103 | + | dynedit.createframe; | |
| 104 | + | dynedit.frame.levelo := -2; | |
| 105 | + | insertwidget(dynedit, makepoint(300, 10)); | |
| 106 | + | dynedit.show; | |
| 107 | + | end; | |
| 108 | + | ``` | |
| 109 | + | ||
| 110 | + | If you need custom value for the `face` property, you can set it up as follows: | |
| 111 | + | ||
| 112 | + | ``` pascal | |
| 113 | + | dynedit.createface; | |
| 114 | + | with dynedit.face do begin | |
| 115 | + | fade_color.count := 2; | |
| 116 | + | fade_color[0] := cl_ltgreen; | |
| 117 | + | fade_color[1] := cl_dkgreen; | |
| 118 | + | fade_direction := gd_down; | |
| 119 | + | end; | |
| 120 | + | ``` | |
| 121 | + | ||
| 122 | + | --- | |
| 123 | + | *From the Free Pascal wiki, page "MSEide MSEgui Howto", as it stood on 2023-07-20 after a change by Fredvs, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 124 | + | Category: MSEide+MSEgui | |
| 125 | + | Category: Tutorials | |
| 126 | + | Category: Windows |
