发布网友 发布时间:2022-04-26 07:43
共1个回答
热心网友 时间:2022-06-25 10:43
非常实用!---- 1.颜色选择API封装对象nvo_ChooseColor---- 先创建一新非可视用户对象,并声明一局部结构ols_ChooseColor long lstructsize ulong hwndowner ulong hinstance long rgbresult blob lpcustcolors long flags long lcustdata long lpfnhook long lptemplatename 然后定义如下的私有实例变量: Private: Ols_ChooseColor istr_choosecolor long il_custominitcolors[16] blob{64} ibl_customcolors 再声明如下局部外部函数: function boolean ChooseColorA (ref os_choosecolor lpcc) library "comdlg32.dll" 在用户对象的构造事件中加入下述代码: //初始化结构实例变量,转换缺省的颜色数组到一BLOB变量中 blobedit(ibl_customcolors,1,il_custominitcolors) istr_choosecolor.lpcustcolors = ibl_customcolors //设置客户定义颜色的指针 istr_choosecolor.lstructsize = 36 //设置结构尺寸 setnull(istr_choosecolor.hwndowner) //设置父窗变量为空 istr_choosecolor.flags = 1 //设置标志 最后声明一公有用户对象函数: public function boolean of_choosecolor (ref long al_rgbresult) 在函数内加入下述代码: boolean lb_ok istr_choosecolor.rgbresult = al_rgbresult lb_ok = choosecolora (istr_choosecolor) al_rgbresult = istr_choosecolor.rgbresult return lb_ok 保存用户对象名为nvo_ChooseColor即可 使用方法:在需要处加入如下代码 long ll_customcolor nvo_ChooseColor nvo_cc nvo_cc = CREATE nvo_ChooseColor of_choosecolor(ll_customcolor) DESTROY nvo_cc ll_customcolor即含有用户选择的色值 ---- 2.目录选择API封装对象nvo_FolderBrowse---- 先创建一新非可视用户对象,并声明若干局部结构 结构一 ols_shitemid unsignedint cb character abid 结构二 ols_itemidlist shitemid mkid 结构三 ols_browseinfo unsignedlong howner unsignedlong pidlroot string pszdisplayname string lpsztitle unsignedint ulflags unsignedlong lpfn long lparam integer iimage 然后声明如下局部外部函数: Protected: Function unsignedlong SHGetPathFromIDListA ( unsignedlong pidl, ref string pszPath) Library 'shell32' Function unsignedlong SHBrowseForFolderA ( ols_browseinfo lpbrowseinfo ) Library 'shell32' Subroutine CoTaskMemFree(ulong idlist) Library 'ole32' 再声明如下实例变量: Protected: unsignedLong BIF_RETURNONLYFSDIRS = 1 声明一公有对象函数 public function string browseforfolder (window awi_parent, string as_caption) 并加入如下代码 ols_browseinfo lstr_bi ols_itemidlist lstr_idl unsignedlong ll_pidl, ll_r,ll_Null Integer li_pos String ls_Path SetNull( ll_Null ) lstr_bi.hOwner = Handle( awi_Parent ) lstr_bi.pidlRoot = 0 lstr_bi.lpszTitle = as_caption lstr_bi.ulFlags = bif_ReturnOnlyFSDirs lstr_bi.pszDisplayName = Space( 255 ) lstr_bi.lpfn = ll_Null ll_pidl = SHBrowseForFolderA( lstr_bi ) ls_Path = Space( 255 ) ll_R = SHGetPathFromIDListA( ll_pidl, ls_Path ) CoTaskMemFree( ll_pidl ) RETURN ls_Path 保存对象名为nvo_FolderBrowse即可 使用方法:在需要处加入如下代码 nvo_FolderBrowse nvo_fb String ls_path nvo_fb=CREATE nvo_FolderBrowse ls_path = nvo_fb.BrowseForFolder ( handle(parent), '请选择目标路径' ) DESTROY nvo_fb ls_path是用户选择的目录路径 ---- 3.打印机属性设置对话框API封装对象nvo_PrinterSetup---- 先创建一新的非可视用户对象,然后声明如下局部外部函数: function boolean OpenPrinterA (ref string pPrinterName,ref ulong phPrinter,ref ulong pDefault ) library "winspool.drv" function boolean PrinterProperties (ulong hwnd1,ulong hPrinter) library "winspool.drv" function boolean ClosePrinter (ulong hPrinter) library "winspool.drv" 最后声明一公有的用户对象函数: public function boolean of_printersetup (string printername,window awin) 加入下述代码: ulong hwnd //父窗口句柄 ulong prnhd //打印机设备句柄 ulong l=0 hwnd=handle(awin) if openprintera(printername,prnhd,l) =false then return false PrinterProperties(hwnd,prnhd) closeprinter(prnhd) return true 将对象另存为nvo_PrinterSetup即可 使用方法:在需要处加入如下代码(假定为一按钮的点击事件) nvo_PrinterSetup nvo_ps window win win = parent nvo_ps = CREATE nvo_PrinterSetup if not of_printersetup(prnname,win) then messagebox("提示","打开打印机失败!") DESTROY nvo_ps ---- 注:printername是目标打印机名,可用系统当前打印机也可用别的已安装的打印机。通常是从下拉列表控件中获得