unable to obtain SCROLLBARINFO in XP

D

decrypted

I am trying to get some information regarding a scrollbar on a
control...specifically on a system.windows.forms.form control (but
ultimately any old control). So I want to use SCROLLBARINFO struct from
win32API via GetScrollBarInfo...my definitions are as follows:

public struct RECT { public int left, top, right, bottom; }

public struct SCROLLBARINFO
{
public int cbSize;
public RECT rcScrollBar;
public int dxyLineButton;
public int xyThumbTop;
public int xyThumbBottom;
public int reserved;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst=6)]
public int[] rgstate;
}

[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref
SCROLLBARINFO sbi);


Now that I have my definitions...I call will the following code in a custom
input control:

SCROLLBARINFO sbi = new SCROLLBARINFO();
GetScrollBarInfo(hWndRef, 0xFFFFFFFA, ref sbi);

this call throws error code 986 out everytime (wether there is a scrollbar
present on the ref control or not) and sbi return as an emtpy struct. Any
thoughts?

thanks in advance,
dec.
 
C

Claes Bergefall

See inline

/claes

decrypted said:
I am trying to get some information regarding a scrollbar on a
control...specifically on a system.windows.forms.form control (but
ultimately any old control). So I want to use SCROLLBARINFO struct from
win32API via GetScrollBarInfo...my definitions are as follows:


[StructLayout(LayoutKind.Sequential)]


public struct RECT { public int left, top, right, bottom; }


[StructLayout(LayoutKind.Sequential)]


public struct SCROLLBARINFO
{
public int cbSize;
public RECT rcScrollBar;
public int dxyLineButton;
public int xyThumbTop;
public int xyThumbBottom;
public int reserved;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst=6)]
public int[] rgstate;
}

[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref
SCROLLBARINFO sbi);


Now that I have my definitions...I call will the following code in a custom
input control:

SCROLLBARINFO sbi = new SCROLLBARINFO();


sbi.cbSize = Marshal.SizeOf(sbi);
 
D

decrypted

Yeah I had included those inline statements...just not in this message.
Double checked it all for kicks...still no go.
Why is this a requirement? sbi.cbSize = Marshal.SizeOf(sbi);

Also...the control handle i am passing is usually a panel or a windows form
that contains a scrollbar...sometimes veritcal sometimes horizontal....Am I
not reading this correctly? Can you perhaps post an example of this working?

Thanks!
-dec

Claes Bergefall said:
See inline

/claes

decrypted said:
I am trying to get some information regarding a scrollbar on a
control...specifically on a system.windows.forms.form control (but
ultimately any old control). So I want to use SCROLLBARINFO struct from
win32API via GetScrollBarInfo...my definitions are as follows:


[StructLayout(LayoutKind.Sequential)]


public struct RECT { public int left, top, right, bottom; }


[StructLayout(LayoutKind.Sequential)]


public struct SCROLLBARINFO
{
public int cbSize;
public RECT rcScrollBar;
public int dxyLineButton;
public int xyThumbTop;
public int xyThumbBottom;
public int reserved;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst=6)]
public int[] rgstate;
}

[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref
SCROLLBARINFO sbi);


Now that I have my definitions...I call will the following code in a custom
input control:

SCROLLBARINFO sbi = new SCROLLBARINFO();


sbi.cbSize = Marshal.SizeOf(sbi);

GetScrollBarInfo(hWndRef, 0xFFFFFFFA, ref sbi);

this call throws error code 986 out everytime (wether there is a scrollbar
present on the ref control or not) and sbi return as an emtpy struct. Any
thoughts?

thanks in advance,
dec.
 
D

decrypted

As a follow-up. When I pass the GetScrollbarInfo the sbi ref...the rgstate
info becomes deinfed as an array containing 6 elements....all of which are
0. Something is happening in there...but its failing along the way.


Claes Bergefall said:
See inline

/claes

decrypted said:
I am trying to get some information regarding a scrollbar on a
control...specifically on a system.windows.forms.form control (but
ultimately any old control). So I want to use SCROLLBARINFO struct from
win32API via GetScrollBarInfo...my definitions are as follows:


[StructLayout(LayoutKind.Sequential)]


public struct RECT { public int left, top, right, bottom; }


[StructLayout(LayoutKind.Sequential)]


public struct SCROLLBARINFO
{
public int cbSize;
public RECT rcScrollBar;
public int dxyLineButton;
public int xyThumbTop;
public int xyThumbBottom;
public int reserved;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,
SizeConst=6)]
public int[] rgstate;
}

[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref
SCROLLBARINFO sbi);


Now that I have my definitions...I call will the following code in a custom
input control:

SCROLLBARINFO sbi = new SCROLLBARINFO();


sbi.cbSize = Marshal.SizeOf(sbi);

GetScrollBarInfo(hWndRef, 0xFFFFFFFA, ref sbi);

this call throws error code 986 out everytime (wether there is a scrollbar
present on the ref control or not) and sbi return as an emtpy struct. Any
thoughts?

thanks in advance,
dec.
 
M

Mattias Sjögren

[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref SCROLLBARINFO sbi);
^^^^

Change long to int.



Mattias
 
D

decrypted

Can't do that....the Win32API def is long, not int....and the sysobjectID's
are as follows

OBJID_WINDOW = 0x00000000,

OBJID_SYSMENU = 0xFFFFFFFF,

OBJID_TITLEBAR = 0xFFFFFFFE,

OBJID_MENU = 0xFFFFFFFD,

OBJID_CLIENT = 0xFFFFFFFC,

OBJID_VSCROLL = 0xFFFFFFFB,

OBJID_HSCROLL = 0xFFFFFFFA,

OBJID_SIZEGRIP = 0xFFFFFFF9,

OBJID_CARET = 0xFFFFFFF8,

OBJID_CURSOR = 0xFFFFFFF7,

OBJID_ALERT = 0xFFFFFFF6,

OBJID_SOUND = 0xFFFFFFF5

Have you ever gotten this functionality to work?

Mattias Sjögren said:
[DLLImport("user32.dll", CharSet=CharSetAuto)]
static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref
SCROLLBARINFO sbi);
^^^^

Change long to int.



Mattias
 
M

Mattias Sjögren

Can't do that....the Win32API def is long, not int....

That def is in C, not C#. An int in C# is a 32-bit signed integer just
like LONG.

OBJID_HSCROLL = 0xFFFFFFFA,

const int OBJID_HSCROLL = unchecked((int)0xFFFFFFFA);

or simply

const int OBJID_HSCROLL = -6;



Mattias
 
D

decrypted

"That def is in C, not C#. An int in C# is a 32-bit signed integer just like
LONG."
Odd. because I tried int and the function called crashed out.

"const int OBJID_HSCROLL = unchecked((int)0xFFFFFFFA);
or simply
const int OBJID_HSCROLL = -6;"

So how about this....

public enum SystemObject : int

{


OBJID_WINDOW = 0,

OBJID_SYSMENU = unchecked((int)0xFFFFFFFF),

OBJID_TITLEBAR = unchecked((int)0xFFFFFFFE),

OBJID_MENU = unchecked((int)0xFFFFFFFD),

OBJID_CLIENT = unchecked((int)0xFFFFFFFC),

OBJID_VSCROLL = unchecked((int)0xFFFFFFFB),

OBJID_HSCROLL = unchecked((int)0xFFFFFFFA),

OBJID_SIZEGRIP = unchecked((int)0xFFFFFFF9),

OBJID_CARET = unchecked((int)0xFFFFFFF8),

OBJID_CURSOR = unchecked((int)0xFFFFFFF7),

OBJID_ALERT = unchecked((int)0xFFFFFFF6),

OBJID_SOUND = unchecked((int)0xFFFFFFF5)

}

When I rewrite the code to match your suggestion I get the following:

An unhandled exception of type 'System.ExecutionEngineException' occurred

The call into user32.dll GetScrollBarInfo is crashing (but works when I use
long instead of int for the objectID param)
However...it is only crashing when the parent control has a scrollbar...it
does not crash on a form with no scrollbar.

You haven't by chance seen this work have you?

Let me explain what I am trying to do here, because I may be going about it
completely wrong.
I am custom drawing a control. Mousing into and out of the control generates
a custom paint command. If the control is partially behind a scrollbar, the
control is rendering 'on top' of the scrollbar instead of clipping the
control. If you need a picture I can email on to you (server won't take
attachments).

My routine is to call user32.dll->GetWindowRect for the controls
parent...which does not adjust the 'Right' property for a visible
scrollbar...then check to see if there is a scrollbar using GetScrollBarInfo
and adjust the rendering of the control as needed. I'm very comfortable with
the Windows32API, but I don't have it committed to memory or anything. Any
idears?

Thanks a bunch for your help thus far.
-dec
 
D

decrypted

After posting that statement I realized that there is a much easier
sollution to the problem statement (check the control relative to the
visable area of the parent outside of the Win32API)....gee...that took me
all of 45 seconds to write.
However, I am still very interested as to why I can't get a SCROLLBARINFO
struct to initialize via GetScrollBarInfo....so I would love to continue
this discussion if you don't mind.

Thanks,
-dec

decrypted said:
"That def is in C, not C#. An int in C# is a 32-bit signed integer just like
LONG."
Odd. because I tried int and the function called crashed out.

"const int OBJID_HSCROLL = unchecked((int)0xFFFFFFFA);
or simply
const int OBJID_HSCROLL = -6;"

So how about this....

public enum SystemObject : int

{


OBJID_WINDOW = 0,

OBJID_SYSMENU = unchecked((int)0xFFFFFFFF),

OBJID_TITLEBAR = unchecked((int)0xFFFFFFFE),

OBJID_MENU = unchecked((int)0xFFFFFFFD),

OBJID_CLIENT = unchecked((int)0xFFFFFFFC),

OBJID_VSCROLL = unchecked((int)0xFFFFFFFB),

OBJID_HSCROLL = unchecked((int)0xFFFFFFFA),

OBJID_SIZEGRIP = unchecked((int)0xFFFFFFF9),

OBJID_CARET = unchecked((int)0xFFFFFFF8),

OBJID_CURSOR = unchecked((int)0xFFFFFFF7),

OBJID_ALERT = unchecked((int)0xFFFFFFF6),

OBJID_SOUND = unchecked((int)0xFFFFFFF5)

}

When I rewrite the code to match your suggestion I get the following:

An unhandled exception of type 'System.ExecutionEngineException' occurred

The call into user32.dll GetScrollBarInfo is crashing (but works when I use
long instead of int for the objectID param)
However...it is only crashing when the parent control has a scrollbar...it
does not crash on a form with no scrollbar.

You haven't by chance seen this work have you?

Let me explain what I am trying to do here, because I may be going about it
completely wrong.
I am custom drawing a control. Mousing into and out of the control generates
a custom paint command. If the control is partially behind a scrollbar, the
control is rendering 'on top' of the scrollbar instead of clipping the
control. If you need a picture I can email on to you (server won't take
attachments).

My routine is to call user32.dll->GetWindowRect for the controls
parent...which does not adjust the 'Right' property for a visible
scrollbar...then check to see if there is a scrollbar using GetScrollBarInfo
and adjust the rendering of the control as needed. I'm very comfortable with
the Windows32API, but I don't have it committed to memory or anything. Any
idears?

Thanks a bunch for your help thus far.
-dec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top