473,396 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SetForegroundWindow in Visual C# Express

Is it possible to use the syntax SetForegroundWindow in Visual C# Express? I
have tried an have had no luck. I'm also having a ruff time with DLLImport
as well. I think this may have something to do with my issue with
SetForegroundWindow. Thanks
Mar 1 '06 #1
6 9012
Is it possible to use the syntax SetForegroundWindow in Visual C# Express?
Sure, as long as you declare the function first.

I have tried an have had no luck.
Can you post the code you tried with?

I'm also having a ruff time with DLLImport as well.


www.pinvoke.net is a good place to look for DllImport method
declarations.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 1 '06 #2
Actually I figured that part out now my code is freezing. I'm sure it is
some newbie error but coud you take a look at my code please?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
public partial class Form1 : Form
{

[DllImport("kernel32.dll")]
static extern void Sleep(uint dwMilliseconds);

public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{

MessageBox.Show("You have five seconds to get into the
game!");
Sleep(5000);
string x = textBox2.Text;
string y = textBox3.Text;
uint a = 0;
int b = 0;
int z = 0;
try
{
a = Convert.ToUInt32(x);
b = Convert.ToInt32(y);
}
catch
{

}
while (z < b)
{

SendKeys.Send(textBox1.Text);
z = z++;
Sleep(a);
}
}
}
}
Mar 2 '06 #3
>Actually I figured that part out now my code is freezing. I'm sure it is
some newbie error but coud you take a look at my code please?


Well you're calling Sleep, the whole point of that is to sleep or
freeze the thread. You should never Sleep a UI thread (and if you
should sleep at all, call System.Threading.Thread.Sleep rather than
using PInvoke).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 2 '06 #4
Okay, I totaly understand what you mean by NOT sleeping at the UI Level. My
only thing is I need to send that key at that time. Is there any other way
to do this? Get rid of sleep and make it more efficent?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication1
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{

MessageBox.Show("You have five seconds to get into the
game!");
System.Threading.Thread.Sleep(5000);
int z = 0;
while (z++ < Convert.ToInt32(textBox3.Text))
{
SendKeys.SendWait(textBox1.Text);

System.Threading.Thread.Sleep(Convert.ToInt32(text Box2.Text));
}
}
}
}

"Mattias Sjögren" wrote:
Well you're calling Sleep, the whole point of that is to sleep or
freeze the thread. You should never Sleep a UI thread (and if you
should sleep at all, call System.Threading.Thread.Sleep rather than
using PInvoke).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 2 '06 #5
backgroundWorker for the win!

"Mattias Sjögren" wrote:
Actually I figured that part out now my code is freezing. I'm sure it is
some newbie error but coud you take a look at my code please?


Well you're calling Sleep, the whole point of that is to sleep or
freeze the thread. You should never Sleep a UI thread (and if you
should sleep at all, call System.Threading.Thread.Sleep rather than
using PInvoke).
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Mar 2 '06 #6
Okay, I totaly understand what you mean by NOT sleeping at the UI Level. My
only thing is I need to send that key at that time. Is there any other way
to do this? Get rid of sleep and make it more efficent?


How about using a Timer (the System.Windows.Forms kind)?
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bootstrap Bill | last post by:
A new Google group has been formed for the purpose of discussing the new Visual Studio Express products. http://groups-beta.google.com/group/Visual-Studio-Express The products are currently in...
30
by: Cowboy \(Gregory A. Beamer\) | last post by:
There seems to be a lot of confusion on the versions of Visual Studio 2005. My latest blog entry covers the different versions: Main URL:...
3
by: clintonG | last post by:
Visual C# 2005 Express Edition is a simple, lightweight, integrated development environment designed for beginning programmers and non-professional developers interested in building Windows Forms,...
5
by: Patrick Olurotimi Ige | last post by:
Hi, I have VStudio.Net 2003 installed but can i install Visual Web Developer also on the same PC. My current .Net Frameork version is 1.1. Will the Visual Web Developer install ASP.NET 2.0? And...
6
by: Brian Henry | last post by:
Visual Basic 2005 Express: http://download.microsoft.com/download/f/c/7/fc7debaf-4513-4300-9e6a-8fe27be88cd1/vbsetup.exe Visual C# 2005 Express:...
4
by: Andrew Robinson | last post by:
My main dev machine has WinXp and VS2005 (pro). 1. I need to install VWD Express Edition so that I can do some instruction on this. Any issues with both on the same machine. Installation order?...
2
by: Progman | last post by:
I have Visual Studio 2005 Standard edition. Is ti the same thing as the Express edition or Standard is more?
2
by: terry.trent | last post by:
I'm new to c# and Visual C# Express, and to normal programming in general (some background in web programming), and i have a question vital to my current project. Basically, i have been asked to...
2
by: Cramer | last post by:
So, what is the relationship between Visual Studio and Visual Web Developer. I find a lot of documentation on MSDN that presents Visual Web Developer as it's own stand-alone product (which I'd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.