Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GetClassName API

Posted on 1998-01-28
3
Medium Priority
?
645 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…
Suggested Courses

618 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