2010-05-14 6 views
8

मैं एक आवेदन पत्र का शीर्षक पट्टी है, जो पूरी तरह से नोटपैड के लिए काम कर रहा है दूर करने के लिए नीचे दिए गए कोड का उपयोग कर रहा हूँ। अब मैं मेनू बार को भी हटाना चाहता हूं। उसकी प्राप्ति कैसे हो ?कैसे खिड़कियों एपीआई का उपयोग कर एक आवेदन के मेनूबार दूर करने के लिए?

//Finds a window by class name 
     [DllImport("USER32.DLL")] 
     public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

     //Sets a window to be a child window of another window 
     [DllImport("USER32.DLL")] 
     public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); 

     //Sets window attributes 
     [DllImport("USER32.DLL")] 
     public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

     //Gets window attributes 
     [DllImport("USER32.DLL")] 
     public static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

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


     //assorted constants needed 
     public static int GWL_STYLE = -16; 
     public static int WS_BORDER = 0x00800000; //window with border 
     public static int WS_DLGFRAME = 0x00400000; //window with double border but no title 
     public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar 

     public void WindowsReStyle() 
     { 
      Process[] Procs = Process.GetProcesses(); 
      foreach (Process proc in Procs) 
      { 

       if (proc.ProcessName.StartsWith("notepad")) 
       { 
        IntPtr pFoundWindow = proc.MainWindowHandle; 
        int style = GetWindowLong(pFoundWindow, GWL_STYLE); 
        SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION)); 
       } 
      } 
    } 
+0

मैं एक ही जरूरत है। लेकिन अपने आवेदन में इस कोड को लागू करने पर है, यह (खींचें और ड्रॉप आदि) उस पर कुछ माउस बातचीत कर रही पर शीर्षक पट्टी छुपाता है। क्या आप मुझे मूल कारण बता सकते हैं? –

उत्तर

7

आप उन्हें छिपा नहीं सकते, आप के बजाय एपीआई का उपयोग कर उन्हें हटाने के लिए की आवश्यकता होगी, YMMV ऐसा करने का परिणाम पर;

[DllImport("USER32.DLL")] 
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); 

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

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

    [DllImport("user32.dll")] 
    static extern int GetMenuItemCount(IntPtr hMenu); 

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

    [DllImport("user32.dll")] 
    static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); 

    public static uint MF_BYPOSITION = 0x400; 
    public static uint MF_REMOVE = 0x1000; 

    public static void WindowsReStyle() { 
     Process[] Procs = Process.GetProcesses(); 
     foreach (Process proc in Procs) { 

      if (proc.ProcessName.StartsWith("notepad")) { 
       //get menu 
       IntPtr HMENU = GetMenu(proc.MainWindowHandle); 
       //get item count 
       int count = GetMenuItemCount(HMENU); 
       //loop & remove 
       for (int i = 0; i < count; i++) 
        RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE)); 

       //force a redraw 
       DrawMenuBar(proc.MainWindowHandle); 
      } 
     } 
    } 
+0

यू मुझे स्थिरांक इस कोड के लिए आवश्यक जानकारी दे सकते हैं? – Anuya

+1

उपरोक्त अद्यतन पोस्ट –

संबंधित मुद्दे