2014-04-16 3 views
-1

Windows Media 인코더를 사용하여 화면 녹화 응용 프로그램을 만들고 있습니다. 비디오를 녹화하고 디스크에 저장할 수 있습니다. 이제는 마우스를 클릭 할 때마다 마우스를 클릭하여 주변을 채워야합니다. 클릭 이벤트 화재 (마우스 누름 이벤트가 발생하는 영역을 밝게하기 위해), 그렇게 할 수있는 방법이 있습니까? 모든 코드 샘플? 고맙습니다!!! 여기에 코드를 삽입하지 미안 내 코드 마침내Winform 외부의 원 그리기

 public void CaptureMoni() 
    { 
     string dateTime = DateTime.Now.ToString("yyyy.MM.dd _ HH.mm"); 
     var dir = @"C:\VIDEOS\" + dateTime; 
     try 
     { 
      System.Drawing.Rectangle _screenRectangle = Screen.PrimaryScreen.Bounds; 
      _screenCaptureJob = new ScreenCaptureJob(); 
      _screenCaptureJob.CaptureRectangle = _screenRectangle; 
      _screenCaptureJob.ShowFlashingBoundary = true; 
      _screenCaptureJob.ScreenCaptureVideoProfile.FrameRate = 10; 
      _screenCaptureJob.CaptureMouseCursor = true; 

      if (!Directory.Exists(dir)) 
      { 
       Directory.CreateDirectory(dir); 
       _screenCaptureJob.OutputScreenCaptureFileName = string.Format(Path.Combine(dir, dateTime + ".wmv")); 
      } 
     } 
     catch (Exception) 
     { 
      MessageBox.Show("Screnn Capturing Failed!"); 
     } 
     string temPath = (_screenCaptureJob.OutputScreenCaptureFileName.ToString()); 
     // MessageBox.Show(temPath); 
    } 
    public ScreenCaptureJob _screenCaptureJob { get; set; } 

내가 PacMani 특별 감사가 필요 그가 나에게 올바른 방법을 지시 않았다

참고입니다 :이 포함 ​​전체 코드가 아닙니다 비디오에서 빨간색 원은이 도움말 @의 PacMAni

public partial class Form1 : Form 
{ 
    public Form1() 
    { 
     InitializeComponent(); 
     WindowState = FormWindowState.Maximized; 
     this.TopMost = true; 


    } 
    protected override void WndProc(ref Message m) 
    { 
     if (m.Msg == (int)RMouseListener.WM.WM_NCHITTEST) 
      m.Result = (IntPtr)RMouseListener.WM.HTTRANSPARENT; 
     else 
      base.WndProc(ref m); 
    } 
    public void draw_circle() 
    { 

     int x = MousePosition.X; 
     int y = MousePosition.Y; 

     System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Salmon); 
     System.Drawing.Graphics formGraphics = this.CreateGraphics(); 
     formGraphics.FillEllipse(myBrush, new Rectangle(x - 60, y - 60, 60, 60)); 
     myBrush.Dispose(); 
     formGraphics.Dispose(); 
     Thread.Sleep(200); 
     this.Invalidate(); 


    } 
    RMouseListener _native; 


    private void button1_Click(object sender, EventArgs e) 
    { 
     //_native = new RMouseListener(); 
     //_native.RButtonClicked += new EventHandler<SysMouseEventInfo>(_native_RButtonClicked); 
     //_native.LButtonClicked += new EventHandler<SysMouseEventInfo>(_native_LButtonClicked); 
    } 

    private void button2_Click(object sender, EventArgs e) 
    { 
     _native.Close(); 
     this.Dispose(); 
    } 
    void _native_RButtonClicked(object sender, SysMouseEventInfo e) 
    { 

     // listBox1.Items.Add(e.WindowTitle); 
     draw_circle(); 
    } 
    void _native_LButtonClicked(object sender, SysMouseEventInfo e) 
    { 

     // listBox2.Items.Add(e.WindowTitle); 
     draw_circle(); 

    } 

    // } 


    public class SysMouseEventInfo : EventArgs 
    { 
     public string WindowTitle { get; set; } 
    } 

    public class RMouseListener 
    { 
     Form1 frm = new Form1(); 
     public RMouseListener() 
     { 

      this.CallBack += new HookProc(MouseEvents); 
      //Module mod = Assembly.GetExecutingAssembly().GetModules()[0]; 
      //IntPtr hMod = Marshal.GetHINSTANCE(mod); 
      using (Process process = Process.GetCurrentProcess()) 
      using (ProcessModule module = process.MainModule) 
      { 
       IntPtr hModule = GetModuleHandle(module.ModuleName); 
       _hook = SetWindowsHookEx(WH_MOUSE_LL, this.CallBack, hModule, 0); 
      } 
     } 
     int WH_MOUSE_LL = 14; 
     int HC_ACTION = 0; 
     HookProc CallBack = null; 
     IntPtr _hook = IntPtr.Zero; 

     public event EventHandler<SysMouseEventInfo> RButtonClicked; 
     public event EventHandler<SysMouseEventInfo> LButtonClicked; 

     int MouseEvents(int code, IntPtr wParam, IntPtr lParam) 
     { 
      //Console.WriteLine("Called"); 
      //MessageBox.Show("Called!"); 
      if (code < 0) 
       return CallNextHookEx(_hook, code, wParam, lParam); 

      if (code == this.HC_ACTION) 
      { 
       // Left button pressed somewhere 
       if (wParam.ToInt32() == (uint)WM.WM_RBUTTONDOWN || wParam.ToInt32() == (uint)WM.WM_LBUTTONDOWN) 
       { 


        MSLLHOOKSTRUCT ms = new MSLLHOOKSTRUCT(); 
        ms = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT)); 
        IntPtr win = WindowFromPoint(ms.pt); 
        string title = GetWindowTextRaw(win); 

        if (RButtonClicked != null || LButtonClicked != null) 
        { 
         RButtonClicked(this, new SysMouseEventInfo { WindowTitle = title }); 
         LButtonClicked(this, new SysMouseEventInfo { WindowTitle = title }); 

        } 
       } 
      } 
      return CallNextHookEx(_hook, code, wParam, lParam); 
     } 

     public void Close() 
     { 
      if (_hook != IntPtr.Zero) 
      { 
       UnhookWindowsHookEx(_hook); 
      } 
     } 
     public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam); 

     [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "SetWindowsHookEx", SetLastError = true)] 
     public static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId); 

     [System.Runtime.InteropServices.DllImport("user32.dll")] 
     public static extern int CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, IntPtr lParam); 

     [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] 
     public static extern IntPtr GetModuleHandle(string lpModuleName); 

     [DllImport("user32.dll")] 
     static extern IntPtr WindowFromPoint(int xPoint, int yPoint); 

     [DllImport("user32.dll")] 
     static extern IntPtr WindowFromPoint(POINT Point); 

     [DllImport("user32.dll", SetLastError = true)] 
     [return: MarshalAs(UnmanagedType.Bool)] 
     static extern bool UnhookWindowsHookEx(IntPtr hhk); 

     [DllImport("user32.dll", CharSet = CharSet.Auto)] 
     static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [Out] StringBuilder lParam); 

     public static string GetWindowTextRaw(IntPtr hwnd) 
     { 
      // Allocate correct string length first 
      //int length = (int)SendMessage(hwnd, (int)WM.WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero); 
      StringBuilder sb = new StringBuilder(65535);//THIS COULD BE BAD. Maybe you shoudl get the length 
      SendMessage(hwnd, (int)WM.WM_GETTEXT, (IntPtr)sb.Capacity, sb); 
      return sb.ToString(); 
     } 



     [StructLayout(LayoutKind.Sequential)] 
     public struct MSLLHOOKSTRUCT 
     { 
      public POINT pt; 
      public int mouseData; 
      public int flags; 
      public int time; 
      public UIntPtr dwExtraInfo; 
     } 
     public enum WM : uint 
     {//all windows messages here 
      WM_LBUTTONDOWN = 0x0201, 
      WM_RBUTTONDOWN = 0x0204, 
      WM_GETTEXT = 0x000D, 
      WM_GETTEXTLENGTH = 0x000E, 
      WM_MOUSE = 0x0200, 
      WM_NCHITTEST = 0x84, 
      HTTRANSPARENT 

     } 


     [StructLayout(LayoutKind.Sequential)] 
     public struct POINT 
     { 
      public int X; 
      public int Y; 

      public POINT(int x, int y) 
      { 
       this.X = x; 
       this.Y = y; 
      } 
     } 
    } 

    private void Form1_Load(object sender, EventArgs e) 
    { 
     _native = new RMouseListener(); 
     _native.RButtonClicked += new EventHandler<SysMouseEventInfo>(_native_RButtonClicked); 
     _native.LButtonClicked += new EventHandler<SysMouseEventInfo>(_native_LButtonClicked); 
    } 
+4

질문 할 때 노력을 기울여야합니다! –

+0

[DrawEllipse] (http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawellipse.aspx) 방법을보십시오 –

+1

@insomnium --- 이것은 내 노력 --- –

답변

2

화면에 감사드립니다 만) (언어 실수 죄송합니다) 빨간색 원을 갖고, 모든 다른 형태의 상단에 투명 양식을 만들기위한 것입니다 녹음 응용 프로그램 양이온은 데스크톱이 아닌 비디오 파일에이 원을 추가합니다. 당신은 여전히 ​​원형 창을 만들려면

, 당신은 당신이 구현해야하는 두 가지로 형태가 필요합니다

또한 글로벌 마우스 클릭을 탐지하기 위해 글로벌 마우스 후크를 등록해야합니다. 나는 당신이 이미 이것을했다고 생각하지만, 당신의 질문은 당신이 한 것과하지 않은 것을 보여주지 못합니다.

마우스 클릭을받은 경우 마우스 좌표 주위에 경계선없는 창을 만들고 (배경색이 투명도 키와 동일하므로 원이 그려지지 않은 곳에 보이지 않게 함) 타원을 그립니다 Paint 이벤트를 후크하고 Graphics 객체 DrawEllipse 메서드 사용).

타이머를 시작한 후에이 창이 다시 사라지거나 원이 영원히 보입니다. 이 원을 다른 화면 녹화 응용 프로그램에서와 같이 애니메이션으로 만들려면 타이머를 사용하여 그림을 애니메이션으로 만듭니다.

+0

예 전 세계 마우스 훅을 만들고 싶습니다. 이전에 시도 했으므로 직접 할 수 있습니다. –

+0

@ PacMani .. 당신의 대답은 정말로 도움이됩니다. –

+0

예 PacMani, 다른 사람들에게도 도움이 될 것이므로 코드를 끝낼 때 업데이트하겠습니다. –