Solved

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

Posted on 2006-11-13
6
1,006 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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