NPPM_DOOPEN: wrong return value
-
The message NPPM_DOOPEN is declared as:
#define NPPM_DOOPEN (NPPMSG + 77) // BOOL NPPM_DOOPEN(0, const TCHAR *fullPathName2Open) // fullPathName2Open indicates the full file path name to be opened. // The return value is TRUE (1) if the operation is successful, otherwise FALSE (0).
The return value is correct when
fullPathName2Open
is a file (path)name.
If, however, thefullPathName2Open
is a folder, Notepad++ does open all the files from this folder, but NPPM_DOOPEN returns 0 ! -
I can at least confirm I am seeing the same behavior as you.
As a side note: the “documentation” in that file has more than a few errors if you actually compare them to the code :)
-
OK, I’ve found how to deal with it. At least, it’s one of possible solutions:
int nFiles = (int) SendNppMsg(NPPM_GETNBOPENFILES, 0, 0); if ( !SendNppMsg(NPPM_DOOPEN, (WPARAM) 0, (LPARAM) params.c_str()) ) { nCmdResult = CMDRESULT_FAILED; DWORD dwAttr = ::GetFileAttributes(params.c_str()); if ( (dwAttr != INVALID_FILE_ATTRIBUTES) && ((dwAttr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY) ) { // NPPM_DOOPEN unexpectedly returns 0 when a folder is specified // as its argument, though in fact it does open all the files // from that folder. int nFilesNow = (int) SendNppMsg(NPPM_GETNBOPENFILES, 0, 0); if ( nFilesNow != nFiles ) { nCmdResult = CMDRESULT_SUCCEEDED; } } }