INT_PTR CALLBACK DlgProcText(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) { RECT rc, pos; HWND button; HMENU hMenu, hMenu1; TCHAR str[4096]; switch (msg) { case WM_INITDIALOG: opt_startup = TRUE; // set windows position, make it top-most GetWindowRect(hdlg, &rc); SetWindowPos(hdlg, HWND_TOPMOST, rc.left, rc.top, 0, 0, SWP_NOSIZE); TranslateDialogDefault(hdlg); // generate the display text for variable list _tcsncpy(str, VAR_LIST_OPT, _countof(str) - 1); SetDlgItemText(hdlg, IDC_VARLIST, str); // make the more variable and other buttons flat SendDlgItemMessage(hdlg, IDC_MORE, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM1, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM2, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM3, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM4, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM5, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM6, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM7, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_TM8, BUTTONSETASFLATBTN, TRUE, 0); SendDlgItemMessage(hdlg, IDC_RESET, BUTTONSETASFLATBTN, TRUE, 0); // load the settings LoadTextSettings(hdlg); opt_startup = FALSE; return TRUE; case WM_COMMAND: if (opt_startup) return TRUE; switch (LOWORD(wParam)) { case IDC_CTEXT: case IDC_BTITLE: case IDC_BTEXT: case IDC_NTEXT: case IDC_XTEXT: case IDC_ETEXT: case IDC_HTEXT: case IDC_BTITLE2: if (HIWORD(wParam) == EN_CHANGE) SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_MORE: // display custom variables list MoreVarList(); break; case IDC_TM1: case IDC_TM2: case IDC_TM3: case IDC_TM4: case IDC_TM5: case IDC_TM6: case IDC_TM7: case IDC_TM8: // display the menu button = GetDlgItem(hdlg, LOWORD(wParam)); GetWindowRect(button, &pos); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_TMMENU)); hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL)) { case ID_MPREVIEW: { // show the preview in a message box, using the weather data from the default station WEATHERINFO winfo = LoadWeatherInfo(opt.DefStn); GetDisplay(&winfo, *var[LOWORD(wParam) - IDC_TM1], str); MessageBox(NULL, str, TranslateT("Weather Protocol Text Preview"), MB_OK | MB_TOPMOST); break; } case ID_MRESET: unsigned varo = LOWORD(wParam) - IDC_TM1; // remove the old setting from db and free memory TCHAR* vartmp = *var[varo]; wfree(&vartmp); SetTextDefault(varname[varo]); SetDlgItemText(hdlg, cname[varo], *var[varo]); break; } DestroyMenu(hMenu); break; case IDC_RESET: // left click action selection menu button = GetDlgItem(hdlg, IDC_RESET); GetWindowRect(button, &pos); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_TMENU)); hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); switch (TrackPopupMenu(hMenu1, TPM_LEFTBUTTON | TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL)) { case ID_T1: // reset to the strings in memory, discard all changes LoadTextSettings(hdlg); break; case ID_T2: // reset to the default setting FreeTextVar(); SetTextDefault("CbBENHX"); LoadTextSettings(hdlg); break; } DestroyMenu(hMenu); break; } return TRUE; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: // save the option TCHAR textstr[MAX_TEXT_SIZE]; // free memory for old settings FreeTextVar(); // save new settings to memory GetDlgItemText(hdlg, IDC_CTEXT, textstr, _countof(textstr)); wSetData(&opt.cText, textstr); GetDlgItemText(hdlg, IDC_BTEXT, textstr, _countof(textstr)); wSetData(&opt.bText, textstr); GetDlgItemText(hdlg, IDC_BTITLE, textstr, _countof(textstr)); wSetData(&opt.bTitle, textstr); GetDlgItemText(hdlg, IDC_ETEXT, textstr, _countof(textstr)); wSetData(&opt.eText, textstr); GetDlgItemText(hdlg, IDC_NTEXT, textstr, _countof(textstr)); wSetData(&opt.nText, textstr); GetDlgItemText(hdlg, IDC_HTEXT, textstr, _countof(textstr)); wSetData(&opt.hText, textstr); GetDlgItemText(hdlg, IDC_XTEXT, textstr, _countof(textstr)); wSetData(&opt.xText, textstr); GetDlgItemText(hdlg, IDC_BTITLE2, textstr, _countof(textstr)); wSetData(&opt.sText, textstr); SaveOptions(); UpdateAllInfo(0, 0); break; } break; } return FALSE; }
// load options from database + set default if the setting does not exist void LoadOptions(void) { memset(&opt, 0, sizeof(opt)); // main options opt.StartupUpdate = db_get_b(NULL, WEATHERPROTONAME, "StartupUpdate", true); opt.AutoUpdate = db_get_b(NULL, WEATHERPROTONAME, "AutoUpdate", true); opt.UpdateTime = db_get_w(NULL, WEATHERPROTONAME, "UpdateTime", 30); opt.NoProtoCondition = db_get_b(NULL, WEATHERPROTONAME, "NoStatus", true); opt.UpdateOnlyConditionChanged = db_get_b(NULL, WEATHERPROTONAME, "CondChangeAsUpdate", true); opt.RemoveOldData = db_get_b(NULL, WEATHERPROTONAME, "RemoveOld", false); opt.MakeItalic = db_get_b(NULL, WEATHERPROTONAME, "MakeItalic", true); opt.AvatarSize = db_get_b(NULL, WEATHERPROTONAME, "AvatarSize", 128); // units opt.tUnit = db_get_w(NULL, WEATHERPROTONAME, "tUnit", 1); opt.wUnit = db_get_w(NULL, WEATHERPROTONAME, "wUnit", 2); opt.vUnit = db_get_w(NULL, WEATHERPROTONAME, "vUnit", 1); opt.pUnit = db_get_w(NULL, WEATHERPROTONAME, "pUnit", 4); opt.dUnit = db_get_w(NULL, WEATHERPROTONAME, "dUnit", 1); opt.eUnit = db_get_w(NULL, WEATHERPROTONAME, "eUnit", 2); ptrT szValue(db_get_tsa(NULL, WEATHERPROTONAME, "DegreeSign")); _tcsncpy_s(opt.DegreeSign, (szValue == NULL) ? _T("") : szValue, _TRUNCATE); opt.DoNotAppendUnit = db_get_b(NULL, WEATHERPROTONAME, "DoNotAppendUnit", 0); opt.NoFrac = db_get_b(NULL, WEATHERPROTONAME, "NoFractions", 0); // texts if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "DisplayText")) wSetData(&opt.cText, TranslateTS(szValue)); else SetTextDefault("C"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "BriefTextTitle")) wSetData(&opt.bTitle, TranslateTS(szValue)); else SetTextDefault("b"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "BriefText")) wSetData(&opt.bText, TranslateTS(szValue)); else SetTextDefault("B"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "NoteText")) wSetData(&opt.nText, TranslateTS(szValue)); else SetTextDefault("N"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "ExtText")) wSetData(&opt.eText, TranslateTS(szValue)); else SetTextDefault("E"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "HistoryText")) wSetData(&opt.hText, TranslateTS(szValue)); else SetTextDefault("H"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "ExtraText")) wSetData(&opt.xText, TranslateTS(szValue)); else SetTextDefault("X"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "StatusText")) wSetData(&opt.sText, TranslateTS(szValue)); else SetTextDefault("S"); // advanced opt.DisCondIcon = db_get_b(NULL, WEATHERPROTONAME, "DisableConditionIcon", false); // popup options opt.UsePopup = db_get_b(NULL, WEATHERPROTONAME, "UsePopUp", true); opt.UpdatePopup = db_get_b(NULL, WEATHERPROTONAME, "UpdatePopup", true); opt.AlertPopup = db_get_b(NULL, WEATHERPROTONAME, "AlertPopup", true); opt.PopupOnChange = db_get_b(NULL, WEATHERPROTONAME, "PopUpOnChange", true); opt.ShowWarnings = db_get_b(NULL, WEATHERPROTONAME, "ShowWarnings", true); // popup colors opt.BGColour = db_get_dw(NULL, WEATHERPROTONAME, "BackgroundColour", GetSysColor(COLOR_BTNFACE)); opt.TextColour = db_get_dw(NULL, WEATHERPROTONAME, "TextColour", GetSysColor(COLOR_WINDOWTEXT)); opt.UseWinColors = (BOOL)db_get_b(NULL, WEATHERPROTONAME, "UseWinColors", false); // popup actions opt.LeftClickAction = db_get_dw(NULL, WEATHERPROTONAME, "LeftClickAction", IDM_M2); opt.RightClickAction = db_get_dw(NULL, WEATHERPROTONAME, "RightClickAction", IDM_M1); // popup delay opt.pDelay = db_get_dw(NULL, WEATHERPROTONAME, "PopupDelay", 0); // popup texts if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "PopupTitle")) wSetData(&opt.pTitle, szValue); else SetTextDefault("P"); if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "PopupText")) wSetData(&opt.pText, szValue); else SetTextDefault("p"); // misc if (szValue = db_get_tsa(NULL, WEATHERPROTONAME, "Default")) _tcsncpy_s(opt.Default, szValue, _TRUNCATE); else opt.Default[0] = 0; }
// copied and modified from NewStatusNotify INT_PTR CALLBACK DlgPopupOpts(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam) { int ID; TCHAR str[512]; HMENU hMenu, hMenu1; RECT pos; HWND button; MCONTACT hContact; switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hdlg); SaveOptions(); // click actions hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); GetMenuString(hMenu1, opt.LeftClickAction, str, sizeof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_LeftClick, TranslateTS(str)); GetMenuString(hMenu1, opt.RightClickAction, str, sizeof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_RightClick, TranslateTS(str)); DestroyMenu(hMenu); // other options CheckDlgButton(hdlg, IDC_E, opt.UsePopup); CheckDlgButton(hdlg, IDC_POP2, opt.AlertPopup); CheckDlgButton(hdlg, IDC_POP1, opt.UpdatePopup); CheckDlgButton(hdlg, IDC_CH, opt.PopupOnChange); CheckDlgButton(hdlg, IDC_W, opt.ShowWarnings); SetDlgItemText(hdlg,IDC_PText, opt.pText); SetDlgItemText(hdlg,IDC_PTitle, opt.pTitle); // setting popup delay option _ltot(opt.pDelay, str, 10); SetDlgItemText(hdlg,IDC_DELAY, str); if (opt.pDelay == -1) CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD2); else if (opt.pDelay == 0) CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD1); else CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3); //Colours. First step is configuring the colours. SendDlgItemMessage(hdlg,IDC_BGCOLOUR,CPM_SETCOLOUR,0,opt.BGColour); SendDlgItemMessage(hdlg,IDC_TEXTCOLOUR,CPM_SETCOLOUR,0,opt.TextColour); //Second step is disabling them if we want to use default Windows ones. CheckDlgButton(hdlg, IDC_USEWINCOLORS,opt.UseWinColors?BST_CHECKED:BST_UNCHECKED); EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOUR), !opt.UseWinColors); EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOUR), !opt.UseWinColors); // buttons SendMessage(GetDlgItem(hdlg,IDC_PREVIEW), BUTTONSETASFLATBTN, TRUE, 0); SendMessage(GetDlgItem(hdlg,IDC_PDEF), BUTTONSETASFLATBTN, TRUE, 0); SendMessage(GetDlgItem(hdlg,IDC_LeftClick), BUTTONSETASFLATBTN, TRUE, 0); SendMessage(GetDlgItem(hdlg,IDC_RightClick), BUTTONSETASFLATBTN, TRUE, 0); SendMessage(GetDlgItem(hdlg,IDC_VAR3), BUTTONSETASFLATBTN, TRUE, 0); return TRUE; case WM_COMMAND: // enable the "apply" button if (HIWORD(wParam) == BN_CLICKED && GetFocus() == (HWND)lParam) SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); if ( !((LOWORD(wParam) == IDC_UPDATE || LOWORD(wParam) == IDC_DEGREE) && (HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus()))) SendMessage(GetParent(hdlg),PSM_CHANGED,0,0); //These are simple clicks: we don't save, but we tell the Options Page to enable the "Apply" button. switch(LOWORD(wParam)) { case IDC_BGCOLOUR: //Fall through case IDC_TEXTCOLOUR: // select new colors if (HIWORD(wParam) == CPN_COLOURCHANGED) SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_USEWINCOLORS: // use window color - enable/disable color selection controls EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOUR), !(opt.UseWinColors)); EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOUR), !(opt.UseWinColors)); SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_E: case IDC_CH: SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; case IDC_RightClick: // right click action selection menu button = GetDlgItem(hdlg, IDC_RightClick); GetWindowRect(button, &pos); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); SelectMenuItem(hMenu1, opt.RightClickAction); ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON|TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL); if (ID) opt.RightClickAction = ID; DestroyMenu(hMenu); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); GetMenuString(hMenu1, opt.RightClickAction, str, sizeof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_RightClick, TranslateTS(str)); DestroyMenu(hMenu); break; case IDC_LeftClick: // left click action selection menu button = GetDlgItem(hdlg, IDC_LeftClick); GetWindowRect(button, &pos); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); TranslateMenu(hMenu1); SelectMenuItem(hMenu1, opt.LeftClickAction); ID = TrackPopupMenu(hMenu1, TPM_LEFTBUTTON|TPM_RETURNCMD, pos.left, pos.bottom, 0, hdlg, NULL); if (ID) opt.LeftClickAction = ID; DestroyMenu(hMenu); hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDR_PMENU)); hMenu1 = GetSubMenu(hMenu, 0); GetMenuString(hMenu1, opt.LeftClickAction, str, sizeof(str), MF_BYCOMMAND); SetDlgItemText(hdlg, IDC_LeftClick, TranslateTS(str)); DestroyMenu(hMenu); break; case IDC_PD1: // Popup delay setting from Popup plugin SetDlgItemText(hdlg, IDC_DELAY, _T("0")); CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD1); break; case IDC_PD2: // Popup delay = permanent SetDlgItemText(hdlg, IDC_DELAY, _T("-1")); CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD2); break; case IDC_DELAY: // if text is edited CheckRadioButton(hdlg, IDC_PD1, IDC_PD3, IDC_PD3); break; case IDC_PDEF: // set the default value for popup texts SetTextDefault("Pp"); SetDlgItemText(hdlg,IDC_PText, opt.pText); SetDlgItemText(hdlg,IDC_PTitle, opt.pTitle); wfree(&opt.pText); wfree(&opt.pTitle); break; case IDC_VAR3: // display variable list _tcscpy(str, _T(" \n")); // to make the message box wider _tcscat(str, TranslateT("%c\tcurrent condition\n%d\tcurrent date\n%e\tdewpoint\n%f\tfeel-like temperature\n%h\ttoday's high\n%i\twind direction\n%l\ttoday's low\n%m\thumidity\n%n\tstation name\n%p\tpressure\n%r\tsunrise time\n%s\tstation ID\n%t\ttemperature\n%u\tupdate time\n%v\tvisibility\n%w\twind speed\n%y\tsun set")); _tcscat(str, _T("\n")); _tcscat(str, TranslateT("%[..]\tcustom variables")); MessageBox(NULL, str, TranslateT("Variable List"), MB_OK|MB_ICONASTERISK|MB_TOPMOST); break; case IDC_PREVIEW: // popup preview hContact = opt.DefStn; ReadPopupOpt(hdlg); // read new options to memory WeatherPopup((WPARAM)opt.DefStn, (BOOL)TRUE); // display popup using new opt DestroyOptions(); LoadOptions(); // restore old option in memory opt.DefStn = hContact; break; } break; case WM_NOTIFY: //Here we have pressed either the OK or the APPLY button. switch (((LPNMHDR)lParam)->code) { case PSN_APPLY: { ReadPopupOpt(hdlg); // save the options, and update main menu SaveOptions(); UpdatePopupMenu(opt.UsePopup); return TRUE; } } break; } return FALSE; }