Passed a quite long time... but finnaly I backed to this matter.
Now with some more HMG knowledge in my small luggage !
This error happen because in the previous code sample was missing
COMMPATH definition.
In HMG instead of Minigui Extended we need to define thru
SET COMMPATH TO command.
- So added SET COMMPATH TO command.
- There was also an hard execution when trying to the button EXIT. I replaced Form.Release by TerminateProcess()
- Some other functions was added like: SetForegroundWindow and SetConsoleTitle.
- Replace SW_MINIMIZE property by SW_HIDE for console opend session
Code: Select all
/*
Based on Grigory MixedMode demo
Adapted version for HMG
By Pablo César Arrascaeta
On February 23rd, 2015
*/
#include <hmg.ch>
REQUEST HB_GT_WIN_DEFAULT
Function Main()
Local title:='Harbour MiniGUI Demo'
SET STATIONNAME TO "MAINPROC"
SET COMMPATH TO GetCurrentFolder()+"\"
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE title+" - GUI" ;
MAIN ;
FONT 'Arial' SIZE 10;
ON INIT ConsoleInit(title+" - Console")
DEFINE LABEL Label1
ROW 10
COL 10
VALUE "Good morning"
END LABEL
DEFINE TEXTBOX Box1
ROW 10
COL 100
WIDTH 60
HEIGHT 24
VALUE " 5"
NUMERIC .F.
END TEXTBOX
DEFINE BUTTON Btn1
ROW 50
COL 10
CAPTION 'Press me'
ACTION {||FN1(), SetProperty("Form_1","Box1","Value",AllTrim(Str(GetData())))}
END BUTTON
DEFINE BUTTON Btn2
ROW 100
COL 10
CAPTION 'Message'
ACTION FN2(Form_1.Box1.value)
END BUTTON
DEFINE BUTTON Btn3
ROW 150
COL 10
CAPTION 'EXIT'
ACTION TerminateProcess() // Form_1.release
END BUTTON
END WINDOW
Form_1.Center()
Form_1.Activate()
Return Nil
FUNCTION FN1()
HIDE WINDOW Form_1
ShowConsole()
CLEAR SCREEN
r1 := 0
r2 := 0
@ 10,10 SAY ' S1 ' get r1 pict '9999'
@ 12,10 SAY ' S2 ' get r2 pict '9999'
read
HideConsole()
Form_1.Restore
Form_1.Show
SetForegroundWindow(Form_1.Handle)
Form_1.Box1.SetFocus
SendData("MAINPROC",r2)
RETURN
FUNCTION FN2(n)
LOCAL i
N:=VAL(n)
HIDE WINDOW Form_1
ShowConsole()
CLEAR SCREEN
FOR i:=1 TO n
? "i= ",i
NEXT
WAIT
HideConsole()
Form_1.Restore
Form_1.Show
MsgBox('Box1 value is '+TRANSFORM(n,'99'),'Test')
RETURN
FUNCTION ConsoleInit(title)
SetConsoleTitle(title)
HideConsole()
RETURN
/*
* embeded C code
* can be put in separate .c file (without #pragma of course)
*/
#pragma BEGINDUMP
#define COMPILE_HMG_UNICODE
#include "HMG_UNICODE.h"
#include "hbapi.h"
#include "hbapiitm.h"
#include <windows.h>
HB_FUNC(HIDECONSOLE )
{
HWND hwnd;
hwnd = FindWindowA("ConsoleWindowClass",NULL);
ShowWindow((LONG) hwnd, SW_HIDE); // SW_MINIMIZE
}
HB_FUNC(SHOWCONSOLE )
{
HWND hwnd;
hwnd = FindWindowA("ConsoleWindowClass",NULL);
ShowWindow((LONG) hwnd, SW_RESTORE); // SW_HIDE
ShowWindow((LONG) hwnd, SW_SHOW); // because 1'st time console stays minimized
SetForegroundWindow ( hwnd );
}
HB_FUNC(SETCONSOLETITLE)
{ char * szTitle=HMG_parc(1);
SetConsoleTitle(szTitle);
}
#pragma ENDDUMP
Now is working in HMG and was clear out this question.
I hope you enjoy it !