- 浏览: 113197 次
文章分类
最新评论
-
myisland:
可以运行!一开始还以为要用本身就是透明背景的png呢,原来不是 ...
在CodeBlocks中用wxWidgets创建不规则窗口 -
lonerzf:
可以的。感谢。但是还有个问题,工程建立的时候有Configur ...
在CodeBlocks中用wxWidgets创建不规则窗口 -
鸵鸟大仙:
麻烦请问一下怎么在wxwidgets中加载msword.olb ...
利用wxwidgets操纵word -
dqifa:
Rat_boy 写道我现在也在做wxWidgets操作Word ...
利用wxwidgets操纵word -
Rat_boy:
我现在也在做wxWidgets操作Word的功能 但是搞了好久 ...
利用wxwidgets操纵word
Literals
A literal is a string written in code with "quotes around it". A literal is not a wxString, and (in wxWidgets 2.8) will not be implicitly converted to one. This means that you can never pass in a raw literal into a wxWidget function or method (unless you don't care about your app not building with Unicode-enabled wxWidgets builds)
MessageBox("I'm a mistake!") // WRONG in WxWidgets 2.8 (OK in 2.9)
Instead, wxWidgets (prior to wxWidgets 2.9) requires you to use one of these macros to turn literals into wxString-compatible characters:
_("text that can be translated") wxT("text that won't be translated") _T("same as wxT") char* c = "sometext"; wxT(c) // WRONG, not a literal
Rather than being a nuisance, the _(), wxT(), and _T() macros take care of some unicode issues and help with internationalization.
char* to wxString
Note that in wxWidgets 2.9, it just works to pass a char array where a wxString parameter is expected, the conversion will be automatic and implicit, using the current locale encoding. So even in wx 2.9, the snippets presented below still make sense when you don't want to be at the mercy of the current locale encoding.
const char* chars = "Hello world"; // if your string is UTF-8 encoded, this is the shortest path : wxString mystring = wxString::FromUTF8(chars); // You can also convert from many encodings by passing the // appropriate wxConv... parameter to the constructor wxString mystring2(chars, wxConvUTF8);
wxString to char*
void my_function(const char* foo) { } ... wxString mystring(wxT("HelloWorld")); // you could give the encoding you want as a parameter to mb_str(), e.g. mb_str(wxConvUTF8) my_function( mystring.mb_str() );
mb_str() returns a temporary pointer; if you need the output for more than one function call (as is the case above), you can store the char buffer for a little while :
wxString s( wxT("some string") ); wxCharBuffer buffer=s.ToUTF8(); foo( buffer.data() ); // data() returns const char * bar( buffer.data(), strlen(buffer.data()) ); // in case you need the length of the data
And if you really need to copy it in to char* (but why would you? ;) :
wxString mystring(wxT("HelloWorld")); char cstring[1024]; // assuming you want UTF-8, change the wxConv* parameter as needed strncpy(cstring, (const char*)mystring.mb_str(wxConvUTF8), 1023);
You can also use ToUTF8(), since which encoding you get is clearer than with mb_str()
From const char* to char*:
Variadic functions (like printf) won't work with mb_str(), but this will work:
Alternatively, use the method recommended in Potential Unicode Pitfalls:
printf("%s", (const char*)mystring.mb_str())
wchar_t* to wxString
const wchar_t* chars = L"Hello world"; wxString mystring(chars);
wxString to wchar_t*
See the following methods in the docs :
wxString to TCHAR
TCHAR tCharString[255]; wxString myString(_T("Hello World")); const wxChar* myStringChars = myString.c_str(); for (int i = 0; i < myString.Len(); i++) { tCharString[i] = myStringChars [i]; } tCharString[myString.Len()] = _T('\0');
int to wxString
or
wxString mystring; mystring << myint;
float to wxString
or
wxString mystring; mystring << myfloat;
wxString to integer number
or
wxString to floating-point number
std::string to wxString
std::string stlstring = "Hello world"; // assuming your string is encoded as UTF-8, change the wxConv* parameter as needed wxString mystring(stlstring.c_str(), wxConvUTF8);
Starting from wxWidgets 2.9, you may also use the appropriate constructor
std::string stlstring = "Hello world"; // assuming your string is encoded as the current locale encoding (wxConvLibc) wxString mystring(stlstring);
wxString to std::string
wxWidgets 2.8 :
Under wxWidgets 2.9, you may use
wxString::ToStdString()
std::wstring to wxString
Starting from wxWidgets 2.9, you may use the appropriate constructor
std::sstring stlstring = L"Hello world"; // assuming your string is encoded as the current locale encoding (wxConvLibc) wxString mystring(stlstring);
wxString to std::wstring
Under wxWidgets 2.9, you may use
wxString::ToStdWstring()
发表评论
-
WX_DEFINE_ARRAY的使用
2018-03-20 12:07 630/**************************** ... -
wxBase64Encode和wxBase64Decode
2016-04-09 15:23 818#include <wx/base64.h> ... -
wxWidgets中 wxButton实现自动点击
2015-06-30 12:59 1060之前在用wxSocket通讯的时候,EVT_SOCKET事件 ... -
按键转换
2015-03-15 12:27 9101 void PopTextCtrl::OnChar(wxK ... -
获取当前路径
2014-03-09 16:51 666#include <wx/stdpaths.h> ... -
程序只运行一个实例,并将前一个实例提到前台
2014-02-28 18:28 875wxWidgets提供了一个用来检测是否只有一个实例(ins ... -
通过重载实现修改wxWidgets文本处理框wxTextCtrl和wxRichTextCtrl的右键弹出菜单
2014-02-27 13:44 2350wxWidget中这块是写死的,这让我感到非常 ... -
过滤wxTextCtrl控件输入的两种方法
2014-02-27 13:40 1939以下两种方法实现wxTextCtrl只接收0-9的数字. ... -
wxBoxSizer,wxFlexGridSizer,wxGridBagSizer,wxGridSizer使用示例
2014-02-26 10:44 1827wxBoxSizer,wxFlexGridSizer,wx ... -
wxWidgets类库结构图
2014-02-26 09:08 1158自从2.5.0开始,wxWidgets既可以编译成单一的代 ... -
wxWidgets框架下基于wxDialog程序的标准退出方法
2014-02-25 16:56 1492退出程序的标准方法 ... -
在exe程序中嵌入图片
2012-10-20 23:44 15591、利用Bin2C将图片转换成“*.c”文件; 2、包含“* ... -
怎样解决静态编译对mingwm10.dll的依赖?
2012-10-15 14:14 1123使用CodeBlocks+wxWidgets2.9.4编写的静 ... -
wxRegEx的使用
2012-10-09 20:35 1602#include <wx/regex.h>#inc ... -
wxWidgets中的wxTimer使用
2012-09-26 15:51 22461、包含头文件: #include <wx/ti ... -
使用wxStringTokenizer分割字符串
2012-08-30 21:51 2368//wxStringTokenizer::wxStringTo ... -
给图片添加图片水印
2012-08-20 10:21 808写在开始 不能用代码同时实现半透明和不规则形状的水印,只能选 ... -
绘制图形并填充
2012-08-17 13:32 955=====文件名:DrawShape.h=== ... -
wxMathPlot
2012-08-17 09:39 1169wxMathPlot wxMathPlot ... -
使用wxWidgets实现所见即所得打印(CodeBlocks)
2012-08-14 18:10 25231、从wxPrintout派生一个类Printout,类源码如 ...
相关推荐
Converting Array to Map in Java
A Methodology For Converting Polygon Based Standard Cell From Bulk CMOS To SOI CMOS
Converting DIB to DDB将一个设备无关的位图转换成设备相关的位图(5KB)
Converting DDB to DIB将一个设备相关的位图转换成设备无关的位图(6KB)
t have a class to serialize or deserialize to, or the JSON is radically different from your class and you need to manually read and write from your objects.">Json.NET is a popular high-performance ...
Json.NET Json.NET is a popular ... you don't have a class to serialize or deserialize to, or the JSON is radically different from your class and you need to manually read and write from your objects.
Converting the CONNECT sample to a local server在本地服务器实现连接的例子(6KB)
提供一种将相位噪声转化为时域抖动的方法。
D3D to opengl converting library
converting-from-speech-to-text-with-javascript 本教程中,我们将尝试使用Web Speech API,这是一个非常强大的浏览器接口,可以用来记录语音并将其转换为文本,同样的,也可以用来朗读字符串。 接下来进入正题,这...
通过简单的GDB的使用,来考察 1、考察C语言的main函数的参数列表*argv[]的特性。 2、考察C语言的二级指针的使用。(pointers arrays;pointers to pointers)
Your Excel Survival Kit: Your Guide to Surviving and Thriving in an Excel world By 作者: Anne Walsh ISBN-10 书号: 161547045X ISBN-13 书号: 9781615470457 出版日期: 2016-06-01 pages 页数: 160 You ...
Terrain To Mesh 2021 is new rebuild, upgraded and improved version of Terrain To Mesh which is on the market since 2015. Owners of the old (now deprecated) Terrain To Mesh can use price reduced ...
Leverage Irregularity to Create Meaning and Importance 234 Interface Surgery: Surfacing the bananas in a process 237 Chapter 10: Reduce and Refine 243 Cluttered task flows 244 The path to ...
今天把最近一直在开发的小程序放安卓手机上测试一下,结果某个页面就一直报错: Uncaught TypeError: Converting circular structure to JSON 先说一下基本的环境: 系统:Android 6.0.1 手机:小米4 微信版本:...
Chapter 3, Controlling Flow, Converting Types, and Handling Exceptions, is about writing code that makes decisions, repeats a block of statements, converts between types, and handles errors. You will ...
-Convert JSON to and from XML -Supports .NET 2, .NET 3.5, .NET 4, .NET 4.5, Silverlight, Windows Phone and Windows 8 Store Documentation: http://james.newtonking.com/projects/json/help/
Built for everything from lightweight web apps to industrial-strength distributed systems, it's perfect for deploying .NET servers to any cloud platform, including AWS and GCP. About the Book .NET ...
The document you are currently reading contains a lot of general information about converting from CVS, and specifically how to use cvs2svn to convert your repository to Subversion. cvs2git....
ADI工程师Walt Kester的Converting Oscillator Phase Noise to Time Jitter,讲述如何通过PLL相噪计算得到jitter