// hKey must have been opened with KEY_SET_VALUE access right static void SetRegStrPrefixValue(HKEY hKey,const TCHAR *pszValPrefix,const TCHAR *pszVal) { size_t dwSize = (mir_tstrlen(pszVal)+mir_tstrlen(pszValPrefix)+1)*sizeof(TCHAR); TCHAR *pszStr = (TCHAR*)_alloca(dwSize); mir_tstrcat(mir_tstrcpy(pszStr, pszValPrefix), pszVal); /* buffer safe */ RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)pszStr, (int)dwSize); }
void write_ping_address(PINGADDRESS &i) { char buff[16]; mir_snprintf(buff, "PING_DEST_%d", i.index); if (i.item_id == 0) { i.item_id = NextID++; db_set_dw(0, PLUG, "NextID", NextID); } db_set_dw(0, buff, "Id", i.item_id); db_set_ts(0, buff, "Address", i.pszName); db_set_ts(0, buff, "Label", i.pszLabel); db_set_w(0, buff, "Status", i.status); db_set_dw(0, buff, "Port", i.port); db_set_s(0, buff, "Proto", i.pszProto); if (mir_tstrlen(i.pszCommand)) db_set_ts(0, buff, "Command", i.pszCommand); else db_unset(0, buff, "Command"); if (mir_tstrlen(i.pszParams)) db_set_ts(0, buff, "CommandParams", i.pszParams); else db_unset(0, buff, "CommandParams"); db_set_w(0, buff, "SetStatus", i.set_status); db_set_w(0, buff, "GetStatus", i.get_status); db_set_w(0, buff, "Index", i.index); }
int SaveOptions(void) { TCHAR prof_dir[MAX_PATH]; db_set_b(0, "AutoBackups", "BackupType", (BYTE)options.backup_types); if (options.period < 1) options.period = 1; db_set_w(0, "AutoBackups", "Period", (WORD)options.period); db_set_b(0, "AutoBackups", "PeriodType", (BYTE)options.period_type); mir_sntprintf(prof_dir, _countof(prof_dir), _T("%s\\"), profilePath); size_t prof_len = mir_tstrlen(prof_dir); size_t opt_len = mir_tstrlen(options.folder); if (opt_len > prof_len && _tcsncmp(options.folder, prof_dir, prof_len) == 0) { db_set_ts(0, "AutoBackups", "Folder", (options.folder + prof_len)); } else db_set_ts(0, "AutoBackups", "Folder", options.folder); TCHAR *tmp = Utils_ReplaceVarsT(options.folder); if (mir_tstrlen(tmp) < 2 || tmp[1] != ':') { _tcsncpy_s(prof_dir, options.folder, _TRUNCATE); mir_sntprintf(options.folder, _countof(options.folder), _T("%s\\%s"), profilePath, prof_dir); } mir_free(tmp); db_set_w(0, "AutoBackups", "NumBackups", options.num_backups); db_set_b(0, "AutoBackups", "NoProgress", (BYTE)options.disable_progress); db_set_b(0, "AutoBackups", "NoPopups", (BYTE)options.disable_popups); db_set_b(0, "AutoBackups", "UseZip", (BYTE)options.use_zip); SetBackupTimer(); return 0; }
void AddDialogString(HWND hWndDlg, const PageHash key) { TCHAR title[2048]; GetWindowText(hWndDlg, title, _countof(title)); if (mir_tstrlen(title) > 0) AddFilterString(key, title); TCHAR szClass[64]; GetClassName(hWndDlg, szClass, _countof(szClass)); if (mir_tstrcmpi(szClass, _T("SysTreeView32")) == 0) { HTREEITEM hItem = TreeView_GetRoot(hWndDlg); AddTreeViewNodes(hWndDlg, key, hItem); return; } if (mir_tstrcmpi(szClass, _T("listbox")) == 0) { if (GetWindowStyle(hWndDlg) & LBS_HASSTRINGS) { int count = ListBox_GetCount(hWndDlg); for (int i=0; i < count; i++) { title[0] = 0; //safety int res = ListBox_GetText(hWndDlg, i, title); if (res != LB_ERR) { title[_countof(title) - 1] = 0; if (mir_tstrlen(title) > 0) AddFilterString(key, title); } } } return; } if (mir_tstrcmpi(szClass, _T("SysListView32")) == 0) { int count = ListView_GetItemCount(hWndDlg); for (int i=0; i < count; i++) { title[0] = 0; //safety ListView_GetItemText(hWndDlg, i, 0, title, _countof(title)); if (mir_tstrlen(title) > 0) AddFilterString(key, title); } return; } if (mir_tstrcmpi(szClass, _T("combobox")) == 0) { if (GetWindowStyle(hWndDlg) & CBS_HASSTRINGS) { int count = ComboBox_GetCount(hWndDlg); for (int i=0; i < count; i++) { title[0] = 0; //safety int res = ComboBox_GetLBText(hWndDlg, i, title); if (res != CB_ERR) { title[_countof(title) - 1] = 0; if (mir_tstrlen(title) > 0) AddFilterString(key, title); } } } } }
/** * load a system library from the Windows system path and return its module * handle. * * return 0 and throw an exception if something goes wrong. */ HMODULE Utils::loadSystemLibrary(const TCHAR* szFilename, bool useGetHandle) { TCHAR sysPathName[MAX_PATH + 2]; HMODULE _h = 0; try { if (0 == ::GetSystemDirectory(sysPathName, MAX_PATH)) throw(CRTException("Error while loading system library", szFilename)); sysPathName[MAX_PATH - 1] = 0; if (mir_tstrlen(sysPathName) + mir_tstrlen(szFilename) >= MAX_PATH) throw(CRTException("Error while loading system library", szFilename)); mir_tstrcat(sysPathName, szFilename); if (useGetHandle) _h = ::GetModuleHandle(sysPathName); else _h = LoadLibrary(sysPathName); if (0 == _h) throw(CRTException("Error while loading system library", szFilename)); } catch (CRTException& ex) { ex.display(); return 0; } return (_h); }
size_t MY_pathToRelative(const TCHAR *pSrc, TCHAR *pOut) { size_t dwSrcLen, dwProfilePathLen; if (!pSrc || !pOut) return 0; dwSrcLen = mir_tstrlen(pSrc); if (!dwSrcLen || dwSrcLen > (MAX_PATH - 1)) return 0; if (!MY_pathIsAbsolute(pSrc)) goto path_not_abs; TCHAR szTmp[MAX_PATH]; memcpy(szTmp, pSrc, (dwSrcLen * sizeof(TCHAR))); szTmp[dwSrcLen] = 0; _tcslwr(szTmp); if (_tcsstr(szTmp, cfg::dat.tszProfilePath)) { dwProfilePathLen = mir_tstrlen(cfg::dat.tszProfilePath); memcpy(pOut, (pSrc + (dwProfilePathLen - 1)), ((dwSrcLen - (dwProfilePathLen - 1)) * sizeof(TCHAR))); pOut[0] = '.'; pOut[dwSrcLen] = 0; return (dwSrcLen - (dwProfilePathLen - 1)); } path_not_abs: memcpy(pOut, pSrc, (dwSrcLen * sizeof(TCHAR))); pOut[dwSrcLen] = 0; return dwSrcLen; }
/** * measure callback for the advanced sidebar button layout (vertical mode * with variable height buttons) */ const SIZE& __fastcall CSideBar::m_measureAdvancedVertical(CSideBarButton* item) { SIZE sz = { 0 }; const TWindowData *dat = item->getDat(); if (dat) { SIZE szFirstLine, szSecondLine; if (dat->ace && dat->ace->hbmPic) sz.cy = item->getLayout()->width; HDC dc = ::GetDC(dat->hwnd); HFONT hOldFont = reinterpret_cast<HFONT>(::SelectObject(dc, CInfoPanel::m_ipConfig.hFonts[IPFONTID_NICK])); ::GetTextExtentPoint32(dc, dat->cache->getNick(), (int)mir_tstrlen(dat->cache->getNick()), &szFirstLine); ::SelectObject(dc, CInfoPanel::m_ipConfig.hFonts[IPFONTID_STATUS]); ::GetTextExtentPoint32(dc, dat->szStatus, (int)mir_tstrlen(dat->szStatus), &szSecondLine); ::SelectObject(dc, hOldFont); ReleaseDC(dat->hwnd, dc); szSecondLine.cx += 18; // icon space sz.cy += max(szFirstLine.cx + 4, szSecondLine.cx + 4); sz.cy += 2; } item->setSize(sz); return(item->getSize()); }
static TCHAR *parseNum(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; int val = ttoi(ai->targv[1]); int padding = ttoi(ai->targv[2]); TCHAR *szVal = itot(val); if (szVal == NULL) return NULL; unsigned zeros = max(padding - (signed int)mir_tstrlen(szVal), 0); TCHAR *res = (TCHAR*)mir_alloc((zeros + mir_tstrlen(szVal) + 1)*sizeof(TCHAR)); if (res == NULL) { mir_free(szVal); return NULL; } memset(res, 0, ((zeros + mir_tstrlen(szVal) + 1) * sizeof(TCHAR))); TCHAR *cur = res; for (unsigned i = 0; i < zeros; i++) *cur++ = '0'; mir_tstrcat(res, szVal); mir_free(szVal); return res; }
static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) { DBVARIANT dbv; if (!db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv)) { if (dbv.ptszVal[0]) { STARTUPINFO si = { 0 }; si.cb = sizeof(si); TCHAR *pszReplace = _tcsstr(dbv.ptszVal, _T("%f")); TCHAR szCmdLine[768]; if (pszReplace) { if (info->szFile[mir_tstrlen(info->szFile) - 1] == '\\') info->szFile[mir_tstrlen(info->szFile) - 1] = '\0'; *pszReplace = 0; mir_sntprintf(szCmdLine, _T("%s\"%s\"%s"), dbv.ptszVal, info->szFile, pszReplace + 2); } else _tcsncpy_s(szCmdLine, dbv.ptszVal, _TRUNCATE); PROCESS_INFORMATION pi; if (CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { if (WaitForSingleObject(pi.hProcess, 3600 * 1000) == WAIT_OBJECT_0) PostMessage(info->hwndReply, M_VIRUSSCANDONE, info->returnCode, 0); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); } } db_free(&dbv); } mir_free(info->szFile); mir_free(info); }
void FormatMessageUrl(LPCTSTR format, LPTSTR buf, LPCTSTR mailbox, LPCTSTR tid) { ULARGE_INTEGER iTid; iTid.QuadPart = _tstoi64(tid); size_t l = mir_tstrlen(buf); mir_sntprintf(buf, l, format, mailbox, iTid.HighPart, iTid.LowPart); assert(l >= mir_tstrlen(buf)); }
void MakeUrlHex(LPTSTR url, LPCTSTR tid) { ULARGE_INTEGER iTid; iTid.QuadPart = _tstoi64(tid); LPTSTR tidInUrl = _tcsstr(url, tid); LPTSTR trail = tidInUrl + mir_tstrlen(tid); wsprintf(tidInUrl, _T("%x%08x"), iTid.HighPart, iTid.LowPart); //!!!!!!!!!!!! wmemmove(tidInUrl + mir_tstrlen(tidInUrl), trail, mir_tstrlen(trail) + 1); }
// hKey must have been opened with KEY_SET_VALUE access right static void SetRegStrPrefixValue(HKEY hKey,const TCHAR *pszValPrefix,const TCHAR *pszVal) { DWORD dwSize=(mir_tstrlen(pszVal)+mir_tstrlen(pszValPrefix)+1)*sizeof(TCHAR); TCHAR *pszStr=(TCHAR*)mir_alloc(dwSize); if (pszStr==NULL) return; mir_tstrcat(mir_tstrcpy(pszStr,pszValPrefix),pszVal); /* buffer safe */ RegSetValueEx(hKey,NULL,0,REG_SZ,(BYTE*)pszStr,dwSize); mir_free(pszStr); }
/** * name: CtrlContactWriteMyItemsToDB * desc: write a list of custom items from combobox to database * param: none * return: always 0 **/ int CtrlContactWriteMyItemsToDB( HWND hCtrl, int iFirstItem, MCONTACT hContact, LPCSTR pszModule, LPCSTR pszProto, LPCSTR szFormatCat, LPCSTR szFormatVal) { CHAR pszSetting[MAXSETTING]; TCHAR szCat[MAX_CAT]; TCHAR szVal[MAXDATASIZE]; LPTSTR pszOther; CBEXITEM cbi; INT_PTR ccOther; int i = 0; if (!CtrlContactWndProc(hCtrl, CBEXM_ISCHANGED, NULL, NULL)) return 1; if (!hContact && !(pszModule = pszProto)) return 1; pszOther = TranslateT("Other"); ccOther = mir_tstrlen(pszOther); cbi.wMask = CBEXIM_CAT|CBEXIM_VAL|CBEXIM_FLAGS; cbi.pszCat = szCat; cbi.ccCat = MAX_CAT; cbi.pszVal = szVal; cbi.ccVal = MAXDATASIZE - 4; cbi.iItem = iFirstItem; cbi.dwID = 0; while (CtrlContactWndProc(hCtrl, CBEXM_GETITEM, NULL, (LPARAM)&cbi) && cbi.iItem < 50) { if (!(cbi.wFlags & CBEXIF_DELETED) && *szVal) { if (cbi.wFlags & CBEXIF_SMS) { mir_tstrncat(szVal, _T(" SMS"), _countof(szVal) - mir_tstrlen(szVal)); } mir_snprintf(pszSetting, szFormatCat, i); if (*szCat && _tcsncmp(szCat, pszOther, ccOther)) { if (db_set_ts(hContact, pszModule, pszSetting, szCat)) return 1; } else db_unset(hContact, pszModule, pszSetting); mir_snprintf(pszSetting, szFormatVal, i); if (db_set_ts(hContact, pszModule, pszSetting, szVal)) return 1; cbi.wFlags &= ~CTRLF_CHANGED; cbi.wMask = CBEXIM_FLAGS; CtrlContactWndProc(hCtrl, CBEXM_SETITEM, NULL, (LPARAM)&cbi); cbi.wMask = CBEXIM_CAT|CBEXIM_VAL|CBEXIM_FLAGS; i++; } cbi.iItem++; } DB::Setting::DeleteArray(hContact, pszModule, szFormatCat, i); DB::Setting::DeleteArray(hContact, pszModule, szFormatVal, i); InvalidateRect(GetDlgItem(hCtrl, EDIT_VALUE), NULL, TRUE); return 0; }
void CDropbox::RequestAccountInfo() { MCONTACT hContact = CDropbox::GetDefaultContact(); ptrA token(db_get_sa(NULL, MODULE, "TokenSecret")); GetAccountInfoRequest request(token); NLHR_PTR response(request.Send(hNetlibConnection)); HandleHttpResponseError(response); JSONNode root = JSONNode::parse(response->pData); if (root.empty()) return; JSONNode referral_link = root.at("referral_link"); if (!referral_link.empty()) db_set_s(hContact, MODULE, "Homepage", referral_link.as_string().c_str()); JSONNode display_name = root.at("display_name"); if (!display_name.empty()) { ptrT display_name(mir_utf8decodeT(display_name.as_string().c_str())); TCHAR *sep = _tcsrchr(display_name, _T(' ')); if (sep) { db_set_ts(hContact, MODULE, "LastName", sep + 1); display_name[mir_tstrlen(display_name) - mir_tstrlen(sep)] = '\0'; db_set_ts(hContact, MODULE, "FirstName", display_name); } else { db_set_ts(hContact, MODULE, "FirstName", display_name); db_unset(hContact, MODULE, "LastName"); } } JSONNode country = root.at("country"); if (!country.empty()) { std::string isocode = country.as_string(); if (isocode.empty()) db_unset(hContact, MODULE, "Country"); else { char *country = (char *)CallService(MS_UTILS_GETCOUNTRYBYISOCODE, (WPARAM)isocode.c_str(), 0); db_set_s(hContact, MODULE, "Country", country); } } JSONNode quota_info = root.at("quota_info"); if (!quota_info.empty()) { db_set_dw(hContact, MODULE, "SharedQuota", quota_info.at("shared").as_int()); db_set_dw(hContact, MODULE, "NormalQuota", quota_info.at("normal").as_int()); db_set_dw(hContact, MODULE, "TotalQuota", quota_info.at("quota").as_int()); } }
static TCHAR *parseLonger(ARGUMENTSINFO *ai) { if (ai->argc != 3) return NULL; if (mir_tstrlen(ai->targv[1]) <= mir_tstrlen(ai->targv[2])) ai->flags |= AIF_FALSE; return mir_tstrdup(_T("")); }
void RemoveTag(TCHAR *to, TCHAR *tag) { TCHAR *st = to; int len = (int)mir_tstrlen(tag); int lastsize = (int)mir_tstrlen(to) + 1; while (st = _tcsstr(st, tag)) { lastsize -= len; memmove((void*)st, (void*)(st + len), (lastsize)*sizeof(TCHAR)); } }
// pszDdeCmd is allowed to be NULL void AddRegOpenWith(const TCHAR *pszAppFileName,BOOL fAllowOpenWith,const TCHAR *pszAppName,const TCHAR *pszIconLoc,const TCHAR *pszRunCmd,const TCHAR *pszDdeCmd,const TCHAR *pszDdeApp,const TCHAR *pszDdeTopic) { HKEY hRootKey,hAppsKey,hExeKey,hShellKey,hVerbKey,hDdeKey; /* try to open interactive user's classes key */ if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Classes"),0,KEY_QUERY_VALUE,&hRootKey)) hRootKey=HKEY_CLASSES_ROOT; /* database */ if (!RegCreateKeyEx(hRootKey,_T("Applications"),0,NULL,0,KEY_CREATE_SUB_KEY,NULL,&hAppsKey,NULL)) { /* filename */ if (!RegCreateKeyEx(hAppsKey,pszAppFileName,0,NULL,0,KEY_SET_VALUE|KEY_CREATE_SUB_KEY,NULL,&hExeKey,NULL)) { /* appname */ RegSetValueEx(hExeKey,NULL,0,REG_SZ,(BYTE*)pszAppName,(int)(mir_tstrlen(pszAppName)+1)*sizeof(TCHAR)); /* no open-with flag */ if (fAllowOpenWith) RegDeleteValue(hExeKey,_T("NoOpenWith")); else RegSetValueEx(hExeKey,_T("NoOpenWith"),0,REG_SZ,NULL,0); /* default icon */ if (pszIconLoc!=NULL) SetRegSubKeyStrDefValue(hExeKey,_T("DefaultIcon"),pszIconLoc); /* shell */ if (!RegCreateKeyEx(hExeKey,_T("shell"),0,NULL,0,KEY_SET_VALUE|KEY_CREATE_SUB_KEY,NULL,&hShellKey,NULL)) { /* default verb (when empty "open" is used) */ RegSetValueEx(hShellKey,NULL,0,REG_SZ,(BYTE*)_T("open"),5*sizeof(TCHAR)); /* verb */ if (!RegCreateKeyEx(hShellKey,_T("open"),0,NULL,0,KEY_SET_VALUE|KEY_CREATE_SUB_KEY,NULL,&hVerbKey,NULL)) { /* friendly appname (mui string) */ RegSetValueEx(hVerbKey,_T("FriendlyAppName"),0,REG_SZ,(BYTE*)pszAppName,(int)(mir_tstrlen(pszAppName)+1)*sizeof(TCHAR)); /* command */ SetRegSubKeyStrDefValue(hVerbKey,_T("command"),pszRunCmd); /* ddeexec */ if (pszDdeCmd!=NULL) if (!RegCreateKeyEx(hVerbKey,_T("ddeexec"),0,NULL,0,KEY_SET_VALUE|KEY_CREATE_SUB_KEY,NULL,&hDdeKey,NULL)) { /* command */ RegSetValueEx(hDdeKey,NULL,0,REG_SZ,(BYTE*)pszDdeCmd,(int)(mir_tstrlen(pszDdeCmd)+1)*sizeof(TCHAR)); /* application */ SetRegSubKeyStrDefValue(hDdeKey,_T("application"),pszDdeApp); /* topic */ SetRegSubKeyStrDefValue(hDdeKey,_T("topic"),pszDdeTopic); RegCloseKey(hDdeKey); } RegCloseKey(hVerbKey); } RegCloseKey(hShellKey); } RegCloseKey(hExeKey); } RegCloseKey(hAppsKey); } if (hRootKey!=HKEY_CLASSES_ROOT) RegCloseKey(hRootKey); }
TCHAR* GetFullName(const TCHAR *filename) { size_t flen = mir_tstrlen(filename); TCHAR* fullname = const_cast<TCHAR*>(filename); if (!_tcschr(filename, _T(':'))) { size_t plen = mir_tstrlen(tszPath); fullname = new TCHAR[plen + flen + 1]; fullname[0] = NULL; mir_tstrcat(fullname, tszPath); mir_tstrcat(fullname, filename); } return fullname; }
CMLuaScript::CMLuaScript(lua_State *L, const TCHAR* path) : L(L), unloadRef(0) { mir_tstrcpy(filePath, path); fileName = _tcsrchr(filePath, '\\') + 1; size_t length = mir_tstrlen(fileName) - 3; ptrT name((TCHAR*)mir_calloc(sizeof(TCHAR) * length)); mir_tstrncpy(name, fileName, mir_tstrlen(fileName) - 3); moduleName = mir_utf8encodeT(name); }
void AddRegOpenWithExtEntry(const TCHAR *pszAppFileName,const char *pszFileExt,const TCHAR *pszFileDesc) { HKEY hRootKey,hAppsKey,hExeKey,hTypesKey; /* try to open interactive user's classes key */ if (RegOpenKeyEx(HKEY_CURRENT_USER,_T("Software\\Classes"),0,KEY_QUERY_VALUE,&hRootKey)) hRootKey=HKEY_CLASSES_ROOT; /* applications */ if (!RegOpenKeyEx(hRootKey,_T("Applications"),0,KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS,&hAppsKey)) { /* filename */ if (!RegOpenKeyEx(hAppsKey,pszAppFileName,0,KEY_CREATE_SUB_KEY,&hExeKey)) { /* supported types */ if (!RegCreateKeyEx(hExeKey,_T("SupportedTypes"),0,NULL,0,KEY_SET_VALUE,NULL,&hTypesKey,NULL)) { TCHAR *ptszFileExt; ptszFileExt=a2t(pszFileExt); if (ptszFileExt!=NULL) RegSetValueEx(hTypesKey,ptszFileExt,0,REG_SZ,(BYTE*)pszFileDesc,(int)(mir_tstrlen(pszFileDesc)+1)*sizeof(TCHAR)); mir_free(ptszFileExt); /* does NULL check */ RegCloseKey(hTypesKey); } RegCloseKey(hExeKey); } RegCloseKey(hAppsKey); } if (hRootKey!=HKEY_CLASSES_ROOT) RegCloseKey(hRootKey); }
WORD MTime::DateFormatAlt(LPTSTR ptszTimeFormat, WORD cchTimeFormat) { if (!ptszTimeFormat || !cchTimeFormat) return 0; WORD wRes = DateFormat(ptszTimeFormat, cchTimeFormat); if (wRes != 0) return wRes; SYSTEMTIME AltSysTime = _SysTime; MTime mtNow; mtNow.GetLocalTime(); AltSysTime.wYear=mtNow.Year(); if ((cchTimeFormat = GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &AltSysTime, NULL, ptszTimeFormat, cchTimeFormat)) == 0) { *ptszTimeFormat = 0; return 0; } TCHAR tszText[10]; _itot(mtNow.Year(), tszText, 10); TCHAR * tszYear = _tcsstr(ptszTimeFormat, tszText); if (tszYear && mir_tstrlen(tszYear) == 4) mir_tstrcpy(tszYear, _T("????")); else { *ptszTimeFormat = 0; return 0; } return cchTimeFormat; }
/** * Measure the metrics for the current item. The side bar layouting will call this * whenever a layout with a dynamic height is active). For fixed dimension layouts, * m_elementWidth and m_elementHeight will be used. * * @return SIZE&: reference to the item's size member. The caller may use cx and cy values * to determine further layouting actions. */ const SIZE& CSideBarButton::measureItem() { SIZE sz; if (m_sideBarLayout->pfnMeasureItem) m_sideBarLayout->pfnMeasureItem(this); // use the current layout's function, if available, else use default else { HDC dc = ::GetDC(m_hwnd); TCHAR tszLabel[255]; HFONT oldFont = reinterpret_cast<HFONT>(::SelectObject(dc, ::GetStockObject(DEFAULT_GUI_FONT))); _tcsncpy_s(tszLabel, m_dat->newtitle, _TRUNCATE); ::GetTextExtentPoint32(dc, tszLabel, (int)mir_tstrlen(tszLabel), &sz); sz.cx += 28; if (m_dat->pContainer->dwFlagsEx & TCF_CLOSEBUTTON) sz.cx += 20; if (m_sideBarLayout->dwFlags & CSideBar::SIDEBARLAYOUT_VERTICALORIENTATION) m_sz.cy = sz.cx; else m_sz.cx = sz.cx; ::SelectObject(dc, oldFont); ::ReleaseDC(m_hwnd, dc); } return(m_sz); }
static INT_PTR CALLBACK DlgProcHistoryFind(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDCANCEL: DestroyWindow(hwndDlg); return TRUE; case IDOK://find Next TCHAR str[128]; HWND hwndParent = (HWND)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); GetDlgItemText(hwndDlg, IDC_FINDWHAT, str, _countof(str)); CharUpperBuff(str, (int)mir_tstrlen(str)); SendMessage(hwndParent, DM_FINDNEXT, 0, (LPARAM)str); return TRUE; } break; } return FALSE; }
/** * The user changed information stored in the control. * * @return nothing **/ void CEditCtrl::OnChangedByUser(WORD wChangedMsg) { if ((wChangedMsg == EN_UPDATE) || (wChangedMsg == EN_CHANGE)) { const int cch = GetWindowTextLength(_hwnd); _Flags.B.hasChanged = mir_tstrlen(_pszValue) != cch; _Flags.B.hasCustom = (cch > 0); if (!_Flags.B.hasChanged && _Flags.B.hasCustom) { BYTE need_free = 0; LPTSTR szText; __try { szText = (LPTSTR)alloca((cch + 1) * sizeof(TCHAR)); } __except (EXCEPTION_EXECUTE_HANDLER) { szText = (LPTSTR)mir_alloc((cch + 1) * sizeof(TCHAR)); need_free = 1; } if (szText != NULL) { GetWindowText(_hwnd, szText, cch + 1); _Flags.B.hasChanged = mir_tstrcmp(_pszValue, szText); if (need_free) MIR_FREE(szText); } else _Flags.B.hasChanged = 0; } InvalidateRect(_hwnd, NULL, TRUE); if (_Flags.B.hasChanged) SendMessage(GetParent(GetParent(_hwnd)), PSM_CHANGED, 0, 0); }
int CSkypeProto::RecvContacts(MCONTACT hContact, PROTORECVEVENT* pre) { PROTOSEARCHRESULT **isrList = (PROTOSEARCHRESULT**)pre->szMessage; DWORD cbBlob = 0; BYTE *pBlob; BYTE *pCurBlob; int i; int nCount = *((LPARAM*)pre->lParam); char* szMessageId = ((char*)pre->lParam + sizeof(LPARAM)); //if (GetMessageFromDb(hContact, szMessageId, pre->timestamp)) return 0; for (i = 0; i < nCount; i++) cbBlob += int(/*mir_tstrlen(isrList[i]->nick.t)*/0 + 2 + mir_tstrlen(isrList[i]->id.t) + mir_strlen(szMessageId)); pBlob = (PBYTE)mir_calloc(cbBlob); for (i = 0, pCurBlob = pBlob; i < nCount; i++) { //mir_strcpy((char*)pCurBlob, _T2A(isrList[i]->nick.t)); pCurBlob += mir_strlen((PCHAR)pCurBlob) + 1; mir_strcpy((char*)pCurBlob, _T2A(isrList[i]->id.t)); pCurBlob += mir_strlen((char*)pCurBlob) + 1; } //memcpy(pCurBlob + 1, szMessageId, mir_strlen(szMessageId)); AddEventToDb(hContact, EVENTTYPE_CONTACTS, pre->timestamp, (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0, cbBlob, pBlob); mir_free(pBlob); return 0; }
void fnDeleteItemFromTree(HWND hwnd, MCONTACT hItem) { ClcContact *contact; ClcGroup *group; struct ClcData *dat = (struct ClcData *) GetWindowLongPtr(hwnd, 0); dat->needsResort = 1; if (!cli.pfnFindItem(hwnd, dat, hItem, &contact, &group, NULL)) { DBVARIANT dbv; int i, nameOffset; if (!IsHContactContact(hItem)) return; if (db_get_ts(hItem, "CList", "Group", &dbv)) return; //decrease member counts of all parent groups too group = &dat->list; nameOffset = 0; for (i=0;; i++) { if (group->scanIndex == group->cl.count) break; if (group->cl.items[i]->type == CLCIT_GROUP) { size_t len = mir_tstrlen(group->cl.items[i]->szText); if (!_tcsncmp(group->cl.items[i]->szText, dbv.ptszVal + nameOffset, len) && (dbv.ptszVal[nameOffset + len] == '\\' || dbv.ptszVal[nameOffset + len] == '\0')) { group->totalMembers--; if (dbv.ptszVal[nameOffset + len] == '\0') break; } } } mir_free(dbv.ptszVal); } else cli.pfnRemoveItemFromGroup(hwnd, group, contact, 1); }
int LoadOptions(void) { options.backup_types = (BackupType)db_get_b(0, "AutoBackups", "BackupType", (BYTE)(BT_PERIODIC)); options.period = (unsigned int)db_get_w(0, "AutoBackups", "Period", 1); options.period_type = (PeriodType)db_get_b(0, "AutoBackups", "PeriodType", (BYTE)PT_DAYS); if (!ServiceExists(MS_FOLDERS_GET_PATH)) { DBVARIANT dbv; if (!db_get_ts(0, "AutoBackups", "Folder", &dbv)) { TCHAR *tmp = Utils_ReplaceVarsT(dbv.ptszVal); if (mir_tstrlen(tmp) >= 2 && tmp[1] == ':') _tcsncpy_s(options.folder, dbv.ptszVal, _TRUNCATE); else mir_sntprintf(options.folder, _countof(options.folder), _T("%s\\%s"), profilePath, dbv.ptszVal); db_free(&dbv); mir_free(tmp); } else mir_sntprintf(options.folder, _countof(options.folder), _T("%s%s"), DIR, SUB_DIR); } options.num_backups = db_get_w(0, "AutoBackups", "NumBackups", 3); options.disable_progress = (BOOL)db_get_b(0, "AutoBackups", "NoProgress", 0); options.disable_popups = (BOOL)db_get_b(0, "AutoBackups", "NoPopups", 0); options.use_zip = (BOOL)db_get_b(0, "AutoBackups", "UseZip", 0); SetBackupTimer(); return 0; }
INT_PTR CALLBACK Utils::DlgProcSetFileName(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { TCHAR *fileName = (TCHAR *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); fileName = (TCHAR *)lParam; SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)fileName); SetDlgItemText(hwndDlg, IDC_NAME, fileName); if (GetDlgCtrlID((HWND)wParam) != IDC_NAME) { SetFocus(GetDlgItem(hwndDlg, IDC_NAME)); SendDlgItemMessage(hwndDlg, IDC_NAME, EM_SETSEL, 0, mir_tstrlen(fileName) - 4); return FALSE; } return TRUE; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { if (LOWORD(wParam) == IDOK) { GetDlgItemText(hwndDlg, IDC_NAME, fileName, 64); EndDialog(hwndDlg, IDOK); } else if (LOWORD(wParam) == IDCANCEL) { EndDialog(hwndDlg, IDCANCEL); } } break; } return FALSE; }
static BOOL IsValidRunCommand(const TCHAR *pszRunCmd) { TCHAR *buf,*pexe,*pargs; TCHAR szFullExe[MAX_PATH],*pszFilePart; buf=mir_tstrcpy((TCHAR*)_alloca((mir_tstrlen(pszRunCmd)+1)*sizeof(TCHAR)),pszRunCmd); /* split into executable path and arguments */ if (buf[0]==_T('\"')) { pargs=_tcschr(&buf[1],_T('\"')); if (pargs!=NULL) *(pargs++)=0; pexe=&buf[1]; if (*pargs==_T(' ')) ++pargs; } else { pargs=_tcschr(buf,_T(' ')); if (pargs!=NULL) *pargs=0; pexe=buf; } if (SearchPath(NULL,pexe,_T(".exe"),_countof(szFullExe),szFullExe,&pszFilePart)) { if (pszFilePart!=NULL) if (!mir_tstrcmpi(pszFilePart,_T("rundll32.exe")) || !mir_tstrcmpi(pszFilePart,_T("rundll.exe"))) { /* split into dll path and arguments */ if (pargs[0]==_T('\"')) { ++pargs; pexe=_tcschr(&pargs[1],_T('\"')); if (pexe!=NULL) *pexe=0; } else { pexe=_tcschr(pargs,_T(',')); if (pexe!=NULL) *pexe=0; } return SearchPath(NULL,pargs,_T(".dll"),0,NULL,NULL)!=0; } return TRUE; } return FALSE; }
int CreateGroup(const TCHAR *group, MCONTACT hContact) { if (group == NULL) return 0; size_t cbName = mir_tstrlen(group); TCHAR *tszGrpName = (TCHAR*)_alloca((cbName + 2)*sizeof(TCHAR)); tszGrpName[0] = 1 | GROUPF_EXPANDED; mir_tstrcpy(tszGrpName + 1, group); // Check for duplicate & find unused id char groupIdStr[11]; for (int groupId = 0;; groupId++) { itoa(groupId, groupIdStr, 10); ptrT tszDbGroup(db_get_tsa(NULL, "CListGroups", groupIdStr)); if (tszDbGroup == NULL) break; if (!mir_tstrcmp((TCHAR*)tszDbGroup+1, tszGrpName+1)) { if (hContact) db_set_ts(hContact, "CList", "Group", tszGrpName + 1); else AddMessage(LPGENT("Skipping duplicate group %s."), tszGrpName + 1); return 0; } } db_set_ts(NULL, "CListGroups", groupIdStr, tszGrpName); if (hContact) db_set_ts(hContact, "CList", "Group", tszGrpName + 1); return 1; }