Reputation: 403
We have the code to get the class name for c# like
// Get Window class
var windowClass = new StringBuilder(256);
Win32.GetClassName((IntPtr) hwnd, windowClass, windowClass.Capacity);
String windowClassName = windowClass.ToString();
How to convert it in objective c?
Upvotes: 0
Views: 411
Reputation: 96323
Short answer: There is no Mac version of that code, because a window does not have a “class name” in this sense on the Mac. You're asking about a Windows API detail that the Mac doesn't have.
Anoop Vaidya's answer is correct for the Objective-C meaning of “class”, but not for Windows's meaning of “window class”.
Here's what a window class in Windows looks like. A window class defines a lot of things; here are just some of them:
lpfnWndProc
: A pointer to the window procedure. You must use theCallWindowProc
function to call the window procedure. For more information, seeWindowProc
.⋮
hIcon
: A handle to the class icon. This member must be a handle to an icon resource. If this member isNULL
, the system provides a default icon.
hCursor
: A handle to the class cursor. This member must be a handle to a cursor resource. If this member isNULL
, an application must explicitly set the cursor shape whenever the mouse moves into the application's window.
hbrBackground
: A handle to the class background brush. [lots and lots of details follow on that one]
lpszMenuName
: Pointer to a null-terminated character string that specifies the resource name of the class menu, as the name appears in the resource file. If you use an integer to identify the menu, use theMAKEINTRESOURCE
macro. If this member isNULL
, windows belonging to this class have no default menu.
hIconSm
: A handle to a small icon that is associated with the window class. If this member isNULL
, the system searches the icon resource specified by thehIcon
member for an icon of the appropriate size to use as the small icon.
This is a very different thing from an Objective-C class.
A class (as Objective-C uses the term) is the recipe of an object. The class defines what instance variables (members), properties, and methods any object of that class possesses. Every object has a class associated with it; classes in the Objective-C sense are not specific to window objects.
A “window class” in Windows, by contrast, defines a lot of window-specific properties. Let's look at the ones above and see what their Mac equivalents are:
backgroundColor
property, which takes an NSColor object. NSColor, in turn, provides numerous predefined background colors for use as window backgrounds (among other purposes).mainMenu
when the main window changes.Most of the other members of a “window class” are more Windows API details that have no Objective-C equivalent.
You should read through Apple's OS X Human Interface Guidelines. There are a lot of differences in how windows (among other things) work between Windows and the Mac, and those interface choices inform the entire API design all the way down.
Upvotes: 2
Reputation: 46533
NSString *className = [objectName className];
This will give you the class-name of the object named objectName.
Similarly you pass the object, and get the class-name.
Upvotes: 1