사과는 사전에 저는 초보자입니다.jna가 편집 제어 메시지를 전송합니다.
저는 Java 및 JNA 라이브러리가있는 rFactor라는 Windows 기반 게임을 사용하려고합니다. 나는 사람들이 C++을 사용하여하고 싶은 것을 보았다.
package au.gov.nsw.lpi.bds.jnatest;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.examples.win32.W32API.HWND;
import com.sun.jna.examples.win32.W32API.LPARAM;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public class IterateChildWindows {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);
int SendMessage(HWND hWnd, int msg, int wParam, byte[] lParam);
boolean FindWindowEx(HWND parent, HWND child, String className, String window);
boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer arg);
boolean EnumChildWindows(HWND parent, WNDENUMPROC callback, LPARAM info);
interface WNDENUMPROC extends StdCallCallback {
boolean callback(HWND name, Pointer arg);
}
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount);
int GetClassNameA(HWND in, byte[] lpString, int size);
}
public static void main(String[] args) {
User32.INSTANCE.EnumWindows(new User32.WNDENUMPROC() {
public boolean callback(HWND hWnd, Pointer userData) {
byte[] textBuffer = new byte[512];
User32.INSTANCE.GetWindowTextA(hWnd, textBuffer, 512);
String wText = Native.toString(textBuffer);
if (wText.contains("ISI Dedicated Server")) {
if (User32.INSTANCE.FindWindowEx(hWnd, null, "Static", "Game Name:")) {
System.out.println(new String(textBuffer).trim() + " - " + hWnd);
User32.INSTANCE.EnumChildWindows(hWnd, new User32.WNDENUMPROC() {
int count = 1;
public boolean callback(HWND hWnd, Pointer userData) {
byte[] textBuffer = new byte[512];
User32.INSTANCE.GetClassNameA(hWnd, textBuffer, 512);
if ((new String(textBuffer).trim()).contains("Edit")) {
System.out.println(new String(textBuffer).trim());
System.out.println(hWnd);
// User32.INSTANCE.SendMessage(hWnd,
// WM_SETTEXT, msg.length(), (LPARAM) msg);
}
if ((new String(textBuffer).trim()).contains("Button")) {
if (count == 8) {
System.out.println(new String(textBuffer).trim() + " " + count);
System.out.println(hWnd);
}
count++;
}
return true;
}
}, null);
}
}
return true;
}
}, null);
}
}
이 생산
ISI Dedicated Server - [email protected] ([email protected])
Edit
[email protected] ([email protected])
Button 8
[email protected] ([email protected])
내가 I로 바른 길에 생각 해요 :
지금까지 나는이 (나는 다른 유래 포스트에서 그것의 대부분을 Java search for on-screen text field 복사) 한 내가 필요한 "편집"과 "버튼"을 격리 시켰습니다. 나는 지금이 ++
SendMessage(chatHwnd, WM_SETTEXT, msgSB.Length, msgSB)
내가 해봤 C :에서 예입니다
int SendMessage(HWND hWnd, int msg, int wParam, byte[] lParam);
사용하여 버튼을 사용하여 다음 편집 필드에 텍스트를 넣어 필요가 생각하지만, 일을 점점 운이 없었다 . 어떤 도움을 주시면 감사하겠습니다.
int SendMessage(HWND hWnd, int msg, int wParam, byte[] lParam);
이
public boolean callback(HWND hWnd, Pointer userData) {
byte[] textBuffer = new byte[512];
User32.INSTANCE.GetClassNameA(hWnd, textBuffer, 512);
if ((new String(textBuffer).trim()).contains("Edit")) {
User32.INSTANCE.SendMessage(hWnd,0xC, msg.length,
Native.toByteArray("MessageFromNick"));
}
if ((new String(textBuffer).trim()).contains("Button")) {
if (count == 8) {
User32.INSTANCE.SendMessage(hWnd, 0x0201, 0, 0);
}
count++;
}
return true;
}
무엇을 시도 했습니까? ['Native.toByteArray (String)'] (http://twall.github.io/jna/4.0/javadoc/com/sun/jna/Native.html#toByteArray (java.lang.String))을 사용해야합니다.))를 사용하여 적절하게 널 문자로 끝나는 바이트 배열 (유니 코드 버전의'SendMessage'를 사용한다면'char'의 배열)을 얻을 수 있습니다. – technomage
답변 해 주셔서 감사합니다. 내가 시도한 것들을 담기 위해 원래의 글을 편집했다. 감사합니다, Nick – user2738572
감사의 말을 전합니다. – user2738572