时间: 2021-07-31 作者:daque
在windows 95/nt/98操纵体例中变换文献翻开办法的题目,又可称为变换文献典型关系的题目,即把某典型(扩充名)的文献与某运用步调关系,比方常常当双击*.txt文献时体例机动挪用notepad.exe。正文引见运用windows备案表编纂器regedit.exe细工或编制程序变换文献翻开办法的本领,并供给步调范例。 一、基础思绪: 1、备案表编纂器regedit.exe是用来变动体例备案表树立的高档东西,包括了对于体例摆设及运转的要害消息,默许考察路途为c:\windows\regedit.exe。双击regedit.exe图标,运转备案表编纂器。在左侧表露栏内看到hkey_classes_root、key_current_user、hkey_local_machine等主键。与文献典型相关的一切主键、键名、键值都寄存在hkey_classes_root下。 ◆双击hkey_classes_root,向下拖动震动条,找到.txt主键,右侧表露栏内“txtfile”证明:在hkey_classes_root下有一txtfile主键,其下寄存了翻开*.txt文献运用步调的相关消息。 ◆向下拖动震动条,找到txtfile主键,右侧表露栏内“文正文档”为文献典型刻画。双击txtfile,defaulticon右侧表露栏内“shell32.dll,-152”为*.txt文献的图标;shell\open\command,右侧表露栏内“c:\windows\notepad.exe %1”为翻开*.txt文献的运用步调称呼及参数。 变换翻开文献办法的本领(比方用visio翻开*.exc文献): ◆细工:翻开体例备案表,在hkey_classes_root下找到.exc及另一主键名,找到此主键,将shell\open\command右侧表露栏内“c:\windows\notepad.exe %1”改为“c:\visio.exe %1”(假如visio.exe的考察路途是c:\,简直视情景而定),按f5革新体例备案表。 ◆编制程序:运用vb、delphi、c++builder等读写体例备案表,可机动变换文献翻开办法。正文供给vb、delphi编制程序范例。 二、编制程序范例: ㈠运用vb编制程序 1、在vb5.0 ide中,兴建工程project1,在form1上增添吩咐按钮command1。 2、采用菜单“工程”—“增添模块”—“模块”—“翻开”,在project第11中学增添模块moudle1。 3、在moudle1“通用—证明”局部证明api因变量和恒量。 const reg_sz = 1 global const hkey_classes_root = &h80000000declare function osregqueryvalueex lib “advapi32”alias “regqueryvalueexa”(byval hkey as long, byval lpszvaluename as string,byval dwreserved as long, lpdwtype as long, lpbdata as any, cbdata as long) as longdeclare function osregopenkey lib “advapi32”alias “regopenkeya”(byval hkey as long, byval lpszsubkey as string, phkresult as long) as longdeclare function osregsetvalueex lib“advapi32”alias “regsetvalueexa”(byval hkey as long, byval lpszvaluename as string,byval dwreserved as long, byval fdwtype as long, lpbdata as any, byval cbdata as long) as longdeclare function osregclosekey lib“advapi32”alias “regclosekey”(byval hkey as long) as long 4、在moudle 第11中学编写因变量。 function regopenkey(byval hkey as long, byval lpszsubkey as string,phkresult as long) as boolean dim lresult as long on error goto 0 ` 封闭缺点组织 lresult = osregopenkey(hkey, lpszsubkey, phkresult) if lresult = 0 then regopenkey = true else regopenkey = false end if end function function regsetstringvalue(byval hkey as long, byval strvaluename as string,byval strdata as string, optional byval flog) as boolean dim lresult as long on error goto 0 lresult = osregsetvalueex(hkey, strvaluename, 0&, reg_sz, byval strdata,lenb(strconv(strdata, vbfromunicode)) + 1) if lresult = 0 then regsetstringvalue = true else regsetstringvalue = false end if end function function stripterminator(byval strstring as string) as string dim intzeropos as integer intzeropos = instr(strstring, chr$(0)) if intzeropos > 0 then stripterminator=left$(strstring, intzeropos - 1) else stripterminator = strstring end if end function function regquerystringvalue(byval hkey as long, byval strvaluename as string,strdata as string) as boolean dim lresult as long dim lvaluetype as long dim strbuf as string dim ldatabufsize as long regquerystringvalue = false on error goto 0 lresult = osregqueryvalueex(hkey, strvaluename, 0&, lvaluetype, byval 0&,ldatabufsize) if lresult = error_success then if lvaluetype = reg_sz then strbuf = string(ldatabufsize, “”) lresult = osregqueryvalueex(hkey, strvaluename, 0&, 0&, byval strbuf,ldatabufsize) if lresult = error_success then regquerystringvalue = true strdata = stripterminator(strbuf) end if end if end if end function 5、双击command1,编写click事变代码。 private sub command1_click() dim hkey as long dim myreturn as long dim mydata as string myreturn = osregopenkey(hkey_classes_root, “.exc”, hkey) myreturn=regquerystringvalue(hkey,“”,mydata) myreturn=osregopenkey(hkey_classes_root, mydata+“\shell\open\command”,hkey) myreturn = regsetstringvalue(hkey,“”,“c:\visio.exe 1%”, false) if myreturn then msgbox “变换文献翻开办法胜利!”,vbinformation,“请提防” else msgbox “变换文献翻开办法波折!”,vbexclamation,“请提防” end if osregclosekey (hkey) end sub 6、按f5运路途序,在简体华文windows95/nt/98、vb5.0/6.0情况中调节和测试经过。