Solved

Force A Click Event

Posted on 2001-06-08
12
167 Views
Last Modified: 2012-06-27
I need to force a click event on a command button WITHOUT using sendkeys.

Does anyone know of an API call or something for this?

Thanks
0
Comment
Question by:RichW
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 2

Accepted Solution

by:
kiprimshot earned 75 total points
ID: 6168158
You should be able to do one of these:

cmdMyButton = true

cmdMyButton_click
0
 
LVL 2

Expert Comment

by:kiprimshot
ID: 6168162
If it is on a different form you will need to make the click event Public instead of private and use form.cmdmybutton_click
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6168169
yes and if you are trying to force a click on command from different form than its owner then;

formname.cmdMyButton=True

to call its click event first you should make that Click sub as Public.

Call cmdMyButton_click

suat
0
 
LVL 17

Expert Comment

by:Suat Ozgur
ID: 6168175
faster one :)
0
 
LVL 4

Author Comment

by:RichW
ID: 6168183
My command button was instantiated from within a class.

I am in another class trying to force the click event.

The command button is called cmdGroup1.

I'm trying Call group.cmdGroup1_Click

It doesn't work.
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6168185
The mouse_event function synthesizes mouse motion and button clicks.

Windows NT: This function has been superseded. Use SendInput instead.

VOID mouse_event(
  DWORD dwFlags, // flags specifying various motion/click variants
  DWORD dx,      // horizontal mouse position or position change
  DWORD dy,      // vertical mouse position or position change
  DWORD dwData,  // amount of wheel movement
  DWORD dwExtraInfo
                 // 32 bits of application-defined information
);
 
Parameters
dwFlags
A set of flag bits that specify various aspects of mouse motion and button clicking. The bits in this parameter can be any reasonable combination of the following values: Value Meaning
MOUSEEVENTF_ABSOLUTE Specifies that the dx and dy parameters contain normalized absolute coordinates. If not set, those parameters contain relative data: the change in position since the last reported position. This flag can be set, or not set, regardless of what kind of mouse or mouse-like device, if any, is connected to the system. For further information about relative mouse motion, see the following Remarks section.
MOUSEEVENTF_MOVE Specifies that movement occurred.
MOUSEEVENTF_LEFTDOWN Specifies that the left button is down.
MOUSEEVENTF_LEFTUP Specifies that the left button is up.
MOUSEEVENTF_RIGHTDOWN Specifies that the right button is down.
MOUSEEVENTF_RIGHTUP Specifies that the right button is up.
MOUSEEVENTF_MIDDLEDOWN Specifies that the middle button is down.
MOUSEEVENTF_MIDDLEUP Specifies that the middle button is up.
MOUSEEVENTF_WHEEL Windows NT: Specifies that the wheel has been moved, if the mouse has a wheel. The amount of movement is given in dwData


dx
Specifies the mouse's absolute position along the x-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual x-coordinate; relative data is given as the number of mickeys moved. A mickey is the amount that a mouse has to move for it to report that it has moved.
dy
Specifies the mouse's absolute position along the y-axis or its amount of motion since the last mouse event was generated, depending on the setting of MOUSEEVENTF_ABSOLUTE. Absolute data is given as the mouse's actual y-coordinate; relative data is given as the number of mickeys moved.
dwData
If dwFlags is MOUSEEVENTF_WHEEL, then dwData specifies the amount of wheel movement. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user. One wheel click is defined as WHEEL_DELTA, which is 120.
If dwFlags is not MOUSEEVENTF_WHEEL, then dwData should be zero.

dwExtraInfo
Specifies an additional 32-bit value associated with the mouse event. An application calls GetMessageExtraInfo to obtain this extra information.
Return Values
This function has no return value.

Remarks
If the mouse has moved, indicated by MOUSEEVENTF_MOVE being set, dx and dy hold information about that motion. The information is given as absolute or relative integer values.

If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface, (65535,65535) maps onto the lower-right corner.

If the MOUSEEVENTF_ABSOLUTE value is not specified, dx and dy specify relative motions from when the last mouse event was generated (the last reported position). Positive values mean the mouse moved right (or down); negative values mean the mouse moved left (or up).

Relative mouse motion is subject to the settings for mouse speed and acceleration level. An end user sets these values using the Mouse control panel application. An application obtains and sets these values with theSystemParametersInfo function.

The system applies two tests to the specified relative mouse motion when applying acceleration. If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating system doubles the distance. If the specified distance along either the x or y axis is greater than the second mouse threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test. It is thus possible for the operating system to multiply relatively-specified mouse motion along the x or y axis by up to four times.

Once acceleration has been applied, the system scales the resultant value by the desired mouse speed. Mouse speed can range from 1 (slowest) to 20 (fastest) and represents how much the pointer moves based on the distance the mouse moves. The default value is 10, which results in no additional modification to the mouse motion.

The mouse_event function is used to synthesize mouse events by applications that need to do so. It is also used by applications that need to obtain more information from the mouse than its position and button state. For example, if a tablet manufacturer wants to pass pen-based information to its own applications, it can write a dynamic-link library (DLL) that communicates directly to the tablet hardware, obtains the extra information, and saves it in a queue. The DLL then calls mouse_event with the standard button and x/y position data, along with, in the dwExtraInfo parameter, some pointer or index to the queued extra information. When the application needs the extra information, it calls the DLL with the pointer or index stored in dwExtraInfo, and the DLL returns the extra information.

Windows CE: Windows CE does not support the MOUSEEVENTF_WHEEL constant in the dwFlags parameter.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:RichW
ID: 6168192
I am declaring it as

Public WithEvents cmdGroup As CommandButton

in a class called CGroup.

I'm in another class trying to call the click event of this buttoin.

0
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6168193
try this
cmdButtun.command = true

Mohammed
0
 
LVL 4

Author Comment

by:RichW
ID: 6168207
Thanks, kiprimshot.  cmdMyButton = true worked.

I upped the point to 75 for the quick response.

Thanks everyone else for your input!

Rich
0
 
LVL 2

Expert Comment

by:kiprimshot
ID: 6168216
Thanks RichW.......glad it worked for you!
0
 
LVL 2

Expert Comment

by:kiprimshot
ID: 6168217
Thanks RichW.......glad it worked for you!
0
 
LVL 6

Expert Comment

by:sharmon
ID: 6168336
Just incase you ever want to do it with the API here is some code for ya...


Option Explicit

Private Const WM_COMMAND = &H111
Private Const GW_CHILD = 5
Private Const GWW_ID = (-12)

Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, _
  ByVal nIndex As Long) As Integer

Private Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lparam As Long) As Long

Public Function ClickButton(ByVal hwnd As Long) As Long
  Dim ChildID As Long
  ChildID = GetWindowWord(hwnd, GWW_ID)
  ClickButton = SendMessageByNum(GetParent(hwnd), WM_COMMAND, ChildID, hwnd)
End Function
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now