|
Hi! Im trying to pause spotify by sending a space to the application.
Im using this code but when i click button1 i get a message telling me "An error occurred in the application"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
IntPtr SpotHandle = FindWindow("SpotifyMainWindow", null);
if (SpotHandle == IntPtr.Zero)
{
MessageBox.Show("Spotify är ej igång");
return;
}
SetForegroundWindow(SpotHandle);
SendKeys.SendWait("{SPACE}");
}
}
}
Why doesnt this code work?
|
|
|
|
|
Debug the application; during which line of code do you receive this error?
Adam Maras | Software Developer
Microsoft Certified Professional Developer
|
|
|
|
|
I got it working by using:
SendKeys.SendWait(" ");
instead of:
SendKeys.SendWait("{SPACE}");
|
|
|
|
|
Wow - there's a revelation. What made you think that the word SPACE would work ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
For future reference, you only need to use the "{xxx}" when it's a character that isn't displayed when pressed.
Full list here[^].
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi,
I am thinking of doing some webcam development using C# and DirectShow. I have never done anything like this before. I am using Visual Studio 2008 and was wondering what other downloads/library’s I will need in order to use DirectShow.
I am currently downloading Windows SDK for Windows Server 2008 and .NET Framework 3.5, will this contain all the libraries that are necessary?
(This is 1.3GB on a very slow connection so tell me if I’m completely wrong!!!)
I know that there are a lot of good looking examples and tutorials (including this site) about using webcams on the internet but if anybody has any they especially recommend I would appreciate it a lot.
Thanks in advance,
Mark
|
|
|
|
|
|
I am trying to access a listbox in a class that is not Form1.cs but I am having difficulty. How do I access this list box?
I have tried:
public class DeckManagement: Form
and
public class DeckManagement: WarGame
|
|
|
|
|
Your code seems totally irrelevant to the problem at hand.
Nathan Revka wrote: but I am having difficulty
Does it not compile, or do you get a runtime error? I would guess you need to make WarGame a public inner class of Form1, but that is terrible design - you should have WarGame as a full class in its own right, in WarGame.cs.
Cheers,
Vikram. (Proud to have finally cracked a CCC!) Recent activities:
TV series: Friends, season 10
Books: Fooled by Randomness, by Nassim Nicholas Taleb. Carpe Diem.
|
|
|
|
|
It is probably a better idea to expose a public method or property in your Form1 class that you would execute from your satellite class.
For example, if you needed to access the listbox from a different class so you can retrieve the selected index, you might within your Form1 class expose a public method:
public partial class Form1
{
...
public int GetListSelectedIndex()
{
return listBox1.SelectedIndex;
}
...
}
|
|
|
|
|
Hi guys
Can anyone show me where there are any tutorials on making a basic server in C#. Something that will run on port X and other computers in that network will be able to contact to the server and the server send a response (plain text).
Thanks guys
|
|
|
|
|
|
Cool
Thanks for the links.
|
|
|
|
|
i m creating a bot for a browser game, i really in the start yet
so, i enter the page and i need to pass password and username etc
so i found that code in vb but i cant find the translation
i so thing i missing a assembly case its really simple
...
wb.documents.all("username").value = "qwerty1"
wb.documents.all("password").value = "qwerty2"
wb.documents.all("submit").value = click
...
thanks
wb is WebBrowser object
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
There are online converters that will do this. If you can't do it yourself, then perhaps you need to understand C# better instead of just copying and pasting code from the web ?
Replace the () with [] and put a ; at the end. That is all.
Except I am not sure that the last line will work, in VB or C#, unless click is a variable that's already defined.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
() or [] doesn´t matter, like i said before i am missing a assembly, i cant find it
i used value propriety before, to pass values to db for exemple
... sql_cmd.Parameters.Add("@my_season", SqlDbType.Int).Value = season; ...
but i cant find the assembly to value propriety this case in order to pass values to site login page
nelsonpaixao@yahoo.com.br
trying to help & get help
modified on Wednesday, July 29, 2009 7:20 PM
|
|
|
|
|
In this code, I want to set the color of the progress bar to one thing, wait, then set it to something else, each time timer1 ticks. It doesn't work. Any suggestions?
private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Thread.Sleep(50);
progressBar2.ForeColor = Color.Black;
}
|
|
|
|
|
Firstly, at 50ms you won't see anything.
Secondly, why don't you just keep the timer ticking and each time you just swap the colours.
Thirdly, Sleep on the UI thread is, no mater how short, not a good idea.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
You'll need a thread.
See here[^].
|
|
|
|
|
Rather than using Timer and Thread.Sleep() , I will suggest you to use, Background worker to do this. Which will manage both the UI and background process.
|
|
|
|
|
Hi,
I also have sometimes the problem that I want to "wait" for a short time (some 10 or 100 milliseconds) and so far I helped myself with Timer and Thread.Sleep... (shame on me but I didn´t know better)
Is there any article or a short example how to do this correctly with Background worker?
Thanks
Thomas
|
|
|
|
|
ThomasManz wrote: Is there any article or a short example how to do this correctly with Background worker?
Yes, Using background worker you can show the progess on UI and aswell as do the process on backgronud.
Here is one sample application.
Using the BackgroundWorker Component in .NET 2 applications
Hope this is Help to you
|
|
|
|
|
therealrustyspork wrote: private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Thread.Sleep(50);
progressBar2.ForeColor = Color.Black;
}
You shouldn't use Thread.Sleep in GUI thread, but if you really want to, you need to redraw the progress bar.
private void timer1_Tick(object sender, EventArgs e)
{
progressBar2.ForeColor = Color.Firebrick;
Application.DoEvents();
Thread.Sleep(50);
progressBar2.ForeColor = this.ForeColor;
}
Greetings - Jacek
|
|
|
|
|
My question is how to create this: for an existing object a new custom property?
"existing object"= an object control in general (ex: a textbox)
"new custom property"= by default this control "textbox" have this property:
textbox.Hide();
...and many other properties off course,but I snipe to this particular one, only.
In what way? Well, I want that a single button to have a custom property write by me, named "myHideShowProperty" that can do 2 things in one package, I mean that when I click once, "Show" that textbox ; and when I click one more time it "Hide" that textbox, then when I click once more it "Show" a textbox,and so on.
In the end, the code I imagine that it must look like this:
btn1.myHideShowProperty.show(textbox);<br />
btn1.myHideShowProperty.hide(textbox);
The idea behind all of this is how to write a customized property for an existing object control.
And of course a solution for my problem, if there is one.
though I must mention that I have made a variant and it works:
private void button1_Click(object sender, EventArgs e)<br />
{<br />
button1.Hide();<br />
button3.Show();<br />
button3.Text = "second btn";<br />
}<br />
<br />
private void button3_Click(object sender, EventArgs e)<br />
{<br />
button3.Hide();<br />
button1.Show();<br />
button1.Text = "first btn";<br />
}<br />
|
|
|
|
|
The normal way is to derive a new class from the control
public class Foo : Button
but there is another way in VS2008 : Extension methods[^] which does exactly what you are asking for.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|