void CSaveAsDlg::OnTypeChange(NMHDR* pNMHDR, LRESULT* pResult) { int idx = m_ofn.nFilterIndex - 1; if (idx >= 0 && idx < m_Ext.GetSize()) { // if valid extension index LPCTSTR pExt = m_Ext[idx]; // get corresponding extension pExt++; // remove leading dot; for details, see CDM_SETDEFEXT CommDlg_OpenSave_SetDefExt(m_hWnd, pExt); // set default extension } }
static UINT_PTR APIENTRY tap_save_hook_proc(HWND hdlg, //handle to child dialog window UINT uiMsg, //message identifier WPARAM wParam, //message parameter LPARAM lParam // message parameter ){ if (uiMsg == WM_INITDIALOG) { SendMessageA(GetDlgItem(hdlg, IDC_CHOOSE_TAP_VERSION), CB_ADDSTRING, 0, (LPARAM) "Version 0"); SendMessageA(GetDlgItem(hdlg, IDC_CHOOSE_TAP_VERSION), CB_ADDSTRING, 0, (LPARAM) "Version 1"); SendMessageA(GetDlgItem(hdlg, IDC_CHOOSE_TAP_VERSION), CB_ADDSTRING, 0, (LPARAM) "Version 2"); SendMessage(GetDlgItem(hdlg, IDC_CHOOSE_TAP_VERSION), CB_SETCURSEL, (WPARAM) 1, 0); } if (uiMsg == WM_NOTIFY) { OFNOTIFY *notify = (OFNOTIFY *) lParam; if (notify->hdr.code == CDN_TYPECHANGE) { switch (notify->lpOFN->nFilterIndex) { case 1: CommDlg_OpenSave_SetDefExt(GetParent(hdlg), "tap"); break; case 2: CommDlg_OpenSave_SetDefExt(GetParent(hdlg), NULL); default: ; } } if (notify->hdr.code == CDN_FILEOK) { HWND main_window = GetParent(GetParent(hdlg)); uint8_t *version = (uint8_t*)notify->lpOFN->lCustData; *version = (uint8_t)SendMessage(GetDlgItem(hdlg, IDC_CHOOSE_TAP_VERSION), CB_GETCURSEL, 0, 0); } } return 0; }