void CMusikFileDialog::OnFileNameChange() { TCHAR dummy_buffer; // Get the required size for the 'files' buffer UINT nfiles = CommDlg_OpenSave_GetSpec( GetParent()->m_hWnd, &dummy_buffer, 1 ); // Get the required size for the 'folder' buffer UINT nfolder = CommDlg_OpenSave_GetFolderPath( GetParent()->m_hWnd, &dummy_buffer, 1 ); // Check if lpstrFile and nMaxFile are large enough if ( nfiles + nfolder > m_ofn.nMaxFile ) { m_bParsed = FALSE; // files if ( m_pstrFiles ) delete[] m_pstrFiles; m_pstrFiles = new TCHAR[nfiles + 1]; CommDlg_OpenSave_GetSpec( GetParent()->m_hWnd, m_pstrFiles, nfiles ); // folder if ( m_pstrFolder ) delete[] m_pstrFolder; m_pstrFolder = new TCHAR[nfolder + 1]; CommDlg_OpenSave_GetFolderPath( GetParent()->m_hWnd, m_pstrFolder, nfolder ); } else if ( m_pstrFiles ) CleanStrings(); CFileDialog::OnFileNameChange(); }
static UINT_PTR CALLBACK FileDialogHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); TRY; HWND parent = ::GetParent(hdlg); switch(uiMsg) { case WM_INITDIALOG: { OPENFILENAME *ofn = (OPENFILENAME *)lParam; jobject peer = (jobject)(ofn->lCustData); env->CallVoidMethod(peer, AwtFileDialog::setHWndMID, (jlong)parent); ::SetProp(parent, ModalDialogPeerProp, reinterpret_cast<HANDLE>(peer)); // fix for 4508670 - disable CS_SAVEBITS DWORD style = ::GetClassLong(hdlg,GCL_STYLE); ::SetClassLong(hdlg,GCL_STYLE,style & ~CS_SAVEBITS); // set appropriate icon for parentless dialogs jobject awtParent = env->GetObjectField(peer, AwtFileDialog::parentID); if (awtParent == NULL) { ::SendMessage(parent, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)AwtToolkit::GetInstance().GetAwtIcon()); } else { env->DeleteLocalRef(awtParent); } // subclass dialog's parent to receive additional messages WNDPROC lpfnWndProc = ComCtl32Util::GetInstance().SubclassHWND(parent, FileDialogWndProc); ::SetProp(parent, NativeDialogWndProcProp, reinterpret_cast<HANDLE>(lpfnWndProc)); ::SetProp(parent, OpenFileNameProp, (void *)lParam); break; } case WM_DESTROY: { WNDPROC lpfnWndProc = (WNDPROC)(::GetProp(parent, NativeDialogWndProcProp)); ComCtl32Util::GetInstance().UnsubclassHWND(parent, FileDialogWndProc, lpfnWndProc); ::RemoveProp(parent, ModalDialogPeerProp); ::RemoveProp(parent, NativeDialogWndProcProp); ::RemoveProp(parent, OpenFileNameProp); break; } case WM_NOTIFY: { OFNOTIFYEX *notifyEx = (OFNOTIFYEX *)lParam; if (notifyEx) { jobject peer = (jobject)(::GetProp(parent, ModalDialogPeerProp)); if (notifyEx->hdr.code == CDN_INCLUDEITEM) { LPITEMIDLIST pidl = (LPITEMIDLIST)notifyEx->pidl; // Get the filename and directory TCHAR szPath[MAX_PATH]; if (!::SHGetPathFromIDList(pidl, szPath)) { return TRUE; } jstring strPath = JNU_NewStringPlatform(env, szPath); // Call FilenameFilter.accept with path and filename UINT uRes = (env->CallBooleanMethod(peer, AwtFileDialog::checkFilenameFilterMID, strPath) == JNI_TRUE); env->DeleteLocalRef(strPath); return uRes; } else if (notifyEx->hdr.code == CDN_FILEOK) { // This notification is sent when user selects some file and presses // OK button; it is not sent when no file is selected. So it's time // to unblock all the windows blocked by this dialog as it will // be closed soon env->CallVoidMethod(peer, AwtFileDialog::setHWndMID, (jlong)0); } else if (notifyEx->hdr.code == CDN_SELCHANGE) { // reallocate the buffer if the buffer is too small LPOPENFILENAME lpofn = (LPOPENFILENAME)GetProp(parent, OpenFileNameProp); UINT nLength = CommDlg_OpenSave_GetSpec(parent, NULL, 0) + CommDlg_OpenSave_GetFolderPath(parent, NULL, 0); if (lpofn->nMaxFile < nLength) { // allocate new buffer LPTSTR newBuffer = new TCHAR[nLength]; if (newBuffer) { memset(newBuffer, 0, nLength * sizeof(TCHAR)); LPTSTR oldBuffer = lpofn->lpstrFile; lpofn->lpstrFile = newBuffer; lpofn->nMaxFile = nLength; // free the previously allocated buffer if (oldBuffer) { delete[] oldBuffer; } } } } } break; } } return FALSE; CATCH_BAD_ALLOC_RET(TRUE); }