Using program in the background (C#) - background

e.g: a game is running and when I press a button, I want my program to show up.
another example : I'm on my desktop and when I press a button, I want my cursor to move to a specific position.
how do I achieve that?

Assuming you are using windows, and using c# to develop the application.
1. You will have to develop a window form application keep it running. write a global mouse event handler, when you detect a mouse click on certain target area, bring your app to front
Global mouse event handler
this.WindowState = FormWindowState.Minimized;
this.Show();
this.WindowState = FormWindowState.Normal;
move mose cursor, you could refer to api mentioned below post
How to move mouse cursor using C#?

Related

How to keep MS Access Forms only in the MS Access Window/Canvas?

I have created my MS Access Program but I have multiple monitors and so do the other people who will be using the program.
Just so you know my forms are popup style, have no borders or record selectors and I am guessing this is where my issue comes in.
I would like to know if there is a way to ensure that when a user opens a form, the form will only open within the MS Access Window/Canvas on the active monitor?
I would also like to know if there is a way for my application to automatically adjust according to the users screen resolution?
As an example my Forms open perfectly when I am using the application on my main screen which has a resolution of 3840 x 2160 but if I open the application on my second screen which has a resolution of 1920 x 1080 the forms that open subsequently, such as the user form, then opens on the main screen so small that no one can read or see it.
Application is on Right monitor and User Form is Open on Left (Main) Monitor
The code I have used for the OnOpen Event is below:
Private Sub Form_Open(Cancel As Integer)
Dim Right As Integer, Down As Integer
Right = Screen.ActiveForm.WindowLeft
Down = Screen.ActiveForm.WindowTop
DoCmd.MoveSize Right, Down
End Sub
This was obtained from some research but I cant seem to bind everything to the Application Window/Canvas.
Thank you.
Well, if you only ever have one window open at one time, then you can do this with ease.
Remember, today most applications are SPA (what we call single page applications). We don't use (nor have) very often a main applcation window, and THEN a child window. For one, they tend to not be touch friendly, and it is VERY hard to move a window around with touch.
but, even desktop browsers even use some "kind" of tabbed interface. And so do most desktop applications. And by tabbed - I don't necessary mean across the top. This access screen shows a tab system from the left side:
So, Access now has a option to use tabbed interface.
And if you :
do NOT use pop windows.
Set access to use tabbed interface, eg this:
Then un-check the display tabs.
If you do above, then you WILL NEVER EVER see the access background window.
You see this:
However, keep this in mind:
The form you launch will re-size to the main size of the Access window - not the other way around.
All forms can't be popup
You are "SPA" like applcation.
So, most accounting and most desktop applications now work this way. And WHEN you launch a form, the window does not re-size tot he form, but remains the current applcation window size.
So, without ANY specials code, you can 100% hide the access background window.
And if you re-size the access application window, then the form will re-size to fill out the current form.
This might look quite bad in some cases - such as this:
Now for above, I on purpose made the form background green - just to PROVE and show that that Access background window NEVER will display with above options.
So, the main issue here?
You can 100% hide the access background window. And you can now do this WITHOUT specials code. Just a few settings.
On startup, you can hide the ribbon - or build a custom one - again your choice.
But, your forms MUST NOT be popup forms anymore.
So, hiding the access background window is very easy - it then becomes a question of form size - size forms re-size to application window size - not the other way around.
On the other hand, if you adopt a tabbed interface (accross the top or left side), then your main window is always in display, and you are in effect swapping out the form (a sub form) for display of that given form. You can write your own code, or use a new navigation form - which does this for you).
If you need to launch separate windows, then you could launch them as popup from this main form - but that main form will of course always hide the access background if you follow above.
If you wish to hide the ribbon, then on your main form - load event, you can add this code:
DoCmd.ShowToolbar "Ribbon", acToolbarNo
So, your main form (which hides access background) could be tabbed inteface (SPA) or it could be a launcher form, and each option clicked on could launch a form as popup - which can be dragged anywhere on your computer - including to the 2nd monitor if you wish.
So, either forms stay always in the main applcation window - but never see the background. Or you use above, and launch forms as popup.

VB.Net events: test if sender is another sub or function

Is there any way to test if an event linked to a control is triggered by the program, rather than by user action?
I have a scroll bar which fires events when the user moves it. I want to be able to move the scroll bar programmatically elsewhere in the code without sending these events. i.e. events should only fire when the user interacts with the control, not when I move the control via code.
I also have radio buttons and numeric up/down controls I'd like to b able to do this with.
Thanks
There maybe better ways to do this but a quick way would be to use a boolean variable that you set when you are programmatically scrolling and unset it when you're done. Then in your event check that before executing the logic.
If IsProgramaticScrolling = False Then
' Do whatever it's supposed to do when your program isn't
' scrolling via code.
End If

How to click on a position of form or a control automatically?

I'm using Visual Basic 2008 (VB.NET) and I have an old control which have some buttons on it. These buttons can not be pressed without actual click and the control have no event or API for that. The control is something like the picture below which has multiple objects and buttons as a single control which controls inside the control can be changed dynamically according to some conditions but at a fixed place and this is why I think simulating a click that I said is the best way in my opinion:(The actual control is completely different that the picture below. It's only a sample)
I can click on the button by doing these steps:
Collecting all controls positions on my form
Moving the control in order to put the button exactly at the left top of the form
MyControl.Left = -43
MyControl.Top = -6
Moving form exactly to the center of the screen
Me.Location = New Point(Screen.PrimaryScreen.WorkingArea.Width / 2 - 1, Screen.PrimaryScreen.WorkingArea.Height / 2 - 1)
Simulating a click action at the center of the screen
Moving back controls to their positions that I got in the first step
It can be done that way but it's not reliable and it might not be user friendly for my program customers.
I want to ask if there are any better method to do that like simulating a click event on a position on the form itself (so I don't have to move controls and do other steps)?
Of course I feel I must tell you that simulating a mouse click in order to programmatically click a button is not a very good idea. Many things can go wrong with this method (The form could move, making your mouse click on the wrong location; Form could be minimized, or another form could be on top of it, etc)
That said, it is possible, so take a look at this article that contains the code to simulate a mouse click.
http://www.developerfusion.com/code/276/simulating-mouse-events/
Once again, please consider doing this a different way. Iterate through the controls in the user control until you find the button you want and use button.performclick. Or you can call the function that the button.click event calls yourself, if it is public

Execute Context Menu Command in External Application

I am trying to write an application that can select all text in the textbox within an external application, copy it to the clipboard, perform changes programmatically to the string and then send the modified string back to the external application. I did not write the external application and do not have access to its code nor can I afford to contact the developer and have them make changes. The external application is Client-Server based and I can only interact with the user interface on the client side.
The problem I am running into is that I can easily send keyboard commands to the application to send or delete text, but I cannot select all of the text. Using keyboard shortcuts Ctrl-A, Ctrl-Shift-Home, Ctrl-Shift-End, etc. do not work. Triple clicking on the text box does not work either.
However, I can right click on the text box and bring up a context menu and then select the command "Select All". I am wondering if there is a way to send the context menu command to the application without having to have the context menu appear.
I want the two applications to appear to be working as seamlessly as possible to the user. Does anyone have any suggestions that might work?
To answer your specific question:
I am wondering if there is a way to send the context menu command to the application without having to have the context menu appear.
When a menu item is clicked, it issues a WM_COMMAND message to the parent window of the menu. You can use a tool like Spy++ to monitor such messages and see which command ID is being sent to which window, and then you can code your app to send the same message directly to that same window. No need to display the actual menu itself.
However, in this particular situation, that is overkill. If you have the HWND of the desired edit control, you can send it WM_GETTEXT and WM_SETTEXT messages instead, or use .NET's UIAutomation interfaces, to get/set the control's text directly. Either way, there is no need to select the text (you can use EM_SETSEL for that) or to involve the clipboard.

Visual Basic 2010 Event Listeners on a List

I have a list of buttons in VB2010.
What is the best way to assign a function to their click event.
So every button has the same function, e.g.:
On Button Click
FireFunction(1)
End On Button Click
Without having to add a click event for every button.
The goal is to produce something similar to what is done with the Control Array idea in Visual Basic 2006.
Define a click function as in:
http://visualbasic.about.com/od/learnvbnet/a/eventhandler.htm
and react based on Sender. There may be a cleaner way to setup delegates in VB.NET, but I use it not.