2011-06-20 16 views
5

मैं एक सी #/डब्ल्यूपीएफ ऐप में किनेक्ट एसडीके के लिए एक इशारा प्रणाली बना रहा हूं। मैं मैग्निफायर ज़ूम इन और आउट के लिए एक इशारा जोड़ना चाहता हूं। मैं अंतर्निहित विंडोज मैग्निफायर या इसके अंतर्निहित तर्क का उपयोग करना पसंद करूंगा, लेकिन एक समान प्रभाव (एकाधिक-मॉनीटर जागरूक) प्राप्त करने का कोई भी तरीका काम करेगा।विंडोज मैग्निफायर को आमंत्रित करें

मैं विंडोज मैग्निफायर की ज़ूम सुविधाओं को प्रोग्रामेटिक रूप से कैसे आमंत्रित कर सकता हूं?

अभी तक, मुझे उम्मीद है कि किसी भी आशा के साथ एकमात्र चीज प्रक्रिया शुरू करने और Win32 के माध्यम से बटन पर क्लिक करना है; लेकिन जब मैं ऐसा करता हूं, तो जब मैं मैग्निफायर विंडो के हैंडल को कॉल करता हूं तो यह खाली, खाली विंडो खींच रहा है।

मैंने सी # के बारे में जो कुछ पता है, उसके संयोजन के माध्यम से मैंने इस कोड को एक साथ जोड़ दिया है, Win32 API कॉल का एक समूह मैं वास्तव में अच्छी तरह से नहीं जानता, और गूगलिंग का एक टन।

private void ZoomIn() 
{ 
    // Make sure the Magnifier is running, and get its handle 
    if (Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").Count() == 0) { 
     Process.Start("magnify.exe"); 
     System.Threading.Thread.Sleep(500); } 
    IntPtr handle = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").First().Handle; 

    // Figure out what size ("mode") it's in 
    WINDOWPLACEMENT placement = new WINDOWPLACEMENT(); 
    placement.length = Marshal.SizeOf(placement); 
    GetWindowPlacement(handle, ref placement); 

    // Move the Magnifier to a predetermined location so we know where to click 
    MoveWindow(handle, new Point(0, 0)); 

    // If Magnifier is in small mode, click it to put it in big mode. 
    if (placement.rcNormalPosition.Size.Width == 132) { 
     SetCursorPos(15, 15); 
     mouse_event((int)HardwareEvents.MouseLeftDown, 15, 15, 0, 0); 
     mouse_event((int)HardwareEvents.MouseLeftUp, 15, 15, 0, 0); } 

    // Click the zoom in button. Yeah, I know, hackish. Isn't Win32 awesome? 
    SetCursorPos(25, 25); 
    mouse_event((int)HardwareEvents.MouseLeftDown, 25, 25, 0, 0); 
    mouse_event((int)HardwareEvents.MouseLeftUp, 25, 25, 0, 0); 
} 
private void MoveWindow(IntPtr handle, Point point) 
{ 
    // TODO: Figure out how to look up the target window's size 
    SetWindowPos(handle, new IntPtr((int)SpecialWindowHandles.HWND_TOP), (int)point.X, (int)point.Y, 500, 500, SetWindowPosFlags.ShowWindow); 
} 

private struct WINDOWPLACEMENT { 
    public int length; 
    public int flags; 
    public int showCmd; 
    public System.Drawing.Point ptMinPosition; 
    public System.Drawing.Point ptMaxPosition; 
    public System.Drawing.Rectangle rcNormalPosition; } 

[DllImport("user32.dll")] 
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndl); 

[DllImport("user32.dll")] 
static extern bool SetCursorPos(int X, int Y); 


public static class HardwareEvents 
{ 
    public static int MouseMove = 0x0001; 
    public static int MouseLeftDown = 0x0002, MouseLeftUp = 0x0004; 
    public static int MouseRightDown = 0x0008, MouseRightUp = 0x0010; // best guess on the 0010 
    public static int MiddleMouseDown = 0x20, MiddleMouseUp = 0x40; 
    public static int MouseWheel = 0x800; 
} 

उत्तर

1

आप बाहर ज़ूम

Windows Input Simulator के लिए
Win + - में शॉर्टकट कुंजी

Win + = खिड़कियों भेज सकते हैं ताल
ज़ूम के लिए Win + + शुरू करने के लिए Windows लोगो कुंजी

तरह कुंजी भेजने के लिए एक अच्छा पुस्तकालय है
+0

। किसी से ऐसा कैसे संभव है? मुझे विन बटन के लिए SendWait कुंजी नहीं दिखाई दे रही है। – tsilb

+0

SendWait/SendKeys के बजाय स्कैन कोड भेजना था, क्योंकि स्पष्ट रूप से उनके पास स्कैन कोड हैं लेकिन कीस्ट्रोक नहीं हैं। अजीब बात यह है कि यह केवल एक मेटा है और ctrl/alt/shift नहीं है। जिनके पास कीस्ट्रोक कोड हैं। – tsilb

+0

मुझे समझ में नहीं आ रहा है क्यों SendKeys में winkey भेज नहीं सकता? –

संबंधित मुद्दे