473,378 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GetClassName()

Hi,

I am using the

IntPtr FindWindow(string lpClassName, string lpWindowName);

to get the handle for a window (notepad in this case), I am then using

int GetClassName(IntPtr hWnd, out StringBuilder lpClassName, int
nMaxCount);

to get the name of this window. Now it all works fine but as prove of
concept i want to print the name of the class to console. The
GetClassName returns 7 (Specifies the length, in TCHAR, of the buffer
pointed to by the lpClassName parameter) which would make sense as
notepad class name is Notepad. I'm having problems printing this to
console. It returns 3 characters to the console. I declared a local
StringBuilder class_name and passed that as an out parameter in my
method.

thanks,

steve.

Jul 14 '06 #1
2 24424
Hi Stephen,
Without seeing your code, it's hard to say exactly what is going wrong,
but I'm guessing it's a problem with the "out" lpClassName parameter to
GetClassName.

Try this instead, it worked for me:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

[DllImport("user32.dll")]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,
int nMaxCount);

static void Main(string[] args)
{
IntPtr hwnd = FindWindow("notepad", null);
StringBuilder lpClassName = new StringBuilder();
GetClassName(hwnd, out lpClassName, 100);
Console.WriteLine(lpClassName.ToString());
}

Hope that helps,
John

st************@gmail.com wrote:
Hi,

I am using the

IntPtr FindWindow(string lpClassName, string lpWindowName);

to get the handle for a window (notepad in this case), I am then using

int GetClassName(IntPtr hWnd, out StringBuilder lpClassName, int
nMaxCount);

to get the name of this window. Now it all works fine but as prove of
concept i want to print the name of the class to console. The
GetClassName returns 7 (Specifies the length, in TCHAR, of the buffer
pointed to by the lpClassName parameter) which would make sense as
notepad class name is Notepad. I'm having problems printing this to
console. It returns 3 characters to the console. I declared a local
StringBuilder class_name and passed that as an out parameter in my
method.

thanks,

steve.
Jul 14 '06 #2
Thanks, that seemed to solve the problem!
John Duval wrote:
Hi Stephen,
Without seeing your code, it's hard to say exactly what is going wrong,
but I'm guessing it's a problem with the "out" lpClassName parameter to
GetClassName.

Try this instead, it worked for me:

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string
lpWindowName);

[DllImport("user32.dll")]
static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName,
int nMaxCount);

static void Main(string[] args)
{
IntPtr hwnd = FindWindow("notepad", null);
StringBuilder lpClassName = new StringBuilder();
GetClassName(hwnd, out lpClassName, 100);
Console.WriteLine(lpClassName.ToString());
}

Hope that helps,
John

st************@gmail.com wrote:
Hi,

I am using the

IntPtr FindWindow(string lpClassName, string lpWindowName);

to get the handle for a window (notepad in this case), I am then using

int GetClassName(IntPtr hWnd, out StringBuilder lpClassName, int
nMaxCount);

to get the name of this window. Now it all works fine but as prove of
concept i want to print the name of the class to console. The
GetClassName returns 7 (Specifies the length, in TCHAR, of the buffer
pointed to by the lpClassName parameter) which would make sense as
notepad class name is Notepad. I'm having problems printing this to
console. It returns 3 characters to the console. I declared a local
StringBuilder class_name and passed that as an out parameter in my
method.

thanks,

steve.
Jul 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Shuttermutt | last post by:
Okay, I'm a relative newcomer to object-oriented PHP, but no stranger to OOP in general. I've spent the last three hours trying to figure out why this code snipped doesn't do what I expect it to: ...
2
by: bala | last post by:
Hi, I want to know how to getclassname of application from python..In python There is no method like GetClassName... Is there any other Method ...I kindly give some example in python.. If anyone...
2
by: Scott Manson | last post by:
StringBuilder bldr=new StringBuilder(); int res=GetClassName(0x00240110,bldr,255); Debug.WriteLine(bldr.ToString()); if(bldr.ToString()=="AfxFrameOrView42s") Debug.Write("Things SHOULD work");...
1
by: Andreas Poller | last post by:
Hello, I have the following problem: I have a class deriving from ICustomTypeDescriptor: public __gc class TPropertyBag : public ICustomTypeDescriptor { private: ...
4
by: Kartic | last post by:
Hi, Declare Ansi Function GetClassName Lib "user32" Alias "GetClassNameA" ( ByVal hWnd As IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Int32) As Int32 I am...
5
by: Lance | last post by:
I want to expose properties of a class to a user via a PropertyGrid class. Some of the properties are of type System.IO.FileInfo. Ideally, an OpenFileDialog window would appear when the user...
3
by: Benjamin GILLET | last post by:
Dear all, I have coded a class called Object with a member method called getClassName(). Here is the code of this class: #include <iostream>
59
by: peter.tornqvist | last post by:
Maybe I'm stupid or maybe I am missing the obvious, but I can't find a way to define a type alias in C# for primitive types (class and interfaces I can inherit from, no problem). I.e I want to...
5
by: Simon Woods | last post by:
Hi Still trying to get to grips with VB.Net so sorry if these seem silly questions ... I have an object which is implementing a secondary interface. I want to get the name of the underlying...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.