Skip to main content

 none
How to gain access to pushbutton labeled “Cancel” IFileOpenDialog/IFileDialog interface RRS feed

Answers

  • Hi

    I am working on IFileOpenDialog/IFileDialog interfaces using MSDN example shown in

    https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appplatform/commonfiledialog

    There is a pushbutton labeled “cancel” in the dialog panel.

    I like to gain access to it so that I can instruct what should happen.

    Can someone help

    Thank you,

    ChangChiTheGraphics


    chang Chi

    Clicking the Cancel button dismisses the dialog and returns an error code to the caller of the IFileDialog::Show method.

    What is it that you want to do upon cancellation that must be done before the dialog is dismissed and the error code is returned?

    You can subclass the dialog to handle the button click event for the Cancel button, but depending on your objectives this may not be necessary.

    In any event, sample code (tested on Win 8.1), uses IFileDialogEvents::OnFolderChange -

    LRESULT CALLBACK IFDProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uidSubclass, DWORD_PTR dwData)
    {
    	switch (msg)
    	{
    	case WM_COMMAND:
    		if (LOWORD(wParam) == IDCANCEL && HIWORD(wParam) == BN_CLICKED)
    		{
    			TCHAR szMsg[128];
    			StringCchPrintf(szMsg, ARRAYSIZE(szMsg), TEXT("Cancel Button Clicked, Button HWND %X\n"), lParam);
    			OutputDebugString(szMsg);
    		}
    		break;
    
    	case WM_DESTROY:
    		RemoveWindowSubclass(hwnd, IFDProc, uidSubclass);
    		break;
    	}
    
    	return DefSubclassProc(hwnd, msg, wParam, lParam);
    }
    
    HRESULT CFileDialogApp::OnFolderChange(IFileDialog *pfd)
    {
    	static bool first = true;
    
    	if (first)
    	{
    		HWND hDlg = NULL;
    		
    		first = false;
    
    		IUnknown_GetWindow(pfd, &hDlg);
    
    		if (hDlg)
    			SetWindowSubclass(hDlg, IFDProc, 41, 0);
    	}
    
    	return S_OK;
    }
    
    


    • Edited by RLWA32 Sunday, March 25, 2018 12:39 PM added sample code
    • Proposed as answer by Hart WangModerator Wednesday, March 28, 2018 8:34 AM
    • Marked as answer by C.H.Chi Wednesday, April 4, 2018 6:14 AM
    Sunday, March 25, 2018 11:14 AM

All replies

  • Hi

    I am working on IFileOpenDialog/IFileDialog interfaces using MSDN example shown in

    https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appplatform/commonfiledialog

    There is a pushbutton labeled “cancel” in the dialog panel.

    I like to gain access to it so that I can instruct what should happen.

    Can someone help

    Thank you,

    ChangChiTheGraphics


    chang Chi

    Clicking the Cancel button dismisses the dialog and returns an error code to the caller of the IFileDialog::Show method.

    What is it that you want to do upon cancellation that must be done before the dialog is dismissed and the error code is returned?

    You can subclass the dialog to handle the button click event for the Cancel button, but depending on your objectives this may not be necessary.

    In any event, sample code (tested on Win 8.1), uses IFileDialogEvents::OnFolderChange -

    LRESULT CALLBACK IFDProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, UINT_PTR uidSubclass, DWORD_PTR dwData)
    {
    	switch (msg)
    	{
    	case WM_COMMAND:
    		if (LOWORD(wParam) == IDCANCEL && HIWORD(wParam) == BN_CLICKED)
    		{
    			TCHAR szMsg[128];
    			StringCchPrintf(szMsg, ARRAYSIZE(szMsg), TEXT("Cancel Button Clicked, Button HWND %X\n"), lParam);
    			OutputDebugString(szMsg);
    		}
    		break;
    
    	case WM_DESTROY:
    		RemoveWindowSubclass(hwnd, IFDProc, uidSubclass);
    		break;
    	}
    
    	return DefSubclassProc(hwnd, msg, wParam, lParam);
    }
    
    HRESULT CFileDialogApp::OnFolderChange(IFileDialog *pfd)
    {
    	static bool first = true;
    
    	if (first)
    	{
    		HWND hDlg = NULL;
    		
    		first = false;
    
    		IUnknown_GetWindow(pfd, &hDlg);
    
    		if (hDlg)
    			SetWindowSubclass(hDlg, IFDProc, 41, 0);
    	}
    
    	return S_OK;
    }
    
    


    • Edited by RLWA32 Sunday, March 25, 2018 12:39 PM added sample code
    • Proposed as answer by Hart WangModerator Wednesday, March 28, 2018 8:34 AM
    • Marked as answer by C.H.Chi Wednesday, April 4, 2018 6:14 AM
    Sunday, March 25, 2018 11:14 AM
  • Thank you,RLWA32.

    I finally got it working and beautifully

    ChangChiTheGraphics


    chang Chi

    Wednesday, April 4, 2018 6:13 AM