//COM 控件查看工具 import win.ui; /*DSG{{*/ var winform = win.form(text="COM控件查看工具";right=830;bottom=648;border="dialog frame";exmode="none") winform.add( btnGen={cls="button";text="生成代码";left=711;top=605;right=796;bottom=635;db=1;dr=1;z=8}; chkLite={cls="checkbox";text="免注册调用";left=51;top=14;right=255;bottom=42;checked=1;dl=1;dt=1;z=5}; cmbCoClass={cls="combobox";left=475;top=14;right=806;bottom=39;dr=1;dt=1;edge=1;items={};mode="dropdown";z=2}; editCode={cls="richedit";left=27;top=53;right=804;bottom=562;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-15);hscroll=1;multiline=1;vscroll=1;z=1}; editConst={cls="richedit";left=28;top=53;right=805;bottom=562;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-15);hscroll=1;multiline=1;vscroll=1;z=10}; editDoc={cls="richedit";left=27;top=53;right=804;bottom=562;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-15);hscroll=1;multiline=1;vscroll=1;z=9}; editEnum={cls="richedit";left=27;top=53;right=804;bottom=562;db=1;dl=1;dr=1;dt=1;edge=1;font=LOGFONT(h=-15);hscroll=1;multiline=1;vscroll=1;z=11}; editOcxPath={cls="edit";left=27;top=606;right=701;bottom=635;align="right";db=1;dl=1;dr=1;edge=1;z=7}; navCode={cls="plus";text="调用代码";left=27;top=562;right=107;bottom=594;border={top=1;color=0xFF008000};db=1;dl=1;z=3}; navConst={cls="plus";text="常量列表";left=188;top=562;right=268;bottom=594;border={top=1;color=0xFF008000};db=1;dl=1;notify=1;z=12}; navDocument={cls="plus";text="控件文档";left=107;top=562;right=187;bottom=594;border={top=1;color=0xFF008000};db=1;dl=1;notify=1;z=14}; navEnum={cls="plus";text="枚举列表";left=268;top=562;right=348;bottom=594;border={top=1;color=0xFF008000};db=1;dl=1;notify=1;z=13}; navRight={cls="plus";left=348;top=562;right=638;bottom=563;bgcolor=0xFFFFFF;border={color=0xFF008000};db=1;dl=1;dr=1;forecolor=0x008000;linearGradient=180;z=6}; static={cls="static";text="可嵌入的COM控件:";left=307;top=17;right=456;bottom=38;align="right";dl=1;dr=1;dt=1;transparent=1;z=4} ) /*}}*/ import win.ui.tabs; var tbs = win.ui.tabs(winform.navCode,winform.navDocument,winform.navConst,winform.navEnum) tbs.margin = 0; tbs.skin({ foreground={ active=0xFFFFFFFF; default=0x00FFFFFF; hover=0xFFCCCCCC; }; checked={ foreground={ default=0x00FFFFFF; }; border = { default = {left=1;right=1;bottom=1;color=0xFF008000} }; } }); tbs.onSelChange = function(idx,strip,form){ winform.editEnum.hide = idx!=4; winform.editConst.hide = idx!=3; winform.editDoc.hide = idx!=2; winform.editCode.hide = idx!=1; } tbs.selIndex = 1; winform.editDoc.enablePopMenu(); winform.editCode.enablePopMenu(); winform.editCode.text = /* 本工具支持 VB/VC 等语言编写的 COM 控件, 请直接拖动 COM 控件到当前窗口上即可生成代码。 在 VB6 中使用 VB6 的 OCX 需要注册, 但在 aardio 中这些 OCX 控件大多不用注册就可以直接调用。 如果OCX控件是用 VB6 编写的,请注意: 1、自 XP 到 Win11,操作系统都自带 VB6 运行库,基本运行是可以的。 2、如果用V B6 编写 OCX,尽量只是调用运行库以及操作系统提供的 API。 尽可能不要调用其他 VB6 编写的控件,这可能导致莫名其妙的问题且难以排查。. */ var codeTemplate = /******* import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469) winform.add( static={cls="static";text="控件";left=11;top=10;right=745;bottom=455;db=1;dl=1;dr=1;dt=1;transparent=1;z=1} ) /*}}*/ import com.activeX; com.activeX.appData("aardio/com/${FILENAME}",$"${PATH}") var axCtrl = winform.static.createEmbedEx("${GUID}"); winform.show(); win.loopMessage(); *******/ var codeTemplateLite = /******* import win.ui; /*DSG{{*/ var winform = win.form(text="aardio form";right=759;bottom=469) winform.add( static={cls="static";text="控件";left=11;top=10;right=745;bottom=455;db=1;dl=1;dr=1;dt=1;transparent=1;z=1} ) /*}}*/ import com.lite; var dll = com.lite.appData("aardio/com/${FILENAME}",$"${PATH}") var axEmbed = dll.createEmbedEx(winform.static,"${GUID}"); winform.show(); win.loopMessage(); *******/ import raw.pefile; var loadTypeAttrs = function(path,typekind){ var pefile = raw.pefile(path); if( (pefile.majorLinkerVersion ==6) && pefile.isImported("MSVBVM60.DLL") ){ winform.chkLite.checked = true; } var tlb; try{ tlb = ..com.LoadTypeLibrary(path); } if(!tlb) return; var r = {} for(i=1;tlb.GetTypeInfoCount()){ var info = tlb.GetTypeInfo(i) var attr = info.GetTypeAttr(); if(attr){ if( typekind && typekind != attr.typekind) continue; attr.name = info.GetDocumentation()[["name"]]; ..table.push(r,attr); for(i=1;attr.ImplTypes;1){ var flags = info.GetImplTypeFlags(i); if(flags[["default"]] && !flags["source"]){ attr.defaultImpltypeInfo = (attr.defaultImpltypeInfo:"") + info.GetImplType(i).DumpTypeInfo(); } } } } var getString = function( tab ){ var strResult = ..table.tostring(tab); strResult = string.replace(strResult,";",';\n'); strResult = string.replace(strResult,"\{ *",'{\n'); strResult = string.replace(strResult,"\}",'\n}'); strResult = string.trim(strResult,"{}");//去掉首尾的构造符 return string.trim(strResult); } var enums = tlb.ExportEnumerations() winform.editEnum.text = getString(enums) var const = {} tlb.ExportConstants(const) const = getString(const) const = string.replace(const,"\n\n+",'\n'); winform.editConst.text = const; return r; } import com.tlbDoc; import com.lite; winform.onDropFiles = function(files){ var path = files[1] var attrs = loadTypeAttrs(files[1],"coclass"); if(!#attrs){return;} winform.cmbCoClass.clear(); winform.cmbCoClass.typeLibAttrs = attrs; for(i=1;#attrs;1){ winform.cmbCoClass.add(attrs[i].name + " " + attrs[i].GUID) } winform.editOcxPath.text = path; winform.cmbCoClass.ocxFilePath = path; winform.cmbCoClass.selIndex = 1; winform.cmbCoClass.onSelChange(); winform.editDoc.text = com.tlbDoc(path); } import string.template; winform.cmbCoClass.onSelChange = function(){ if(!winform.cmbCoClass.selIndex){ return; } var typeAttr = winform.cmbCoClass.typeLibAttrs[[winform.cmbCoClass.selIndex]] if(typeAttr){ var codeTemp = string.template(); if( typeAttr.flags.hidden ) return; if(winform.chkLite.checked){ codeTemp.template = codeTemplateLite; } else { codeTemp.template = codeTemplate; } winform.editCode.text = codeTemp.format( GUID=typeAttr.GUID; PATH=winform.cmbCoClass.ocxFilePath; FILENAME=io.splitpath(winform.cmbCoClass.ocxFilePath).file; IMPLTYPEINFO=typeAttr.defaultImpltypeInfo; ) } } winform.chkLite.oncommand = function(id,event){ winform.cmbCoClass.onSelChange(); } winform.btnGen.oncommand = function(id,event){ var path = ..io.exist(winform.editOcxPath.text) if(!path) return winform.msgboxErr("请检查控件文件路径是否正确") var attrs = loadTypeAttrs(path,"coclass"); if(!#attrs){return;} winform.cmbCoClass.clear(); winform.cmbCoClass.typeLibAttrs = attrs; for(i=1;#attrs;1){ winform.cmbCoClass.add(attrs[i].name + " " + attrs[i].GUID) } winform.cmbCoClass.ocxFilePath = path; winform.cmbCoClass.selIndex = 1; winform.cmbCoClass.onSelChange() winform.editDoc.text = com.tlbDoc(path); } winform.show() win.loopMessage();