|
That doesn't help though. Within my code, I don't know which program just started or which program just had focus. It could be notepad, it could be IE, it could Vis Studio, or FireFox.
It doesn't matter what the program is, I want the window handle of the window that had focus prior to my program.
|
|
|
|
|
Unless your application is already running when the focus changes, there's no way to tell which application just had the focus. Your application will start way too late to get any notification of which window just lost the focus.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yes, exactly. It will already be running.
Here's the example again. My program is running, but doesn't have focus. I start IE or MS Word and do blah blah blah in it. I click back or focus my program. What's the handle of the app that just had focus before mine?
-- modified at 9:11 Wednesday 12th October, 2005
|
|
|
|
|
There is no API call you can make to give you the last window that had the focus.
The only thing I can think of is to override the WndProc procedure in your main window and handle the WM_ACTIVATE[^] message. You'll have to track the window handle of the window that is being deactivated, then get the parent window of that window handle until you reach the top-level window handle of the application.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I couldn't seem to get that to work.
However, I did find another solution. I found a class that receives all mouse and keyboard events from the system.
I hooked up a couple events and now my program is told when someone clicks the mouse or presses a key. Then I just GetForeGroundWindow to get the active window and change the IntPtr my program is using to know what has focus.
Works great!
|
|
|
|
|
Hi,
the main question is: (see details and more detailed questions below)
"Is there any big performance difference on implementing
two services on the same service process instead of creating
two separate Windows services (each one on its own process)?"
Details:
I developed two Windows services that needed to share data.
One should be almost real-time (like a performance metrics
monitor). The other will transfer such captured data over
Web services, can be slow and should use data persistence.
Implementing separated services, I could do it with
MMF + P/Invoke, or use something elegant solution,
such as Natty Gur's (DevGlobalCache), found here at CP.
Alternatively, I could implement both services inside same
Windows service process. In such case I could leave MMF P/Invoke
(since it´s not native in C# == I´m using VS.NET 2003).
Though, I don´t know whether such alternative solution would
be feasible, due to the following doubts:
1. If a Windows service process has two or more services,
does Windows treat each one as a thread, or *only* the
entire proccess as a thread? If the second option is the
case, so both services cannot live on the same process
with no impact on performance.
2. On the other hand, if Windows doesn´t treat them as
separate threads, probably a Mutex won´t be necessary if
both as on the same process.
Any comments on this would be very appreciated.
Thanks in advance.
Eugenio
|
|
|
|
|
Check out this post by Larry Osterman about svchost.exe
http://blogs.msdn.com/larryosterman/archive/2005/09/09/463018.aspx[^]
If you can run your services in the same process they will use fewer resources.
Each service is event driven. Don't count on the start and stop events to be called from the same thread. Other then those operations your service should manage it's own thread management. Either implicitly using a timer or other event object, or creating your own thread pool.
|
|
|
|
|
Is there a way to display a image on a Button with button.FlatStyle = FlatStyle.System. Currently I have applied XP theme to the controls.
|
|
|
|
|
Have you thought about just using a PictureBox control as your button? Or are you wanting the "effect" of a "downward click" when the mouse is clicked?
|
|
|
|
|
Yes. I need "downward click" "effect". When I do button.FlatStyle = FlatStyle.Standard, everything works fine but the look and feel of the button is like windows 2000 button.
|
|
|
|
|
Then I'm going to go with making a custom control that has the style + effect + picture.
|
|
|
|
|
Thanks for your time. Please see the next reply for an article on the same.
|
|
|
|
|
Heh, exactly what I posted except I didn't have an example...
|
|
|
|
|
Yes you did. Thats why I pointed you to the article. It might be useful for you also.
Anyway, thanks for your help.
|
|
|
|
|
Ohhh, ok.. well thanks for the info then and I'm happy to help (even a little)
|
|
|
|
|
No. You have to implement this yourself. Check out this link.
http://www.codeproject.com/cs/miscctrl/MgXpImageButton.asp
I implemented something similar in a project.
I hope this helps.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Bingo.
This is exactly what I was looking for.
Thanks.
|
|
|
|
|
Is it possible to bind the text of a label to a variable so that if the variable changes, the displayed text on the label changes?
|
|
|
|
|
Sort of... one easy way to do this is to create a get/set for the variable and in the SET just change the text of the label as well:
<code>
private string myVariable;
public string MyVariable
{
get
{
return this.myVariable;
}
set
{
this.myVariable = value;
this.Label1.Text = value;
}
}
</code>
Now when you do something like: MyVariable = "Blah";
it will run through the "set" portion of the code and change the label as well as the internal private variable
-- modified at 14:57 Monday 10th October, 2005
|
|
|
|
|
[EDIT] Forget it, I don't think it will work the way you want.[/EDIT]
Does this work?
class MainForm : Form
{
string labelText = "Blah";
public MainForm()
{
InitializeComponent();
label1.DataBindings.Add("Text", this, "labelText");
}
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
-- modified at 21:27 Monday 10th October, 2005
|
|
|
|
|
I am working on this project in which I create dynamic dropdown lists with C# ASP.NET and I want to save each dropdownlist so that I can see what value the user selected when they click the submit button. The only thing is when a postback occurs, everything is reset. I tried saving the dropdowns in Session variables but that does not seem to work. If anyone can help, I would really appreciate that. Thanks
Sincerely,
The Major Rager
|
|
|
|
|
Typically this means you're not setting up your drop down lists in a !IsPostback block.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This is usually (in my experience) done in the Page_Load event. Just use an if(!Page.IsPostback) block like stated above.
|
|
|
|
|
Is it possible to add an Underlined letter style shortcut to the buttons of a MessageBox dialog without wrting my own class to do it.
|
|
|
|
|
No
Christian Graus - Microsoft MVP - C++
|
|
|
|