
// using fnQApplication_topLevelWidgets = QListData * (_cdecl*)(void*);
var fnQApplication_topLevelWidgets = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?topLevelWidgets@QApplication@@SA?AV?$QList@PAVQWidget@@@@XZ'),
  'pointer', 
  ['pointer'],
  'mscdecl'
);

// ?x@QWidget@@QBEHXZ
// 符号(已解码)=public: int __thiscall QWidget::x(void)const
var fnQWidget_x = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?x@QWidget@@QBEHXZ'),
  'int', 
  ['pointer'],
  'thiscall'
);
// ?y@QWidget@@QBEHXZ
// 符号(已解码)=public: int __thiscall QWidget::y(void)const
var fnQWidget_y = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?y@QWidget@@QBEHXZ'),
  'int', 
  ['pointer'],
  'thiscall'
);
// ?mapFromGlobal@QWidget@@QBE?AVQPoint@@ABV2@@Z
// 符号(已解码)=public: class QPoint __thiscall QWidget::mapFromGlobal(class QPoint const &)const
var fnQWidget_mapFromGlobal = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?mapFromGlobal@QWidget@@QBE?AVQPoint@@ABV2@@Z'),
  'pointer', 
  ['pointer', 'pointer', 'pointer'],
  'thiscall'
);
// ?mapToGlobal@QWidget@@QBE?AVQPoint@@ABV2@@Z
// 符号(已解码)=public: class QPoint __thiscall QWidget::mapToGlobal(class QPoint const &)const
var fnQWidget_mapToGlobal = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?mapToGlobal@QWidget@@QBE?AVQPoint@@ABV2@@Z'),
  'pointer', 
  ['pointer', 'pointer', 'pointer'],
  'thiscall'
);

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 获取相对于顶层窗口的坐标
function ez_fnQWidget_pos(obj) {
  var qpoint_param = Memory.alloc(8);
  try {
    var ret = fnQWidget_pos(obj, qpoint_param);
    var x = ret.add(0).readS32();
    var y = ret.add(4).readS32();
    // MyLogD('\t\t ez_fnQWidget_pos', qpoint_param.readU64().toString(16), ',x=', x, ',y=', y);
  } catch (error) {
    MyLogE('【catch】 ez_fnQWidget_pos', error);
  }

  return ret;
}
function ez_fnQWidget_mapFromGlobal(obj, point) {
  var ret;
  try {
    var ret2 = Memory.alloc(8);
    ret = fnQWidget_mapFromGlobal(obj, ret2, point);
    var x = ret.add(0).readS32();
    var y = ret.add(4).readS32();
    MyLogD('\t\t ez_fnQWidget_mapFromGlobal', ret2.readU64().toString(16), ',x=', x, ',y=', y);
  } catch (error) {
    MyLogE('【catch】 ez_fnQWidget_mapFromGlobal', error, ret);
  }

  return ret;
}
function ez_fnQWidget_mapFromGlobal_x(obj) {
  try {
    var pos = ez_fnQWidget_pos(obj);
    var pos2 = ez_fnQWidget_mapFromGlobal(obj, pos);
    if (pos2) {
      return pos2.readU32();
    }    
  } catch (error) {
    
  }
  return -1;
}
function ez_fnQWidget_mapFromGlobal_y(obj) {
  try {
    var pos = ez_fnQWidget_pos(obj);
    var pos2 = ez_fnQWidget_mapFromGlobal(obj, pos);
    if (pos2) {
      return pos2.add(4).readU32();
    }    
  } catch (error) {
    
  }
  return -2;
}
function ez_fnQWidget_mapFromGlobal_xy(obj) {
  try {
    var pos = ez_fnQWidget_pos(obj);
    // MyLogD('【 111 】 ez_fnQWidget_mapFromGlobal_xy', pos);
    if(pos) {
      var pos2 = ez_fnQWidget_mapFromGlobal(obj, pos);
      // MyLogD('【 222 】 ez_fnQWidget_mapFromGlobal_xy', pos2);
      if (pos2) {
        // MyLogD('【 333 】 ez_fnQWidget_mapFromGlobal_xy', pos2);
        return `${pos2.readS32()},${pos2.add(4).readS32()}`;
      }
    } 
  } catch (error) {
    MyLogE('【catch】 ez_fnQWidget_mapFromGlobal_xy', error);
  }
  return `-1,-2`;
}
function ez_fnQWidget_mapToGlobal(obj, point) {
  var ret2 = Memory.alloc(8);
  try {
    var ret = fnQWidget_mapToGlobal(obj, point, ret2);
    // var x = ret.add(0).readS32();
    // var y = ret.add(4).readS32();
    // MyLogD('\t\t ez_fnQWidget_mapToGlobal', ret2.readU64().toString(16), ',x=', x, ',y=', y);
  } catch (error) {
    MyLogE('【catch】 ez_fnQWidget_mapToGlobal', error);
  }
  return ret2;
}
function ez_fnQWidget_mapToGlobal_xy(obj) {
  try {
    var pos = ez_fnQWidget_pos(obj);
    // MyLogD('【 111 】 ez_fnQWidget_mapToGlobal_xy', pos);
    if(pos) {
      var pos2 = ez_fnQWidget_mapToGlobal(obj, pos);
      // MyLogD('【 222 】 ez_fnQWidget_mapToGlobal_xy', pos2);
      if (pos2) {
        // MyLogD('【 333 】 ez_fnQWidget_mapToGlobal_xy', pos2);
        return `${pos2.readS32()},${pos2.add(4).readS32()}`;
      }
    } 
  } catch (error) {
    MyLogE('【catch】 ez_fnQWidget_mapToGlobal_xy', error);
  }
  return `-1,-2`;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

// ?isVisible@QWidget@@QBE_NXZ
// public: bool __thiscall QWidget::isVisible(void)const
var fnQWidget_isVisible = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?isVisible@QWidget@@QBE_NXZ'),
  'bool', 
  ['pointer'],
  'thiscall'
);
// public: class QPoint __thiscall QWidget::pos(void)const
var fnQWidget_pos = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?pos@QWidget@@QBE?AVQPoint@@XZ'),
  'pointer', 
  ['pointer', 'pointer'],
  'thiscall'
);
// public: class QSize __thiscall QWidget::size(void)const
var fnQWidget_size = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?size@QWidget@@QBE?AVQSize@@XZ'),
  'pointer', 
  ['pointer', 'pointer'],
  'thiscall'
);



// public: void __thiscall QLineEdit::setText(class QString const &)
var fnQLineEdit_setText = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?setText@QLineEdit@@QAEXABVQString@@@Z'),
  'void', 
  ['pointer', 'pointer'],
  'thiscall'
);
// public: void __thiscall QLineEdit::textChanged(class QString const &)
var fnQLineEdit_textChanged = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?textChanged@QLineEdit@@QAEXABVQString@@@Z'),
  'void', 
  ['pointer', 'pointer'],
  'thiscall'
);
// public: void __thiscall QCheckBox::setCheckState(enum Qt::CheckState)
var fnQCheckBox_setCheckState = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?setCheckState@QCheckBox@@QAEXW4CheckState@Qt@@@Z'),
  'void', 
  ['pointer', 'int'],
  'thiscall'
);
// public: void __thiscall QAbstractButton::setChecked(bool)
var fnQAbstractButton_setChecked = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?setChecked@QAbstractButton@@QAEX_N@Z'),
  'void', 
  ['pointer', 'bool'],
  'thiscall'
);
// 符号(已解码)=public: void __thiscall QAbstractButton::click(void)
var fnQAbstractButton_click = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?click@QAbstractButton@@QAEXXZ'),
  'void', 
  ['pointer'],
  'thiscall'
);
// fnQAbstractButton_click(ptr(my_read_u32(ptr(0xee7178).add(0x70))))

// 符号=?text@QAbstractButton@@QBE?AVQString@@XZ
// 符号(已解码)=public: class QString __thiscall QAbstractButton::text(void)const
var fnQAbstractButton_text = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?text@QAbstractButton@@QBE?AVQString@@XZ'),
  'pointer', 
  ['pointer', 'pointer'],
  'thiscall'
);
function ez_fnQAbstractButton_text(obj) {
  var s = ez_fnQString_fromUtf8('')
  fnQAbstractButton_text(obj, s);
  return QString2JsString(s)
}



// public: class QString __thiscall QLabel::text(void)const
var fnQLabel_text = new NativeFunction(
  Module.findExportByName('Qt5Widgets.dll', '?text@QLabel@@QBE?AVQString@@XZ'),
  'void', 
  ['pointer','pointer'],
  'thiscall'
);
function ez_fnQLabel_text(obj) {
  // var retQString = Memory.alloc(Process.pointerSize);
  var retQString = ez_fnQString_fromUtf8('');
  fnQLabel_text(obj, ptr(retQString));
  MyLogD(retQString);
  return my_read_u32_to_obj(retQString).add(0x10).readUtf16String();
}
