Click here to Skip to main content
15,900,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Executing a delegate from one class and project to another [modified] Pin
PIEBALDconsult7-Jun-11 17:34
mvePIEBALDconsult7-Jun-11 17:34 
GeneralRe: Executing a delegate from one class and project to another Pin
MAW307-Jun-11 20:48
MAW307-Jun-11 20:48 
GeneralRe: Executing a delegate from one class and project to another Pin
PIEBALDconsult8-Jun-11 2:31
mvePIEBALDconsult8-Jun-11 2:31 
QuestionHelp reading window titles and text in c sharp Pin
turbosupramk37-Jun-11 6:15
turbosupramk37-Jun-11 6:15 
AnswerRe: Help reading window titles and text in c sharp Pin
SledgeHammer017-Jun-11 7:32
SledgeHammer017-Jun-11 7:32 
GeneralRe: Help reading window titles and text in c sharp Pin
turbosupramk37-Jun-11 11:05
turbosupramk37-Jun-11 11:05 
GeneralRe: Help reading window titles and text in c sharp Pin
SledgeHammer017-Jun-11 11:44
SledgeHammer017-Jun-11 11:44 
AnswerRe: Help reading window titles and text in c sharp [modified] Pin
DaveyM697-Jun-11 10:14
professionalDaveyM697-Jun-11 10:14 
You can P/Invoke functions in User32.dll for this - untested, but these declarations should work.

I'll leave it to you how to work out how to use these to get the functionality you desire.

C#
using System;
using System.Runtime.InteropServices;
using System.Text;

internal static class NativeMethods
{
    /*
BOOL WINAPI SetWindowText(
  __in      HWND hWnd,
  __in_opt  LPCTSTR lpString
); */
    public static bool SetWindowText(IntPtr hWnd)
    {
        return SetWindowText(hWnd, null);
    }
    [DllImport("User32.dll", SetLastError = true)]
    public static extern bool SetWindowText(IntPtr hWnd, string lpString);

    /*
int WINAPI GetWindowText(
  __in   HWND hWnd,
  __out  LPTSTR lpString,
  __in   int nMaxCount
); */
    public static string GetWindowText(IntPtr hWnd)
    {
        int count = GetWindowTextLength(hWnd) + 1;
        StringBuilder resultBuilder = new StringBuilder(count);
        GetWindowText(hWnd, resultBuilder, count);
        return resultBuilder.ToString();
    }
    [DllImport("User32.dll", SetLastError = true)]
    public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

    /*
int WINAPI GetWindowTextLength(
  __in  HWND hWnd
); */
    [DllImport("User32.dll", SetLastError = true)]
    public static extern int GetWindowTextLength(IntPtr hWnd);

    /*
BOOL WINAPI EnumWindows(
  __in  WNDENUMPROC lpEnumFunc,
  __in  LPARAM lParam
); */
    [DllImport("User32.dll", SetLastError = true)]
    public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

    /* 
BOOL CALLBACK EnumWindowsProc(
  __in  HWND hwnd,
  __in  LPARAM lParam
); */
    public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
}

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 on Tuesday, June 7, 2011 5:40 PM

GeneralRe: Help reading window titles and text in c sharp Pin
turbosupramk37-Jun-11 11:00
turbosupramk37-Jun-11 11:00 
GeneralRe: Help reading window titles and text in c sharp Pin
DaveyM697-Jun-11 11:25
professionalDaveyM697-Jun-11 11:25 
GeneralRe: Help reading window titles and text in c sharp Pin
Pete O'Hanlon7-Jun-11 11:38
mvePete O'Hanlon7-Jun-11 11:38 
GeneralRe: Help reading window titles and text in c sharp Pin
DaveyM697-Jun-11 11:54
professionalDaveyM697-Jun-11 11:54 
GeneralRe: Help reading window titles and text in c sharp Pin
DaveyM697-Jun-11 12:00
professionalDaveyM697-Jun-11 12:00 
QuestionWhy exception is not caught in BackgroundWorker DoWork routine? Pin
Chesnokov Yuriy7-Jun-11 3:56
professionalChesnokov Yuriy7-Jun-11 3:56 
AnswerRe: Why exception is not caught in BackgroundWorker DoWork routine? Pin
Ian Shlasko7-Jun-11 4:07
Ian Shlasko7-Jun-11 4:07 
GeneralRe: Why exception is not caught in BackgroundWorker DoWork routine? Pin
Chesnokov Yuriy7-Jun-11 4:17
professionalChesnokov Yuriy7-Jun-11 4:17 
QuestionRe: Why exception is not caught in BackgroundWorker DoWork routine? Pin
Luc Pattyn7-Jun-11 4:43
sitebuilderLuc Pattyn7-Jun-11 4:43 
AnswerRe: Why exception is not caught in BackgroundWorker DoWork routine? Pin
Ian Shlasko7-Jun-11 5:12
Ian Shlasko7-Jun-11 5:12 
AnswerRe: Why exception is not caught in BackgroundWorker DoWork routine? Pin
ShadowUz7-Jun-11 21:12
ShadowUz7-Jun-11 21:12 
QuestionNotifying Network Applications Pin
NameNotYetTaken7-Jun-11 3:18
NameNotYetTaken7-Jun-11 3:18 
AnswerRe: Notifying Network Applications Pin
Dave Kreskowiak7-Jun-11 3:46
mveDave Kreskowiak7-Jun-11 3:46 
AnswerRe: Notifying Network Applications Pin
Luc Pattyn7-Jun-11 4:51
sitebuilderLuc Pattyn7-Jun-11 4:51 
GeneralRe: Notifying Network Applications Pin
NameNotYetTaken7-Jun-11 5:18
NameNotYetTaken7-Jun-11 5:18 
AnswerRe: Notifying Network Applications Pin
Luc Pattyn7-Jun-11 5:39
sitebuilderLuc Pattyn7-Jun-11 5:39 
GeneralRe: Notifying Network Applications Pin
NameNotYetTaken7-Jun-11 6:08
NameNotYetTaken7-Jun-11 6:08 

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.