oracledba.help
QuickStarts

HMG Notes

<- QuickStarts

Page Under Construction

  1. Create New Project
  2. Create Menu
  3. Create ToolBar
  4. Add a Header File (.ch)
  5. Add a New Module (.prg)
  6. Embed Image Into .Exe
  7. Embed Icon Into .Exe

Create New Project

1. Create a directory for new app.
   Ex: C:\app\hmg\dev\MyApp
2. Run the HMG IDE and select: File -> New Project
3. Enter path for new project file and press Save.
   Ex: C:\app\hmg\dev\MyApp\MyApp.hbp
   A new base app framework is created.
4. Press the Run button to create the .exe file ensuring everything is OK.

Create Menu

1. From the Project Browser - Forms Tab, open the Main.fmg window.
2. Select the Main Menu Builder button.
3. To create a parent (File) menu.
   a. Caption: File
   b. Action: <leave blank>
   c. name: mnuFile
4. Add submenu item selecting Next.
   a. Caption: About
   b. Action: MsgInfo('My applciation 1.0','About')
   c. Name: itmAbout
   d. Use left arrow making the item a child of the parent menu.
5. Run\test your application seeing the new menu.
6. Repeat steps as required.

For an Exit item action you can use: Main.Release

Example main.prg

#include "common.ch"
#include <error.ch>
#include <hmg.ch>
#require "rddsql"

REQUEST SDDODBC, SQLMIX

Function Main
   // PUBLIC Vars
   PUBLIC gcCfgFile, gaRows, gaSystems
   PUBLIC gcSystems, gcDriver, gcSID, gcPort, gcUsername, gcLicense, gcSystem_Schema
   PUBLIC gcConnStr, ghConn, gcSQL

   // Init Main Window
   Load Window Main
   Main.Center
   Main.Activate
Return

PROCEDURE winMain_onInit()
   local i

   Set(_SET_DATEFORMAT, "yyyy-mm-dd")
   rddSetDefault("SQLMIX")

   // Init Cfg\Global Vars
   gcCfgFile  := hb_DirBase() + AppBaseName() + ".ini"
   gcSystems  := ""
   gcDriver   := ""
   gcSID      := ""
   gcPort     := ""
   gcUsername := ""
   gcLicense  := ""
   gcSystem_Schema := ""

   // Init Global\Public Vars
   INI_init(gcCfgFile)
   gaSystems := hb_atokens(gcSystems, ",")

   // Fill LBX
   Main.lbxDatabases.DeleteAllItems
   for i := 1 to Len(gaSystems)
      DoMethod ( "Main", "lbxDatabases", 'AddItem', gaSystems[i] )
   next
RETURN Nil

PROCEDURE winMain_onRelease()
   dbCloseAll()
RETURN Nil

Create ToolBar

1. From the Project Browser - Forms Tab, open the Main.fmg window.
2. Select the ToolBar button.
3. Select Properties button and provide main tool bar info:
   a. TlBar Name: tbMain
   b. Button Width:  35
   c. Button Height: 35
   d. Select desired attributes: Flat, Border ...
4. Enter Button Properties
   Name:    btnTest
   Caption: Test
   Picture: <image file name> Ex: test.png
   Action:  MsgInfo('Testing...','Test')
5. Run\test your application seeing the new ToolBar.
6. Repeat steps as required.

Add a Header File (.ch)

1. From the Project Menu: New Include
2. Enter Name: (Ex: common)
3. Enter header file definitions as needed. Example below:
#DEFINE RDD_CONNECT    1001
#DEFINE RDD_DISCONNECT 1002

Add a New Module (.prg)

1. From the Project Menu: New Module
2. Enter Name: (Ex: common)
3. Enter program file (Ex: common.prg) to associate it with your main.prg. Example below:
#include "common.ch"
#include <error.ch>
#include <hmg.ch>
#require "rddsql"

FUNCTION About(cAppinfo)   
   MsgInfo(cAppinfo,"About")
RETURN

FUNCTION AppBaseName()   
   local cGetProgramFileName, nPosOfDot, cAppName
   cGetProgramFileName := TOKEN( GetProgramFileName(),"\" )
   nPosOfDot           := at('.',cGetProgramFileName)
   cAppName            := SubStr( cGetProgramFileName, 1, nPosOfDot -1 )
RETURN cAppName

FUNCTION CfgValue(cFile,cSection,cEntry,cDefault)
   local cCfgValue
   IF file(cFilePath)
      BEGIN INI FILE (cFilePath)
         GET cCfgValue SECTION cSection ENTRY cEntry
      END INI
   ELSE
      cCfgValue := cDefault
   ENDIF   
RETURN cCfgValue

FUNCTION Darkmatter_get(cDarkStringIn)
   LOCAL cClearString
   cClearString := HB_Base64Decode(cDarkStringIn,1)
RETURN cClearString

FUNCTION Darkmatter_set(cClearStringIn)
   LOCAL cDarkString
    cDarkString := HB_StrFormat(HB_Base64Encode(cClearStringIn,1)) 
RETURN cDarkString

FUNCTION INI_init(cFilePath)
   IF .NOT. file(cFilePath)
      INI_default(cFilePath)
   ENDIF

   // getValues
   BEGIN INI FILE (cFilePath)
      GET gcSystems        SECTION "Oracle" ENTRY "Systems"
      GET gcDriver         SECTION "Oracle" ENTRY "Driver"
      GET gcSID            SECTION "Oracle" ENTRY "SID"
      GET gcPort           SECTION "Oracle" ENTRY "Port"
      GET gcUsername       SECTION "Oracle" ENTRY "Username"         
      GET gcLicense        SECTION "Oracle" ENTRY "License"
      GET gcSystem_Schema  SECTION "Oracle" ENTRY "System_Schema"
   END INI
   gcLicense := Darkmatter_get(gcLicense)
   gaSystems := hb_atokens(gcSystems, ",")
RETURN Nil

FUNCTION INI_default(cFilePath)
      BEGIN INI FILE (cFilePath)
         SET SECTION "Oracle" ENTRY "Systems"       TO "localhost"
         SET SECTION "Oracle" ENTRY "Driver"        TO "Oracle in OraDB12Home1"
         SET SECTION "Oracle" ENTRY "SID"           TO "DB01"
         SET SECTION "Oracle" ENTRY "Port"          TO "1521"
         SET SECTION "Oracle" ENTRY "Username"      TO "SCOTT"
         SET SECTION "Oracle" ENTRY "License"       TO "kj3452jh4kh5k2345gf"
         SET SECTION "Oracle" ENTRY "System_Schema" TO "X15"
         MsgBox("Created a default config file: " + cFilePath)
      END INI
RETURN Nil

FUNCTION Password_change()
   LOCAL cPW
   cPW := alltrim(InputBox("Enter new password:","Password Change"))
   IF .NOT. empty(cPW)
      BEGIN INI FILE (gcCfgFile)
         SET SECTION "Oracle" ENTRY "License" TO Darkmatter_set(cPW)
      END INI
      MsgInfo("New password saved.","Status")
   ELSE
      MsgInfo("No change has been made to the password.","Status")
      RETURN
   ENDIF
RETURN

After this the procedures\functions in your new module can be called from your main.prg and window (fmg). Menu Example: Action: About("My App 1.01")

Embed Image Into .Exe

1. Copy your image to the dir your project is in.
2. Close IDE.
3. Edit the .rc file for project and add entry for your image.
   Format: <IDName> <type> <FileName.ext>
   Examples: 
   ImgJPG JPG myimage.jpg
   ImgBMP BITMAP myimage.BMP
   ImgGIF GIF myimage.GIF
   ImgTIF TIF myimage.TIF
   ImgPNG PNG myimage.PNG
   ImgWMF WMF myimage.WMF
   ImgICO ICO myimage.ICO
   ImgCUR CUR myimage.CUR
4. Open your project.
5. Associate your image with your button or other control using the IDName.
   Ex: Referring to above .rc entries, for a Toolbar Picture
       you would use ImgPNG as the value (not file name).
6. Run project (image is now embedded into the .exe file).

Notes:
- 32x32 and larger good for toolbars.

Embed Icon Into .Exe

TBD