Solved

using Help.ShowHelp ... how to maximize and or close help window??

Posted on 2006-11-13
6
998 Views
Last Modified: 2012-06-21
I am opening Help using C# built in help, such as
Help.ShowHelp(this, "help.chm");

Is there a way to mazimize the help window that opens, and how do I close it?
0
Comment
Question by:shmitnols
  • 6
6 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17932715
I don't think there's an easy way because the method does not return a window handle.
You could use the findwindow api asing the lpClassName of "HH Parent" which is what the help uses.
once you have the window handle you should be able to maximise and/or close it.
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17932741
DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17932789
Sorry forgot the other two :

[DllImport("user32.dll")]
static extern bool SetWindowPlacement(IntPtr hWnd,   [In] ref WINDOWPLACEMENT lpwndpl);

Can be used to maximise window.

[DllImport("user32.dll")]
static extern bool CloseWindow(IntPtr hWnd);


Can be used to close window.


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:ozymandias
ID: 17933089
Fisrt you need to define these :

      [StructLayout(LayoutKind.Sequential)]
      public struct WINDOWPLACEMENT {
            public int length;
            public int flags;
            public int showCmd;
            public POINT ptMinPosition;
            public POINT ptMaxPosition;
            public RECT rcNormalPosition;
      }

      [StructLayout( LayoutKind.Sequential )]
      public struct POINT {
            public int X;
            public int Y;

            public POINT( int x, int y ) {
                  this.X = x;
                  this.Y = y;
            }

            public static implicit operator System.Drawing.Point( POINT p ) {
                  return new System.Drawing.Point( p.X,  p.Y );
            }

            public static implicit operator POINT( System.Drawing.Point p ) {
                  return new POINT( p.X, p.Y );
            }
      }

      [Serializable, StructLayout(LayoutKind.Sequential)]
      public struct RECT {
            public int Left;
            public int Top;
            public int Right;
            public int Bottom;

            public RECT(int left_, int top_, int right_, int bottom_) {
                  Left = left_;
                  Top = top_;
                  Right = right_;
                  Bottom = bottom_;
            }

            public int Height { get { return Bottom - Top; } }
            public int Width { get { return Right - Left; } }
            public Size Size { get { return new Size(Width, Height); } }

            public Point Location { get { return new Point(Left, Top); } }

            public Rectangle ToRectangle() {
          return Rectangle.FromLTRB(Left, Top, Right, Bottom); }

            public static RECT FromRectangle(Rectangle rectangle) {
                  return new RECT(rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
            }

            public override int GetHashCode() {
                  return Left ^ ((Top << 13) | (Top >> 0x13))
                        ^ ((Width << 0x1a) | (Width >> 6))
                        ^ ((Height << 7) | (Height >> 0x19));
            }

            #region Operator overloads

            public static implicit operator Rectangle( RECT rect ) {
                  return Rectangle.FromLTRB(rect.Left, rect.Top, rect.Right, rect.Bottom);
            }

            public static implicit operator RECT( Rectangle rect ) {
                  return new RECT(rect.Left, rect.Top, rect.Right, rect.Bottom);
            }

            #endregion
      }

      public enum SHOWWINDOW : uint {
            SW_HIDE         = 0,
            SW_SHOWNORMAL       = 1,
            SW_NORMAL       = 1,
            SW_SHOWMINIMIZED    = 2,
            SW_SHOWMAXIMIZED    = 3,
            SW_MAXIMIZE     = 3,
            SW_SHOWNOACTIVATE   = 4,
            SW_SHOW         = 5,
            SW_MINIMIZE     = 6,
            SW_SHOWMINNOACTIVE  = 7,
            SW_SHOWNA       = 8,
            SW_RESTORE      = 9,
            SW_SHOWDEFAULT      = 10,
            SW_FORCEMINIMIZE    = 11,
            SW_MAX          = 11,
      }
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17933100
Finally these three functions :

            private void ShowHelp_Click(object sender, System.EventArgs e) {
                  Help.ShowHelp(this, @"path_to_your_chm_file");
            }

            private void CloseHelp_Click(object sender, System.EventArgs e) {
                  IntPtr hWnd = FindWindow("HH Parent", null);
                  if (hWnd.ToInt32() != 0){
                        CloseWindow(hWnd);
                  }
            }

            private void MaxHelp_Click(object sender, System.EventArgs e) {
                  IntPtr hWnd = FindWindow("HH Parent", null);
                  if (hWnd.ToInt32() != 0){
                        WINDOWPLACEMENT WP = new WINDOWPLACEMENT();
                        WP.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                        WP.showCmd = (int)SHOWWINDOW.SW_MAXIMIZE;
                        SetWindowPlacement(hWnd, ref WP);
                  }
            }
0
 
LVL 15

Accepted Solution

by:
ozymandias earned 500 total points
ID: 17933118
Sorry, the middle step was of course to add these but for some reason it didn't post :

            [DllImport("user32.dll", SetLastError = true)]
            static extern IntPtr FindWindow(string lpClassName, string lpWindowName);


            [DllImport("user32.dll")]
            static extern bool SetWindowPlacement(IntPtr hWnd,   [In] ref WINDOWPLACEMENT lpwndpl);


            [DllImport("user32.dll")]
            static extern bool CloseWindow(IntPtr hWnd);
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Not showing page correctly 3 30
Run time Error 4 34
C# Single Form 8 28
C#.NET and microsoft certification. 3 32
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now