- 浏览: 116927 次
文章分类
最新评论
-
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 670/**************************** ... -
wxBase64Encode和wxBase64Decode
2016-04-09 15:23 892#include <wx/base64.h> ... -
wxWidgets中 wxButton实现自动点击
2015-06-30 12:59 1112之前在用wxSocket通讯的时候,EVT_SOCKET事件 ... -
按键转换
2015-03-15 12:27 10131 void PopTextCtrl::OnChar(wxK ... -
获取当前路径
2014-03-09 16:51 696#include <wx/stdpaths.h> ... -
程序只运行一个实例,并将前一个实例提到前台
2014-02-28 18:28 936wxWidgets提供了一个用来检测是否只有一个实例(ins ... -
通过重载实现修改wxWidgets文本处理框wxTextCtrl和wxRichTextCtrl的右键弹出菜单
2014-02-27 13:44 2451wxWidget中这块是写死的,这让我感到非常 ... -
过滤wxTextCtrl控件输入的两种方法
2014-02-27 13:40 2028以下两种方法实现wxTextCtrl只接收0-9的数字. ... -
wxBoxSizer,wxFlexGridSizer,wxGridBagSizer,wxGridSizer使用示例
2014-02-26 10:44 1896wxBoxSizer,wxFlexGridSizer,wx ... -
wxWidgets类库结构图
2014-02-26 09:08 1233自从2.5.0开始,wxWidgets既可以编译成单一的代 ... -
wxWidgets框架下基于wxDialog程序的标准退出方法
2014-02-25 16:56 1554退出程序的标准方法 ... -
在exe程序中嵌入图片
2012-10-20 23:44 16141、利用Bin2C将图片转换成“*.c”文件; 2、包含“* ... -
怎样解决静态编译对mingwm10.dll的依赖?
2012-10-15 14:14 1193使用CodeBlocks+wxWidgets2.9.4编写的静 ... -
wxRegEx的使用
2012-10-09 20:35 1642#include <wx/regex.h>#inc ... -
wxWidgets中的wxTimer使用
2012-09-26 15:51 22711、包含头文件: #include <wx/ti ... -
使用wxStringTokenizer分割字符串
2012-08-30 21:51 2401//wxStringTokenizer::wxStringTo ... -
给图片添加图片水印
2012-08-20 10:21 847写在开始 不能用代码同时实现半透明和不规则形状的水印,只能选 ... -
绘制图形并填充
2012-08-17 13:32 992=====文件名:DrawShape.h=== ... -
wxMathPlot
2012-08-17 09:39 1271wxMathPlot wxMathPlot ... -
使用wxWidgets实现所见即所得打印(CodeBlocks)
2012-08-14 18:10 25831、从wxPrintout派生一个类Printout,类源码如 ...
相关推荐
A Methodology For Converting Polygon Based Standard Cell From Bulk CMOS To SOI CMOS
7. **可视化辅助**:`Converting Array to Map in Java.png`可能是一个流程图或示意图,帮助理解转换过程的可视化表示。在实际编程中,这类图表有助于解释代码逻辑,特别是在团队协作或技术文档中。 8. **异常处理*...
这个“Converting integer up to 16 to bit pattern”主题涉及了将16位整数转换为位模式的概念,这是在编程AB PLC时常见的操作。 在AB PLC编程中,我们经常需要处理二进制数据,因为PLC内部是以二进制形式存储和...
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.
### MT-008 将振荡器相位噪声转换为时间抖动 #### 引言 在现代信号处理和通信系统中,高精度的时间稳定度对于实现高性能模数转换器(ADC)至关重要。ADC的孔径抖动规格是决定其信噪比(SNR)水平的关键因素之一。...
今天把最近一直在开发的小程序放安卓手机上测试一下,结果某个页面就一直报错: Uncaught TypeError: Converting circular structure to JSON 先说一下基本的环境: 系统:Android 6.0.1 手机:小米4 微信版本:...
D3D to opengl converting library
converting-from-speech-to-text-with-javascript 本教程中,我们将尝试使用Web Speech API,这是一个非常强大的浏览器接口,可以用来记录语音并将其转换为文本,同样的,也可以用来朗读字符串。 接下来进入正题,这...
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 ...
通过简单的GDB的使用,来考察 1、考察C语言的main函数的参数列表*argv[]的特性。 2、考察C语言的二级指针的使用。(pointers arrays;pointers to pointers)
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 ...
"Converting the CONNECT sample to a local server"的主题聚焦于将一个基于CONNECT的示例应用移植到用户的本地服务器环境。这个过程通常包括几个关键步骤,涉及代码调整、配置更改以及对本地环境的适应。 首先,...
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/
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....
Expert PHP and MySQL takes you beyond learning syntax to showing you how to apply proven software development methods to building commerce-grade PHP and ...Converting existing data to the new application
### 使用FFmpeg将音频转换为MP3格式 在数字媒体处理领域,FFmpeg是一个非常强大的工具,能够处理视频、音频以及图像数据。本篇文档主要介绍如何使用FFmpeg将各种音频或视频文件转换成MP3格式。...