MainWindow.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. namespace EasyWeChatClient
  20. {
  21. /// <summary>
  22. /// MainWindow.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class MainWindow : Window
  25. {
  26. public MainWindow()
  27. {
  28. InitializeComponent();
  29. Console.SetOut(new TextBoxWriter(a1));
  30. CommonMethodCallBackHandlers.DownLoadQRCodeCompleted += CommonMethodCallBackHandlers_DownLoadQRCodeCompleted;
  31. CommonMethodCallBackHandlers.LoginScranQRCodeCompleted += CommonMethodCallBackHandlers_LoginScranQRCodeCompleted;
  32. CommonMethodCallBackHandlers.LoginCompleted += CommonMethodCallBackHandlers_LoginCompleted;
  33. CommonMethodCallBackHandlers.ReceivedMsgAnalyseMsgCompleted += CommonMethodCallBackHandlers_ReceivedMsgAnalyseMsgCompleted;
  34. CommonMethodCallBackHandlers.SendMsgCompleted += CommonMethodCallBackHandlers_SendMsgCompleted;
  35. new Task(() =>
  36. {
  37. WeiChat.InitWeiChatRobot();
  38. }).Start();
  39. }
  40. void CommonMethodCallBackHandlers_SendMsgCompleted(bool obj)
  41. {
  42. }
  43. void CommonMethodCallBackHandlers_ReceivedMsgAnalyseMsgCompleted(WeChatCore.Entity.MsgEntity obj)
  44. {
  45. }
  46. private void CommonMethodCallBackHandlers_LoginCompleted(bool obj)
  47. {
  48. if (obj)
  49. {
  50. this.Dispatcher.Invoke(new Action(() =>
  51. {
  52. Image1.Visibility = Visibility.Collapsed;
  53. a1.Visibility = Visibility.Visible;
  54. }));
  55. }
  56. }
  57. private void CommonMethodCallBackHandlers_LoginScranQRCodeCompleted(string obj)
  58. {
  59. this.Dispatcher.Invoke(new Action(() =>
  60. {
  61. Image1.Source = new BitmapImage(new Uri(obj));
  62. }
  63. ));
  64. }
  65. private void CommonMethodCallBackHandlers_DownLoadQRCodeCompleted()
  66. {
  67. this.Dispatcher.Invoke(new Action(() =>
  68. {
  69. Image1.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "\\Check.jpg"));
  70. }));
  71. }
  72. private void a1_TextChanged(object sender, TextChangedEventArgs e)
  73. {
  74. a1.ScrollToEnd();
  75. }
  76. }
  77. }