INT_PTR SceneSwitcherSettings::ProcMessage(UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: MsgInitDialog(); return TRUE; case WM_COMMAND: return MsgClicked(LOWORD(wParam), HIWORD(wParam), (HWND)lParam); case WM_CTLCOLORSTATIC: if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_RUN) { HDC hdc = (HDC)wParam; SetTextColor(hdc, thePlugin->IsRunning() ? RGB(0,255,0) : RGB(255,0,0)); SetBkColor(hdc, GetSysColor(COLOR_3DFACE)); return (INT_PTR)GetSysColorBrush(COLOR_3DFACE); } break; case WM_NOTIFY: switch (LOWORD(wParam)) { case IDC_WSMAP: { const NMITEMACTIVATE* lpnmitem = (LPNMITEMACTIVATE)lParam; if(lpnmitem->hdr.idFrom == IDC_WSMAP && lpnmitem->hdr.code == NM_CLICK) { const int sel = lpnmitem->iItem; if(sel >= 0) { HWND wsMap = GetDlgItem(hwnd, IDC_WSMAP); HWND hwndAppList = GetDlgItem(hwnd, IDC_APPLIST); HWND hwndMainScn = GetDlgItem(hwnd, IDC_MAINSCN); // Get the text from the item String wnd; wnd.SetLength(256); ListView_GetItemText(wsMap, sel, 0, wnd, 256); String scn; scn.SetLength(256); ListView_GetItemText(wsMap, sel, 1, scn, 256); // Set the combos SetWindowText(hwndAppList, wnd); SendMessage(hwndMainScn, CB_SETCURSEL, SendMessage(hwndMainScn, CB_FINDSTRINGEXACT, -1, (LPARAM)scn.Array()), 0); } } return TRUE; } break; } } return FALSE; }
//Handler for Dragging/Dropping files void __fastcall TForm1::WMDropFiles(TWMDropFiles &message){ unsigned int filecount = DragQueryFile((HDROP)message.Drop, 0xFFFFFFFF, NULL, 0); //for(unsigned int i=0; i<filecount; i++){ // ok, ok, only do the first file if(filecount > 0){ String fileName; fileName.SetLength(MAX_PATH); int length = DragQueryFile((HDROP)message.Drop, 0, fileName.c_str(), fileName.Length()); fileName.SetLength(length); ProcessFile(fileName); } DragFinish((HDROP)message.Drop); }
String FormattedStringva(CTSTR lpFormat, va_list arglist) { int iSize = vtscprintf(lpFormat, arglist); if(!iSize) return String(); String newString; newString.SetLength(iSize); int retVal = vtsprintf_s(newString, iSize+1, lpFormat, arglist); if(retVal == -1) return newString.Clear(); else return newString.SetLength(retVal); }
__declspec(dllexport) void ProcessRemoteCallServerMessages(PVOID pContext) { if (!pContext) return; RemoteCallServerContext *pSrv = (RemoteCallServerContext *)pContext; DWORD dwAvail = 0; if (!PeekNamedPipe(pSrv->m_hPipe, NULL, 0, NULL, &dwAvail, NULL)) { if (GetLastError() == ERROR_BROKEN_PIPE) pSrv->CreateAnotherInstance(); return; } if (!dwAvail) return; String request; DWORD dwDone = 0; ReadFile(pSrv->m_hPipe, request.PreAllocate(dwAvail, false), dwAvail, &dwDone, NULL); request.SetLength(dwDone); if (dwDone != dwAvail) return; PipeMessage msg = {0,}; ProcessRemoteCall(request.c_str(), &msg); WriteFile(pSrv->m_hPipe, &msg, sizeof(msg), &dwDone, NULL); pSrv->CreateAnotherInstance(); }
String XConfig::ProcessString(TSTR &lpTemp) { TSTR lpStart = lpTemp; BOOL bFoundEnd = FALSE; BOOL bPreviousWasEscaped = FALSE; while(*++lpTemp) { if (*lpTemp == '\\' && lpTemp[-1] == '\\') { bPreviousWasEscaped = TRUE; continue; } if(*lpTemp == '"' && (bPreviousWasEscaped || lpTemp[-1] != '\\')) { bFoundEnd = TRUE; break; } bPreviousWasEscaped = FALSE; } if(!bFoundEnd) return String(); ++lpTemp; TCHAR backupChar = *lpTemp; *lpTemp = 0; String string = lpStart; *lpTemp = backupChar; if (string.Length() == 2) return String(); String stringOut = string.Mid(1, string.Length()-1); if (stringOut.IsEmpty()) return String(); TSTR lpStringOut = stringOut; while(*lpStringOut != 0 && (lpStringOut = schr(lpStringOut, '\\')) != 0) { switch(lpStringOut[1]) { case 0: *lpStringOut = 0; break; case '"': *lpStringOut = '"'; scpy(lpStringOut+1, lpStringOut+2); break; case 't': *lpStringOut = '\t'; scpy(lpStringOut+1, lpStringOut+2); break; case 'r': *lpStringOut = '\r'; scpy(lpStringOut+1, lpStringOut+2); break; case 'n': *lpStringOut = '\n'; scpy(lpStringOut+1, lpStringOut+2); break; case '/': *lpStringOut = '/'; scpy(lpStringOut+1, lpStringOut+2); break; case '\\': scpy(lpStringOut+1, lpStringOut+2); break; } lpStringOut++; } stringOut.SetLength(slen(stringOut)); return stringOut; }
String GetLVText(HWND hwndList, UINT id) { String strText; strText.SetLength(256); ListView_GetItemText(hwndList, id, 0, (LPWSTR)strText.Array(), 256); return strText; }
String GetEditText(HWND hwndEdit) { String strText; strText.SetLength((UINT)SendMessage(hwndEdit, WM_GETTEXTLENGTH, 0, 0)); if(strText.Length()) SendMessage(hwndEdit, WM_GETTEXT, strText.Length()+1, (LPARAM)strText.Array()); return strText; }
VOID GenerateGUID(String &strGUID) { BYTE junk[20]; if (!CryptGenRandom(hProvider, sizeof(junk), junk)) return; strGUID.SetLength(41); HashToString(junk, strGUID.Array()); }
String& String::operator+(String& str) { String* s = new String(); s->SetLength(this->GetLength() + str.GetLength()); s->Alloc(s->GetLength()); char* p = s->mBuffer; strncpy(p,this->string(), this->GetLength()); strncpy(p+this->GetLength(), str.string(), str.GetLength()); return *s; }
BOOL STDCALL OSFileHasChanged (OSFileChangeData *data) { BOOL hasModified = FALSE; if(HasOverlappedIoCompleted(&data->directoryChange)) { FILE_NOTIFY_INFORMATION *notify = (FILE_NOTIFY_INFORMATION*)data->changeBuffer; for (;;) { if (notify->Action != FILE_ACTION_RENAMED_OLD_NAME && notify->Action != FILE_ACTION_REMOVED) { String strFileName; strFileName.SetLength(notify->FileNameLength); scpy_n(strFileName, notify->FileName, notify->FileNameLength/2); strFileName.KillSpaces(); String strFileChanged; strFileChanged << data->strDirectory << strFileName; if(strFileChanged.CompareI(data->targetFileName)) { hasModified = TRUE; break; } } if (!notify->NextEntryOffset) break; notify = (FILE_NOTIFY_INFORMATION*)((BYTE *)notify + notify->NextEntryOffset); } CloseHandle (data->directoryChange.hEvent); DWORD test; zero(&data->directoryChange, sizeof(data->directoryChange)); zero(data->changeBuffer, sizeof(data->changeBuffer)); data->directoryChange.hEvent = CreateEvent (NULL, TRUE, FALSE, NULL); if(ReadDirectoryChangesW(data->hDirectory, data->changeBuffer, 2048, FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_SIZE, &test, &data->directoryChange, NULL)) { } else { CloseHandle(data->directoryChange.hEvent); CloseHandle(data->hDirectory); return hasModified; } } return hasModified; }
void NoiseGateSettings::ApplySettings() { String str; int val; HWND ctrlHwnd; // Gate enabled if(SendMessage(GetDlgItem(hwnd, IDC_ENABLEGATE), BM_GETCHECK, 0, 0) == BST_CHECKED) parent->isEnabled = true; else parent->isEnabled = false; // Attack time ctrlHwnd = GetDlgItem(hwnd, IDC_ATTACKTIME_EDIT); str.SetLength(GetWindowTextLength(ctrlHwnd)); GetWindowText(ctrlHwnd, str, str.Length() + 1); parent->attackTime = (float)str.ToInt() * 0.001f; // Hold time ctrlHwnd = GetDlgItem(hwnd, IDC_HOLDTIME_EDIT); str.SetLength(GetWindowTextLength(ctrlHwnd)); GetWindowText(ctrlHwnd, str, str.Length() + 1); parent->holdTime = (float)str.ToInt() * 0.001f; // Release time ctrlHwnd = GetDlgItem(hwnd, IDC_RELEASETIME_EDIT); str.SetLength(GetWindowTextLength(ctrlHwnd)); GetWindowText(ctrlHwnd, str, str.Length() + 1); parent->releaseTime = (float)str.ToInt() * 0.001f; // Close threshold val = (int)SendMessage(GetDlgItem(hwnd, IDC_CLOSETHRES_SLIDER), TBM_GETPOS, 0, 0); parent->closeThreshold = dbToRms((float)(-val)); // Open threshold val = (int)SendMessage(GetDlgItem(hwnd, IDC_OPENTHRES_SLIDER), TBM_GETPOS, 0, 0); parent->openThreshold = dbToRms((float)(-val)); // Save to file parent->SaveSettings(); }
String ANSIStringToString(const TempStringA &str) { ANSI_STRING srcString; str.FillNTString(&srcString); String ret; size_t newLen = RtlAnsiStringToUnicodeSize(&srcString) / sizeof(wchar_t); if (!NT_SUCCESS(RtlAnsiStringToUnicodeString(ret.ToNTString(newLen), &srcString, FALSE))) ret.SetLength(0); else ret.UpdateLengthFromNTString(); return ret; }
String StringHash::StringList(char separator) { String list; for (unsigned int i = 0; i < size; i++) if (SlotInUse(i)) list += *strings[i] + separator; list.SetLength(list.Length() - 1); return list; }
String String::Mid(UINT iStart, UINT iEnd) { if( (iStart >= curLength) || (iEnd > curLength || iEnd <= iStart) ) { AppWarning(TEXT("Bad call to String::Mid. iStart or iEnd is bigger than the current length (string: %s)."), lpString); return String(); } String newString = lpString+iStart; return newString.SetLength(iEnd-iStart); }
void LocalizeWindow(HWND hwnd, LocaleStringLookup *lookup) { if(!lookup) lookup = locale; bool bRTL = LocaleIsRTL(lookup); int textLen = (int)SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0); String strText; strText.SetLength(textLen); GetWindowText(hwnd, strText, textLen+1); if(strText.IsValid() && lookup->HasLookup(strText)) SetWindowText(hwnd, lookup->LookupString(strText)); //------------------------------- RECT rect = { 0 }; GetClientRect(hwnd, &rect); HWND hwndChild = GetWindow(hwnd, GW_CHILD); while(hwndChild) { int textLen = (int)SendMessage(hwndChild, WM_GETTEXTLENGTH, 0, 0); strText.SetLength(textLen); GetWindowText(hwndChild, strText, textLen+1); if(strText.IsValid()) { if(strText[0] == '.') SetWindowText(hwndChild, strText.Array()+1); else { if(strText.IsValid() && lookup->HasLookup(strText)) SetWindowText(hwndChild, lookup->LookupString(strText)); } } hwndChild = GetNextWindow(hwndChild, GW_HWNDNEXT); } };
String GetCBText(HWND hwndCombo, UINT id) { UINT curSel = (id != CB_ERR) ? id : (UINT)SendMessage(hwndCombo, CB_GETCURSEL, 0, 0); if(curSel == CB_ERR) return String(); String strText; strText.SetLength((UINT)SendMessage(hwndCombo, CB_GETLBTEXTLEN, curSel, 0)); if(strText.Length()) SendMessage(hwndCombo, CB_GETLBTEXT, curSel, (LPARAM)strText.Array()); return strText; }
String STDCALL GetStringSection(const TCHAR *lpStart, const TCHAR *lpOffset) { assert(lpStart && lpOffset && lpOffset > lpStart); if(lpStart >= lpOffset) return String(); String newStr; newStr.SetLength((UINT)(lpOffset-lpStart)); scpy_n(newStr, lpStart, (UINT)(lpOffset-lpStart)); return newStr; }
String FileFormat::Status() const { size_type len = 0; (*API->FileFormat->GetFileFormatStatus)( m_data->handle, 0, &len, 0/*reserved*/ ); String status; if ( len > 0 ) { status.SetLength( len ); if ( (*API->FileFormat->GetFileFormatStatus)( m_data->handle, status.Begin(), &len, 0/*reserved*/ ) == api_false ) throw APIFunctionError( "GetFileFormatStatus" ); status.ResizeToNullTerminated(); } return status; }
String Edit::SelectedText() const { size_type len = 0; (*API->Edit->GetEditSelectedText)( handle, 0, &len ); String text; if ( len > 0 ) { text.SetLength( len ); if ( (*API->Edit->GetEditSelectedText)( handle, text.Begin(), &len ) == api_false ) throw APIFunctionError( "GetEditSelectedText" ); text.ResizeToNullTerminated(); } return text; }
String CreateHTTPURL(String host, String path, String extra, bool secure) { URL_COMPONENTS components = { sizeof URL_COMPONENTS, secure ? L"https" : L"http", secure ? 5 : 4, secure ? INTERNET_SCHEME_HTTPS : INTERNET_SCHEME_HTTP, host.Array(), host.Length(), secure ? INTERNET_DEFAULT_HTTPS_PORT : INTERNET_DEFAULT_HTTP_PORT, nullptr, 0, nullptr, 0, path.Array(), path.Length(), extra.Array(), extra.Length() }; String url; url.SetLength(MAX_PATH); DWORD length = MAX_PATH; if (!WinHttpCreateUrl(&components, ICU_ESCAPE, url.Array(), &length)) return String(); url.SetLength(length); return url; }
String ProcessParameter::ScriptComment() const { size_type len = 0; (*API->Process->GetParameterScriptComment)( m_data->handle, 0, &len ); String comment; if ( len > 0 ) { comment.SetLength( len ); if ( (*API->Process->GetParameterScriptComment)( m_data->handle, comment.c_str(), &len ) == api_false ) throw APIFunctionError( "GetParameterScriptComment" ); comment.ResizeToNullTerminated(); } return comment; }
String ProcessParameter::Description() const { size_type len = 0; (*API->Process->GetParameterDescription)( m_data->handle, 0, &len ); String description; if ( len > 0 ) { description.SetLength( len ); if ( (*API->Process->GetParameterDescription)( m_data->handle, description.c_str(), &len ) == api_false ) throw APIFunctionError( "GetParameterDescription" ); description.ResizeToNullTerminated(); } return description; }
String Label::Text() const { size_type len = 0; (*API->Label->GetLabelText)( handle, 0, &len ); String text; if ( len > 0 ) { text.SetLength( len ); if ( (*API->Label->GetLabelText)( handle, text.c_str(), &len ) == api_false ) throw APIFunctionError( "GetLabelText" ); text.ResizeToNullTerminated(); } return text; }
String FileFormatInstance::FilePath() const { size_type len = 0; (*API->FileFormat->GetImageFilePath)( handle, 0, &len ); String path; if ( len > 0 ) { path.SetLength( len ); if ( (*API->FileFormat->GetImageFilePath)( handle, path.Begin(), &len ) == api_false ) throw APIFunctionError( "GetImageFilePath" ); path.ResizeToNullTerminated(); } return path; }
String FileFormatInstance::ImageProperties() const { size_type len = 0; (*API->FileFormat->GetImageProperties)( handle, 0, &len ); String properties; if ( len > 0 ) { properties.SetLength( len ); if ( (*API->FileFormat->GetImageProperties)( handle, properties.Begin(), &len ) == api_false ) throw APIFunctionError( "GetImageProperties" ); properties.ResizeToNullTerminated(); } return properties; }
String TabBox::PageLabel( int idx ) const { size_type len = 0; (*API->TabBox->GetTabBoxPageLabel)( handle, idx, 0, &len ); String label; if ( len > 0 ) { label.SetLength( len ); if ( (*API->TabBox->GetTabBoxPageLabel)( handle, idx, label.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTabBoxPageLabel" ); label.ResizeToNullTerminated(); } return label; }
String ExternalProcess::WorkingDirectory() const { size_type len = 0; (*API->ExternalProcess->GetExternalProcessWorkingDirectory)( handle, 0, &len ); String dirPath; if ( len > 0 ) { dirPath.SetLength( len ); if ( (*API->ExternalProcess->GetExternalProcessWorkingDirectory)( handle, dirPath.c_str(), &len ) == api_false ) throw APIFunctionError( "GetExternalProcessWorkingDirectory" ); dirPath.ResizeToNullTerminated(); } return dirPath; }
String TabBox::PageToolTip( int idx ) const { size_type len = 0; (*API->TabBox->GetTabBoxPageToolTip)( handle, idx, 0, &len ); String tip; if ( len > 0 ) { tip.SetLength( len ); if ( (*API->TabBox->GetTabBoxPageToolTip)( handle, idx, tip.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTabBoxPageToolTip" ); tip.ResizeToNullTerminated(); } return tip; }
String FileFormat::Implementation() const { size_type len = 0; (*API->FileFormat->GetFileFormatImplementation)( m_data->handle, 0, &len ); String implementation; if ( len > 0 ) { implementation.SetLength( len ); if ( (*API->FileFormat->GetFileFormatImplementation)( m_data->handle, implementation.c_str(), &len ) == api_false ) throw APIFunctionError( "GetFileFormatImplementation" ); implementation.ResizeToNullTerminated(); } return implementation; }
String FileFormat::Description() const { size_type len = 0; (*API->FileFormat->GetFileFormatDescription)( m_data->handle, 0, &len ); String description; if ( len > 0 ) { description.SetLength( len ); if ( (*API->FileFormat->GetFileFormatDescription)( m_data->handle, description.Begin(), &len ) == api_false ) throw APIFunctionError( "GetFileFormatDescription" ); description.ResizeToNullTerminated(); } return description; }