Hi, i want SHBrowseForFolder function in my RGSS, i have this code:
# =============================================================================
module SHBrowseForFolder# by Newold
#--------------------------------------------------------------------------
# Open finder folder dialog
SHBrowseForFolder = Win32API.new('shell32', 'SHBrowseForFolder', 'p', 'l')
# Get path
SHGetPathFromIDList = Win32API.new('shell32', 'SHGetPathFromIDList', 'lp', 'l')
# send msg
SendMessage = Win32API.new('User32','SendMessage','lllp','l')
# last dir checked
@pidlRoot = 0
@lastBuffer = ""
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
def new(hWndOwner=0,pIDLRoot=0,pszDisplayName="\0" * 260,
lpszTitle="Select Folder with a RPG Maker proyect:",
ulFlags=0,lpfnCallback=nil,lParam=0,iImage=-1)
begin
buffer = "\0" * 260
browseInfo = [hWndOwner.to_i,pIDLRoot.to_i,pszDisplayName,
lpszTitle,ulFlags.to_i,lpfnCallback,lParam.to_i,
iImage.to_i].pack("llpplpll")
@pidlRoot = idList = SHBrowseForFolder.(browseInfo) rescue 0
return false if idList == 0
SHGetPathFromIDList.(idList,buffer)
buffer.delete!("\0")
@lastBuffer = buffer.dup
buffer.gsub!("\\","/")
unless buffer.match(/\/$/) or buffer.size == 0
buffer << '/'
end
return buffer
rescue Exception => e
return ''
end
end
#--------------------------------------------------------------------------
def lastPID
return @pidlRoot
end
#--------------------------------------------------------------------------
end
# =============================================================================
I can get a path from dir with this, (DIR = SHBrowseForFolder.new) but i dont know how set initial dir in find folder dialog.
I know i have to pass a BrowseCallbackProc at param lpfnCallback in my function
def browseCallbackProc(hwnd, uMsg, lParam, lpData)
case uMsg
when BFFM_INITIALIZED
if(lpData)
SendMessage.(hwnd, BFFM_SETSELECTION, 1, lpData);
end
when BFFM_SELCHANGED
when BFFM_VALIDATEFAILED
else
end
return 0;
end
As I do then to set a default directory, for example "c:\ program files"
I have another problem. When i call finder folder dialog i need to use a rescue because some times, after you select a folder and press ok button, it go to crash and i dont know why :(