2017-01-17 7 views
1

에서 버튼을 제거합니다. 해당 버튼을 제거하거나 숨기려고합니다. "user32.dll 사용"또는 다른 접근 방식을 사용할 수 있습니까?숨기거나 내 WPF 프로젝트에서 외부 프로그램을 runnig하고 내가</p> <p>외부 응용 프로그램이 종료 버튼이 "USER32.DLL"를 사용하여 내 WPF 양식 내에서 외부 응용 프로그램을 걸었습니다 외부 응용 프로그램

미리 감사드립니다.

+0

이 * external * 앱을 만들 수있는 액세스 권한이 있습니까? – OmegaMan

+0

@OmegaMan 예, 외부 exe 파일입니다. 그 버튼에 접근하고 싶습니다. – Kerberos

+0

이 종료 버튼은 표준 프레임의 일부입니까, 아니면 화면의 임의 버튼입니까? – OmegaMan

답변

0

은 각 앱 USER32.DLL을 사용할 수 없습니다

없음 "을 USER32.DLL을 사용하지 않는 것은"말하자면 외부 원치 않는 행동을 불 침투성해야 자신의 샌드 박스에 있습니다.

(Q : 외부 앱을 만들려면 액세스 권한이 있습니까? A ​​: Y) ... 또는 다른 접근 방식이 필요합니까?

두 앱의 코드에 액세스 할 수 있으므로 프로세스 간 파이프를 구현해야합니다. 수신 응용 프로그램에서 버튼을 끄거나 윈도우 프레임 스타일을 변경하는 메시지를 파이프에서 모니터링합니다.

How to: Use Named Pipes for Network Interprocess Communication

0

는 아래의 코드는 버튼을 발견하고 숨 깁니다 참조하십시오. 그것은 내 시스템에서 정상적으로 작동합니다. 이 코드는 창 제목을 검색 한 다음 컨트롤을 찾습니다. 창 제목과 단추 텍스트를 제공해야합니다. 필요에 따라 코드를 업데이트 할 수 있습니다.

참고 : 아래 코드는 일치하는 텍스트가 TEXT_BUTTON 상수로 지정된 모든 컨트롤을 숨 깁니다.

const string TEXT_TITLE = "My Specific Window"; 
const string TEXT_BUTTON = "&HideMeButton"; 

public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr parameter); 

[DllImport("user32.dll")] 
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow); 
const int SW_HIDE = 0; 

[DllImport("user32")] 
[return: MarshalAs(UnmanagedType.Bool)] 
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i); 

[DllImport("user32.dll", EntryPoint = "GetWindowText", CharSet = CharSet.Auto)] 
static extern IntPtr GetWindowCaption(IntPtr hwnd, StringBuilder lpString, int maxCount); 

public void HideSpecificButton() 
{    
    //Contains the handle, can be zero if title not found 
    var handleWindow = WinGetHandle(TEXT_TITLE); 
    if (GetWindowCaption(handleWindow).Trim() != TEXT_TITLE) 
     MessageBox.Show("Window is hidden or not running."); 
    else 
     GetChildWindows(handleWindow);    
} 

public IntPtr WinGetHandle(string title) 
{ 
    IntPtr hWnd = IntPtr.Zero; 
    foreach (Process pList in Process.GetProcesses()) 
    { 
     if (pList.MainWindowTitle.Contains(title)) 
     { 
      hWnd = pList.MainWindowHandle; 
     } 
    } 
    return hWnd; 
} 

private string GetWindowCaption(IntPtr hwnd) 
{ 
    StringBuilder sb = new StringBuilder(256); 
    GetWindowCaption(hwnd, sb, 256); 
    return sb.ToString(); 
} 

public void GetChildWindows(IntPtr parent) 
{ 
    List<IntPtr> result = new List<IntPtr>(); 
    GCHandle listHandle = GCHandle.Alloc(result); 
    try 
    { 
     EnumWindowProc childProc = new EnumWindowProc(EnumControls); 
     EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle)); 
    } 
    finally 
    { 
     if (listHandle.IsAllocated) 
      listHandle.Free(); 
    } 
} 

private bool EnumControls(IntPtr handle, IntPtr pointer) 
{ 
    var controlTitle = GetWindowCaption(handle).Trim(); 
    if (string.Equals(controlTitle, TEXT_BUTTON, StringComparison.CurrentCultureIgnoreCase)) 
    { 
     //hide the control 
     ShowWindow(handle, SW_HIDE); 
    } 

    return true; 
}