winAPI

2010-05-14 11 views
8

का उपयोग कर किसी अन्य एप्लिकेशन की विंडो शैली को संशोधित करें मेरा एप्लिकेशन एक और एप्लिकेशन शुरू करता है। जिससे, मैं उस एप्लिकेशन के शीर्षक पट्टी को हटाना चाहता हूं जो सी # का उपयोग शुरू कर दिया गया है।winAPI

मैं नीचे दिए गए कोड के टुकड़े से शुरू कैसे कर सकता हूं?

//Get current style 
lCurStyle = GetWindowLong(hwnd, GWL_STYLE) 

//remove titlebar elements 
lCurStyle = lCurStyle And Not WS_CAPTION 
lCurStyle = lCurStyle And Not WS_SYSMENU 
lCurStyle = lCurStyle And Not WS_THICKFRAME 
lCurStyle = lCurStyle And Not WS_MINIMIZE 
lCurStyle = lCurStyle And Not WS_MAXIMIZEBOX 

//apply new style 
SetWindowLong hwnd, GWL_STYLE, lCurStyle 

//reapply a 3d border 
lCurStyle = GetWindowLong(hwnd, GWL_EXSTYLE) 

SetWindowLong hwnd, GWL_EXSTYLE, lCurStyle Or WS_EX_DLGMODALFRAME 

//redraw 
SetWindowPos hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_FRAMECHANGED 
+0

कोड आपके द्वारा पोस्ट की है ** नहीं ** ग # – Oded

+0

@Oded, मुझे पता है इसके नहीं ग # कि। मैंने कहा कि, मेरा सी # एप्लिकेशन एक एप्लीकेशन शुरू करता है, जिसमें मैं टाइटल बार को हटाना चाहता हूं। आश्चर्य है कि, डीएल के रूप में कोड का उपयोग कर सकते हैं। मेरे कोड में उस डीएल को कॉल करें और पूरा करें। धन्यवाद। – Anuya

+1

संभवतः। यदि आपके पास सी विंडोज़ डीएल है, तो आप इसमें 'PInvoke' कर सकते हैं। लेकिन आप सीधे सी # में सी का उपयोग नहीं कर सकते हैं। – Oded

उत्तर

10
#region Constants 
//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); 

[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); 

//assorted constants needed 
public static uint MF_BYPOSITION = 0x400; 
public static uint MF_REMOVE = 0x1000; 
public static int GWL_STYLE = -16; 
public static int WS_CHILD = 0x40000000; //child window 
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 static int WS_SYSMENU = 0x00080000; //window menu 
#endregion 

public static 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); 

      //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); 
      SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_SYSMENU)); 
      SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION)); 
     } 
    } 
} 
संबंधित मुद्दे