|
How can I get the title from a program that is active?
I will develop a program that logs every program that a user have used. For example if someone opens notepad I want to retrieve "Untitled - Notepad"
I'm using .NET 2.0
Thanks!
|
|
|
|
|
You need to use the Windows API to lookup that sort of information, and get an IntPtr to the window
perhaps this[^] will help
kind regards,
g00fy
|
|
|
|
|
<br />
<br />
public class Foo<br />
{<br />
<br />
[DllImport("user32.dll")]<br />
public static extern IntPtr GetForegroundWindow();<br />
<br />
[DllImport("user32.dll", CharSet=CharSet.Auto)]<br />
public static extern uint GetWindowText(IntPtr hwnd, StringBuilder text, int maxCount);<br />
<br />
public string GetActiveWindowText()<br />
{<br />
IntPtr hwnd = GetForegrondWindow();<br />
<br />
StringBuilder builder = new StringBuilder(255);<br />
GetWindowText(hwnd, builder, 255);<br />
return builder.ToString();<br />
}<br />
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
|
That doesn't get the result he wants. To use that method you need a process instance. He wants to get the title of the window the user is interacting with. For that he needs some equivalent of GetForegroundWindow().
Jared Parsons
jaredp@beanseed.org
http://spaces.msn.com/members/jaredp/
|
|
|
|
|
Hi,
I am trying to change the selection of a combobox but am unable to do so, or that is to say I am unable to figure out what event I need to use or how to do it properly...perhaps a more detailed explanation will suffice.
I have some items in my combobox like:
Item A (1)
Item B (2)
Item C (43)
Item D (57)
When the user selects one I want to place the number that is in parens in combobox.Text.
The problem is I can't seem to figure out how to do this. I used the event SelectedValueChanged but as soon as the event is done, the picked value goes in. Here is the code:
private void _cbo_SelectedValueChanged(object sender, System.EventArgs e)
{
int index1 = _cbo.Text.IndexOf("(") + 1;
int index2 = _cbo.Text.IndexOf(")");
_cbo.Text = _cbo.Text.Substring(index1, index2 - index1);
}
The code works I see the text in the combobox but then it is replaced with what the user selected again.
Any help would be greatly appreciated.
Sean
|
|
|
|
|
you may also need to set one of
SelectedText
SelectedItem
|
|
|
|
|
I have tried messing with those and get some very odd results. I am missing something, I must have the wrong event. Any other ideas?
Sean
|
|
|
|
|
Is there a way to "hide" some of the printers that are normally seen in a PrintDialog? I have an application that's required to show only the printers (not faxes or imaging drivers) when printing or only faxes when faxing.
cobra2005
|
|
|
|
|
Only if you create your own PrintDialog and enumerate the installed printers yourself. The system and .NET PrintDialogs will show all installed printers, no matter what type they are.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hello ...
I need to extract the first frame of a given video and convert it to an image .
i'm developing an editor for HTML using C#.
i want to use it when a webbrowser fails to download a video
as follows
|
|
|
|
|
Hi
I am dumping a table's data into xml document using C#. I am getting the data but the problem is that "<" character appears as "& l t ;" (I inserted the empty space intentionally).
Similarly, there are other characters appearing incorrectly.
What should I do to make it appear correctly like "<" . Please advise.
Thanks
Pankaj
-- modified at 17:14 Friday 16th December, 2005
|
|
|
|
|
pankazmittal wrote: that "<" character appears as "<".
pankazmittal wrote: it appear correctly like "<" .
|
|
|
|
|
its actually
"<" character appears as "& l t ;" (remove empty spaces )
|
|
|
|
|
you must be outputing the XML yourself.
System.Xml.XmlDocument
|
|
|
|
|
Where are they appearing incorrectly? If you mean that they are stored that way in the xml file, it's not incorrect, they have to be stored that way.
---
b { font-weight: normal; }
|
|
|
|
|
If I understand you correctly, you have a table like the following:
<table>
<tr>
<td>
Some table data.
</td>
</tr>
</table> and when you put it in the XML document, you get:
<myXml>
</tableData>
<table>
<tr>
<td>
Some table data.
</td>
</tr>
</table>
</tableData>
</myXml> If so, then when you dump it into the XML document, your code (intentionally or not) has replaced the predefined XML entities with their ENTITY counterparts. Five predefined entities exist:- > becomes >
- < becomes <
- " becomes "
- ' becomes '
- & becomes &
Perhaps you can post how you put the table data into the XML document and we can help you avoid these automatic conversions.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Thanks for understanding. I am simply pulling the data from table and access it using dataset "dsCC" in following code.
Here is the code I am using:
--------------------Code Starts here-------------------------------
if (dsCC.Tables.Count > 0)
{
dvCC = dsCC.Tables[0].DefaultView ;
if (dvCC.Count > 0)
{
xDoc = new XmlDocument();
XmlElement xElmntRoot;
XmlElement xElmntAccount;
xElmntRoot = xDoc.CreateElement("root");
xDoc.AppendChild(xElmntRoot);
InsertTextNode(xDoc, xElmntRoot, dvCC.Table.Columns[0].ColumnName, Convert.ToString(dvCC[0][0]));
xElmntAccount = xDoc.CreateElement("Accounts"); // xElmntRoot. //xElmntRoot.AppendChild("Accounts");
xElmntRoot.AppendChild(xElmntAccount);
for (int nRowCounter = 0; nRowCounter <= dvCC.Count - 1; nRowCounter++)
{
for (int nColCounter = 1; nColCounter <= dvCC.Table.Columns.Count - 1; nColCounter++)
{
InsertTextNode(xDoc, xElmntAccount, dvCC.Table.Columns[nColCounter].ColumnName, Convert.ToString(dvCC[nRowCounter][nColCounter]));
}
}
sDestinationFileWithPath = HttpContext.Current.Request.ServerVariables["APPL_PHYSICAL_PATH"] + @"ClientConfig.xml";
xDoc.Save(sDestinationFileWithPath);
}
}
private XmlElement InsertTextNode(XmlDocument xDoc,XmlNode xNode ,string strTag, string strText)
{
// Insert a text node a child of xNode.
// Set the tag to be strTag, and the text to be strText. return a pointer to the new node.
XmlNode xNodeTemp;
xNodeTemp = xDoc.CreateElement(strTag);
xNodeTemp.AppendChild(xDoc.CreateTextNode(strText));
xNode.AppendChild(xNodeTemp);
return (XmlElement) (xNodeTemp);
}
--------------------Code Ends-------------------------------
When I open the xml file, the data looks like
<EncryptionType>&lt;![CDATA[etPublicKey]]&gt;</EncryptionType>
-----------------------------
What I want is
<EncryptionType><![CDATA[etPublicKey]]></EncryptionType>
-----------------------------
I hope I am clear now Thanks
Pankaj
|
|
|
|
|
In InsertTextNode(...) , try replacing xNodeTemp.AppendChild(xDoc.CreateTextNode(strText)); with xNodeTemp.AppendChild(xDoc.CreateCDataSection(strText)); . Maybe that'll work correctly for you.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Playing with the ListView to try to get colored backgrounds.
ListViewItem lviGrossMargin = new ListViewItem(strListViewItem);
lvOptions.Items.Add(lviGrossMargin);
lviGrossMargin.SubItems[0].BackColor = System.Drawing.Color.Wheat;
lviGrossMargin.SubItems[1].BackColor = System.Drawing.Color.SpringGreen;
lviGrossMargin.SubItems[2].BackColor = System.Drawing.Color.YellowGreen; If I set lvOptions.Background, I color the entire background the identified color. But coding as above, I get the same result. Setting SubItems[0] to Wheat sets all SubItems. Setting SubItems[1] or [2] does nothing.
Playing with the SubItems[n].Text does apply the expected text in each column. If I play with ForeColor, same as BackColor occurs. [0] is recognized and applies it to all SubItems. It is only the colors that don't seem to work.
Is there a step I skipped that has to be done before manipulating colors or is it a feature that doesn't work correctly in VS Studio 2003?
|
|
|
|
|
|
That was the key. Thank you very much!
|
|
|
|
|
Hi,
I have a datagrid with a datatable, and am using the MouseMove event to make a tooltip pop up whenever the text in the cell is longer than the cell width. This works ok, but there's a problem. When the mouse enters the cell, the cell backcolor turns off-white/beige and the text is highlighted. (This also happens when I just click on a cell to select the row - at least until the I release the mouse button.) I do have a CustomDataTableStyle where I set
ts.BackColor = Color.Black;<br />
ts.ForeColor = Color.LightGray;
ts.SelectionBackColor = Color.Black;<br />
ts.SelectionForeColor = Color.CornflowerBlue;
Is there anything to prevent this from happening, or anything I can add that says that, upon MouseEnter the backcolor is black and the forecolor is cornflowerblue, or any other ideas?
Thanks!!!
Mel
|
|
|
|
|
Hello,
I created a simple Windows service using the code from http://msdn.microsoft.com/msdnmag/issues/05/03/SchedulingASPNETCode/default.aspx[^], I didn't change the code much accept the name of the service.
Installation goes perfect, but when the service is started, it stops right away giving me a message that the Serivce has no work to do so it is stopped.
Can anyone help me in determinig what the problem is here? All I am trying to do is create a simple timer service that will write to a text file at a given interval.
Thanks
Mike
<br />
using System;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Diagnostics;<br />
using System.ServiceProcess;<br />
using System.Configuration;<br />
using System.Globalization;<br />
<br />
using System.IO;<br />
<br />
namespace MyWinServices<br />
{<br />
public class InvokeMyWinService : System.ServiceProcess.ServiceBase<br />
{<br />
private System.ComponentModel.Container components = null;<br />
protected System.Timers.Timer timer;<br />
<br />
private double _intervalTest = 0;<br />
<br />
<br />
public static void Main() <br />
{<br />
ServiceBase.Run(new InvokeG6EntWinService());<br />
}<br />
<br />
<br />
public InvokeMyWinService()<br />
{<br />
InitializeComponent();<br />
CanPauseAndContinue = true;<br />
this.ServiceName = "MyWinServices";<br />
<br />
if( ! EventLog.SourceExists("MyWinServiceEventLog"))<br />
{<br />
EventLog.CreateEventSource("MyWinServiceEventLog", "MyWinServiceLog");<br />
}<br />
EventLog.Source = "MyWinServiceEventLog";<br />
EventLog.Log = "MyWinServiceLog";<br />
}<br />
<br />
<br />
private void InitializeComponent()<br />
{<br />
this.timer = new System.Timers.Timer();<br />
((System.ComponentModel.ISupportInitialize)(this.timer)).BeginInit();<br />
this.timer.Enabled = true;<br />
this.timer.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_Elapsed);<br />
this.ServiceName = "MyWinServices";<br />
((System.ComponentModel.ISupportInitialize)(this.timer)).EndInit();<br />
<br />
}<br />
<br />
protected override void Dispose( bool disposing )<br />
{<br />
if( disposing )<br />
{<br />
if (components != null) <br />
{<br />
components.Dispose();<br />
}<br />
}<br />
base.Dispose( disposing );<br />
}<br />
<br />
protected void InitializeTimer()<br />
{<br />
if (timer == null)<br />
{<br />
timer = new System.Timers.Timer();<br />
timer.AutoReset = true;<br />
timer.Interval = ReadAppSettingInterval();<br />
timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);<br />
}<br />
}<br />
private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
RunCommands();<br />
}<br />
<br />
protected void RunCommands()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service ran ok");<br />
<br />
FileStream fs = new FileStream(@"c:\temp\MyWinServices.txt" , FileMode.OpenOrCreate, FileAccess.Write); <br />
StreamWriter m_streamWriter = new StreamWriter(fs); <br />
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End); <br />
m_streamWriter.WriteLine(" MyWinServices: Doing Job at: " + DateTime.Now + "\n"); <br />
m_streamWriter.WriteLine(" _intervalTest: " + _intervalTest + "\n"); <br />
m_streamWriter.Flush();<br />
m_streamWriter.Close(); <br />
}<br />
<br />
protected double ReadAppSettingInterval()<br />
{<br />
double interval = 600000, tempInterval;
if (ConfigurationSettings.AppSettings != null && <br />
ConfigurationSettings.AppSettings["IntervalMinutes"] != null)<br />
{<br />
string intervalMin;<br />
intervalMin =ConfigurationSettings.AppSettings["IntervalMinutes"];<br />
if (Double.TryParse(intervalMin, NumberStyles.Any,<br />
NumberFormatInfo.InvariantInfo, out tempInterval))<br />
interval = tempInterval * 60000;<br />
}<br />
<br />
_intervalTest = interval;
return interval;<br />
}<br />
<br />
protected override void OnStart(string[] args)<br />
{<br />
EventLog.WriteEntry(ServiceName + " 3 Service started");<br />
InitializeTimer();<br />
timer.Enabled = true; <br />
}<br />
<br />
protected override void OnStop()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service stopped");<br />
timer.Enabled = false;<br />
}<br />
protected override void OnPause()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service paused");<br />
timer.Enabled = false;<br />
}<br />
<br />
protected override void OnContinue()<br />
{<br />
EventLog.WriteEntry(ServiceName + " Service continued");<br />
timer.Enabled = true;<br />
}<br />
<br />
<br />
}<br />
}<br />
App.config
<br />
<?xml version="1.0" encoding="utf-8" ?><br />
<configuration><br />
<appSettings><br />
<add key="IntervalMinutes" value="5"/><br />
</appSettings><br />
</configuration><br />
<br />
|
|
|
|
|
Hi!
I'm not going to debug your code but tell you how you can do it yourself.
First of all, insert a call to System.Windows.Forms.MessageBox.Show("Attach a debugger and then press OK"); right at the start of OnStart() . Set a breakpoint immediately after the MessageBox. Compile and replace the new executable.
Then you'll have to allow the service desktop interaction (you can do this via the Services control panel).
If you start the service now, the MessageBox will pop up. Then you can attach your running VS to the process (you'll have to hurry a bit, before the start request for your service times out). Then you can klick OK in your MessageBox and the debugger will stop at the next breakpoint so you can step through the code and find out what goes wrong.
Regards,
mav
|
|
|
|