Why did the program pause?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Why did the program pause?

Post by huiyi_ch »

HI friends
我有一问题需向大家请教。当运行下面的程序时,如果在窗口上点击右键或右键点击notify icon 时,程序将不再继续运行,只有手动关闭窗口,程序才可继续运行。如何解决这个问题,请大家帮忙。
I have a question to ask you.When running the following program, if you right-click on window or notify icon , the program will no longer continue to run, and the program can only continue to run if the window is closed manually.How to solve this problem, please help.

Code: Select all

#include <hmg.ch>
Function Main()

 SET DATE TO ANSI
 SET CENTURY ON
 SET MULTIPLE off
 
 DEFINE WINDOW form_main AT 0 ,0 WIDTH 0 HEIGHT 0 ;
      TITLE "" ICON NIL ;
	  MAIN noshow ;
	  ON INIT start() ;
	  NOTIFYICON "NETW0028" NOTIFYTOOLTIP "Test  and notify menu" ;
	  ON NOTIFYCLICK nil
      DEFINE NOTIFY MENU
	      ITEM 'About' ACTION msginfo("hello!")
		  SEPARATOR
		  ITEM "Exit" ACTION THISWINDOW.RELEASE
      END MENU
 END WINDOW

form_main.Center
form_main.Activate
Return NIL


function start()
local  oWEB
  form_main.HIDE
  oWEB:=dss_web_http():NEW()
  form_main.release  
return


#include "hbclass.ch"

class dss_web_http 
    var oObj init nil
	method new()
end class

method new() class  dss_web_http 
local i:=1
   for i:=1 to 5
   ::oObj:=jyfx_MK_IMAGE():new()
   ::oObj:http_view()
   next
return self

CLASS jyfx_MK_IMAGE
  method new() 
  method http_view()
endclass

method new() class jyfx_MK_IMAGE

 LOCAL cString:=""
 LOCAL oHtmlDoc:=nil
 
 cString+= "<p>Please right-click on the window or click the notify icon in the lower right corner,"
 cString+="the window will no longer close automatically,"
 cString+="Only when the window is closed manually,the program can continue to run. Why?How to avoid it? <p>"
 
 oHtmlDoc := THtmlDocument():new( cString )
 oHtmlDoc:writeFile( "TEMP.html" )
 return self
 
method http_view() class jyfx_MK_IMAGE
local oObject
local filename

	DEFINE WINDOW Win1  ; 
		WIDTH 1360 ;
		HEIGHT 768 ;
		TITLE 'View' ;
		MODAL
				
		DEFINE ACTIVEX Test
			ROW 0
			COL 0
			WIDTH 1360  
			HEIGHT 768 
			PROGID "shell.explorer.2"  
		END ACTIVEX
        DEFINE TIMER Timer_1 INTERVAL 1500 ACTION (this.enabled:=.f.,thiswindow.release)
    END WINDOW

	oObject := GetProperty('Win1','Test','Object')
	filename:="file:///"+getcurrentfolder()+"/"+"temp.html"
	oObject:Navigate(filename)
    Win1.Center
    Win1.Activate

RETURN nil




edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Why did the program pause?

Post by edk »

Why do you disable the timer? The "ThisWindow.Release" releases all controls for this window, including the timer.

With

Code: Select all

DEFINE TIMER Timer_1 INTERVAL 1500 ACTION thiswindow.release
works OK
huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Re: Why did the program pause?

Post by huiyi_ch »

这是一个经过程简化的程序例子。在定时器事件触发后,执行事件的函数比较费时,为防止定时器事件再次触发,所以disable the timer
This is an example of a simplified procedure.After the timer event is triggered, the function that executes the event is more time-consuming, so disable the timer to prevent the timer event from being triggered again
huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Re: Why did the program pause?

Post by huiyi_ch »

如果将修改定时器事件为
DEFINE TIMER Timer_1 INTERVAL 1000 ACTION (sss(),thiswindow.release)

function sss()
for i:=1 to 5
hb_idlesleep(0.3)
Next
return
在窗口点击右键时又会出现错误:
Date:2020.07.15 Time: 22:54:13
Error: HMG 3.4.4 Stable (32 bits)
Window: Win1 is not active. Program terminated
Called from _RELEASEWINDOW(3880)
Called from DOMETHOD(9020)
Called from (b)JYFX_MK_IMAGE_HTTP_VIEW(84)
Called from _DOCONTROLEVENTPROCEDURE(6056)
Called from EVENTS(1631)
Called from C_MSGSTOP(0)
Called from SHOWERROR(181)
Called from MSGHMGERROR(77)
Called from _RELEASEWINDOW(3880)
Called from DOMETHOD(9020)
Called from (b)JYFX_MK_IMAGE_HTTP_VIEW(84)
Called from _DOCONTROLEVENTPROCEDURE(6056)
Called from EVENTS(1631)
Called from DOEVENTS(0)
Called from _SHOWWINDOW(4003)
Called from _ACTIVATEWINDOW(5688)
Called from DOMETHOD(9003)
Called from JYFX_MK_IMAGE:HTTP_VIEW(91)
Called from DSS_WEB_HTTP:NEW(45)
Called from START(29)
Called from (b)MAIN(13)
Called from _PROCESSINITPROCEDURE(5876)
Called from _ACTIVATEWINDOW(5627)
Called from DOMETHOD(9003)
Called from MAIN(22)
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: Why did the program pause?

Post by edk »

IMHO because of event queue.
Try

Code: Select all

DEFINE TIMER Timer_1 INTERVAL 1000 ACTION (sss(), if (IsWindowActive ( Win_1), Win_1.release , Nil))

function sss()
Static lisInProgress:=.F.

If lisInProgress
   Return
Endif
lisInProgress:=.T.
for i:=1 to 5
hb_idlesleep(0.3)
Next
lisInProgress:=.F.
return

huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Re: Why did the program pause?

Post by huiyi_ch »

按照您的建议我修改了程序,当在窗口中点击右键,程序仍然暂停。问题仍然存在。
I modified the program according to your suggestion. When I right-click in the window, the program still paused.Problems remain.
User avatar
AUGE_OHR
Posts: 2093
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Why did the program pause?

Post by AUGE_OHR »

hi,

not sure but i "think" you are using NOTIFYICON wrong.

my "Main" Windows is just to "inform" User that there is a right-Mouse click Menu on Task-Icon.
from Menu i start "My Window" which have a Context-Menu (right-Mouse click)

so try to create a Windows in your CLASS, not Main, to run your Code
have fun
Jimmy
huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Re: Why did the program pause?

Post by huiyi_ch »

hi EDK,
According to your train of thought, I have modified the timer event again, this time the program works normally! You're a genius. Thank you very much!

Code: Select all

DEFINE TIMER Timer_1 INTERVAL 1000 ACTION (sss(), if (IsWindowActive ( Win1), Win1.release , WIN1.SetFocus()))

Post Reply