2010-05-14 2 views
1

C 언어로 코드를 찾을 수있는 창 스타일을 바꿀 방법을 찾았을 때 제목을 숨길 수 있도록 C# 응용 프로그램에서 아래 스 니펫을 어떻게 사용할 수 있습니까? 외부 응용 프로그램 바? 나는C 코드 사용 #

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

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

/* 
This function sets the parent of the window with class 
ClassClass to the form/control the method is in. 
*/ 
public void Reparent() 
{ 
//get handle of parent form (.net property) 
IntPtr par = this.Handle; 
//get handle of child form (win32) 
IntPtr child = FindWindow("ClassClass", null); 
//set parent of child form 
SetParent(child, par); 
//get current window style of child form 
int style = GetWindowLong(child, GWL_STYLE); 

//take current window style and remove WS_CAPTION from it 
SetWindowLong(child, GWL_STYLE, (style & ~WS_CAPTION)); 
} 
+0

: 당신이 시도 할 수 윈도우 검색하십시오

? - 귀하의 응용 프로그램 또는 모든 창에 해당합니까? Winforms, ASP, WPF? 귀하의 다른 게시물과 같습니다. – ChrisBD

+0

@ChrisBD, 응용 프로그램의 제목 표시 줄을 숨기고 싶습니다. [제 3 자] 하나의 양식 만 있습니다. 그리고이 응용 프로그램은 내 C# Windows 응용 프로그램에서 시작합니다. 모든 창문이 아닙니다. – Anuya

답변

2

저는 P/Invoke experet가 아니지만보고있는 곳 : http://www.pinvoke.net/default.aspx/coredll/SetWindowLong.html Reparent가없는 창 스타일을 변경하려면 SetWindowLong을 호출 할 수 있습니다. 당신은 윈도우 스타일을 변경하려면

Process[] processes = Process.GetProcessesByName("notepad.exe"); 
foreach (Process p in processes) 
{ 
    IntPtr pFoundWindow = p.MainWindowHandle; 
    // now you have the window handle 
} 
1

당신이 게시 한 코드 조각은 C#으로있다가,하지 C.에서 당신은 당신의 형태에 해당 코드를 추가하고 Reparent 메소드를 호출 할 수 있어야하기 전에 "C를".. 사용하지 않았습니다. (WinForms을 사용한다고 가정)

Reparent 메서드는 창 스타일을 변경하는 것은 물론 창을 자식의 부모로 사용하려고 시도합니다.

+0

어떻게 응용 프로그램 이름을이 함수에 전달할 수 있습니까? 메모장의 제목 표시 줄을 제거 할 수 있도록 "NotePad.exe"라고 말하십시오. 또한 Reparent를 피하는 데 도움이됩니다. 감사. – Anuya

+0

@karthik 당신은 @digEmAll 방식으로 특정 프로세스에 대한 메인 윈도우를 찾는'FindWindow' (클래스로 윈도우를 찾는다)를 바꿀 필요가있다. –