Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than user32, prefix the name with the module name and a period.
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Private Shared Function GetClassName(ByVal hWnd As System.IntPtr, _
ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer
' Leave function empty
End Function
Alternate VB.NET Signature:
Public Declare Auto Function GetClassName Lib "User32.dll" (ByVal hwnd As IntPtr, _
<Out()> ByVal lpClassName As System.Text.StringBuilder, _
ByVal nMaxCount As Integer) As Integer
VB Signature
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Notes:
In .NET Framework 4.0, only CharSet.Ansi seems to produce the result.
The return type int seems to crash the .NET application in 64-bit mode (occasionally), long seems to work better. Maybe it should even be IntPtr? Please modify this note if you have more insights.
Tips & Tricks:
Please add some!
Sample Code:
C# Sample Code
private static bool isIEServerWindow(IntPtr hWnd)
{
int nRet;
// Pre-allocate 256 characters, since this is the maximum class name length.
StringBuilder ClassName = new StringBuilder(256);
//Get the window class name
nRet = GetClassName(hWnd, ClassName, ClassName.Capacity);
if(nRet != 0)
{
return (string.Compare(ClassName.ToString(), "Internet Explorer_Server",true,CultureInfo.InvariantCulture) == 0);
}
else
{
return false;
}
}
VB.NET Sample Code
Create a new VB .NET form and add a button Button1 to it.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim sClassName As New StringBuilder("", 256)
'pass in the handle of the object for which to get
'the class name; for example, the form's handle
Call GetClassName(Me.Handle, sClassName, 256)
MessageBox.Show(sClassName.ToString)
End Sub
class ManagedWinapi.SystemWindow that has a ClassName property.
Click to read this page
4/6/2008 7:23:14 AM - anonymous
An IntPtr is a pointer to a memory location (unmanaged) that adapts to the platform it is running on (64-bit, etc.) UNLIKE a standard int/Integer. You should always use this type for unmanaged calls that require it, even though an int will appear to work on your development machine.
1/13/2008 4:00:13 AM - Damon Carr-72.43.165.29
http://mwinapi.sourceforge.net/
3/31/2008 6:53:29 AM - -217.54.254.83
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).