?
Solved

GetClassName API

Posted on 1998-01-28
3
Medium Priority
?
607 Views
Last Modified: 2006-11-17
I wish to use an API call to find out an object's class name. Here's the code I used:
----------
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Private Declare Function ChildWindowFromPoint Lib "user32" (ByVal hwnd As Long, ByVal xPoint As Long, ByVal yPoint As Long) As Long

dim lngHwnd as Long
Dim classname As String
lngHwnd = ChildWindowFromPoint(Me.hwnd, 10, 10)
GetClassName(lngHwnd, classname, 50)
----------
However, every time 0 is return by GetClassName and classname does not change to the class's name.
I've tried changing:
   ByVal lpClassName As String
to
   ByRef lpClassName As String
in the declaration of GetClassName. But the program crash.

What should I do?
0
Comment
Question by:leeal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:shogi
ID: 1453988
What exactly you want to do with the class name?
0
 

Accepted Solution

by:
grimhosp earned 200 total points
ID: 1453989
Hi,

I've taken a look at your code and got it to return the classname with no problems.  I did this by doing the following.

Firstly you need to make sure that the 'classname' variable which is used in the GetClassName call is preset to the correct size.  This can be achieved by placing the command 'classname = space$(51)' directly after the dim statement.  The size of 51 is just the last property of the API call +1.

Secondly you need to pass the return value from the API call back to a variable so instead of just doing 'GetClassName(lngHwnd,classname,50)' you need to use 'l% = GetClassName(lngHwnd,classname,50)'.

So the final code will read:

----------------------------------------------------------------

 Dim lngHwnd As Long
 Dim classname As String
 classname = Space$(51)

 lngHwnd = ChildWindowFromPoint(Me.hWnd, 10, 10)
 l% = GetClassName(lngHwnd, classname, 50)

 MsgBox classname

----------------------------------------------------------------

Running the above code should result in the classname for the specified window being displayed.

Hope this helps

Pete

P.S. The value returned to l% is the length of the classname string.
0
 
LVL 1

Author Comment

by:leeal
ID: 1453990
Thanks a lot.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question