-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm1.cs
More file actions
198 lines (175 loc) · 7.72 KB
/
Form1.cs
File metadata and controls
198 lines (175 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using System.Drawing.Imaging;
using WodToolKit.Http;
namespace QQLogin
{
public partial class Form1 : Form
{
QQQuickLogin qQQuickLogin;
private ImageList imageList1;
private Dictionary<string, PictureBox> animatedPictures = new Dictionary<string, PictureBox>();
public Form1()
{
InitializeComponent();
// 设置ListView为大图标视图模式
listView1.View = View.LargeIcon;
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
// 清空ListView
listView1.Items.Clear();
// 初始化ImageList用于显示头像
imageList1 = new ImageList();
imageList1.ImageSize = new Size(64, 64); // 增大头像尺寸
listView1.LargeImageList = imageList1; // 使用大图标列表
// 创建QQQuickLogin实例
qQQuickLogin = new QQQuickLogin(QQAppType.Qun);
// 获取所有QQ用户列表
List<QQQuickLogin.uins> uinsList = qQQuickLogin.GetUins();
// 遍历每个用户,获取头像并添加到ListView
foreach (var uinInfo in uinsList)
{
try
{
// 获取用户头像信息
QQQuickLogin.QQFaceInfo faceInfo = qQQuickLogin.GetFace(uinInfo);
// 创建ListView项,UIN作为文本标签(将显示在头像下方)
ListViewItem item = new ListViewItem(uinInfo.uin.ToString());
// 添加到ListView
listView1.Items.Add(item);
if (faceInfo.IsSuccess && !string.IsNullOrEmpty(faceInfo.FaceUrl))
{
// 同步加载头像图片
LoadAvatar(item, faceInfo.FaceUrl);
}
}
catch (Exception ex)
{
// 记录单个用户处理失败的错误,但继续处理其他用户
Console.WriteLine($"处理用户 {uinInfo.uin} 时出错: {ex.Message}");
// 添加错误信息到ListView
ListViewItem errorItem = new ListViewItem(uinInfo.uin.ToString());
listView1.Items.Add(errorItem);
}
}
}
catch (Exception ex)
{
// 显示整体错误信息
MessageBox.Show($"加载QQ用户信息失败: {ex.Message}", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 同步加载头像图片
/// </summary>
private void LoadAvatar(ListViewItem item, string imageUrl)
{
try
{
if (!string.IsNullOrEmpty(imageUrl))
{
// 使用HttpRequestClass同步下载图片数据
byte[] imageData = null;
try
{
// 创建新的HttpRequestClass实例进行请求
var http = new HttpRequestClass();
http.Open(imageUrl);
http.Send();
HttpResponseData response = http.GetResponse();
if (response.StatusCode == 200 && response.rawResult != null)
{
imageData = response.rawResult;
}
else
{
throw new Exception($"下载失败,状态码: {response.StatusCode}");
}
}
catch (Exception ex)
{
Console.WriteLine($"HttpRequestClass下载图片失败: {ex.Message}");
throw; // 重新抛出异常以便上层处理
}
// 检查是否为GIF格式
bool isGif = false;
if (imageData.Length > 4)
{
isGif = imageData[0] == 0x47 && imageData[1] == 0x49 &&
imageData[2] == 0x46 && imageData[3] == 0x38;
}
if (isGif)
{
// 对于GIF图片,创建一个隐藏的PictureBox来显示动画
string key = item.Text;
PictureBox animatedBox = new PictureBox();
animatedBox.Size = new Size(64, 64);
animatedBox.SizeMode = PictureBoxSizeMode.StretchImage;
animatedBox.Visible = false; // 隐藏但仍然会播放动画
// 创建内存流的副本
MemoryStream ms = new MemoryStream(imageData);
animatedBox.Image = Image.FromStream(ms);
// 添加到字典以便后续访问
animatedPictures[key] = animatedBox;
this.Controls.Add(animatedBox); // 添加到控件集合以启用动画
// 使用第一帧作为静态图标
Image frame = animatedBox.Image.Clone() as Image;
frame.SelectActiveFrame(FrameDimension.Time, 0);
// 添加到ImageList
imageList1.Images.Add(frame);
item.ImageIndex = imageList1.Images.Count - 1;
}
else
{
// 对于非GIF图片,直接添加到ImageList
using (MemoryStream ms = new MemoryStream(imageData))
{
Image avatarImage = Image.FromStream(ms);
// 创建适合大图标模式的头像大小
Image largeAvatar = new Bitmap(avatarImage, new Size(64, 64));
// 添加到ImageList
imageList1.Images.Add(largeAvatar);
item.ImageIndex = imageList1.Images.Count - 1;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine($"加载头像失败 {imageUrl}: {ex.Message}");
}
}
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
{
// 获取鼠标点击位置下的ListView项
ListViewItem clickedItem = listView1.GetItemAt(e.X, e.Y);
if (clickedItem != null)
{
// 获取选中的QQ号
string qqNumber = clickedItem.Text;
qQQuickLogin = new QQQuickLogin(QQAppType.Qun);
foreach (var uinInfo in qQQuickLogin.GetUins())
{
if (uinInfo.uin.ToString() == qqNumber)
{
textBox1.Text = qQQuickLogin.Login(uinInfo);
break;
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
using (InputDialog inputDialog = new InputDialog("请输入skey"))
{
if (inputDialog.ShowDialog() == DialogResult.OK)
{
int sign = common.Get_G_tk(inputDialog.InputText);
//复制
Clipboard.SetText(sign.ToString());
}
}
}
}
}