INT CommandAssoc (LPTSTR param) { /* print help */ if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_ASSOC_HELP); return 0; } nErrorLevel = 0; if (_tcslen(param) == 0) PrintAllAssociations(); else { LPTSTR lpEqualSign = _tcschr(param, _T('=')); if (lpEqualSign != NULL) { LPTSTR fileType = lpEqualSign + 1; LPTSTR extension = cmd_alloc((lpEqualSign - param + 1) * sizeof(TCHAR)); _tcsncpy(extension, param, lpEqualSign - param); extension[lpEqualSign - param] = (TCHAR)0; if (_tcslen(fileType) == 0) /* if the equal sign is the last character in the string, then delete the key */ { RemoveAssociation(extension); } else /* otherwise, add the key and print out the association*/ { AddAssociation( extension, fileType); PrintAssociation(extension); } cmd_free(extension); } else { /* no equal sign, print all associations */ INT retval = PrintAssociation(param); if (retval == 0) /* if nothing printed out */ ConOutResPrintf(STRING_ASSOC_ERROR, param); } } return 0; }
BOOL CALLBACK PreferencesDialog5Proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COMMAND: /* Process control messages */ { switch (LOWORD(wParam)) { case ID_TEXTFILESCHK: case ID_HTMLFILESCHK: case ID_STYLESHEETFILESCHK: case ID_JAVASCRIPTFILESCHK: case ID_PHPFILESCHK: { if (HIWORD(wParam) == BN_CLICKED) { SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0); } break; } case ID_ALLFILESBTN: { if (HIWORD(wParam) == BN_CLICKED) { CheckDlgButton(hDlg, ID_TEXTFILESCHK, BST_CHECKED); CheckDlgButton(hDlg, ID_HTMLFILESCHK, BST_CHECKED); CheckDlgButton(hDlg, ID_STYLESHEETFILESCHK, BST_CHECKED); CheckDlgButton(hDlg, ID_JAVASCRIPTFILESCHK, BST_CHECKED); CheckDlgButton(hDlg, ID_PHPFILESCHK, BST_CHECKED); SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0); } break; } case ID_NOFILESBTN: { if (HIWORD(wParam) == BN_CLICKED) { CheckDlgButton(hDlg, ID_TEXTFILESCHK, BST_UNCHECKED); CheckDlgButton(hDlg, ID_HTMLFILESCHK, BST_UNCHECKED); CheckDlgButton(hDlg, ID_STYLESHEETFILESCHK, BST_UNCHECKED); CheckDlgButton(hDlg, ID_JAVASCRIPTFILESCHK, BST_UNCHECKED); CheckDlgButton(hDlg, ID_PHPFILESCHK, BST_UNCHECKED); SendMessage(GetParent(hDlg), PSM_CHANGED, (WPARAM)hDlg, 0); } break; } } return TRUE; } case WM_INITDIALOG: { /* Set up controls */ /* Display Preferences */ int Count = IsAssociateTo(".txt", true) + IsAssociateTo(".ini", true) + IsAssociateTo(".inf", true) + IsAssociateTo(".log", true); if (Count == 4) CheckDlgButton(hDlg, ID_TEXTFILESCHK, BST_CHECKED); else if (Count > 0) CheckDlgButton(hDlg, ID_TEXTFILESCHK, BST_INDETERMINATE); else CheckDlgButton(hDlg, ID_TEXTFILESCHK, BST_UNCHECKED); Count = IsAssociateTo(".html", true) + IsAssociateTo(".htm", true) + IsAssociateTo(".htt", true) + IsAssociateTo(".shtml", true) + IsAssociateTo(".xht", true) + IsAssociateTo(".xhtml", true) + IsAssociateTo(".xml", true); if (Count == 7) CheckDlgButton(hDlg, ID_HTMLFILESCHK, BST_CHECKED); else if (Count > 0) CheckDlgButton(hDlg, ID_HTMLFILESCHK, BST_INDETERMINATE); else CheckDlgButton(hDlg, ID_HTMLFILESCHK, BST_UNCHECKED); Count = IsAssociateTo(".css", true) + IsAssociateTo(".xsl", true); if (Count == 2) CheckDlgButton(hDlg, ID_STYLESHEETFILESCHK, BST_CHECKED); else if (Count > 0) CheckDlgButton(hDlg, ID_STYLESHEETFILESCHK, BST_INDETERMINATE); else CheckDlgButton(hDlg, ID_STYLESHEETFILESCHK, BST_UNCHECKED); Count = IsAssociateTo(".js", true); if (Count == 1) CheckDlgButton(hDlg, ID_JAVASCRIPTFILESCHK, BST_CHECKED); else if (Count > 0) CheckDlgButton(hDlg, ID_JAVASCRIPTFILESCHK, BST_INDETERMINATE); else CheckDlgButton(hDlg, ID_JAVASCRIPTFILESCHK, BST_UNCHECKED); Count = IsAssociateTo(".php", true) + IsAssociateTo(".php4", true); if (Count == 2) CheckDlgButton(hDlg, ID_PHPFILESCHK, BST_CHECKED); else if (Count > 0) CheckDlgButton(hDlg, ID_PHPFILESCHK, BST_INDETERMINATE); else CheckDlgButton(hDlg, ID_PHPFILESCHK, BST_UNCHECKED); return TRUE; } case WM_NOTIFY: { switch (((NMHDR *)lParam)->code) { case PSN_APPLY: { /* Save file associations*/ AssociateTo(".lpg", true); if (IsDlgButtonChecked(hDlg, ID_TEXTFILESCHK) == BST_CHECKED) { AssociateTo(".txt", true); AssociateTo(".ini", true); AssociateTo(".inf", true); AssociateTo(".log", true); } else if (IsDlgButtonChecked(hDlg, ID_TEXTFILESCHK) == BST_UNCHECKED) { RemoveAssociation(".txt", true); RemoveAssociation(".ini", true); RemoveAssociation(".inf", true); RemoveAssociation(".log", true); } if (IsDlgButtonChecked(hDlg, ID_HTMLFILESCHK) == BST_CHECKED) { AssociateTo(".html", false); AssociateTo(".htm", false); AssociateTo(".htt", true); AssociateTo(".shtml", false); AssociateTo(".xht", false); AssociateTo(".xhtml", false); AssociateTo(".xml", false); } else if (IsDlgButtonChecked(hDlg, ID_HTMLFILESCHK) == BST_UNCHECKED) { RemoveAssociation(".html", false); RemoveAssociation(".htm", false); RemoveAssociation(".htt", true); RemoveAssociation(".shtml", false); RemoveAssociation(".xht", false); RemoveAssociation(".xhtml", false); RemoveAssociation(".xml", false); } if (IsDlgButtonChecked(hDlg, ID_STYLESHEETFILESCHK) == BST_CHECKED) { AssociateTo(".css", true); AssociateTo(".xsl", false); } else if (IsDlgButtonChecked(hDlg, ID_STYLESHEETFILESCHK) == BST_UNCHECKED) { RemoveAssociation(".css", true); RemoveAssociation(".xsl", false); } if (IsDlgButtonChecked(hDlg, ID_JAVASCRIPTFILESCHK) == BST_CHECKED) { AssociateTo(".js", true); } else if (IsDlgButtonChecked(hDlg, ID_JAVASCRIPTFILESCHK) == BST_UNCHECKED) { RemoveAssociation(".js", true); } if (IsDlgButtonChecked(hDlg, ID_PHPFILESCHK) == BST_CHECKED) { AssociateTo(".php", true); AssociateTo(".php4", true); } else if (IsDlgButtonChecked(hDlg, ID_PHPFILESCHK) == BST_UNCHECKED) { RemoveAssociation(".php", true); RemoveAssociation(".php4", true); } return TRUE; } } return FALSE; } default: return FALSE; } }