[FormulaDraw08]WINAPI使用ComDlg.h的注意事项

本文介绍了使用memset初始化颜色通用对话框和选择文件对话框结构的过程。通过具体代码示例展示了如何设置对话框的各项属性,如文件过滤器、所有者窗口句柄等。

建立对应结构后用memset将结构体清零后再注册相关成员变量,随后调用创建ComDlg函数,范例如下:

//颜色通用对话框
COLORREF RGB_CLR,CustColors[16];
CHOOSECOLOR CD_CLR;
memset(&CD_CLR,0,sizeof(CD_CLR));
CD_CLR.lStructSize = sizeof(CHOOSECOLOR);
CD_CLR.hwndOwner = hWnd;
CD_CLR.Flags = CC_FULLOPEN;
CD_CLR.lpCustColors = (LPDWORD)CustColors;//此处不可缺


//选择文件通用对话框
OPENFILENAME FILE;
memset(&FILE,0,sizeof(FILE));  
FILE.lStructSize = sizeof(OPENFILENAME);
FILE.hwndOwner = hWnd;
FILE.hInstance = hInst;
FILE.Flags = OFN_FILEMUSTEXIST |OFN_EXPLORER;
FILE.lpstrFilter = "Formula Draw 2008 File(*.fd8)/0*.fd8/0";
FILE.nFilterIndex = 1;
FILE.nMaxFile = MAX_PATH;
FILE.lpstrFile = FILENAME;
FILE.lpstrDefExt = TEXT("*.fd8");//默认文件后缀
FILE.lpstrTitle   =   "保存图像";

`Winapi.Security.Cryptography` 是Windows API中的一部分,它提供了底层的加密服务,可用于实现各种加密算法,如对称加密、非对称加密和哈希算法等。而 `IdCipherAES` 和 `IdCipher` 是Indy库中的组件,用于实现加密功能,其中 `IdCipherAES` 专门用于AES加密,`IdCipher` 是加密类的基类。 #### 关联 当缺少 `IdCipherAES` 和 `IdCipher` 时,可以考虑使用 `Winapi.Security.Cryptography` 作为替代方案。`Winapi.Security.Cryptography` 提供了底层的加密功能,虽然使用起来相对复杂,但可以实现与 `IdCipherAES` 类似的AES加密功能。 #### 解决方案 以下是一个使用 `Winapi.Security.Cryptography` 实现AES加密和解密的示例代码: ```delphi uses Winapi.Security.Cryptography, System.SysUtils, System.TypInfo; function AESEncrypt(const Input: string; const Key: string): string; var hProv: HCRYPTPROV; hKey: HCRYPTKEY; Buffer: array [0..4095] of Byte; InputBytes: TBytes; OutputBytes: TBytes; DataLen: DWORD; Final: BOOL; begin if CryptAcquireContext(@hProv, nil, nil, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) then try InputBytes := TEncoding.UTF8.GetBytes(Input); DataLen := Length(InputBytes); SetLength(OutputBytes, DataLen + 16); // 预留一些额外空间 if CryptGenKey(hProv, CALG_AES_256, CRYPT_EXPORTABLE, @hKey) then try if CryptEncrypt(hKey, 0, TRUE, 0, @InputBytes[0], @DataLen, Length(OutputBytes)) then begin SetLength(OutputBytes, DataLen); Result := TEncoding.UTF8.GetString(OutputBytes); end; finally CryptDestroyKey(hKey); end; finally CryptReleaseContext(hProv, 0); end; end; function AESDecrypt(const Input: string; const Key: string): string; var hProv: HCRYPTPROV; hKey: HCRYPTKEY; InputBytes: TBytes; OutputBytes: TBytes; DataLen: DWORD; Final: BOOL; begin if CryptAcquireContext(@hProv, nil, nil, PROV_RSA_AES, CRYPT_VERIFYCONTEXT) then try InputBytes := TEncoding.UTF8.GetBytes(Input); DataLen := Length(InputBytes); SetLength(OutputBytes, DataLen); if CryptGenKey(hProv, CALG_AES_256, CRYPT_EXPORTABLE, @hKey) then try if CryptDecrypt(hKey, 0, TRUE, 0, @InputBytes[0], @DataLen) then begin SetLength(OutputBytes, DataLen); Result := TEncoding.UTF8.GetString(OutputBytes); end; finally CryptDestroyKey(hKey); end; finally CryptReleaseContext(hProv, 0); end; end; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值