Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

unable to obtain SCROLLBARINFO in XP

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
decrypted - 23 Sep 2004 23:49 GMT
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.
Claes Bergefall - 24 Sep 2004 08:21 GMT
See inline

   /claes

> 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
> {
[quoted text clipped - 17 lines]
>
> SCROLLBARINFO sbi = new SCROLLBARINFO();

sbi.cbSize = Marshal.SizeOf(sbi);

> GetScrollBarInfo(hWndRef, 0xFFFFFFFA, ref sbi);
>
[quoted text clipped - 4 lines]
> thanks in advance,
> dec.
decrypted - 24 Sep 2004 17:40 GMT
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

> See inline
>
[quoted text clipped - 44 lines]
> > thanks in advance,
> > dec.
decrypted - 24 Sep 2004 17:57 GMT
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.

> See inline
>
[quoted text clipped - 44 lines]
> > thanks in advance,
> > dec.
Mattias Sj?gren - 24 Sep 2004 20:55 GMT
>[DLLImport("user32.dll", CharSet=CharSetAuto)]
>static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref SCROLLBARINFO sbi);
                                                       ^^^^

Change long to int.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

decrypted - 24 Sep 2004 21:29 GMT
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?

> >[DLLImport("user32.dll", CharSet=CharSetAuto)]
> >static public extern int GetScrollBarInfo(IntPtr hWnd, long idObject, ref SCROLLBARINFO sbi);
[quoted text clipped - 3 lines]
>
> Mattias
Mattias Sj?gren - 25 Sep 2004 10:18 GMT
>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

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

decrypted - 27 Sep 2004 18:43 GMT
"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

> >Can't do that....the Win32API def is long, not int....
>
[quoted text clipped - 10 lines]
>
> Mattias
decrypted - 27 Sep 2004 19:13 GMT
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

> "That def is in C, not C#. An int in C# is a 32-bit signed integer just like
> LONG."
[quoted text clipped - 79 lines]
> >
> > Mattias

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.