高级Unicode GUI用于Windows / Linux / Mac的C ++本机应用程序
API级别的Unicode GUI用于Windows / Linux / Mac OS X的C ++本机应用程序。
我正在寻找一个简单的Unicode , GUI , Native ,应用程序,它可以运行而无需使用GNU-GCC(g ++)编译的C ++编写的任何非标准库。
不
我并不是说任何一个代码源都可以运行,但是3(Win / Linux / Mac)代码源! 运行无库(原生应用程序)。
*原生应用程序
应用程序可以运行而不需要任何非标准库,只需要操作系统C ++运行时(如Windows上的MSVCRT)。
* Unicode应用程序
从右到左的窗口布局(支持从右到左的阅读语言),使用两个按钮[Message]在消息框中显示UTF-8刺(“اهلابالعالم”),[Exit]到... i想出口! :p
===================================
适用于Windows的解决方案(Windows 7)
编译器:MinGW g ++ 4.5.0
命令行:
g++ -Wl,--enable-auto-import -O2 -fno-strict-aliasing -DWIN32_LEAN_AND_MEAN -D_UNICODE -DUNICODE -mwindows -Wall test.cpp -o test.exe
#include (windows.h)
#include (tchar.h)
#include (string)
typedef std::basic_string ustring;
LONG StandardExtendedStyle;
TCHAR buffer_1[1024];
TCHAR buffer_2[1024];
static HWND button_1;
static HWND button_2;
inline int ErrMsg(const ustring& s)
{
return MessageBox(0,s.c_str(),_T("ERROR"),MB_OK|MB_ICONEXCLAMATION);
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
button_1=CreateWindow(L"button",L"UTF-8 Message",WS_CHILD|WS_VISIBLE,10,10,120,25,hwnd,(HMENU)1,NULL,NULL);
button_2=CreateWindow(L"button",L"Exit",WS_CHILD|WS_VISIBLE,10,50,120,25,hwnd,(HMENU)2,NULL,NULL);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 1:
_stprintf(buffer_1,L"اهلا بالعالم");
_stprintf(buffer_2,L"Hello World in Arabic !");
MessageBoxW(hwnd,buffer_1,buffer_2,MB_ICONINFORMATION|MB_OK|MB_RTLREADING|MB_RIGHT);
break;
case 2:
PostQuitMessage(0);
break;
}break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR pStr,int nCmd)
{
ustring classname=_T("window");
WNDCLASSEX window={0};
window.cbSize = sizeof(WNDCLASSEX);
window.lpfnWndProc = WndProc;
window.hInstance = hInst;
window.hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(100), IMAGE_ICON, 16, 16, 0);
window.hCursor = reinterpret_cast(LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0,LR_SHARED));
window.hbrBackground = reinterpret_cast(COLOR_BTNFACE+1);
window.lpszClassName = classname.c_str();
if (!RegisterClassEx(&window))
{
ErrMsg(_T("Failed to register wnd class"));return -1;
}
int desktopwidth=GetSystemMetrics(SM_CXSCREEN);
int desktopheight=GetSystemMetrics(SM_CYSCREEN);
HWND hwnd=CreateWindowEx(0,classname.c_str(),_T("The solution for Windows"),WS_OVERLAPPEDWINDOW,desktopwidth/4,desktopheight/4,270,150,0,0,
hInst,0);
if (!hwnd)
{
ErrMsg(_T("Failed to create wnd"));
return -1;
}
StandardExtendedStyle=GetWindowLong(hwnd,GWL_EXSTYLE);
SetWindowLong(hwnd,GWL_EXSTYLE,StandardExtendedStyle|WS_EX_LAYOUTRTL);
ShowWindow(hwnd,nCmd);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,0,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return static_cast(msg.wParam);
}
http://download.seifsoftware.com/the_solution_for_%20windows_in_c++.png
NOT:此应用程序仅附带MSVCRT.DLL,这意味着本机Windows C ++应用程序。
===================================
Linux的解决方案
请帮忙!
如何在Linux上运行应用程序而不告诉用户安装这个和这个..本地Linux应用程序!
任何人都知道Linux的解决方案?
===================================
适用于Mac OS X的解决方案
请帮忙!
我认为Mac OS X的解决方案是C ++中的Cocoa和G ++! 但我很确定!
或Qt。 不是'本地',但MFC,WPF,Silverlight也不是。
X11 没有本地GUI库。 学习wxWidgets并在所有三个平台上使用它。 它会为你处理Win32和Quartz的接口。
Windows API:
#undef UNICODE
#define UNICODE
#include <windows.h>
int main()
{
MessageBox(
0,
L"اهلا بالعالم",
L"Hello World in Arabic !",
MB_ICONINFORMATION | MB_SETFOREGROUND
);
}
用MinGW g ++编译(生成a.exe ):
C: test> g ++ --version | 找到“++”g ++
(TDM-2 mingw32)4.4.1
C: test> g ++ -O -pedantic -std = c ++ 98 -Wall -Wwrite-strings -Wno-long-long -mwindows x.cpp
C: test> _
使用Visual C ++构建(生成x.exe ):
C: test>(cl / nologo- 2>&1)| 找到“++”
Microsoft(R)32位C / C ++优化编译器版本16.00.30319.01,适用于80x86
C: test> cl / nologo / EHsc / GR / Zc:forScope,wchar_t / W4 x.cpp / link user32.lib / subsystem:windows / entry:mainCRTStartup
x.cpp
C: test> _
我认为这是相当“完整”的,但尚不清楚“完整”是什么意思。
无论如何,hth。
链接地址: http://www.djcxy.com/p/95247.html上一篇: level Unicode GUI Native apps in C++ for Windows/Linux/Mac
