How to trigger button click events programmatically?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

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

How to trigger button click events programmatically?

Post by huiyi_ch »

Hello,
How to trigger button click events programmatically?
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: How to trigger button click events programmatically?

Post by Rathinagiri »

Just call the function whenever required!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
huiyi_ch
Posts: 173
Joined: Sat May 21, 2016 5:27 am

Re: How to trigger button click events programmatically?

Post by huiyi_ch »

Rathinagiri wrote: Thu Feb 17, 2022 3:37 am Just call the function whenever required!
That's one way!
Can I send a message trigger using SENDMESSAGE()? , if possible, how to write code?
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: How to trigger button click events programmatically?

Post by andyglezl »

No me queda clara la pregunta...
*----------------------------------------
The question is not clear to me...

Code: Select all

FUNCTION Main() 

	DEFINE WINDOW FormMain . . . . .

		@ nRen , nCol BUTTON BTN1 OF FormMain CAPTION "ALGO"  WIDTH  25 HEIGHT . . . . .   ONCLICK MsgBox("Title") 

		ON KEY CTRL+ALT+BACK OF FormMain ACTION MsgBox("Title")

		ON KEY F2 OF FormMain ACTION MsgBox("Title")

		DEFINE CONTEXT MENU OF FormMain
			MENUITEM "ALGO" ACTION MsgBox("Title")
		END MENU

	END WINDOW

	MsgBox("Title")

	ACTIVATE WINDOW FormMain

RETURN
Andrés González López
Desde Guadalajara, Jalisco. México.
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How to trigger button click events programmatically?

Post by edk »

Hi, try:

Code: Select all

Eval ( _GetControlAction ( <cButtonName> , <cParentWindowName> ) )
viewtopic.php?p=66597#p66597
hansmarc
Posts: 40
Joined: Thu Jun 23, 2016 5:38 am
Location: Belgium

Re: How to trigger button click events programmatically?

Post by hansmarc »

Hello,

or why not use :

domethod( "cWinname", "cButtonId", "ONCLICK")

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

Re: How to trigger button click events programmatically?

Post by edk »

hansmarc wrote: Thu Feb 17, 2022 10:15 am Hello,

or why not use :

domethod( "cWinname", "cButtonId", "ONCLICK")

Regards
Hans
The button has no such method 🤔
hansmarc
Posts: 40
Joined: Thu Jun 23, 2016 5:38 am
Location: Belgium

Re: How to trigger button click events programmatically?

Post by hansmarc »

Hi Edk,

i am sorry to say but this method does exist, see button example below.

Regards
Hans

-------------------------------------------------

Code: Select all

#include "hmg.ch"

Function Main()

set century on
set date ital

   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 300 ;
      HEIGHT 300 ;
      MAIN;
      TITLE 'Button Test'

      DEFINE MAIN MENU
              POPUP 'Test'
                ITEM 'Disable button' ACTION Form_1.Button_1.Enabled := .f.
                ITEM 'Enable button'  ACTION Form_1.Button_1.Enabled := .t.
              END POPUP
      END MENU

      @ 30,30 BUTTON Button_1 PICTURE "button.bmp" WIDTH 50 HEIGHT 50 ACTION getprinter()
      @ 30,90 BUTTON Button_2 CAPTION "Sim Onclick button 1" WIDTH 150 HEIGHT 50 ACTION Sim_Onclickbutton1()
      @ 150,70 textbox t1 value date() date

   END WINDOW
   CENTER WINDOW Form_1
   ACTIVATE WINDOW Form_1

Return

// 
function Sim_Onclickbutton1()
   domethod("Form_1","Button_1","onclick")
return nil
edk
Posts: 999
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: How to trigger button click events programmatically?

Post by edk »

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

Re: How to trigger button click events programmatically?

Post by huiyi_ch »

Thank you very much to Rathinagiri, EDK and Hansmarc for answering,
After trying to trigger a button in a program, there are several ways:
1, doMethod (cWinname cButtonid, "onClick")
2, Eval(_GetControlAction(cButtonid, cWinname))
3, SendMessage(GetControlHandle(cButtonid, cWinname),BM_CLICK,0,0)
Post Reply