Skip to content

Instantly share code, notes, and snippets.

@LaraSQP
Last active September 22, 2021 21:27
Show Gist options
  • Save LaraSQP/f800e0bb119d0e4488bb7cfbcaeadc46 to your computer and use it in GitHub Desktop.
Save LaraSQP/f800e0bb119d0e4488bb7cfbcaeadc46 to your computer and use it in GitHub Desktop.
public const int GWL_STYLE = -16;
public const int WS_HSCROLL = 0x00100000;
public const int WS_VSCROLL = 0x00200000;
[ DllImport( "user32.dll", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto ) ]
public static extern IntPtr GetWindowLong32( IntPtr hWnd, int nIndex );
[ DllImport( "user32.dll", EntryPoint = "GetWindowLongPtr", CharSet = CharSet.Auto ) ]
public static extern IntPtr GetWindowLongPtr64( IntPtr hWnd, int nIndex );
[ DllImport( "user32.dll", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto ) ]
public static extern IntPtr SetWindowLongPtr32( IntPtr hWnd, int nIndex, int dwNewLong );
[ DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr", CharSet = CharSet.Auto ) ]
public static extern IntPtr SetWindowLongPtr64( IntPtr hWnd, int nIndex, int dwNewLong );
public static int GetWindowLong( IntPtr hWnd, int nIndex )
{
if( IntPtr.Size == 4 )
{
return (int)GetWindowLong32( hWnd, nIndex );
}
else
{
return (int)(long)GetWindowLongPtr64( hWnd, nIndex );
}
}
public static int SetWindowLong( IntPtr hWnd, int nIndex, int dwNewLong )
{
if( IntPtr.Size == 4 )
{
return (int)SetWindowLongPtr32( hWnd, nIndex, dwNewLong );
}
else
{
return (int)(long)SetWindowLongPtr64( hWnd, nIndex, dwNewLong );
}
}
protected override void WndProc( ref Message m )
{
switch( m.Msg )
{
case WM_NCCALCSIZE:
{
var style = (int)GetWindowLong( this.Handle, GWL_STYLE );
if( ( style & WS_HSCROLL ) == WS_HSCROLL )
{
SetWindowLong( Handle, GWL_STYLE, style & ~WindowsNative.WS_HSCROLL );
}
break;
}
}
base.WndProc( ref m );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment