2013-02-21 4 views
0

저는 C#에 대해서만 알고 있으며 대부분 코드가 Google과 다릅니다. 내가 노력하고있는 일은 창문을 움직이는 것이다. 나는 SetWindowPos을 사용하여이 작업을한다. 그러나 화면을 부분적으로 화면 외부에 표시하고 싶지만 Microsoft Windows에서는 허용하지 않습니다. 아래 코드는 지금까지 내가 가진 것입니다. 물론 Google에서 답변을 검색하고 답변을 찾았습니다.이 프로그램을 내 프로그램에 넣는 방법은 내가 모르는 유일한 방법입니다.화면 외부에 SetWindowPos가 있습니다.

누군가 내 응용 프로그램에 이것을 어떻게 넣을지 설명 할 수 있습니까?

구글 응답 : Move a window partially off the top of the screen

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.ComponentModel; 
using System.Data; 
using System.Runtime.InteropServices; 
using System.Diagnostics; 

namespace WindowMover 
{ 

    static class Logic 
    { 

     [DllImport("user32.dll", EntryPoint = "SetWindowPos")] 
     public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags); 

     public static void Main() 
     { 
      const short SWP_NOSIZE = 1; 
      const short SWP_NOZORDER = 0X4; 
      const int SWP_NOACTIVATE = 0x0010; 

      Process[] processes = Process.GetProcesses("DeviceEmulator"); 
      foreach (var process in processes) 
      { 
       if (process.ProcessName == "DeviceEmulator") 
       { 
        var handle = process.MainWindowHandle; 
        SetWindowPos(handle, 0, 0, 0, -100, -100, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); 
       } 
      } 
     } 
    } 
} 
+0

코드가 의미가 없기 때문에 창 크기를 음수로 지정하려고합니다. 물론 불가능합니다. 또한 SWP_NOSIZE를 지정하여 SetWindowPos()에 크기를 변경하지 말 것을 지정합니다. 대신 위치를 변경하십시오. 화면의 왼쪽 상단 모서리에 (0, 0)을 전달하지 마십시오. 화면의 일부분이 아니라 정의에 의해 나타납니다. –

+0

고마워요, 적어도 하나의 신비가 풀 렸습니다! – user2097402

답변

0
  1. 이동 클래스 범위에 상수와 그들을 위해 public 수정을 추가합니다.

  2. .cs 파일

  3. 에 저장 Logic 클래스

  4. 에서 제거 Main() 프로젝트에 파일을 추가합니다.

  5. 상단

    using WindowMover;

  6. 폼 디자이너에서 더블 클릭 Form1에 줄을 추가, 메인 폼 클래스는 Form1.cs이었다 가정, 그것은 당신을 위해 Load 이벤트 처리기를 추가하고 코드 편집 모드로 들어갑니다 것이다

  7. this.Handle와 전화 SetWindowPos, 그리고 후자의 파라미터는 귀하의 요구 사항

  8. ,617을에 달려있다
관련 문제