谁有测试软盘和打印机是否准备好的代码?
或者谁知道哪儿有下载!最近小弟开发一个软件遇到点问题!!!
谢谢了!
*!* 先通过SET(‘PRINTER’,2)等方法获取名称(如:BJC-255SP),然后再通过注册表获取相关信息。如下: *!* [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\BJC-255SP] *!* "ChangeID"=dword:024f329e *!* "Status"=dword:00000180 *!* "Name"="BJC-255SP" *!* "Share Name"="" *!* "Print Processor"="WinPrint" *!* "Datatype"="RAW" *!* "Parameters"="" *!* "ObjectGUID"="" *!* "DsKeyUpdate"=dword:00000003 *!* "Description"="" *!* "Printer Driver"="Canon Bubble-Jet BJC-255SP" * 或者直接写10进制数:
#DEFINE HKEY_CLASSES_ROOT 2147483648 && 0x80000000,或用负数: -2147483648 #DEFINE HKEY_CURRENT_USER 2147483649 && 0x80000001,-2147483647 #DEFINE HKEY_LOCAL_MACHINE 2147483650 && 0x80000002,-2147483646 #DEFINE HKEY_USERS 2147483651 && 0x80000003,-2147483645 #DEFINE HKEY_PERFORMANCE_DATA 2147483652 && 0x80000004,-2147483644 #DEFINE HKEY_CURRENT_CONFIG 2147483653 && 0x80000005,-2147483643 #DEFINE HKEY_DYN_DATA 2147483654 && 0x80000006,-2147483642
* 键值的数据类型:1-字符串,3-二进制,4-整数 #DEFINE REG_NONE 0 && Undefined Type #DEFINE REG_SZ 1 && 0~多个字节, 以一个null字符结尾的字符串 #DEFINE REG_EXPAND_SZ 2 && 0~多个字节, 以一个null字符结尾的字符串 && 包含 OS 环境变量 #DEFINE REG_BINARY 3 && 0~多个字节, 可以包含任何数据的二进制 #DEFINE REG_DWORD 4 && 4字节 DWORD值 #DEFINE REG_DWORD_BIG_ENDIAN 5 && 4字节 一个DWORD值的逆序存储形式 #DEFINE REG_MULTI_SZ 7 && 0~多个字节, 以null字符分隔的字符串集合, && 集合中的最后一个字符串以两个null字符结尾 lsPrinterName=SET("Printer" ,2) LOCAL nKey, cSubKey, cEntry, cvalueRead nKey =HKEY_LOCAL_MACHINE cSubKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\&lsPrinterName." cEntry = "Printer Driver" cvalueRead = ReadREG_SZ(nKey, cSubKey, cEntry) IF (EMPTY(cvalueRead)) THEN =MESSAGEBOX("从注册表读打印机 [&lsPrinterName.] 驱动信息失败.") ELSE =MESSAGEBOX("从注册表读打印机 [&lsPrinterName.] 驱动信息是: '" + cvalueRead + "'") ENDIF RETURN
*====================================================================== FUNCTION ReadREG_SZ * 读注册表字符串值(REG_SZ 或 REG_EXPAND_SZ)
* This function reads a REG_SZ value from the registry. * If successful, it will return the value read. * If not successful, it will return an empty string. LPARAMETERS tnHKey, tcSubKey, tcEntry * tnHKey The root key to open. It can be any of the constants defined below. * #DEFINE HKEY_CLASSES_ROOT -2147483648 * #DEFINE HKEY_CURRENT_USER -2147483647 * #DEFINE HKEY_LOCAL_MACHINE -2147483646 * #DEFINE HKEY_USERS -2147483645 * tcSubKey The SubKey to open. * tcEntry The value that is going to be read.
* WIN 32 API functions that are used DECLARE Integer RegOpenKey IN ADVAPI32.DLL ; Integer nHKey, String @cSubKey, Integer @nResult
*!* DECLARE Integer RegQueryvalueEx IN ADVAPI32.DLL ; *!* Integer nHKey, String lpszvalueName, Integer dwReserved,; *!* Integer @lpdwType,string @lpbData, Integer @lpcbData Declare Integer RegQueryvalueEx IN ADVAPI32.DLL ; Integer nKey, ; String cvalueName, ; Integer nReserved, ; Integer @nType, ; String @cBuffer, ; Integer @nBufferSize
DECLARE Integer RegCloseKey IN ADVAPI32.DLL ; Integer nHKey
* Local variables used LOCAL nErrCode && Error Code returned from Registry functions LOCAL nKeyHandle && Handle to Key that is opened in the Registry LOCAL lpdwvalueType && Type of value that we are looking for LOCAL lpbvalue && The data stored in the value LOCAL lpcbvalueSize && Size of the variable LOCAL lpdwReserved && Reserved Must be 0
tnHKey = IIF(TYPE("tnHKey") = "N", tnHKey, HKEY_LOCAL_MACHINE)
* Initialize the variables nKeyHandle = 0 lpdwReserved = 0 lpdwvalueType = REG_SZ lpbvalue = ""
nErrCode = RegOpenKey(tnHKey, tcSubKey, @nKeyHandle) * If the error code isn't 0, then the key doesn't exist or can't be opened. IF (nErrCode # 0) THEN RETURN "" ENDIF
lpcbvalueSize = 1 * Get the size of the data in the value nErrCode = RegQueryvalueEx(nKeyHandle, tcEntry, lpdwReserved, ; @lpdwvalueType, @lpbvalue, @lpcbvalueSize)
* Make the buffer big enough lpbvalue = SPACE(lpcbvalueSize) nErrCode = RegQueryvalueEx(nKeyHandle, tcEntry, lpdwReserved, ; @lpdwvalueType, @lpbvalue, @lpcbvalueSize)
= RegCloseKey(nKeyHandle) IF (nErrCode # 0) THEN RETURN "" ENDIF
lpbvalue = LEFT(lpbvalue, lpcbvalueSize - 1) RETURN lpbvalue