Page 1 of 1

How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 2:41 am
by huiyi_ch
Hello,
How to trigger button click events programmatically?

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 3:37 am
by Rathinagiri
Just call the function whenever required!

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 3:51 am
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?

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 6:42 am
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

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 9:15 am
by edk
Hi, try:

Code: Select all

Eval ( _GetControlAction ( <cButtonName> , <cParentWindowName> ) )
viewtopic.php?p=66597#p66597

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 10:15 am
by hansmarc
Hello,

or why not use :

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

Regards
Hans

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 6:13 pm
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 🤔

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 9:53 pm
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

Re: How to trigger button click events programmatically?

Posted: Thu Feb 17, 2022 10:46 pm
by edk

Re: How to trigger button click events programmatically?

Posted: Fri Feb 18, 2022 9:49 am
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)