從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 結構的長度是否要忽略新的三個元素的長度。
國內最大的酷站演示中心!