Solved

GetClassName API

Posted on 1998-01-28
3
583 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 50 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

690 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