aaa

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        System.Windows.Threading.DispatcherTimer timmer;
        const int WM_CLOSE = 0x00000111;
        [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
        static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);

        public MainWindow()
        {
            InitializeComponent();
        }

        private void msgShow_Click1(object sender, RoutedEventArgs e)
        {
            timmer = new System.Windows.Threading.DispatcherTimer();
            timmer.Tick += Timmer_Tick;
            timmer.Interval = new TimeSpan(0, 0, 3);
            timmer.Start();

            MessageBoxResult result = MessageBox.Show("hello", "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            if (result == MessageBoxResult.OK)
            {
                Console.WriteLine("OK");
            }

            ToolTip toolTip = grid.ToolTip as ToolTip;
            toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
            toolTip.PlacementTarget = sender as Button;
            toolTip.Visibility = Visibility.Visible;
            toolTip.IsOpen = true;
            toolTip.Content = "zhang : 3 \r\nzhou : 5";
        }

        private void msgShow_Click2(object sender, RoutedEventArgs e)
        {
            timmer = new System.Windows.Threading.DispatcherTimer();
            timmer.Tick += Timmer_Tick;
            timmer.Interval = new TimeSpan(0, 0, 3);
            timmer.Start();

            MessageBoxResult result = MessageBox.Show("hello", "Information", MessageBoxButton.YesNo, MessageBoxImage.Information);
            if (result == MessageBoxResult.Yes)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            ToolTip toolTip = grid.ToolTip as ToolTip;
            toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
            toolTip.PlacementTarget = sender as Button;
            toolTip.Visibility = Visibility.Visible;
            toolTip.IsOpen = true;
            toolTip.Content = "zhang : 7 \r\nzhou : 8";
        }

        private void msgShow_Click3(object sender, RoutedEventArgs e)
        {
            timmer = new System.Windows.Threading.DispatcherTimer();
            timmer.Tick += Timmer_Tick;
            timmer.Interval = new TimeSpan(0, 0, 3);
            timmer.Start();

            MessageBoxResult result = MessageBox.Show("hello", "Information", MessageBoxButton.OKCancel, MessageBoxImage.Information);
            if (result == MessageBoxResult.OK)
            {
                Console.WriteLine("ok");
            }
            else
            {
                Console.WriteLine("Cancle");
            }

            ToolTip toolTip = grid.ToolTip as ToolTip;
            toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
            toolTip.PlacementTarget = sender as Button;
            toolTip.Visibility = Visibility.Visible;
            toolTip.IsOpen = true;
            toolTip.Content = "zhang : 9 \r\nzhou : 10";
        }

        private void msgShow_Click4(object sender, RoutedEventArgs e)
        {
            timmer = new System.Windows.Threading.DispatcherTimer();
            timmer.Tick += Timmer_Tick;
            timmer.Interval = new TimeSpan(0, 0, 3);
            timmer.Start();

            MessageBoxResult result = MessageBox.Show("hello", "Information", MessageBoxButton.YesNoCancel, MessageBoxImage.Information);
            if (result == MessageBoxResult.Yes)
            {
                Console.WriteLine("Yes");
            }
            else if (result == MessageBoxResult.Cancel)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Cancle");
            }

            ToolTip toolTip = grid.ToolTip as ToolTip;
            toolTip.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
            toolTip.PlacementTarget = sender as Button;
            toolTip.Visibility = Visibility.Visible;
            toolTip.IsOpen = true;
            toolTip.Content = "zhang : 11 \r\nzhou : 12";
        }

        private void Timmer_Tick(object sender, EventArgs e)
        {
            timmer.Stop();

            IntPtr mbWnd = FindWindow(null, "Information");
            if (mbWnd != IntPtr.Zero)
            {
                SendMessage(mbWnd, WM_CLOSE, new IntPtr(7), IntPtr.Zero);
            }
        }

        private void msgShow_MouseLeave(object sender, MouseEventArgs e)
        {
            ToolTip toolTip = grid.ToolTip as ToolTip;
            toolTip.Visibility = Visibility.Hidden;
        }
    }
}

 

posted @ 2017-02-27 06:35  keyiei  阅读(111)  评论(0编辑  收藏  举报