예제 #1
0
    public static int EntryPoint(string arg)
    {
        _sharpScrobbler         = new SharpScrobbler();
        _sharpScrobblerGCHandle = GCHandle.Alloc(_sharpScrobbler);

        _managedExports = new ManagedExports
        {
            FreeManagedExports = FreeManagedExports,
            LogInfo            = LogInfo,
            LogWarning         = LogWarning,
            LogVerbose         = LogVerbose,
            AskUserForNewAuthorizedSessionKey = _sharpScrobbler.AskUserForNewAuthorizedSessionKey,
            SetSessionKey        = _sharpScrobbler.SetSessionKey,
            OnTrackCanScrobble   = _sharpScrobbler.OnTrackCanScrobble,
            OnTrackStartsPlaying = _sharpScrobbler.OnTrackStartsPlaying,
            OnTrackCompletes     = _sharpScrobbler.OnTrackCompletes,
        };
        _managedExportsGCHandle = GCHandle.Alloc(_managedExports);

        // ManagedExports is not blittable, so we need a copy.
        // Making a copy in unmanaged memory from the managed side ensures the GC will not mess with it (I hope)
        _pManagedExports = Marshal.AllocHGlobal(Marshal.SizeOf(_managedExports));
        Marshal.StructureToPtr(_managedExports, _pManagedExports, false);

        NativeImports.InitializeManagedExports(_pManagedExports);

        return(0);
    }
예제 #2
0
        void Place_EndOfTaskbar(Rectangle taskbarRect)
        {
            // TODO: Implement Secondary Taskbar
            if (!Taskbar.IsPrimary)
            {
                Place_RightOfTaskButtons(taskbarRect);
                return;
            }

            IntPtr btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            IntPtr trayHwnd = TaskbarUtils.GetPrimaryTaskTrayNotifyHwnd(Taskbar.Handle);

            int w = TargetSize.Width;

            // shrink the task bar buttons area
            if (NativeImports.GetWindowRect(btnsHwnd, out NativeImports.RECT btnsRect))
            {
                NativeImports.SetWindowPos(btnsHwnd, IntPtr.Zero, 0, 0, (btnsRect.Right - btnsRect.Left) - w, btnsRect.Bottom - btnsRect.Top, NativeImports.SetWindowPosFlags.SWP_NOMOVE | NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // enlarge and move the tray area to the left
            if (NativeImports.GetWindowRect(trayHwnd, out NativeImports.RECT trayRect))
            {
                Rectangle clientRect = new Rectangle(trayRect.Left - taskbarRect.X, trayRect.Top - taskbarRect.Top, trayRect.Right - trayRect.Left, trayRect.Bottom - trayRect.Top);
                NativeImports.SetWindowPos(trayHwnd, IntPtr.Zero, clientRect.Left - w, clientRect.Top, clientRect.Width + w, clientRect.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);

                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);
                NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
                NativeImports.SetParent(Handle, trayHwnd);
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, clientRect.Width, 0, ActualSize.Width, ActualSize.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // Listen for changes of the tray area
            Taskbar.RegisterObservableChild(trayHwnd);
        }
예제 #3
0
 internal static void FreeDll()
 {
     if (UnmanagedModule != IntPtr.Zero)
     {
         NativeImports.FreeLibrary(UnmanagedModule);
     }
 }
예제 #4
0
        /// <summary>
        /// Return the handle of the clock of the primary taskbar
        /// </summary>
        /// <returns></returns>
        public static IntPtr GetPrimaryTaskbarClockHwnd()
        {
            // todo: error handling
            IntPtr trayclockwclass = NativeImports.FindWindowEx(GetPrimaryTaskbarTrayHwnd(GetPrimaryTaskbarHwnd()), IntPtr.Zero, "trayclockwclass", null);

            return(trayclockwclass);
        }
예제 #5
0
        /// <summary>
        /// Invoke the primary taskbar's calendar flyout
        /// </summary>
        private static bool InvokeCalendarFlyOut()
        {
            // in order to show the calendar flyout
            // we simulate a click on the primary taskbars clock
            var clockHwnd   = GetPrimaryTaskbarClockHwnd();
            var taskbarHwnd = GetPrimaryTaskbarHwnd();

            if (clockHwnd == IntPtr.Zero || taskbarHwnd == IntPtr.Zero)
            {
                return(false);
            }

            // get clock window bounds
            NativeImports.RECT clockRect;
            if (!NativeImports.GetWindowRect(clockHwnd, out clockRect))
            {
                return(false);
            }

            // the click has to be sent to the taskbar (not to the clock hwnd)
            // but at the clocks location
            IntPtr wParam = new IntPtr(NativeImports.HTCAPTION);
            // simulate the click, some pixels inside the tray clock
            IntPtr lParam = new IntPtr(((clockRect.Top + 10) << 16) | clockRect.Left + 10);

            NativeImports.PostMessage(taskbarHwnd, NativeImports.WM_NCLBUTTONDOWN, wParam.ToInt32(), lParam.ToInt32());
            NativeImports.PostMessage(taskbarHwnd, NativeImports.WM_NCLBUTTONUP, wParam.ToInt32(), lParam.ToInt32());

            // remove the focus highlight
            NativeImports.PostMessage(taskbarHwnd, NativeImports.WM_MOUSELEAVE, 0, 0);

            return(true);
        }
예제 #6
0
        public void ShowMainWindow()
        {
            var handle = Process.GetCurrentProcess().MainWindowHandle;

            NativeImports.ShowWindow(handle, 5);
            NativeImports.SetForegroundWindow(handle);
        }
예제 #7
0
        public static void SetCanRedraw(IntPtr handle, bool canRedraw)
        {
            NativeImports.SendMessage(handle, NativeImports.WM_SETREDRAW, canRedraw ? 1 : 0, IntPtr.Zero);

            if (canRedraw)
            {
                NativeImports.RedrawWindow(handle, IntPtr.Zero, IntPtr.Zero, NativeImports.RedrawWindowFlags.Frame | NativeImports.RedrawWindowFlags.Invalidate | NativeImports.RedrawWindowFlags.AllChildren);
            }
        }
예제 #8
0
        void Place_BetweenTrayAndClock(Rectangle taskbarRect)
        {
            if (!Taskbar.IsPrimary)
            {
                // there is no tray area on secondary taskbars
                // place normally
                Place_RightOfTaskButtons(taskbarRect);
                return;
            }

            IntPtr btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            IntPtr trayHwnd = TaskbarUtils.GetPrimaryTaskTrayNotifyHwnd(Taskbar.Handle);

            int w = TargetSize.Width;

            // shrink the task bar buttons area
            if (NativeImports.GetWindowRect(btnsHwnd, out NativeImports.RECT btnsRect))
            {
                NativeImports.SetWindowPos(btnsHwnd, IntPtr.Zero, 0, 0, (btnsRect.Right - btnsRect.Left) - w, btnsRect.Bottom - btnsRect.Top, NativeImports.SetWindowPosFlags.SWP_NOMOVE | NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
            }

            // enlarge and move the tray area to the left
            if (NativeImports.GetWindowRect(trayHwnd, out NativeImports.RECT trayRect))
            {
                Rectangle clientRect = new Rectangle(trayRect.Left - taskbarRect.X, trayRect.Top - taskbarRect.Top, trayRect.Right - trayRect.Left, trayRect.Bottom - trayRect.Top);
                NativeImports.SetWindowPos(trayHwnd, IntPtr.Zero, clientRect.Left - w, clientRect.Top, clientRect.Width + w, clientRect.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);
                // adjust
                trayRect.Left -= w;

                // move clock and other elements to the right
                var elements = TaskbarUtils.GetPrimaryTaskTrayElementsRightOfIcons(Taskbar.Handle);
                int initialX = -1;
                foreach (var elWnd in elements)
                {
                    if (NativeImports.GetWindowRect(elWnd, out NativeImports.RECT elementRect))
                    {
                        Rectangle elementClientRect = new Rectangle(elementRect.Left - trayRect.Left, elementRect.Top - trayRect.Top, elementRect.Right - elementRect.Left, elementRect.Bottom - elementRect.Top);
                        if (initialX == -1)
                        {
                            initialX = elementClientRect.X;
                        }

                        NativeImports.SetWindowPos(elWnd, IntPtr.Zero, elementClientRect.X + w, elementClientRect.Y, elementClientRect.Width, elementClientRect.Height, 0);
                    }
                }

                // place TaskbarWindow between icons and clock
                ActualSize = new Size(TargetSize.Width, clientRect.Height);
                NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
                NativeImports.SetParent(Handle, trayHwnd);
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, initialX, clientRect.Y, ActualSize.Width, ActualSize.Height, NativeImports.SetWindowPosFlags.SWP_NOREPOSITION);

                // listen for size changes of the tray area
                Taskbar.RegisterObservableChild(trayHwnd);
            }
        }
예제 #9
0
        public bool IsIgnored(string filePath)
        {
            // If no ignore pattern is given then include all files. Otherwise ignore the ones that match an ignore pattern
            if (ignorePatterns.Any() && ignorePatterns.Any(ignorePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(ignorePattern))))
            {
                return(true);
            }

            return(false);
        }
 public void UnPrepareHeader()
 {
     lock (_syncRoot)
     {
         _header = null;
         if (_prepared)
         {
             NativeImports.ThrowOnError(NativeImports.midiInUnprepareHeader(_inputHandle, Ptr));
         }
         _prepared = false;
     }
 }
예제 #11
0
 private void Hide_BTN_Click(object sender, RoutedEventArgs e)
 {
     if (_processes.Length > ProcessCB.SelectedIndex && ProcessCB.SelectedIndex >= 0)
     {
         var window = _processes[ProcessCB.SelectedIndex].MainWindowHandle;
         NativeImports.HideWindow(window);
     }
     else
     {
         Logger.Warn("Please pick a process to hide");
     }
 }
예제 #12
0
        /// <summary>
        /// Return all handles of taskbar elements to the right of the tray icons
        /// </summary>
        public static IntPtr[] GetPrimaryTaskTrayElementsRightOfIcons(IntPtr taskbarHwnd)
        {
            var tnaWnd = GetPrimaryTaskTrayNotifyHwnd(taskbarHwnd);

            if (tnaWnd == IntPtr.Zero)
            {
                return(new IntPtr[0]);
            }

            string[] classnames = new string[] { PrimaryTrayClockWndClassName, PrimaryTrayNotificationCenterBtnClassName, PrimaryTrayShowDesktopBtnClassName };
            return(classnames.Select(cname => NativeImports.FindWindowEx(tnaWnd, IntPtr.Zero, cname, null)).Where(x => x != IntPtr.Zero).ToArray());
        }
예제 #13
0
 /// <summary>
 /// Get the bounds of the window with the given handle
 /// ((Wrapper around Win32 GetWindowRect)
 /// </summary>
 /// <param name="handle"></param>
 /// <returns></returns>
 public static Rectangle GetWindowBounds(IntPtr handle)
 {
     NativeImports.RECT rect;
     if (NativeImports.GetWindowRect(handle, out rect))
     {
         return(new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top));
     }
     else
     {
         throw new InvalidOperationException("Could not get window bounds.");
     }
 }
예제 #14
0
        /// <summary>
        /// Show the primary taskbar's calendar flyout at the given location with the given alignment
        /// </summary>
        public static void ShowCalendarFlyOut(Rectangle alignTo, FlyoutAlignment alignment)
        {
            // get all window handles which have the same class as the
            // flyout, so that we know these are not the flyout
            var nonFlyoutHandles = WindowUtils.ListWindowsWithClass(CalendarFlyoutClassName);

            // invoke the primary taskbar's calendar flyout
            if (TaskbarUtils.InvokeCalendarFlyOut())
            {
                // wait for it to open (max. 2 seconds)
                IntPtr flyoutHwnd = IntPtr.Zero;
                int    start      = Environment.TickCount;
                while (flyoutHwnd == IntPtr.Zero && (Environment.TickCount - start <= 2000))
                {
                    flyoutHwnd = TaskbarUtils.GetCalendarFlyoutHwnd(nonFlyoutHandles);
                }

                if (flyoutHwnd != IntPtr.Zero)
                {
                    // and move it to this clock's location
                    NativeImports.RECT flyoutRect;
                    if (NativeImports.GetWindowRect(flyoutHwnd, out flyoutRect))
                    {
                        int flyoutWidth  = flyoutRect.Right - flyoutRect.Left;
                        int flyoutHeight = flyoutRect.Bottom - flyoutRect.Top;

                        switch (alignment)
                        {
                        case FlyoutAlignment.Below:
                            // place the calendar flyout below the clock
                            NativeImports.SetWindowPos(flyoutHwnd, IntPtr.Zero, alignTo.Right - flyoutWidth, alignTo.Bottom, 0, 0, NativeImports.SetWindowPosFlags.SWP_NOSIZE);
                            break;

                        case FlyoutAlignment.Above:
                            // place the calendar flyout above the clock
                            NativeImports.SetWindowPos(flyoutHwnd, IntPtr.Zero, alignTo.Right - flyoutWidth, alignTo.Top - flyoutHeight, 0, 0, NativeImports.SetWindowPosFlags.SWP_NOSIZE);
                            break;

                        case FlyoutAlignment.ToTheRight:
                            // place the calendar flyout to the right of the clock
                            NativeImports.SetWindowPos(flyoutHwnd, IntPtr.Zero, alignTo.Right, alignTo.Bottom - flyoutHeight, 0, 0, NativeImports.SetWindowPosFlags.SWP_NOSIZE);
                            break;

                        case FlyoutAlignment.ToTheLeft:
                            // place the calendar flyout to the left of the clock
                            NativeImports.SetWindowPos(flyoutHwnd, IntPtr.Zero, alignTo.Left - flyoutWidth, alignTo.Bottom - flyoutHeight, 0, 0, NativeImports.SetWindowPosFlags.SWP_NOSIZE);
                            break;
                        }
                    }
                }
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposedValue)
     {
         if (disposing)
         {
             // nothing here
         }
         NativeImports.midiOutReset(_midiHandle);
         NativeImports.midiOutClose(_midiHandle);
         _disposedValue = true;
     }
 }
예제 #16
0
        /// <summary>
        /// Returns the handles of all top-level windows of the given class
        /// </summary>
        /// <param name="className">The class name to search fore</param>
        public static ISet <IntPtr> ListWindowsWithClass(string className)
        {
            HashSet <IntPtr> resultHandles = new HashSet <IntPtr>();

            IntPtr currChild = NativeImports.FindWindowEx(IntPtr.Zero, IntPtr.Zero, className, null);

            while (currChild != IntPtr.Zero)
            {
                resultHandles.Add(currChild);
                // next window (if any)
                currChild = NativeImports.FindWindowEx(IntPtr.Zero, currChild, className, null);
            }

            return(resultHandles);
        }
        public static uint?FindOutputIdByName(string name)
        {
            uint midiDevNum = NativeImports.midiOutGetNumDevs();

            for (uint i = 0; i < midiDevNum; i++)
            {
                MIDIOUTCAPS capsResult = default;
                NativeImports.ThrowOnError(NativeImports.midiOutGetDevCaps(i, ref capsResult));
                if (capsResult.szPname == name)
                {
                    return(i);
                }
            }
            return(null);
        }
예제 #18
0
        private bool IsFileEligibleForInstrumentation(string filePath)
        {
            // If no include patterns are given then include all files. Otherwise include only the ones that match an include pattern
            if (includePatterns.Any() && !includePatterns.Any(includePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(includePattern))))
            {
                return(false);
            }

            // If no exclude pattern is given then exclude none otherwise exclude the patterns that match any given exclude pattern
            if (excludePatterns.Any() && excludePatterns.Any(excludePattern => NativeImports.PathMatchSpec(filePath, FileProbe.NormalizeFilePath(excludePattern))))
            {
                return(false);
            }

            return(true);
        }
 public Win32MidiInput(uint id)
 {
     lock (_syncRoot)
     {
         _midiInProc = new NativeImports.MidiInProc(MidiInProc);
         NativeImports.ThrowOnError(NativeImports.midiInOpen(out _midiHandle, id, _midiInProc, IntPtr.Zero));
         NativeImports.ThrowOnError(NativeImports.midiInStart(_midiHandle));
         while (_longMessageBuffers.Count < LongMessageBufferCount)
         {
             var b = new MidiInputLongDataBuffer(_midiHandle);
             b.PrepareHeader();
             b.AddBuffer();
             _longMessageBuffers.Add(b.Ptr, b);
         }
     }
 }
예제 #20
0
        public void disconnect()
        {
            //this step is actually not needed for the disconnect function to execute
            //currently in v3.3.560, WiinUSoft will be left in a glitched state if a device is disconnected that does not have an actively open DataStream
            //this is because the device dispose procedure is occurs executed with an actively read data stream is interupted
            bool wasConnected = Connected;

            if (wasConnected || ((device.DataStream as WinBtStream).OpenConnection() && device.DataStream.CanRead))
            {
                if (!wasConnected)
                {
                    device.BeginReading();
                }
            }


            //controller disconnect function used to disconnect bluetooth device by mac address
            long lbtAddr = Convert.ToInt64(deviceMac.Replace(":", ""), 16);
            bool success = false;

            int IOCTL_BTH_DISCONNECT_DEVICE = 0x41000c;
            int bytesReturned = 0;
            var radioParams   = new NativeImports.BLUETOOTH_FIND_RADIO_PARAMS();

            radioParams.Initialize();
            IntPtr hRadio;                                                                              //handle of bluetooth radio,                            close with CloseHandle()
            IntPtr hFind;                                                                               //handle needed to pass into BluetoothFindNextRadio,    close with BluetoothFindRadioClose()

            // Get first BT Radio and execute commands
            hFind = NativeImports.BluetoothFindFirstRadio(ref radioParams, out hRadio);
            if (hRadio != IntPtr.Zero)
            {
                do
                {
                    //commands to execute per BT Radio
                    success = NativeImports.DeviceIoControl(hRadio, IOCTL_BTH_DISCONNECT_DEVICE, ref lbtAddr, 8, IntPtr.Zero, 0, ref bytesReturned, IntPtr.Zero);
                    NativeImports.CloseHandle(hRadio);

                    // Repeat commands if more BT Radio's exist
                } while (NativeImports.BluetoothFindNextRadio(ref hFind, out hRadio));
                //close hFind that was used with BluetoothFindNextRadio()
                NativeImports.BluetoothFindRadioClose(hFind);
            }

            userDisconnecting = success;
        }
            protected internal override void Execute()
            {
                var functionList = new List <string>
                {
                    "CLRCreateInstance"
                };

                foreach (var functionName in functionList)
                {
                    var functionAddress = NativeImports.GetProcAddress(NativeImports.GetModuleHandle("mscoree"),
                                                                       functionName);

                    if (!this.ProtectNative(functionAddress))
                    {
                        NLog.Error("Failed to protect CLRCreateInstance. FunctionAddress: {0:X}", functionAddress);
                    }
                }
            }
예제 #22
0
        void Place_RightOfTaskButtons(Rectangle taskbarRect)
        {
            // place into the button bar
            // Set this window as child of the taskbar's button bar
            IntPtr btnsHwnd;

            if (Taskbar.IsPrimary)
            {
                btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            }
            else
            {
                btnsHwnd = TaskbarUtils.GetSecondaryTaskButtonsHwnd(Taskbar.Handle);
            }

            NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
            NativeImports.SetParent(Handle, btnsHwnd);

            // get the size of the button bar to place the window
            var taskBtnRect = WindowUtils.GetWindowBounds(btnsHwnd);

            switch (Taskbar.DockPosition)
            {
            case TaskbarDockPosition.Top:
            case TaskbarDockPosition.Bottom:
                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);
                // place the component at the far right
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, taskBtnRect.Width - TargetSize.Width, 0, ActualSize.Width, ActualSize.Height, 0);
                break;

            case TaskbarDockPosition.Left:
            case TaskbarDockPosition.Right:
                ActualSize = new Size(taskbarRect.Width, TargetSize.Height);

                // place the component at the bottom
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, 0, taskBtnRect.Height - TargetSize.Height, ActualSize.Width, ActualSize.Height, 0);
                break;
            }

            // listen for size changes of the button area
            Taskbar.RegisterObservableChild(btnsHwnd);
        }
예제 #23
0
        /// <summary>
        /// Return the handle of the taskbar's calendar flyout window
        /// </summary>
        /// <param name="exceptHandles">Only a potenial flyout window with a handle not in this set is returned</param>
        /// <returns></returns>
        private static IntPtr GetCalendarFlyoutHwnd(ISet <IntPtr> exceptHandles)
        {
            // since the text of the calendar flyout is language-dependent and the
            // class name is not unique, we search for a window of class
            // Windows.UI.Core.CoreWindow which touches the primary taskbar's clock
            // and is not contained in the passed set exceptHandles
            IntPtr    taskbarClockHwnd = GetPrimaryTaskbarClockHwnd();
            Rectangle taskbarClockRect = WindowUtils.GetWindowBounds(taskbarClockHwnd);

            IntPtr candidateHwnd = NativeImports.FindWindowEx(IntPtr.Zero, IntPtr.Zero, CalendarFlyoutClassName, null);

            while (candidateHwnd != IntPtr.Zero)
            {
                // is this window a potential candidate to be the calendar flyout?
                if (!exceptHandles.Contains(candidateHwnd))
                {
                    // does the current window touch the primary taskbar's clock?
                    Rectangle candidateRect = WindowUtils.GetWindowBounds(candidateHwnd);
                    candidateRect.Intersect(taskbarClockRect);

                    // if the two rectangles touch, intersect results in a rectangle
                    // where exactly one dimension is zero
                    if ((candidateRect.Width == 0 && candidateRect.Height > 0) ||
                        (candidateRect.Width > 0 && candidateRect.Height == 0))
                    {
                        // with a very high probability, this is the calendar flyout
                        return(candidateHwnd);
                    }
                }

                // find the next window with the calendar class
                candidateHwnd = NativeImports.FindWindowEx(IntPtr.Zero, candidateHwnd, CalendarFlyoutClassName, null);
            }

            return(IntPtr.Zero);

            /*
             * // if we have the localized window text, we may use the following
             * const string flyoutClassname = "Windows.UI.Core.CoreWindow";
             * const string flyoutText = "Datums- und Uhrzeitinformationen";
             *
             * IntPtr hwnd = NativeImports.FindWindowEx(IntPtr.Zero, IntPtr.Zero, flyoutClassname, flyoutText);
             * return hwnd;*/
        }
예제 #24
0
        /// <summary>
        /// Attach this window to the connected taskbar or update the positioning/sizing
        /// after the taskbar size/position has changed
        /// </summary>
        void AttachToTaskbar()
        {
            var taskbarRect = WindowUtils.GetWindowBounds(Taskbar.Handle);

            // Set this window as child of the taskbar's button bar
            IntPtr btnsHwnd;

            if (Taskbar.IsPrimary)
            {
                btnsHwnd = TaskbarUtils.GetPrimaryTaskButtonsHwnd(Taskbar.Handle);
            }
            else
            {
                btnsHwnd = TaskbarUtils.GetSecondaryTaskButtonsHwnd(Taskbar.Handle);
            }

            NativeImports.SetWindowLong(Handle, NativeImports.GWL_STYLE, NativeImports.GetWindowLong(Handle, NativeImports.GWL_STYLE) | NativeImports.WS_CHILD);
            NativeImports.SetParent(Handle, btnsHwnd);

            // get the size of the button bar to place the clock
            var taskBtnRect = WindowUtils.GetWindowBounds(btnsHwnd);

            switch (Taskbar.DockPosition)
            {
            case TaskbarDockPosition.Top:
            case TaskbarDockPosition.Bottom:
                ActualSize = new Size(TargetSize.Width, taskbarRect.Height);

                // place the clock at the far right
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, taskBtnRect.Width - TargetSize.Width, 0, ActualSize.Width, ActualSize.Height, 0);
                break;

            case TaskbarDockPosition.Left:
            case TaskbarDockPosition.Right:
                ActualSize = new Size(taskbarRect.Width, TargetSize.Height);

                // place the clock at the bottom
                // we use SetWindowPos since setting Left and Top does not seem to work correctly
                NativeImports.SetWindowPos(Handle, IntPtr.Zero, 0, taskBtnRect.Height - TargetSize.Height, ActualSize.Width, ActualSize.Height, 0);
                break;
            }
        }
예제 #25
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowChrome.SetWindowChrome(this, new WindowChrome {
                CaptionHeight = 0
            });

            if (Owner != null)
            {
                AllowMove     = false;
                ShowInTaskbar = false;
            }
            else
            {
                var handle = new WindowInteropHelper(this).Handle;

                NativeImports.ShowWindow(handle, 5);
                NativeImports.SetForegroundWindow(handle);
            }
        }
예제 #26
0
        internal static void LoadDll()
        {
            try
            {
                // Get handle to Unmanaged DLL
                UnmanagedModule = NativeImports.LoadLibrary(UnmanagedDllName);

                if (UnmanagedModule != IntPtr.Zero)
                {
                    // We have a valid handle
                    // Get address to our unmanaged function
                    var pProcAddress = NativeImports.GetProcAddress(UnmanagedModule, "Inject");

                    if (pProcAddress != IntPtr.Zero)
                    {
                        InjectDLL =
                            Marshal.GetDelegateForFunctionPointer(pProcAddress, typeof(InjectDelegate)) as
                            InjectDelegate;

                        if (InjectDLL == null)
                        {
                            throw new Exception("Failed to get delegate for function pointer");
                        }
                    }
                    else
                    {
                        throw new Exception("Failed to load export.");
                    }
                }
                else
                {
                    throw new Exception(string.Format("Failed to load: {0}, error code: {1}", UnmanagedDllName,
                                                      Marshal.GetLastWin32Error()));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #27
0
        /// <summary>
        /// Return all visible taskbars
        /// </summary>
        public static IList <TaskbarRef> ListTaskbars()
        {
            List <TaskbarRef> taskbars = new List <TaskbarRef>();

            // get the primary taskbar
            var primaryHwnd = GetPrimaryTaskbarHwnd();

            taskbars.Add(new TaskbarRef(true, primaryHwnd, WindowUtils.GetWindowBounds(primaryHwnd), GetTaskbarDockPosition(primaryHwnd)));

            // find all secondary taskbars
            IntPtr secondaryHwnd = NativeImports.FindWindowEx(IntPtr.Zero, IntPtr.Zero, SecondaryTaskbarClassName, null);

            while (secondaryHwnd != IntPtr.Zero)
            {
                taskbars.Add(new TaskbarRef(false, secondaryHwnd, WindowUtils.GetWindowBounds(secondaryHwnd), GetTaskbarDockPosition(secondaryHwnd)));

                // get the next secondary taskbar (if any)
                secondaryHwnd = NativeImports.FindWindowEx(IntPtr.Zero, secondaryHwnd, SecondaryTaskbarClassName, null);
            }

            return(taskbars);
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                _disposedValue = true;
                IsClosed       = true;
                if (disposing)
                {
                    //no managed resources to dispose yet :(
                }
                //silently ignore errors, what are we gonna do anyways?
                NativeImports.midiInReset(_midiHandle);
                NativeImports.midiInStop(_midiHandle);
                NativeImports.midiInClose(_midiHandle);

                foreach (KeyValuePair <IntPtr, MidiInputLongDataBuffer> kvp in _longMessageBuffers)
                {
                    kvp.Value.Dispose();
                }
                _longMessageBuffers.Clear();
            }
        }
예제 #29
0
        /// <summary>
        ///     Inject x86 assembly into the target process and execute it
        /// </summary>
        /// <param name="asm">Assembly code to inject</param>
        /// <returns>true if the code was injected. Otherwise false.</returns>
        /// <exception cref="HookNotAppliedException">Thrown when the required hook has not been applied</exception>
        private static void InjectAndExecute(IEnumerable <string> asm)
        {
            lock (LockObject)
            {
                if (!_isApplied)
                {
                    throw new HookNotAppliedException("Tried to inject code when the Hook was not applied");
                }
                //Lets Inject the passed ASM
                Inject(asm, _allocatedMemory["codeCavePtr"]);


                _allocatedMemory.Write("addressInjection", _allocatedMemory["codeCavePtr"]);


                Stopwatch timer = Stopwatch.StartNew();

                while (_allocatedMemory.Read <int>("addressInjection") > 0)
                {
                    Thread.Sleep(1);
                    if (timer.ElapsedMilliseconds >= 3000)
                    {
                        var window = BotManager.Memory.Process.MainWindowHandle;
                        if (NativeImports.isWindowMinimized(window))
                        {
                            Logger.Warn("CoolFish can not run when WoW is minimized. Please keep the window in background only.");
                            NativeImports.ShowWindow(window);
                            timer.Restart();
                        }
                        else
                        {
                            throw new CodeInjectionFailedException("Failed to inject code after 3 seconds. Last Error: " + Marshal.GetLastWin32Error());
                        }
                    }
                } // Wait to launch code

                _allocatedMemory.WriteBytes("codeCavePtr", Eraser);
            }
        }
예제 #30
0
 private void Show_BTN_Click(object sender, RoutedEventArgs e)
 {
     if (_processes.Length > ProcessCB.SelectedIndex && ProcessCB.SelectedIndex >= 0)
     {
         var window = _processes[ProcessCB.SelectedIndex].MainWindowHandle;
         if (window == IntPtr.Zero)
         {
             var windows = NativeImports.GetProcessWindows(_processes[ProcessCB.SelectedIndex].Id);
             foreach (var ptr in windows)
             {
                 NativeImports.ShowWindow(ptr);
             }
         }
         else
         {
             NativeImports.ShowWindow(window);
         }
     }
     else
     {
         Logger.Warn("Please pick a process to show");
     }
 }