Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
AnswerRe: Logging all mouse clicks in an application Pin
Eddy Vluggen19-Jun-12 3:19
professionalEddy Vluggen19-Jun-12 3:19 
GeneralRe: Logging all mouse clicks in an application Pin
Dewald19-Jun-12 3:31
Dewald19-Jun-12 3:31 
GeneralRe: Logging all mouse clicks in an application Pin
Eddy Vluggen19-Jun-12 8:44
professionalEddy Vluggen19-Jun-12 8:44 
GeneralRe: Logging all mouse clicks in an application Pin
BobJanova20-Jun-12 3:16
BobJanova20-Jun-12 3:16 
GeneralRe: Logging all mouse clicks in an application Pin
Eddy Vluggen20-Jun-12 3:23
professionalEddy Vluggen20-Jun-12 3:23 
QuestionRdlc report Pin
sonumanwal18-Jun-12 20:40
sonumanwal18-Jun-12 20:40 
Questionhow to get current application windows title? Pin
a.fatemeh18-Jun-12 11:08
a.fatemeh18-Jun-12 11:08 
AnswerRe: how to get current application windows title? PinPopular
DaveyM6918-Jun-12 11:45
professionalDaveyM6918-Jun-12 11:45 
To use C++ functions you need to do some research into P/Invoke.

Here's how to declare the functions you need in C#:
C#
// NativeMethods.cs

using System;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplicationTest
{
    internal static class NativeMethods
    {
        [DllImport("User32.dll")]
        public static extern IntPtr GetForegroundWindow();

        [DllImport("User32.dll")]
        public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
    }
}

Usage example:
C#
// Program.cs

using System;
using System.Text;

namespace ConsoleApplicationTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key to get text");
            Console.ReadKey();
            IntPtr handle = NativeMethods.GetForegroundWindow();
            if (handle != IntPtr.Zero)
            {
                StringBuilder builder = new StringBuilder(255);
                NativeMethods.GetWindowText(handle, builder, builder.Capacity);
                Console.WriteLine(builder.ToString());
            }
            Console.ReadKey();
        }
    }
}

I have used a hardcoded max length of 255. You can use GetWindowText[^] to get the length of the text before getting the text so you won;t be wasting memory with your string builder or risk truncating if it's longer than you expect.

I'll leave implementing that (which is simple) as an exercise for you.
Dave

Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.
Astonish us. Be exceptional. (Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)




modified 18-Jun-12 17:55pm.

QuestionDebugging c# code called from a c++ binary exe Pin
bonosa18-Jun-12 7:48
bonosa18-Jun-12 7:48 
AnswerRe: Debugging c# code called from a c++ binary exe Pin
lewax0018-Jun-12 8:39
lewax0018-Jun-12 8:39 
GeneralRe: Debugging c# code called from a c++ binary exe Pin
bonosa19-Jun-12 4:29
bonosa19-Jun-12 4:29 
AnswerRe: Debugging c# code called from a c++ binary exe Pin
Bernhard Hiller18-Jun-12 21:58
Bernhard Hiller18-Jun-12 21:58 
GeneralRe: Debugging c# code called from a c++ binary exe Pin
bonosa19-Jun-12 4:32
bonosa19-Jun-12 4:32 
GeneralRe: Debugging c# code called from a c++ binary exe Pin
Dave Kreskowiak19-Jun-12 4:59
mveDave Kreskowiak19-Jun-12 4:59 
QuestionDisplayFormat Question Pin
Jassim Rahma18-Jun-12 6:39
Jassim Rahma18-Jun-12 6:39 
AnswerRe: DisplayFormat Question Pin
Sandeep Mewara18-Jun-12 6:50
mveSandeep Mewara18-Jun-12 6:50 
GeneralRe: DisplayFormat Question Pin
Jassim Rahma18-Jun-12 7:04
Jassim Rahma18-Jun-12 7:04 
QuestionReporting Services ReportViewer Pin
Piot00717-Jun-12 23:45
Piot00717-Jun-12 23:45 
QuestionFull Code with error msg Pin
Member 833684817-Jun-12 22:29
Member 833684817-Jun-12 22:29 
AnswerRe: Full Code with error msg Pin
Richard MacCutchan17-Jun-12 22:36
mveRichard MacCutchan17-Jun-12 22:36 
GeneralRe: Full Code with error msg Pin
Member 833684817-Jun-12 22:54
Member 833684817-Jun-12 22:54 
GeneralRe: Full Code with error msg Pin
Richard MacCutchan17-Jun-12 23:05
mveRichard MacCutchan17-Jun-12 23:05 
AnswerRe: Full Code with error msg Pin
OriginalGriff17-Jun-12 22:37
mveOriginalGriff17-Jun-12 22:37 
QuestionPDU to Text / String Pin
M Riaz Bashir17-Jun-12 22:15
M Riaz Bashir17-Jun-12 22:15 
AnswerRe: PDU to Text / String Pin
Richard MacCutchan17-Jun-12 22:33
mveRichard MacCutchan17-Jun-12 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.