本文整理汇总了C++中wxStringBuffer函数的典型用法代码示例。如果您正苦于以下问题:C++ wxStringBuffer函数的具体用法?C++ wxStringBuffer怎么用?C++ wxStringBuffer使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wxStringBuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _pop
LogPacket _pop()
{
LogPacket ret;
u32 c_get = m_get;
const u32& sprefix = *(u32*)&m_buffer[c_get];
c_get += sizeof(u32);
if(sprefix) memcpy(wxStringBuffer(ret.m_prefix, sprefix), &m_buffer[c_get], sprefix);
c_get += sprefix;
const u32& stext = *(u32*)&m_buffer[c_get];
c_get += sizeof(u32);
if(stext) memcpy(wxStringBuffer(ret.m_text, stext), &m_buffer[c_get], stext);
c_get += stext;
const u32& scolour = *(u32*)&m_buffer[c_get];
c_get += sizeof(u32);
if(scolour) memcpy(wxStringBuffer(ret.m_colour, scolour), &m_buffer[c_get], scolour);
c_get += scolour;
m_get = c_get;
if(!HasNewPacket()) Flush();
return ret;
}
示例2: WXUNUSED
bool wxFileDataObject::SetData(size_t WXUNUSED(size),
const void *WXUNUSED_IN_WINCE(pData))
{
#ifndef __WXWINCE__
m_filenames.Empty();
// the documentation states that the first member of DROPFILES structure is
// a "DWORD offset of double NUL terminated file list". What they mean by
// this (I wonder if you see it immediately) is that the list starts at
// ((char *)&(pDropFiles.pFiles)) + pDropFiles.pFiles. We're also advised
// to use DragQueryFile to work with this structure, but not told where and
// how to get HDROP.
HDROP hdrop = (HDROP)pData; // NB: it works, but I'm not sure about it
// get number of files (magic value -1)
UINT nFiles = ::DragQueryFile(hdrop, (unsigned)-1, NULL, 0u);
wxCHECK_MSG ( nFiles != (UINT)-1, FALSE, wxT("wrong HDROP handle") );
// for each file get the length, allocate memory and then get the name
wxString str;
UINT len, n;
for ( n = 0; n < nFiles; n++ ) {
// +1 for terminating NUL
len = ::DragQueryFile(hdrop, n, NULL, 0) + 1;
UINT len2 = ::DragQueryFile(hdrop, n, wxStringBuffer(str, len), len);
m_filenames.Add(str);
if ( len2 != len - 1 ) {
wxLogDebug(wxT("In wxFileDropTarget::OnDrop DragQueryFile returned\
%d characters, %d expected."), len2, len - 1);
}
}
示例3: wxGetWindowClass
wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd)
{
wxString str;
if ( hWnd )
{
int len = 256; // some starting value
for ( ;; )
{
int count = ::GetClassName((HWND)hWnd, wxStringBuffer(str, len), len);
if ( count == len )
{
// the class name might have been truncated, retry with larger
// buffer
len *= 2;
}
else
{
break;
}
}
}
return str;
}
示例4: wxGetEnv
bool wxGetEnv(const wxString& WXUNUSED_IN_WINCE(var),
wxString *WXUNUSED_IN_WINCE(value))
{
#ifdef __WXWINCE__
// no environment variables under CE
return false;
#else // Win32
// first get the size of the buffer
DWORD dwRet = ::GetEnvironmentVariable(var.t_str(), NULL, 0);
if ( !dwRet )
{
// this means that there is no such variable
return false;
}
if ( value )
{
(void)::GetEnvironmentVariable(var.t_str(),
wxStringBuffer(*value, dwRet),
dwRet);
}
return true;
#endif // WinCE/32
}
示例5: wxT
void ReportDialog::OnButtonSave(wxCommandEvent& event)
{
wxFileDialog dialog
(
this,
wxT("Spara rapport"),
wxEmptyString,
wxT("TPTest5 rapport.txt"),
wxT("Text files (*.txt)|*.txt"),
wxSAVE | wxOVERWRITE_PROMPT | wxCHANGE_DIR
);
wxString dir;
#ifdef WIN32
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, wxStringBuffer(dir, MAX_PATH));
if(SUCCEEDED(result)) // or FAILED(result)
{
// Do something
}
#endif
dialog.SetDirectory(dir);
if (dialog.ShowModal() == wxID_OK)
{
wxFileOutputStream output( dialog.GetPath() );
wxTextOutputStream text( output );
text.WriteString( m_Output->GetValue() );
}
}
示例6: wxStrcpy
void StringTestCase::StringBuf()
{
// check that buffer can be used to write into the string
wxString s;
wxStrcpy(wxStringBuffer(s, 10), wxT("foo"));
CPPUNIT_ASSERT_EQUAL(3, s.length());
CPPUNIT_ASSERT(wxT('f') == s[0u]);
CPPUNIT_ASSERT(wxT('o') == s[1]);
CPPUNIT_ASSERT(wxT('o') == s[2]);
{
// also check that the buffer initially contains the original string
// contents
wxStringBuffer buf(s, 10);
CPPUNIT_ASSERT_EQUAL( wxT('f'), buf[0] );
CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[1] );
CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[2] );
CPPUNIT_ASSERT_EQUAL( wxT('\0'), buf[3] );
}
{
wxStringBufferLength buf(s, 10);
CPPUNIT_ASSERT_EQUAL( wxT('f'), buf[0] );
CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[1] );
CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[2] );
CPPUNIT_ASSERT_EQUAL( wxT('\0'), buf[3] );
// and check that it can be used to write only the specified number of
// characters to the string
wxStrcpy(buf, wxT("barrbaz"));
buf.SetLength(4);
}
CPPUNIT_ASSERT_EQUAL(4, s.length());
CPPUNIT_ASSERT(wxT('b') == s[0u]);
CPPUNIT_ASSERT(wxT('a') == s[1]);
CPPUNIT_ASSERT(wxT('r') == s[2]);
CPPUNIT_ASSERT(wxT('r') == s[3]);
// check that creating buffer of length smaller than string works, i.e. at
// least doesn't crash (it would if we naively copied the entire original
// string contents in the buffer)
*wxStringBuffer(s, 1) = '!';
}
示例7: CrashHandlerSaveEditorFiles
inline void CrashHandlerSaveEditorFiles(wxString& buf)
{
wxString path;
//get the "My Files" folder
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, wxStringBuffer(path, MAX_PATH));
if (FAILED(result))
{ //get at least the profiles folder
path = ConfigManager::GetHomeFolder();
}
path << _T("\\cb-crash-recover");
if (!wxDirExists(path)) wxMkdir(path);
//make a sub-directory of the current date & time
wxDateTime now = wxDateTime::Now();
path << now.Format(_T("\\%Y%m%d-%H%M%S"));
EditorManager* em = Manager::Get()->GetEditorManager();
if (em)
{
bool AnyFileSaved = false;
if (wxMkdir(path) && wxDirExists(path))
{
for (int i = 0; i < em->GetEditorsCount(); ++i)
{
cbEditor* ed = em->GetBuiltinEditor(em->GetEditor(i));
if (ed)
{
wxFileName fn(ed->GetFilename());
wxString fnpath = path + _T("/") + fn.GetFullName();
wxString newfnpath = fnpath;
// add number if filename already exists e.g. main.cpp.001, main.cpp.002, ...
int j = 1;
while (wxFileExists(newfnpath))
newfnpath = fnpath + wxString::Format(wxT(".%03d"),j);
if (cbSaveToFile(newfnpath,
ed->GetControl()->GetText(),
ed->GetEncoding(),
ed->GetUseBom() ) )
{
AnyFileSaved = true;
}
}
}
if (AnyFileSaved)
{
buf << _("The currently opened files have been saved to the directory\n");
buf << path;
buf << _("\nHopefully, this will prevent you from losing recent modifications.\n\n");
}
else
wxRmdir(path);
}
}
}
示例8: Length
off_t wxUtfFile::Read(wxString &str, off_t nCount)
{
if (nCount == (off_t) - 1)
nCount = Length() - Tell();
if (!nCount)
return 0;
char *buffer = new char[nCount + 4];
// on some systems, len returned from wxFile::read might not reflect the number of bytes written
// to the buffer, but the bytes read from file. In case of CR/LF translation, this is not the same.
memset(buffer, 0, nCount + 4);
off_t len = wxFile::Read(buffer, nCount);
if (len >= 0)
{
memset(buffer + len, 0, 4);
if (m_conversion)
{
int decr;
size_t nLen = 0;
// We are trying 4 times to convert, in case the last utf char
// was truncated.
for (decr = 0 ; len > 0 && decr < 4 ; decr++)
{
nLen = m_conversion->MB2WC(NULL, buffer, 0);
if ( nLen != (size_t) - 1 )
break;
len--;
buffer[len] = 0;
}
if (nLen == (size_t) - 1)
{
if (!m_strFileName.IsEmpty())
{
wxLogWarning(_("The file \"%s\" could not be opened because it contains characters that could not be interpreted."), m_strFileName.c_str());
}
Seek(decr - nLen, wxFromCurrent);
return (size_t) - 1;
}
if (decr)
Seek(-decr, wxFromCurrent);
m_conversion->MB2WC((wchar_t *)(wxChar *)wxStringBuffer(str, nLen + 1), (const char *)buffer, (size_t)(nLen + 1));
}
else
str = (wxChar *)buffer;
}
delete[] buffer;
return len;
}
示例9: dc
wxSize wxDatePickerCtrl::DoGetBestSize() const
{
wxClientDC dc(const_cast<wxDatePickerCtrl *>(this));
// we can't use FormatDate() here as the CRT doesn't always use the same
// format as the date picker control
wxString s;
for ( int len = 100; ; len *= 2 )
{
if ( ::GetDateFormat
(
LOCALE_USER_DEFAULT, // the control should use the same
DATE_SHORTDATE, // the format used by the control
NULL, // use current date (we don't care)
NULL, // no custom format
wxStringBuffer(s, len), // output buffer
len // and its length
) )
{
// success
break;
}
const DWORD rc = ::GetLastError();
if ( rc != ERROR_INSUFFICIENT_BUFFER )
{
wxLogApiError(wxT("GetDateFormat"), rc);
// fall back on wxDateTime, what else to do?
s = wxDateTime::Today().FormatDate();
break;
}
}
// the best size for the control is bigger than just the string
// representation of todays date because the control must accommodate any
// date and while the widths of all digits are usually about the same, the
// width of the month string varies a lot, so try to account for it
s += wxT("WW");
int x, y;
dc.GetTextExtent(s, &x, &y);
// account for the drop-down arrow or spin arrows
x += wxSystemSettings::GetMetric(wxSYS_HSCROLL_ARROW_X);
// and for the checkbox if we have it
if ( HasFlag(wxDP_ALLOWNONE) )
x += 3*GetCharWidth();
wxSize best(x, EDIT_HEIGHT_FROM_CHAR_HEIGHT(y));
CacheBestSize(best);
return best;
}
示例10: CASE_EXCEPTION
wxString wxCrashContext::GetExceptionString() const
{
wxString s;
#define CASE_EXCEPTION( x ) case EXCEPTION_##x: s = wxT(#x); break
switch ( code )
{
CASE_EXCEPTION(ACCESS_VIOLATION);
CASE_EXCEPTION(DATATYPE_MISALIGNMENT);
CASE_EXCEPTION(BREAKPOINT);
CASE_EXCEPTION(SINGLE_STEP);
CASE_EXCEPTION(ARRAY_BOUNDS_EXCEEDED);
CASE_EXCEPTION(FLT_DENORMAL_OPERAND);
CASE_EXCEPTION(FLT_DIVIDE_BY_ZERO);
CASE_EXCEPTION(FLT_INEXACT_RESULT);
CASE_EXCEPTION(FLT_INVALID_OPERATION);
CASE_EXCEPTION(FLT_OVERFLOW);
CASE_EXCEPTION(FLT_STACK_CHECK);
CASE_EXCEPTION(FLT_UNDERFLOW);
CASE_EXCEPTION(INT_DIVIDE_BY_ZERO);
CASE_EXCEPTION(INT_OVERFLOW);
CASE_EXCEPTION(PRIV_INSTRUCTION);
CASE_EXCEPTION(IN_PAGE_ERROR);
CASE_EXCEPTION(ILLEGAL_INSTRUCTION);
CASE_EXCEPTION(NONCONTINUABLE_EXCEPTION);
CASE_EXCEPTION(STACK_OVERFLOW);
CASE_EXCEPTION(INVALID_DISPOSITION);
CASE_EXCEPTION(GUARD_PAGE);
CASE_EXCEPTION(INVALID_HANDLE);
default:
// unknown exception, ask NTDLL for the name
if ( !::FormatMessage
(
FORMAT_MESSAGE_IGNORE_INSERTS |
FORMAT_MESSAGE_FROM_HMODULE,
::GetModuleHandle(wxT("NTDLL.DLL")),
code,
0,
wxStringBuffer(s, 1024),
1024,
0
) )
{
s.Printf(wxT("UNKNOWN_EXCEPTION(%d)"), code);
}
}
#undef CASE_EXCEPTION
return s;
}
示例11: wxGetFullHostName
wxString wxGetFullHostName()
{
static const size_t hostnameSize = 257;
wxString buf;
bool ok = wxGetFullHostName(wxStringBuffer(buf, hostnameSize), hostnameSize);
if ( !ok )
buf.Empty();
return buf;
}
示例12: wxGetUserName
wxString wxGetUserName()
{
static const int maxUserNameLen = 1024; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserName(wxStringBuffer(buf, maxUserNameLen), maxUserNameLen);
if ( !ok )
buf.Empty();
return buf;
}
示例13: wxGetWindowText
wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
{
wxString str;
if ( hWnd )
{
int len = GetWindowTextLength((HWND)hWnd) + 1;
::GetWindowText((HWND)hWnd, wxStringBuffer(str, len), len);
}
return str;
}
示例14: SHGetSpecialFolderLocation
/// Set File to hash in wxTextCtrl
void
AlcFrame::SetFileToHash()
{
#ifdef __WXMSW__
wxString browseroot;
LPITEMIDLIST pidl;
HRESULT hr = SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl);
if (SUCCEEDED(hr)) {
if (!SHGetPathFromIDList(pidl, wxStringBuffer(browseroot, MAX_PATH))) {
browseroot = wxFileName::GetHomeDir();
}
} else {
browseroot = wxFileName::GetHomeDir();
}
if (pidl) {
LPMALLOC pMalloc;
SHGetMalloc(&pMalloc);
if (pMalloc) {
pMalloc->Free(pidl);
pMalloc->Release();
}
}
#elif defined(__WXMAC__)
FSRef fsRef;
wxString browseroot;
if (FSFindFolder(kUserDomain, kDocumentsFolderType, kCreateFolder, &fsRef) == noErr)
{
CFURLRef urlRef = CFURLCreateFromFSRef(NULL, &fsRef);
CFStringRef cfString = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle);
CFRelease(urlRef) ;
#if wxCHECK_VERSION(2, 9, 0)
browseroot = wxCFStringRef(cfString).AsString(wxLocale::GetSystemEncoding());
#else
browseroot = wxMacCFStringHolder(cfString).AsString(wxLocale::GetSystemEncoding());
#endif
} else {
browseroot = wxFileName::GetHomeDir();
}
#else
wxString browseroot = wxFileName::GetHomeDir();
#endif
const wxString & filename =
wxFileSelector (_("Select the file you want to compute the eD2k link"),
browseroot, wxEmptyString, wxEmptyString, wxT("*.*"),
wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
if (!filename.empty ())
{
m_inputFileTextCtrl->SetValue(filename);
}
}
示例15: wxGetUserId
wxString wxGetUserId()
{
static const int maxLoginLen = 256; // FIXME arbitrary number
wxString buf;
bool ok = wxGetUserId(wxStringBuffer(buf, maxLoginLen), maxLoginLen);
if ( !ok )
buf.Empty();
return buf;
}