從 windows me、windows 2000 開始,用于 getopenfilename() 和 getsavefilename() 函數的 openfilename 結構添加了三個新元素。我們先來看一下:
type openfilename
lstructsize as long
hwndowner as long
hinstance as long
lpstrfilter as string
lpstrcustomfilter as string
nmaxcustfilter as long
nfilterindex as long
lpstrfile as string
nmaxfile as long
lpstrfiletitle as string
nmaxfiletitle as long
lpstrinitialdir as string
lpstrtitle as string
flags as long
nfileoffset as integer
nfileextension as integer
lpstrdefext as string
lcustdata as long
lpfnhook as long
lptemplatename as string
'#if (_win32_winnt >= 0x0500)
pvreserved as long
dwreserved as long
flagsex as long
'#endif // (_win32_winnt >= 0x0500)
end type
關于新的元素 pvreserved、dwreserved 不難看出是保留的,可能 windows me、windows 2000 發布的時候尚未完成相關功能,所以……不過,flagsex 元素倒是有一個可以使用的參數 ofn_ex_noplacesbar(1)。設置了這個位標記可以關閉 windows 2000(或 windows me) “打開文件”對話框左邊的快捷欄。這個快捷欄總共可以存放五個快捷方式,可以通過修改注冊表來指定自己的快捷方式。至于如何修改,不是我們今天的話題,所以暫且不討論。但是,在實際使用中,我發現了一個問題:采用這種新結構的程序無法在 windows 98/95/nt4 上面運行。原因可能是設置 lstructsize 時算入了新的三個成員,導致結構長度增加 12 個字節,而舊版本的 comdlg32.dll 無法辨認,誤認為結構長度錯誤。其最終結果就是“打開文件”和“保存文件”對話框無法顯示。
鑒于這個問題,我們采用了如下思路解決:用 getversionex() 函數檢測 windows 版本,如果不是 windows me、windows 2000,就在用 len() 算出 openfilename 結構長度之后減去 12 字節,再賦值給 lstructsize。這樣,就版本的 comdlg32.dll 就會忽略新增的三個元素。經實踐,證明這種方法可行。
當然,我們還考慮到可能有的 windows 95/98/nt4 由于某些軟件的安裝而擁有新版本的 comdlg32.dll,這樣就完全可以使用新的特性了。所以最好的辦法還是檢測 comdlg32.dll 本身的版本,再決定 openfilename 結構的長度是否要忽略新的三個元素的長度。
國內最大的酷站演示中心!新聞熱點
疑難解答