修改ShowDialog弹出对话框窗口样式,增加最大化最小化按钮

仅供参考

function SetWindowLong(){    

    const user32 = ffi.LoadLibrary("user32.dll",{    

             IsWindow : { returnType: "bool", parameters: ["uint32"] },
             GetWindowLongW : { returnType: "uint32", parameters: ["uint32","int32"] },
             SetWindowLongW : { returnType: "uint32", parameters: ["uint32","int32","uint32"] },
             FindWindowW: {returnType: "uint32", parameters: ["pointer","pointer"]}
    })
    
    const u16str = ffi.Buffer("u16string")
    const captionStr = new u16str("WPS 基础接口 参考文档")  //对话框窗口 标题
    const classStr = new u16str("Qt5QWindowIcon")             //对话框窗口 类
    
    const dialogHwnd = user32.FindWindowW(FFI.BigIntToPointer(classStr.ref().Read("uint32",0)),FFI.BigIntToPointer(captionStr.ref().Read("uint32",0)))
    console.log("对话框窗口句柄:" + dialogHwnd)
    
    let result = user32.IsWindow(dialogHwnd)
    console.log("对话框窗口是否存在:" + result)
    
    let style = user32.GetWindowLongW(dialogHwnd,-16)
    console.log("当前窗口样式:"+style)
    
    //0x16cf0000 设置最大化 最小化按钮。0x16cc0000 取消最大化 最小化按钮
    let laststyle = user32.SetWindowLongW(dialogHwnd,-16,0x16cf0000)
    console.log("上一次窗口样式:"+laststyle)    
    
}

加载项实现过程

function doAction() {		
let hwnd = wps.Application.ExecuteExcel4Macro(`CALL("user32","FindWindowA","JCC","Qt5QWindowIcon","WPS 基础接口 参考文档")`)
console.log("对话框窗口查找结果:" + hwnd);	
if (!hwnd) {		
let mydialog = wps.ShowDialog(Application.Env.GetAppDataPath() + "/kingsoft/wps/jsaddons/WPS_ADDINS_0.03/WPS_API_REFERENCE.html","WPS 基础接口 参考文档",1500,700,false,true,true);		
console.log("对话框窗口创建结果:" + mydialog);		
if(mydialog){						
hwnd = wps.Application.ExecuteExcel4Macro(`CALL("user32","FindWindowA","JCC","Qt5QWindowIcon","WPS 基础接口 参考文档")`)			
if(hwnd){				
let style = wps.Application.ExecuteExcel4Macro(`CALL("user32","GetWindowLongW","JJJ",${hwnd},-16)`)				
console.log("style:" + style)				
let laststyle = wps.Application.ExecuteExcel4Macro(`CALL("user32","SetWindowLongW","JJJJ",${hwnd},-16,382664704)`)				
console.log("laststyle:" + laststyle)			
}else{				
console.log("未找到窗口句柄")			
}		
}else{			
console.log("创建对话框失败")		
}	
}else{				    		
let mydialog = wps.Application.ExecuteExcel4Macro(`CALL("user32","PostMessageA","JJJJJ",${hwnd},16,0,0)`)			
//wps.PluginStorage.setItem("taskpaneid", 0);			
console.log("对话框窗口销毁结果:" + mydialog);			
}			
return true;
}

黑龙江省
浏览 85
2
7
分享
7 +1
2
2 +1
全部评论 2
 
初心不忘
正想写这个功能,白嫖了大佬
· 江苏省
回复
恰同学少年
互助,共勉!
· 黑龙江省
回复