|
Window titles do not define a class of windows. If you want to enumerate windows for a particular window class (applications typically define their own window classes, like Word always uses the window class "OpusApp" while Internet Explorer uses "IEFrame", which you can see from using Spy++ that ships with Visual Studio and the Platform SDK tools.
With that in mind, you can P/Invoke EnumWindows and then P/Invoke GetClassName to get the Window class name. An example follows:
using System;
using System.Runtime.InteropServices;
using System.Text;
class EnumWindowExample
{
static void Main(string[] args)
{
if (args.Length < 1)
{
Console.Error.WriteLine("Error: Please specify a window class.");
Environment.Exit(1);
}
IntPtr ptr = IntPtr.Zero;
try
{
ptr = Marshal.StringToHGlobalAuto(args[0]);
EnumWindows(new EnumWindowsProc(Callback), ptr);
}
finally
{
if (ptr != IntPtr.Zero)
Marshal.FreeHGlobal(ptr);
}
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int GetClassName(IntPtr hWnd, [Out] StringBuilder lpClassName,
int nMaxCount);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern int GetWindowText(IntPtr hWnd, [Out] StringBuilder lpString,
int nMaxCount);
delegate bool EnumWindowsProc(IntPtr hwnd, IntPtr lParam);
const int MAX_CLASS = 256;
const int MAX_TITLE = 256;
static bool Callback(IntPtr hwnd, IntPtr lParam)
{
StringBuilder windowClass = new StringBuilder(MAX_CLASS);
StringBuilder windowTitle;
string cls = Marshal.PtrToStringAuto(lParam);
if (GetClassName(hwnd, windowClass, MAX_CLASS) != 0)
{
if (string.Compare(windowClass.ToString(), cls, true) == 0)
{
windowTitle = new StringBuilder(MAX_TITLE);
if (GetWindowText(hwnd, windowTitle, MAX_TITLE) != 0)
Console.WriteLine(windowTitle.ToString());
}
}
return true;
}
} Just compile the app and pass a class name like "IEFrame" to get all the Internet Explorer windows (those started with iexplore.exe, mind you).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
If you're trying to determine what process owns a particular window, then Heath's excellent example is the way to go. The only caveat with that approach is that you'll have to know the class name(s) that a given application uses in order to map the window class to the application.
If, on the other hand, you're just trying to identify processes that are running on the machine, you can use the System.Diagnostics.Process class. This approach would allow you to identify all processes on the machine, including those that do not have windows.
<br />
using System;<br />
using System.Diagnostics;<br />
<br />
namespace EnumProcesses<br />
{<br />
class EnumProcsExample<br />
{<br />
[STAThread]<br />
static void Main(string[] args)<br />
{<br />
Console.WriteLine( "Enumerating processes..." );<br />
<br />
Process [] processes = Process.GetProcesses( );<br />
<br />
foreach ( Process process in processes )<br />
{<br />
Console.WriteLine( String.Format( "{0} : {1} ({2})", process.ProcessName, process.MainWindowTitle, process.MainWindowHandle ) );<br />
}<br />
<br />
Console.WriteLine( "Done." );<br />
Console.ReadLine( );<br />
<br />
<br />
}<br />
}<br />
}<br />
For the processes that do have windows, you can get the title and handle of the main window. You will not be able to get handles to all of the process's windows without some additional work, however. To do this, you could P/Invoke EnumThreadWindows to get all the non-child windows created by each thread in the process, and then you could P/Invoke EnumChildWindows for each of those windows.
If you need to be able to enumerate the windows for the process, let me know, and I'll throw together a sample for that.
Hope this helps,
PatrickShane
|
|
|
|
|
Hi all,
I need some samples for licensing the windows form application.My criteria is whenever user attempting to login the application i want to check the license key which is stored in a database table. The way to generate the license is, wherever application is installed, a KEY is generated with that computers CPU number.When user is logging in, how do we check this, (i.e.) we have application running on a server 10 users who are connecting to a server, we don't have to install the license on all the clients (PC's).
This should be checked only on the server side.
We should check the license when any one connects to a server (MSSQL) (I don't want to install license on every client, it should be only on the server, here ever the MS SQL you have installed or connecting to)
Any body have idea about this type of requirement, please send me the code samples or documentation .
thanks
sai sastry
Sai Sastry ch
|
|
|
|
|
I have this wierd problem. I have an instance of the PowerPoint class and I am calling Quit(); For whatever reason, when i do this in my console application, it works no problem. But when i do this from a Windows Service that I have made, it does not work. Is there a good reason for this?
I tried to think of some possible reasons but i can't think of any as my service and my console application are seemingly identical.
Thanks a lot!
Jim
|
|
|
|
|
I get the impression TAPI and C# has been discussed to death and I don't want to rub salt into the wounds, but how do I place a GSM call on my PocketPC (Mobile Phone Edition) using C# and .net CF.
The device (MDA II / XDA II) even offers a 'wireless modem' feature to any external device - just connect per Bluetooth/USB/serial/IrDA and issue AT commands just like any other normal modem. But I am not an external device - I am (in this context!) an application running on the MDA II / XDA II.
How do I get to place a GSM call (for V110 data) - I just want to dial my phone number and be told when I am connected, with the option to abort if this takes too long. C++ is a number too big for me and TAPI is way too complex for what I want - has somebody got a neat, lightweight C# solution... or at least a push in the right direction!
Peter Beedell
"Remember that age and treachery will always triumph over youth and ability." Quoted from the BBC Comedy 'The Office'.
|
|
|
|
|
Hi all !
I have a RichTextBox control containing red-colored text "Hello world." and
I need to get (for example but not strongly !) the following html-page:
<html><body style="color:red">
Hello world.
</body></html>
Does FCL contain any classes and methods to solve my problem ?
Many thanks !
|
|
|
|
|
Eugene Ostroukhov wrote:
Does FCL contain any classes and methods to solve my problem ?
No. You need to write your own converter. Of course, there are many, many RTF->HTML converters available on the web, some even free. Search google and sourceforge for plenty of hits.
Any remotely useful information on my blog will be removed immediately. There are 10 kinds of people in the world. Those who have heard of the ubiquitous, overused, worn-out-like-an-old-shoe binary "joke" and those who haven't.
Judah Himango
|
|
|
|
|
Hello forum,
I want to display the input of a logfile in a textbox. The difficulty is that the logfile grows and the content of the textbox should also display the new entries in realtime. I do not want to read the whole content of the logfile and display it in the textbox. What I am looking for is to read the stream till "readline = null" and then try to read every x seconds from that position on.
Does anyone know if that is possible?
Thanks in advance,
MG
|
|
|
|
|
I would recommend the usage of the FileSystemWatcher class, so that you only re-read your log file when it has changed instead of every x seonds.
To prevent the reading of already retrieved text, store the Position property of your stream after every reading and then seek forward to this position when re-reading the log file.
www.troschuetz.de
|
|
|
|
|
|
|
hello,
i developped a web usercontrol and want to use it into a vb project, but nothing happens. actually i added the c# .ascx into the vb project (add existing item menu). in vb there is no code behind the user control.
how can i make this work ?
thanks
patrick
|
|
|
|
|
we want to do c projects.give me some ideas.
|
|
|
|
|
|
|
First of all, any questions about ASP.NET - despite the language unless it's truly a problem with using the language - belong in the ASP.NET forum.
Second, are you talking about using a C# control in a VB.NET project? It's simply a matter of referencing the assembly that defines the UserControl . When you compile C#, VB.NET, MC++ (well, mostly for .NET 1.0 and 1.1), or any other managed language that targets the CLI you get about the same output, and the output can be used by any other managed language. That's what the CLI (Common Language Infrastructure) is all about - hence the name. The CLR (Common Language Runtime) is Microsoft's implementation of the CLI.
If you're trying to reference a web UserControl in a Windows Forms application you can reference the class but it won't do you much good. A Windows Forms control draws to a device context while a web control renders HTML.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i have a windows application in C#. in the windows form i have a toolbar which has a list of buttons in the form images selected from the image list.
how to do i write code for the seprate buttons.
this toolbar is similar to the toolbar of word where there is a open icon,save icon and on click performs some function
where can i write the code for the icons separately
i have the index of the button in the toolbar
plssss help
Sukanya
|
|
|
|
|
I'm afraid I don't understand what you're asking? Are you asking how you handle button clicks for each button? You don't. You handle the ToolBar.ButtonClick event, which passes a ToolBarButtonClickEventArgs , which contains the Button property that reference the ToolBarButton that was clicked.
If you read the documentation[^] for the ToolBarButton.ButtonClick event in the .NET Framework SDK you can see an example.
If this is not what you're asking about, please explain a little more clearly what you're trying to do.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello, Sir and Madam
I have a TextBox that allow user enter a small source code
(
example:
.
.
.
int i, x;
if(i>2)
x=3;
return x;
.
.
.
}
please give me an idea how to compile the source code from user and get the return value from it.
Thank You.
Sorry for bad English
|
|
|
|
|
Ever tried to search CodeProject?
http://www.codeproject.com/info/search.asp?cats=2&cats=3&cats=4&cats=5&searchkw=compile+runtime&Submit1=Search&author=&sd=11%2F15%2F1999&ed=1%2F21%2F2005
|
|
|
|
|
Courtesy of the Clickety Cops[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Heyas All,
I'm trying to populate a listview control with data from a configuration file (xml). Here's what I have so far:
<code>
XmlTextReader configReader = new XmlTextReader("katalog.config");
configReader.WhitespaceHandling = WhitespaceHandling.None;
XmlDocument configDoc = new XmlDocument();
configDoc.Load(configReader);
configReader.Close();
XmlNode xnod = configDoc.DocumentElement;
String strValue = (String)xnod.Name;
if(strValue == "category")
ProgramCategoryListBox.Items.Add(strValue);
</code>
here is the configuration file:
<code>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<category>
Operating System
Productivity
Entertainment
Games
Misc
</category>
</configuration>
</code>
I need the Items under category listed in the listview.
Could anyone give me some help, or a hint, or anything?
Thanks
|
|
|
|
|
Hi!
Instead of testing an element's Name you could simply call configDoc.SelectSingleNode() to select the node you need.
Furthermore, instead of packing all ListBox items into a single node you could use a node for each entry and then use configDoc.SelectNodes() to find them.
Then you don't have to worry about how to split the string containing the items.
Your config file would look similar to this:
<configuration>
<category>Operating System</category>
<category>productivity</category>
<category>Entertainment</category>
<category>Games</category>
</configuration>
Regards,
mav
|
|
|
|
|
I am programming with C# and windows media encoder sdk.
Can XML be used to create an index for a video file?
Please help.
|
|
|
|
|
I am writing a utility that will interact with another piece of software (Civ III). What I am trying to do is to access the turn number from my application. However, I am having difficulty finding information on how to do this. Can anyone direct me to a good example of this, or have any suggestions?
Thanks.
edit: let me clarify, I need general information on accessing memory from another application, not on the specifics of Civ III.
|
|
|
|
|