Download documentation |
Let us start writing our application from creating an icon for it calculator.ico. You can use any icon editor for that. Then we need to create a resource file with dialog boxes and the icon. With ResEd mentioned in the Introduction, we will created the resource file calculator.rc. It will contain the main dialog box, the "About" dialog box and the icon. We will make our calculator keyboard-oriented without numeric and functional buttons in the main dialog box. We will have the field for entering expressions at the top, the fields for variable values to the left and two fields to display results in the decimal and hexadecimal forms to the right.
Use any resource compiler, for example GoRC, to create the file calculator.res out of calculator.rc. It is this file that we will use further on.
And now we will create the file calculator.gt with necessary descriptions.
Let us describe the text resources of our program.
<english language default type = keys>
aboutver = Calculator v1.0 Freeware
caption = Calculator
...
The description of linked resources (an icon and two dialog boxes) follows this.
<appres resource >
<icon = 3000 icon>
<about = IDD_ABOUT dialog cmdproc = aboutproc >
<main = IDD_MAIN dialog cmdproc = mainproc >
</appres>
Besides, we need to specify the font for the name of the program in the "About" dialog box.
<fonts fonts>
<head name = "Arial" size = 10 bold></head>
</fonts>
And we will also describe the items of the dialog boxes that are not standard control elements.
<dlgitem>
<url class = GWurl text = url></>
<email class = GWurl text = email shell = emailshell ></email>
<about class = static font = fonts/head></about>
</dlgitem>
Now we can get down directly to writing the program calculator.gt. We include calculator.gt into our program and specify the values of some items present in the dialog boxes.
global {
str gtstr = "\<calculator.gt>"
}
define
{
IDC_ABOUTHEAD = 1003
IDC_ABOUT = 1005
IDC_EXPR = 1006
}
Let us take the event handler of the "About" dialog box.
func uint aboutproc( uint wnd id ctl codedlg )
{
switch id
{
case 0
{
langsetwin( wnd )
SetFocus( GetDlgItem( wnd, $IDOK ))
dlgsubst( wnd )
setdlgtext( wnd, $IDC_ABOUTHEAD, "aboutver".getlang())
}
case $IDOK,$IDCANCEL
{
EndDialog( wnd, 1 )
return 1
}
}
return 0
}
If id equals zero, the dialog box is initiated. We use langsetwin to specify text resources and dlgsubst to change the items described in calculator.gt as dlgitem/.... We define a similar handling function for the main dialog box. We also add handling a click on the "About" button
case $IDC_ABOUT : showdialog( "appres/about" )
We finish our source code with the main function. gtapp is a global variable of the gt type that should contain all necessary data.
After you launch this example, you will see a dialog box where only the "About" and "Exit" buttons function. A click on the "About" button will open the "About" dialog box.
![]() |
![]() Copyright © 2004-2005 Gentee, Inc. All rights reserved. ![]() |