2010-05-13 4 views
12

का उपयोग कर बाहरी एप्लिकेशन के शीर्षक पट्टी को हटाकर मेरा एप्लिकेशन एक और बाहरी एप्लिकेशन शुरू करता है।सी #

मैं इसे शुरू करने के बाद इस बाहरी एप्लिकेशन के शीर्षक पट्टी को हटाना चाहता हूं।

क्या यह व्यवहार्य है, और यदि ऐसा है तो यह कैसे किया जाएगा?

टिप्पणी नीचे

//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_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 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

'सार्वजनिक स्थैतिक int WS_CAPTION = WS_BORDER | WS_DLGFRAME; 'गलत है क्योंकि WS_DLGFRAME कैप्शन का हिस्सा नहीं है। संदर्भ: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx –

उत्तर

9

कोई ज़रूरत नहीं कुछ भी सुई तुम सिर्फ खिड़कियों शैली बिट्स संशोधित कर सकते हैं (या, यदि आप कर सकते हैं, यदि आप Windows एपीआई, जो चुनौतीपूर्ण हो सकता है, अपने अनुभव के आधार पर में खुदाई करने के लिए की जरूरत है।), एपीआई का उपयोग करने के रूप में, उदाहरण के लिए यह नोटपैड के लिए काम करता है, हालांकि आपके साथ खेलने वाले ऐप के आधार पर वाईएमएमवी।

alt text http://img297.imageshack.us/img297/8580/40498359.png

//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

क्या आप कोड के साथ अधिक विस्तृत हो सकते हैं। धन्यवाद। – Anuya

+0

ज़रूर; http://stackoverflow.com/questions/2832828/how-to-remove-the-menubar-of-an-plplication-using-windows-api;) –

+0

छविशैक यूआरएल "मृत" प्रतीत होता है? –

2

सामान्य तौर पर मैं काम कर कोड का उपयोग कर रहा आधार पर, आप ऐसा नहीं कर सकते कि जब तक वहाँ में आवेदन के द्वारा आप उदाहरण के लिए शुरू कर रहे हैं (के लिए प्रत्यक्ष समर्थन है, अगर यह टाइटल बार को हटाने के लिए कमांड लाइन स्विच लेता है)।

आप केवल उन चीज़ों को नियंत्रित कर सकते हैं जो ProcessStartInfo कक्षा (यानी एक नई विंडो खोलें, न्यूनतम/अधिकतम आदि शुरू करें ...) पर पहले से मौजूद हैं।

+0

क्या इस तृतीय-पक्ष एप्लिकेशन के शीर्षक पट्टी को छिपाने का कोई और तरीका है? इसमें केवल एक ही रूप है जिसके लिए मुझे इसे हटाने की आवश्यकता है। – Anuya

+0

@ कार्तिक - केवल अगर यह पहले से ही इस कार्यक्षमता का समर्थन करता है। यह कुछ नहीं है _you_ सीधे नियंत्रण कर सकते हैं। – Oded

1

यह पहले पूछे जाने वाले प्रश्न के समान है, और मुझे पूरा यकीन है कि जवाब यह है कि आप इसे नहीं कर सकते हैं।

How to add button to other apps window title bar (XP/Vista)

+1

यह सही नहीं है। आप इसे कर सकते हैं, और यहां सूचीबद्ध समाधान काम करते हैं। –

2

ठीक है, एलेक्स कोड के साथ कभी नहीं सविस्तार, अच्छी तरह से कम से कम यह एक प्लग-एन-खेलने समाधान था, लेकिन अभी भी इसके लिए मुख्य क्रेडिट उसे को जाता है ... यह जब तक आप इसे किसी भी प्रकार के कंटेनर (जैसे फॉर्म या पैनल) में रखने के लिए "सेटपेरेंट" का उपयोग नहीं करते हैं, तब तक यह बग्गी है जब मैंने सोचा कि मैं परिणाम साझा करूंगा।

विजुअल बेसिक:

Option Strict On 
Public Class Form1 
    Const WS_BORDER As Integer = 8388608 
    Const WS_DLGFRAME As Integer = 4194304 
    Const WS_CAPTION As Integer = WS_BORDER Or WS_DLGFRAME 
    Const WS_SYSMENU As Integer = 524288 
    Const WS_THICKFRAME As Integer = 262144 
    Const WS_MINIMIZE As Integer = 536870912 
    Const WS_MAXIMIZEBOX As Integer = 65536 
    Const GWL_STYLE As Integer = -16& 
    Const GWL_EXSTYLE As Integer = -20& 
    Const WS_EX_DLGMODALFRAME As Integer = &H1L 
    Const SWP_NOMOVE As Integer = &H2 
    Const SWP_NOSIZE As Integer = &H1 
    Const SWP_FRAMECHANGED As Integer = &H20 
    Const MF_BYPOSITION As UInteger = &H400 
    Const MF_REMOVE As UInteger = &H1000 
    Declare Auto Function GetWindowLong Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer 
    Declare Auto Function SetWindowLong Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer 
    Declare Auto Function SetWindowPos Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean 
    Public Sub MakeExternalWindowBorderless(ByVal MainWindowHandle As IntPtr) 
     Dim Style As Integer 
     Style = GetWindowLong(MainWindowHandle, GWL_STYLE) 
     Style = Style And Not WS_CAPTION 
     Style = Style And Not WS_SYSMENU 
     Style = Style And Not WS_THICKFRAME 
     Style = Style And Not WS_MINIMIZE 
     Style = Style And Not WS_MAXIMIZEBOX 
     SetWindowLong(MainWindowHandle, GWL_STYLE, Style) 
     Style = GetWindowLong(MainWindowHandle, GWL_EXSTYLE) 
     SetWindowLong(MainWindowHandle, GWL_EXSTYLE, Style Or WS_EX_DLGMODALFRAME) 
     SetWindowPos(MainWindowHandle, New IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE Or SWP_FRAMECHANGED) 
    End Sub 
End Class 

C शार्प (सी #)

using System.Runtime.InteropServices; 
public class Form1 
{ 
    const int WS_BORDER = 8388608; 
    const int WS_DLGFRAME = 4194304; 
    const int WS_CAPTION = WS_BORDER | WS_DLGFRAME; 
    const int WS_SYSMENU = 524288; 
    const int WS_THICKFRAME = 262144; 
    const int WS_MINIMIZE = 536870912; 
    const int WS_MAXIMIZEBOX = 65536; 
    const int GWL_STYLE = -16L; 
    const int GWL_EXSTYLE = -20L; 
    const int WS_EX_DLGMODALFRAME = 0x1L; 
    const int SWP_NOMOVE = 0x2; 
    const int SWP_NOSIZE = 0x1; 
    const int SWP_FRAMECHANGED = 0x20; 
    const uint MF_BYPOSITION = 0x400; 
    const uint MF_REMOVE = 0x1000; 
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] 
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex); 
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] 
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)] 
    public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); 
    public void MakeExternalWindowBorderless(IntPtr MainWindowHandle) 
    { 
     int Style = 0; 
     Style = GetWindowLong(MainWindowHandle, GWL_STYLE); 
     Style = Style & !WS_CAPTION; 
     Style = Style & !WS_SYSMENU; 
     Style = Style & !WS_THICKFRAME; 
     Style = Style & !WS_MINIMIZE; 
     Style = Style & !WS_MAXIMIZEBOX; 
     SetWindowLong(MainWindowHandle, GWL_STYLE, Style); 
     Style = GetWindowLong(MainWindowHandle, GWL_EXSTYLE); 
     SetWindowLong(MainWindowHandle, GWL_EXSTYLE, Style | WS_EX_DLGMODALFRAME); 
     SetWindowPos(MainWindowHandle, new IntPtr(0), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); 
    } 
} 

फिर, धन्यवाद एलेक्स

+1

हाय, आपके कोड के लिए धन्यवाद, यह सी # अनुभाग में कुछ त्रुटियों में सुधार के बाद मेरे लिए काम करता है। शैली और! WS_CAPTION काम नहीं करता है। आपको स्टाइल और ~ WS_CAPTION लिखना होगा। –

5
Process[] processes = Process.GetProcessesByName("notepad"); 
IntPtr windowHandle = processes[0].MainWindowHandle; 

const int GWL_STYLE = (-16); 
const UInt32 WS_VISIBLE = 0x10000000; 
SetWindowLong(windowHandle, GWL_STYLE, (WS_VISIBLE));`