MainWindow.xaml.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using EasyWeChatClient.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using WeChatCore;
  18. using WeChatCore.Common;
  19. using WeChatCore.Entity;
  20. namespace EasyWeChatClient
  21. {
  22. /// <summary>
  23. /// MainWindow.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class MainWindow : Window
  26. {
  27. public MainWindow()
  28. {
  29. InitializeComponent();
  30. Console.SetOut(new TextBoxWriter(a1));
  31. CommonMethodCallBackHandlers.DownLoadQRCodeCompleted += CommonMethodCallBackHandlers_DownLoadQRCodeCompleted;
  32. CommonMethodCallBackHandlers.LoginScranQRCodeCompleted += CommonMethodCallBackHandlers_LoginScranQRCodeCompleted;
  33. CommonMethodCallBackHandlers.LoginCompleted += CommonMethodCallBackHandlers_LoginCompleted;
  34. CommonMethodCallBackHandlers.ReceivedMsgAnalyseMsgCompleted += CommonMethodCallBackHandlers_ReceivedMsgAnalyseMsgCompleted;
  35. CommonMethodCallBackHandlers.SendMsgCompleted += CommonMethodCallBackHandlers_SendMsgCompleted;
  36. new Task(() =>
  37. {
  38. WeChat.InitWeiChatRobot();
  39. }).Start();
  40. }
  41. void CommonMethodCallBackHandlers_SendMsgCompleted(bool obj)
  42. {
  43. }
  44. void CommonMethodCallBackHandlers_ReceivedMsgAnalyseMsgCompleted(MsgEntity obj)
  45. {
  46. }
  47. private void CommonMethodCallBackHandlers_LoginCompleted(bool obj)
  48. {
  49. if (obj)
  50. {
  51. this.Dispatcher.Invoke(new Action(() =>
  52. {
  53. Image1.Visibility = Visibility.Collapsed;
  54. a1.Visibility = Visibility.Visible;
  55. }));
  56. }
  57. }
  58. private void CommonMethodCallBackHandlers_LoginScranQRCodeCompleted(string obj)
  59. {
  60. this.Dispatcher.Invoke(new Action(() =>
  61. {
  62. Image1.Source = new BitmapImage(new Uri(obj));
  63. }
  64. ));
  65. }
  66. private void CommonMethodCallBackHandlers_DownLoadQRCodeCompleted()
  67. {
  68. this.Dispatcher.Invoke(new Action(() =>
  69. {
  70. Image1.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Check.jpg"));
  71. }));
  72. }
  73. private void a1_TextChanged(object sender, TextChangedEventArgs e)
  74. {
  75. a1.ScrollToEnd();
  76. }
  77. }
  78. }