How to close a MessageBox generated by some Application - c#

I am trying to close the message box which is generated by Internet explorer. Actually when I play a game on line it shows me a message box "You have played More than 30min. Click OK to exit or Cancel to play more". I want to click on Cancel button, for this I have designed a program :
private void timer2_Tick(object sender, EventArgs e)
{
string Col = GetPixelColor(407, 302).B.ToString();
if (Col == "200")
{
SendKeys.Send("{ESC}");
}
}
this programs check the colour of pixel (belong to Messagebox) and if found it sends Escape key The title of message box is "Windows Internet Explorer". But this program fails when unfortunatily the back ground of game become Light grey and it sends the Escape key which closes the game and lost the score.

I would take a look at FindWindow. Some information and source code can be found here.

Related

How to change a video once the current has stopped?

I am currently working with .NET 4.5. Programming a photobooth. The photobooth should start wit fullscreen:
Show an Intro screen with an intro video.
When the user clicks on the screen, it has to show a get ready! video
When the get ready video finishes playing, it has to show a countdown video
When the countdown video finishes, it has to take a picture.
Right now I can do #1 and #2. I can also take pictures. My problem is with the sequence. Once a video finishes, I need to change the video, but since everything runs in the event handler, it only plays the video WHILE the program is running the event handler.
Is there any better and smarter way to do this?
Here is my code:
What I have and works right now:
private void Form1_Load(object sender, EventArgs e)
{
// maximize the screen
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Maximized;
TopMost = true;
// play an intro video without the UI controls
this.videoPath = this.basePath + "intro.mp4";
this.wmpVideo.URL = this.videoPath;
this.wmpVideo.settings.setMode("Loop", true);
this.wmpVideo.Ctlcontrols.play();
this.wmpVideo.uiMode = "none";
}
Then, if the user clicks on the video, it will change the video to a new file:
private void wmpVideo_MouseDownEvent(object sender, AxWMPLib._WMPOCXEvents_MouseDownEvent e)
{
if (this.current == 0) //this means that currently we are in the intro
{
// Then I change the video to "get ready!"
this.changeVideo("getready.mp4",1);
}
changeVideo basically updates the video to getready.mp4. Then, I need it to change it to countdown.mp4.
In order to move from one video to another, I need to check when the video finishes. I do this right now with:
wmpVideo.PlayStateChange += new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(checkGetReadyFinished);
And the event handler looks like this:
private void checkGetReadyFinished(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 8) {
// If we are currently in the "getready state"
if (this.current == 1)
{
// then I change the video to the countdown.mp4
this.changeVideo("countdown.mp4", 2);
}
}
}
PROBLEM
I noticed the video ONLY plays when I am on the event handler method. I realized this because I saw that no video was played, so I added a MessageBox in the changeVideo method. I saw that as long as the MessageBox was showing, the video was playing. When I clicked "OK", the video disappeared
I.E., I need to stay in the event handler method.
QUESTION
Is there any other better way to show a video1, then show video2 when video1 finishes. As I mentioned, I need to do a photobooth program.
I also tried calling another form, but as soon as I set it to fullscreen, the screen sort of flashes.
Is there any optimal way of doing this?

How do I make a WT41N0 scanner not to scan barcode or pass carriage return to messageBox in C#

I have a application which runs on WT41N0. This application has a form which accepts the label scanned by the scanner in a textbox on keyDown event.
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
{
string lstrBarCodeID = txtBarCode.Text.Trim();
}
}
The problem is when I have a messagebox on the screen waiting for user input (Yes/No) and someone scans a barcode, the application takes action on the messagebox. This happens because the barcode scanner has a 'ENTER' (carriage return) symbol set at the end, which is being held in the input stream and 'fired' when I open a message box leading to the closure of MessageBox.
I want the application not to scan or scan but don't let the message box go disappear as a result. When user is using the application without looking at the screen, they keep on scanning without realizing that there is a message on the screen and keep scanning leading to issues with the operations. I just want to stop the application to perform any action until the user takes a action on the message on the screen.
I might be missing a trick as I am new to front-end programming with C#.

Create a message box that user can choose to "Don't show it again."

Made a mass messenger & a multi-message/spammer in one, works fine, just want to make it even better. Obviously I had to write code to have skype allow the program so it can do what it does, here it is,
private void Form1_Load(object sender, EventArgs e)
{
//I entered a message box so it doesn't crash instantly.
MessageBox.Show("Please allow SkypeBot.vshost.exe to access skype. (Look at your Skype application)");
Skype skype = new Skype();
skype.Attach();
getContacts(skype);
}
how can I make it stop showing the MessageBox and just go straight to loading the form if the user already allowed it in the past (since it doesn't ask to allow it anymore after you've allowed it once)
here is what it looks like, if any are wondering, for some reason;
http://imgur.com/f0aaiZN,
works fine, just want to improve it so any answers to the requests above are appreciated :D
You can prevent showing the message by adding a check box to the dialog so the user can choose "Don't show this message again". Then you can save the value of the check box in settings and based on that setting, decide to show or not to show the dialog.
As a simple solution, you can create your own custom message box:
Create a new Form and name it MessageForm as your custom message box and put buttons like "OK" button and other buttons if you want. And for each button set proper value for DialogResult property. So when you show your form using ShowDialog if you click on a button, without writing code, the form will close with that dialog result.
Add a bool setting to your project Settings file, for example name it DontShow.
Put a check box on form and set its text to "Don't show this message again" and then handle CheckedChanged event and save the value of check box in the DontShow setting:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.DontShow = this.checkBox1.Checked;
Properties.Settings.Default.Save();
}
Now you can show your MessageForm this way:
if(!Properties.Settings.Default.DontShow)
new MessageForm().ShowDialog();
You can enhance your MessageForm by accepting the message in constructor or even adding a public static void ShowMessage(string) to it to use it like message box.

want to stop user input by messagebox but bypassed by a Enter keydown

I'm coding a windows form application running on a barcode scanner.
The plantform is .Net2.0CF/C#.
What i want is whenever user input wrong, the app will pop a messagebox and block the next input(actually,a scan action) until user click the OK on the screen.
But normally the user will continuously scan the next stuff as they didn't find anything went wrong, this will insert a Enter keydown so the messagebox will be closed, in one word, the messagebox does not stop the user.
How can i code this? Below is a very simple code snippet
private void tb_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.ToString() == "Return")
{
if(!ValidateInput(tb.Text))
MessageBox.Show("Error");
}
}
You can create your own window (Form) that displays the error message, but does not react on the enter key.
It should contain a button which the user can click (as you wrote), however you need to make sure the button does not have focus when the window is displayed. (Because if it had focus, pressing the return key will "click" the button.)
A simple way for doing this is adding another control which has TabStop set to true (e.g. a textbox, another button) and which has a lower TabIndex property than the button.
Additionally, maybe you might want to do a
System.Media.SystemSounds.Beep.Play();
when showing the window to draw the user's attention to the window.

Close c# application when video stops playing

I am trying to figure out how to close my application when the video that the form plays stops playing. Currently, the user clicks a button to bring up Form2. The control for the video is set to force the video full screen, and start playing from the beginning of the video. I am using axWindowsMediaPlayer to provide the video. I am also a complete neophyte when it comes to C#.
How would I get my application to close when the video stops playing?
You need to detect when the media has ended, here is a tutorial on: "Detect the End of Media - axWindowsMediaPlayer". Then you need to call Close(); to close the form you are currently playing the media from.
Example (snippets from msdn):
// Subscribe to the Play State Change event
player.PlayStateChange +=
new AxWMPLib._WMPOCXEvents_PlayStateChangeEventHandler(player_PlayStateChange);
Then you need the event handler that can look like this:
private void player_PlayStateChange(object sender,
AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
// 8 = Media Ended
if(e.newState == 8) { Close(); }
}

Categories

Resources