Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Retrieve multiple files

28 views
Skip to first unread message

Ampere Kana

unread,
Jul 16, 2010, 6:49:08 AM7/16/10
to
Hi,
A file open box usually only retrieve one file. Can I retrieve or
highlight multiple files by x++?

Thanks a lot.
Ampere

Alex K. at dot

unread,
Jul 20, 2010, 8:15:15 AM7/20/10
to
Hi,

Sure you can, however you should modify some forms and classes.


1. You need to create new EDT similar to \Data Dictionary\Extended Data
Types\FilenameOpen (duplicate it, lets call it FilenameOpenMulty)
2. You need to create new Form similar to \Forms\SysOpenFileName (duplicate
it, lets call it SysOpenFileNameMulty)
3. You need to create new class method in WinAPI class similar to
getOpenFileName (create new method, copy getOpenFileName to it, rename
method to getOpenFileNameMulty)

Changes in FilenameOpenMulty:
Property 'FormHelp' of FilenameOpenMulty should be SysOpenFileNameMulty.

Changes in SysOpenFileNameMulty:
Form method 'run' of SysOpenFileNameMulty form should contain:
in method declaration:
container returnFiles;
int i;

before string " if (s != '')":
returnFiles = WinAPI::getOpenFileNameMulty(
hwnd,
this.args().caller().filenameLookupFilter(),
initialPath,
this.args().caller().filenameLookupTitle(),
'',
this.args().caller().filenameLookupFileName(),
0x00000200 );

for(i=1; i< conlen(returnFiles)+1;i++)
{
info(conpeek(returnFiles, i));
}

You probably would like to change this method in future. At this point it is
more than enough just to call info() method in order to show that our
OpenFile routine works.


Changes in getOpenFileNameMulty:

Change return type to container;

Change the method body to:

{
Binary oFN, bFileName, bStrFilter, bStrInitialPath, bDialogTitle,
bstrDefaultExtension;
Binary bnOffset;
str #fileNamelength sFileName;

//alexk->
int nOffset;
str nextStr;
container conRet;
//<----

DLL _DLL = new DLL(#CommonDialogDLL);
DLLFunction _getOpenFileName = new DLLFunction(_DLL, 'GetOpenFileNameW');
_getOpenFileName.returns(ExtTypes::DWord);
_getOpenFileName.arg(ExtTypes::Pointer);

oFN = new Binary(#structSize);
bstrDefaultExtension = new Binary(_strDefaultExtension,true);
bStrInitialPath = new Binary(_strInitialPath,true);
bDialogTitle = new Binary(_dialogTitle,true);

//assuming that returning string no longer than 1024 chars (path +
filenames)
bFileName = new Binary(1024 * 2); // used as input/output
parameter, allocate fileNamelength TCHARs
bFileName.wString(0,_strDefaultFileName);
bStrFilter = WinAPI::filenameFilter2Binary(_conFilter);

oFN.dWord( #Offset0 , #structSize);
oFN.dWord( #offset4 , _hwnd);
oFN.dWord( #offset8 , infolog.instance());
oFN.binary(#offset12 , bStrFilter);
oFN.dWord( #offset16 , 0);
oFN.dWord( #offset20 , 0);
oFN.dWord( #offset24 , 1);
oFN.binary(#offset28 , bFileName);
oFN.dWord( #offset32 , 1024);//#fileNamelength); // size in TCHARs
oFN.dWord( #offset36 , 0);
oFN.dWord( #offset40 , 0);
oFN.binary(#offset44 , bStrInitialPath);
oFN.binary(#offset48 , bDialogTitle);
oFN.dWord( #offset52 , #OFN_HIDEREADONLY |
#OFN_PATHMUSTEXIST |
#OFN_SHAREAWARE |
#OFN_NOCHANGEDIR |
_flags |
#OFN_EXPLORER);
oFN.word( #offset56 , 0);//
oFN.word( #offset58 , 0);
oFN.binary(#offset60 , bstrDefaultExtension);
oFN.dWord( #offset64 , 0);
oFN.dWord( #offset68 , 0);
oFN.dWord( #offset72 , 0);

if(_getOpenFileName.call(oFN))
{
nOffset = 0;
sFileName = bFileName.wString(#Offset0);
nextStr = sFileName;

do
{
conRet = conpoke(conRet, conlen(conRet)+1, nextStr);
nOffset += (strlen(nextStr)*2 + 2);
nextStr = bFileName.wString(nOffset);
} while(strlen(nextStr) > 0);
}
else
{
sFileName = '';
conpoke(conRet, conlen(conRet), sFileName);
}

return conRet;
}

Although, it is not perfect code it does work. Probably should be solution
to receive actual length of string that WinAPI function should return (here
its is fixed to 1024 symbols).

Now you can add new EDT to Form control and should be able to select and
receive multiple selected files.

P.S. Hope I haven't missed anything :)

--
Regards,
Alex
----
Microsoft Dynamics AX Add-on for developers(Imptoved IntelliSense,
additional hotkeys etc) -http://www.axassist.com

Alex K. at dot

unread,
Jul 20, 2010, 9:00:27 AM7/20/10
to
More info about WinAPI function used in this example could be found here:

Function:
http://msdn.microsoft.com/en-us/library/ms646927(VS.85).aspx
Structure:
http://msdn.microsoft.com/en-us/library/ms646839(v=VS.85).aspx

--
Regards,
Alex
----
Microsoft Dynamics AX Add-on for developers(Imptoved IntellySense,

additional hotkeys etc) -http://www.axassist.com

Ampere Kana

unread,
Jul 27, 2010, 6:56:00 AM7/27/10
to
Hi, Alex

I try it, then it works.

Thanks a lot.
Ampere ^_^

0 new messages