Hello. I was wondering if it was possible to see if the user was viewing the desktop(not on any other screen). If so, how? Thank you!
Printable View
Hello. I was wondering if it was possible to see if the user was viewing the desktop(not on any other screen). If so, how? Thank you!
That doesn't really make a lot of sense. Perhaps you could provide a more complete description of what you want to achieve and why. Are you saying that you want to detect whether a logged-in user doesn't have any windows open?
I'm making a hot key program. I want it to trigger tho only when the user is on the main desktop. Like no other windows in focus, just looking at the desktop and the icon(s) they have. (i was also thinking of doing an option for this, if yes check if no don't). I don't want the user to do Control + A on a notepad document and open up a program when all they wanted to do was select all.
You should be able to use the GetForegroundWindow API to get the handle of the window with focus. If it's the desktop then that handle should be zero I think. You can certainly test that theory.
It does not work. I tried it and 0 did not work... It turns out the desktop was 131232 or something, and when i was just viewing the desktop it wouldn't trigger... Anyone else? please help... I need this for a project in tech class.
I am sleepy and came up with this. Its working fine but pretty expensive.
vb Code:
[DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); bool IsOnDesktop() { // Get all the processes. Process[] proc = Process.GetProcesses(); // Get current window handle. IntPtr cWin = GetForegroundWindow(); foreach (Process x in proc) { if (x.MainWindowHandle == cWin) { return false; } } return true; }
Have you declared this API call?
vb Code:
[DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow();
I don't know what's causing that.
it would be good if you could post your code that you currently have in its entirety. we cannot second guess what you have coded
Alright. I will tomarrow afternoon, since the code is at school atm.
OFF TOPIC: question, am I allowed to have 2 threads up at once?
Two forum threads up at once? Yes you may. As long as they are about different questions. Each question goes in a new thread. It helps organize the different threads on the forum so people can search for answers better. If the topics are extremely similiar then they can be put into the same thread. Sometimes someone gets an answer in a thread that leads into another question.