|
右边是易语言拖动设计的界面,左边是根据窗口句柄,生成的json信息,然后根据json信息,创建回来的窗口
包括
类名,标题,菜单,控件id,样式,扩展样式,左顶高宽
列表框,组合框 包括 列表项目,列表数值,当前选择
滚动条 包括最小,最大,当前位置
其他通过控件,还没有完成收集信息
[JavaScript] 纯文本查看 复制代码 {
"children" : [
{
"classname" : "ScrollBar",
"exstyle" : 0,
"height" : 32,
"id" : 370,
"left" : 440,
"max" : 2,
"min" : 1,
"page" : 0,
"pos" : 2,
"style" : 1409286144,
"text" : "",
"top" : 296,
"width" : 184
},
{
"classname" : "_EL_Label",
"exstyle" : 0,
"height" : 32,
"id" : 360,
"left" : 8,
"style" : 1417674752,
"text" : "标签",
"top" : 136,
"width" : 80
},
{
"classname" : "_EL_Label",
"exstyle" : 0,
"height" : 32,
"id" : 350,
"left" : 8,
"style" : 1417674752,
"text" : "标签",
"top" : 96,
"width" : 80
},
{
"classname" : "ComboBox",
"cursel" : 2,
"exstyle" : 0,
"height" : 20,
"id" : 340,
"items" : [
{
"data" : 11,
"text" : "A"
},
{
"data" : 22,
"text" : "B"
},
{
"data" : 33,
"text" : "combo"
}
],
"left" : 264,
"style" : 1409352259,
"text" : "combo",
"top" : 312,
"width" : 152
},
{
"children" : [
{
"classname" : "ComboLBox",
"exstyle" : 512,
"height" : 56,
"id" : 1000,
"left" : 0,
"style" : 1409318977,
"text" : "",
"top" : 20,
"width" : 152
},
{
"classname" : "Edit",
"exstyle" : 0,
"height" : 14,
"id" : 1001,
"left" : 3,
"style" : 1342178176,
"text" : "",
"top" : 3,
"width" : 146
}
],
"classname" : "ComboBox",
"cursel" : 2,
"exstyle" : 0,
"height" : 96,
"id" : 330,
"items" : [
{
"data" : 11,
"text" : "A"
},
{
"data" : 22,
"text" : "B"
},
{
"data" : 33,
"text" : "combo"
}
],
"left" : 264,
"style" : 1409352257,
"text" : "",
"top" : 216,
"width" : 152
},
{
"classname" : "ListBox",
"cursel" : 3,
"exstyle" : 512,
"height" : 160,
"id" : 320,
"items" : [
{
"data" : 0,
"text" : "aa"
},
{
"data" : 0,
"text" : "bb"
},
{
"data" : 0,
"text" : "cc"
},
{
"data" : 0,
"text" : "dd"
}
],
"left" : 136,
"style" : 1409352065,
"text" : "",
"top" : 184,
"width" : 120
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 72,
"id" : 310,
"left" : 600,
"style" : 1412501700,
"text" : "编辑框222\r\n2222",
"top" : 136,
"width" : 136
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 32,
"id" : 300,
"left" : 488,
"style" : 1409351842,
"text" : "",
"top" : 176,
"width" : 80
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 32,
"id" : 290,
"left" : 488,
"style" : 1409353858,
"text" : "编辑框",
"top" : 136,
"width" : 80
},
{
"classname" : "msctls_updown32",
"exstyle" : 131072,
"height" : 32,
"id" : 284,
"left" : 568,
"style" : 1409286144,
"text" : "",
"top" : 96,
"width" : 18
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 32,
"id" : 280,
"left" : 488,
"style" : 1409351809,
"text" : "编辑框",
"top" : 96,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 270,
"left" : 360,
"style" : 1409286663,
"text" : "分组2",
"top" : 136,
"width" : 120
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 260,
"left" : 272,
"style" : 1409362435,
"text" : "选择框",
"top" : 136,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 250,
"left" : 272,
"style" : 1409361155,
"text" : "选择框",
"top" : 96,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 240,
"left" : 184,
"style" : 1409296905,
"text" : "单选框",
"top" : 136,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 230,
"left" : 184,
"style" : 1409295625,
"text" : "单选框",
"top" : 96,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 220,
"left" : 96,
"style" : 1409362432,
"text" : "按钮",
"top" : 136,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 210,
"left" : 96,
"style" : 1409361152,
"text" : "按钮",
"top" : 96,
"width" : 80
},
{
"classname" : "ScrollBar",
"exstyle" : 0,
"height" : 104,
"id" : 200,
"left" : 632,
"max" : 100,
"min" : 1,
"page" : 0,
"pos" : 10,
"style" : 1409286145,
"text" : "",
"top" : 224,
"width" : 40
},
{
"children" : [
{
"classname" : "Edit",
"exstyle" : 0,
"height" : 14,
"id" : 1001,
"left" : 3,
"style" : 1342178176,
"text" : "",
"top" : 3,
"width" : 129
}
],
"classname" : "ComboBox",
"cursel" : 2,
"exstyle" : 0,
"height" : 20,
"id" : 190,
"items" : [
{
"data" : 11,
"text" : "A"
},
{
"data" : 22,
"text" : "B"
},
{
"data" : 33,
"text" : "combo"
}
],
"left" : 264,
"style" : 1409352258,
"text" : "",
"top" : 184,
"width" : 152
},
{
"classname" : "ListBox",
"cursel" : 0,
"exstyle" : 257,
"height" : 160,
"id" : 180,
"items" : [
{
"data" : 0,
"text" : "aa"
},
{
"data" : 0,
"text" : "bb"
},
{
"data" : 0,
"text" : "cc"
},
{
"data" : 0,
"text" : "dd"
}
],
"left" : 8,
"style" : 1409354113,
"text" : "",
"top" : 184,
"width" : 120
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 72,
"id" : 170,
"left" : 600,
"style" : 1409355844,
"text" : "编辑框222\r\n2222",
"top" : 56,
"width" : 136
},
{
"classname" : "Edit",
"exstyle" : 512,
"height" : 32,
"id" : 160,
"left" : 488,
"style" : 1409351808,
"text" : "编辑框",
"top" : 56,
"width" : 80
},
{
"children" : [
{
"classname" : "Button",
"exstyle" : 0,
"height" : 24,
"id" : 150,
"left" : 24,
"style" : 1409363712,
"text" : "按钮",
"top" : 24,
"width" : 56
}
],
"classname" : "Button",
"exstyle" : 0,
"height" : 64,
"id" : 140,
"left" : 360,
"style" : 1409286407,
"text" : "分组",
"top" : 56,
"width" : 120
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 130,
"left" : 272,
"style" : 1409363715,
"text" : "选择框",
"top" : 56,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 120,
"left" : 184,
"style" : 1409298185,
"text" : "单选框",
"top" : 56,
"width" : 80
},
{
"classname" : "Button",
"exstyle" : 0,
"height" : 32,
"id" : 110,
"left" : 96,
"style" : 1409363712,
"text" : "按钮",
"top" : 56,
"width" : 80
},
{
"classname" : "_EL_Label",
"exstyle" : 0,
"height" : 32,
"id" : 100,
"left" : 8,
"style" : 1417674752,
"text" : "标签",
"top" : 56,
"width" : 80
}
],
"classname" : "WTWindow",
"exstyle" : 256,
"height" : 593,
"left" : 1013,
"menuitems" : [
{
"flags" : 272,
"menuitems" : [
{
"flags" : 0,
"id" : 20001,
"text" : "bb"
}
],
"text" : "文件(&F)"
},
{
"flags" : 272,
"menuitems" : [
{
"flags" : 0,
"id" : 20003,
"text" : "fff"
}
],
"text" : "-"
},
{
"flags" : 1040,
"menuitems" : [
{
"flags" : 0,
"id" : 20005,
"text" : "e1"
},
{
"flags" : 2051,
"id" : 20006,
"text" : ""
},
{
"flags" : 0,
"id" : 20007,
"text" : "e2"
},
{
"flags" : 0,
"id" : 20008,
"text" : "e3"
}
],
"text" : "编辑(&E)"
},
{
"flags" : 272,
"menuitems" : [
{
"flags" : 0,
"id" : 20010,
"text" : "啊啊啊"
}
],
"text" : "关于"
}
],
"style" : 382337024,
"text" : "测试中文",
"top" : 110,
"width" : 761
}
源码
[C++] 纯文本查看 复制代码 #if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#include <windows.h>
#include <CommCtrl.h>
#include "json/json.h"
using namespace std;
using namespace Json;
#pragma comment(lib,R"(C:\Users\Administrator\Desktop\窗口json\packages\jsoncpp-vc140-static-32_64.1.8.0\lib\native\libs\x86\static\Debug\jsoncpp.lib)")
void parsemenu(Value& json, HMENU hMenuParent) {
for (int i = 0; i < GetMenuItemCount(hMenuParent); i++) {
Value& jsonItem = json.append(ValueType::objectValue);
char szText[257];
GetMenuStringA(hMenuParent, i, szText, _countof(szText), MF_BYPOSITION);
jsonItem["text"] = szText;
UINT nFlags=GetMenuState(hMenuParent, i, MF_BYPOSITION);
jsonItem["flags"] = nFlags;
if (nFlags & MF_POPUP) {
parsemenu(jsonItem["menuitems"], GetSubMenu(hMenuParent,i));
}
else {
jsonItem["id"] = GetMenuItemID(hMenuParent, i);
}
}
}
void parsewindow(Value& json, HWND hwndParent, bool bIncludeMenu) {
char szClsName[257]{};
GetClassNameA(hwndParent, szClsName,_countof(szClsName));
json["classname"] = szClsName;
int nLen = SendMessageA(hwndParent, WM_GETTEXTLENGTH, 0, 0) + 1;
char* pText = new char[nLen] {};
SendMessageA(hwndParent, WM_GETTEXT, nLen, (LPARAM)pText);
json["text"] = pText;
delete[] pText;
if (bIncludeMenu) {
HMENU hMenu = GetMenu(hwndParent);
if (hMenu) {
parsemenu(json["menuitems"], hMenu);
}
}
else {
json["id"] = (int)GetWindowLongA(hwndParent, GWL_ID);
}
RECT rc{};
GetWindowRect(hwndParent, &rc);
json["width"] = (int)(rc.right - rc.left);
json["height"] = (int)(rc.bottom - rc.top);
ScreenToClient(GetParent(hwndParent), (PPOINT)&rc);
json["left"] = (int)rc.left;
json["top"] = (int)rc.top;
json["style"] = (int)GetWindowLongA(hwndParent, GWL_STYLE);
json["exstyle"] = (int)GetWindowLongA(hwndParent, GWL_EXSTYLE);
if (_stricmp(szClsName, WC_STATICA)==0) {
}
else if (_stricmp(szClsName, WC_BUTTONA) == 0) {
}
else if (_stricmp(szClsName, WC_EDITA) == 0) {
}
else if (_stricmp(szClsName, WC_LISTBOXA) == 0) {
int nCount = SendMessageA(hwndParent, LB_GETCOUNT, 0, 0);
if (nCount > 0) {
json["cursel"] = (int)SendMessageA(hwndParent, LB_GETCURSEL, 0, 0);
json["items"] = ValueType::arrayValue;
for (int i = 0; i < nCount; i++) {
Value &item=json["items"].append(ValueType::objectValue);
int nLen = SendMessageA(hwndParent, LB_GETTEXTLEN, i, 0);
char *pText = new char[nLen + 1]{};
SendMessageA(hwndParent, LB_GETTEXT, i, (LPARAM)pText);
item["text"] = pText;
item["data"] = (int)SendMessageA(hwndParent, LB_GETITEMDATA, i, 0);
}
}
}
else if (_stricmp(szClsName, WC_COMBOBOXA) == 0) {
int nCount = SendMessageA(hwndParent, CB_GETCOUNT, 0, 0);
if (nCount > 0) {
json["cursel"] = (int)SendMessageA(hwndParent, CB_GETCURSEL, 0, 0);
json["items"] = ValueType::arrayValue;
for (int i = 0; i < nCount; i++) {
Value& item = json["items"].append(ValueType::objectValue);
int nLen = SendMessageA(hwndParent, CB_GETLBTEXTLEN, i, 0);
char* pText = new char[nLen + 1]{};
SendMessageA(hwndParent, CB_GETLBTEXT, i, (LPARAM)pText);
item["text"] = pText;
item["data"] = (int)SendMessageA(hwndParent, CB_GETITEMDATA, i, 0);
}
}
}
else if (_stricmp(szClsName, WC_SCROLLBARA) == 0) {
SCROLLINFO si;
si.cbSize = sizeof si;
si.fMask = SIF_ALL;
SendMessageA(hwndParent, SBM_GETSCROLLINFO, 0, (LPARAM)&si);
json["min"] = si.nMin;
json["max"] = si.nMax;
json["pos"] = si.nPos;
json["page"] = si.nPage;
}
else if (_stricmp(szClsName, TOOLBARCLASSNAMEA) == 0) {
}
HWND hwnd = GetWindow(hwndParent, GW_CHILD);
if (hwnd) {
json["children"] = ValueType::arrayValue;
while (hwnd) {
parsewindow(json["children"].append(ValueType::objectValue), hwnd, false);
hwnd = GetWindow(hwnd, GW_HWNDNEXT);
}
}
}
HMENU createmenu(Value& json, bool bTop) {
/*for (int i = 0; i < GetMenuItemCount(hMenuParent); i++) {
Value& jsonItem = json.append(ValueType::objectValue);
char szText[257];
GetMenuStringA(hMenuParent, i, szText, _countof(szText), MF_BYPOSITION);
jsonItem["text"] = szText;
UINT nFlags = GetMenuState(hMenuParent, i, MF_BYPOSITION);
jsonItem["flags"] = nFlags;
if (nFlags & MF_POPUP) {
parsemenu(jsonItem["menuitems"], GetSubMenu(hMenuParent, i));
}
else {
jsonItem["id"] = GetMenuItemID(hMenuParent, i);
}
}*/
HMENU hMenu = bTop ? CreateMenu() : CreatePopupMenu();
hMenu = CreateMenu();
for (int i = 0; i < json.size(); i++) {
Value& jsonItem = json;
if (jsonItem["menuitems"].isArray()) {
HMENU hSubMenu = createmenu(jsonItem["menuitems"], false);
//MessageBoxA(NULL, jsonItem["text"].asCString(), 0, 0);
AppendMenuA(hMenu, MF_POPUP, (UINT_PTR)hSubMenu, jsonItem["text"].asCString());
}
else {
AppendMenuA(hMenu, jsonItem["flags"].asInt(), jsonItem["id"].asInt(), jsonItem["text"].asCString());
}
}
return hMenu;
}
HWND createwindow(Value& json,HWND hwndParent) {
if (json["classname"].asString() == "_EL_Label") {
json["classname"] = WC_STATICA;
}
HMENU hMenu = NULL;
if (json["menuitems"].isArray()) {
hMenu = createmenu(json["menuitems"], true);
}
else {
hMenu = (HMENU)json["id"].asInt();
}
HWND hWnd = CreateWindowExA(json["exstyle"].asInt(), json["classname"].asCString(), json["text"].asCString(), json["style"].asInt(),
json["left"].asInt(), json["top"].asInt(), json["width"].asInt(), json["height"].asInt(), hwndParent, hMenu, NULL, NULL);
SendMessageA(hWnd, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT),0);
if(_stricmp( json["classname"].asCString(),WC_LISTBOXA)==0){
if (json["items"].isArray()) {
for (int i = 0; i < json["items"].size(); i++) {
Value& jsonItem = json["items"];
SendMessageA(hWnd, LB_ADDSTRING, 0, (LPARAM)jsonItem["text"].asCString());
SendMessageA(hWnd, LB_SETITEMDATA, i, jsonItem["data"].asInt());
}
SendMessageA(hWnd, LB_SETCURSEL, json["cursel"].asInt(),0);
}
}else if (_stricmp(json["classname"].asCString(), WC_COMBOBOXA)==0) {
if (json["items"].isArray()) {
for (int i = 0; i < json["items"].size(); i++) {
Value& jsonItem = json["items"];
SendMessageA(hWnd, CB_ADDSTRING, 0, (LPARAM)jsonItem["text"].asCString());
SendMessageA(hWnd, CB_SETITEMDATA, i, jsonItem["data"].asInt());
}
SendMessageA(hWnd, CB_SETCURSEL, json["cursel"].asInt(), 0);
}
return hWnd;
}
for (int i = 0; i < json["children"].size(); i++) {
createwindow(json["children"], hWnd);
}
return hWnd;
}
int main() {
HWND hwnd = FindWindowA("WTWindow", "测试中文");
Value j(ValueType::objectValue);
parsewindow(j, hwnd, true);
puts(j.toStyledString().c_str());
{
WNDCLASSEX wndClassEx{ 0 };
wndClassEx.cbSize = sizeof(WNDCLASSEX);
wndClassEx.hbrBackground = (HBRUSH)COLOR_WINDOW;
wndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClassEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wndClassEx.hInstance = NULL;
wndClassEx.lpfnWndProc = &DefWindowProc;
wndClassEx.lpszClassName = TEXT("WTWindow");
wndClassEx.lpszMenuName = NULL;
wndClassEx.style = CS_VREDRAW | CS_HREDRAW;
RegisterClassEx(&wndClassEx);
HWND hWnd = createwindow(j, NULL);
//ShowWindow(hWnd, SW_SHOW);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//printf(j.dump(2,32,false, json::error_handler_t::replace).c_str());
getchar();
}
|
评分
-
查看全部评分
|