Page 183 - DCAP408_WEB_PROGRAMMING
P. 183

Unit 10: Menus




          using  System.Windows.Forms;                                                          Notes
          using  System.Data;
          using  System.Runtime.InteropServices;
          .........
                         #region  API  Declarations
                         //  return  the  handle  for  the  system  menu
                         [DllImport  (“user32.dll”)]
                         public static extern int GetSystemMenu(int hwnd, bool bRevert);
                         //  append  a  menu  item  to  the  menu
                         [DllImport  (“user32.dll”,  EntryPoint=“AppendMenuA”)]
                         public  static  extern  long  AppendMenu(int  hMenu,  int
                         wFlags,  int  wIDNewItem,  string  lpNewItem);
                         //  remove  a  menu  item  from  the  menu
                         [DllImport  (“user32.dll”)]
                         public  static  extern  long  RemoveMenu(int  hMenu,  int
                         nPosition,  int  wFlags);
                         #endregion  //  API  Declarations
                         //  constants
                         private  const  int  MF_BYPOSITION  =  1024;
                         private  const  int  MF_SEPERATOR  =  2048;
                         private  const  int  MF_REMOVE  =  4096;
                         private  const  int  WM_SYSCOMMAND  =  274;
                         #region  System  Menu  API
                         ///  <summary>
                         ///  Returns  the  handle  for  the  System  Menu  with  the
                               associate  form
                         ///  </summary>
                         ///  <param  name=”frmHandle”>The  handle  to  the  form  to  retrieve
          the  menu  handle</param>
                         public  int  GetSysMenuHandle(int  frmHandle)
                         {
                                return  GetSystemMenu(frmHandle,  false);
                         }
                         ///  <summary>
                         ///  Removes  a  system  menu
                         ///  </summary>
                         ///  <param  name=”mnuHandle”>Then  handle  to  the  system  menu.
          Use  GetSysMenuHandle</param>
                         ///  <param  name=”mnuPosition”>Zero  based  position  of  the
          menu  item  to  delete</param>
                         ///  <returns>returns  nonzero  on  success,  returns  0  on  fail</
          returns>
                         public  long  RemoveSysMenu(int  mnuHandle,  int  mnuPosition)




                                           LOVELY PROFESSIONAL UNIVERSITY                                   177
   178   179   180   181   182   183   184   185   186   187   188