Skip to content

Commit 3ce4924

Browse files
author
lcy.company
committed
first commit
1 parent ff7b951 commit 3ce4924

File tree

3 files changed

+195
-0
lines changed

3 files changed

+195
-0
lines changed

pom.xml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>cn.lcy9</groupId>
6+
<artifactId>qqmsg4l</artifactId>
7+
<version>0.1</version>
8+
<packaging>jar</packaging>
9+
10+
<name>qqmsg4l</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>junit</groupId>
20+
<artifactId>junit</artifactId>
21+
<version>3.8.1</version>
22+
<scope>test</scope>
23+
</dependency>
24+
25+
26+
<!-- https://mvnrepository.com/artifact/org.jodd/jodd-http -->
27+
<dependency>
28+
<groupId>org.jodd</groupId>
29+
<artifactId>jodd-http</artifactId>
30+
<version>3.7.1</version>
31+
</dependency>
32+
33+
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
34+
<dependency>
35+
<groupId>net.java.dev.jna</groupId>
36+
<artifactId>jna</artifactId>
37+
<version>4.2.2</version>
38+
</dependency>
39+
40+
41+
42+
43+
</dependencies>
44+
</project>
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package cn.lcy9.qqmsg4l;
2+
3+
import java.io.IOException;
4+
import java.io.UnsupportedEncodingException;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import com.sun.jna.Native;
9+
import com.sun.jna.Pointer;
10+
import com.sun.jna.win32.StdCallLibrary;
11+
12+
import jodd.http.HttpRequest;
13+
14+
public class Main {
15+
16+
static interface User32 extends StdCallLibrary {
17+
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
18+
19+
interface WNDENUMPROC extends StdCallCallback {
20+
boolean callback(Pointer hWnd, Pointer arg);
21+
}
22+
23+
boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer userData);
24+
25+
int GetWindowTextA(Pointer hWnd, byte[] lpString, int nMaxCount);
26+
27+
int GetClassNameA(Pointer hWnd, byte[] lpString, int nMaxCount);
28+
29+
//Pointer GetWindow(Pointer hWnd, int uCmd);
30+
}
31+
32+
public static List<String> getAllWindowNames() {
33+
34+
System.setProperty("jna.encoding", "GBK");
35+
36+
final List<String> windowNames = new ArrayList<>();
37+
final User32 user32 = User32.INSTANCE;
38+
user32.EnumWindows(new User32.WNDENUMPROC() {
39+
40+
@Override
41+
public boolean callback(Pointer hWnd, Pointer arg) {
42+
final byte[] windowText1 = new byte[512];
43+
final byte[] windowText2 = new byte[512];
44+
45+
user32.GetWindowTextA(hWnd, windowText1, 512);
46+
final String wText1 = Native.toString(windowText1).trim();
47+
48+
user32.GetClassNameA(hWnd, windowText2, 512);
49+
final String wText2 = Native.toString(windowText2).trim();
50+
51+
if (!wText1.isEmpty()) {
52+
try {
53+
windowNames.add(new String(wText1.getBytes(), "gbk")+ "\t" + wText2);
54+
} catch (UnsupportedEncodingException e) {
55+
// TODO Auto-generated catch block
56+
e.printStackTrace();
57+
}
58+
//System.out.println(wText1 + "\t" + wText2);
59+
}
60+
61+
62+
return true;
63+
}
64+
}, null);
65+
66+
return windowNames;
67+
}
68+
69+
public static void main(String[] args) throws IOException, InterruptedException {
70+
71+
//final List<String> winNameList = getAllWindowNames();
72+
73+
//final List<String> windownames = FileUtils.readLines(new File(args[0]), "utf-8");
74+
75+
if(args.length != 1){
76+
System.out.println("Usage:\n\tjava -jar qq_notice.jar <server url>\n\nhttps://github.com/binaryer/qqmsg4l");
77+
return;
78+
}
79+
80+
while(true){
81+
Thread.sleep(3000L);
82+
83+
final StringBuffer sbtitles = new StringBuffer();
84+
for (final String winName : getAllWindowNames()) {
85+
86+
final String[] winNames = winName.trim().split("\t");
87+
88+
final String title = winNames[0].trim();
89+
final String classname = winNames[1].trim();
90+
if(title.equals("")) continue;
91+
if(!classname.equals("TXGuiFoundation")) continue;
92+
if(title.equals("QQ")) continue;
93+
if(title.equals("TXMenuWindow")) continue;
94+
sbtitles.append(title).append('\n');
95+
//System.out.println(title);
96+
97+
}
98+
99+
try{
100+
HttpRequest.post(args[0])
101+
.charset("gbk")
102+
.form("action", "notice", "titles", sbtitles.toString())
103+
.send();
104+
}catch(Throwable t){
105+
t.printStackTrace();
106+
}
107+
108+
}
109+
110+
111+
}
112+
113+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package cn.lcy9.qqmsg4l;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)