level Unicode GUI Native apps in C++ for Windows/Linux/Mac

API-level Unicode GUI Native apps in C++ for Windows / Linux / Mac OS X.


I am looking for writing a simple Unicode , GUI , Native , application, that can be run without need any non-standard library, written in C++ compiled with GNU-GCC (g++).

NOT

I don't mean one-code-source run-anywhere, but 3 (Win/Linux/Mac) code source! run-without-library (native application).

* Native application

Application can run without need any non-standard library, only the operating system C++ runtime (like MSVCRT on Windows).

* Unicode application

Right-to-left Window Layout (to support Right to left reading languages), with two buttons [Message] to show UTF-8 stings ("اهلا بالعالم") in a message-box, and [Exit] to... i think exit! :p

===================================

The solution for Windows (Windows 7)

Compiler: MinGW g++ 4.5.0
Command line:

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: This application is attached only with MSVCRT.DLL, that mean is a native windows C++ application.

===================================

The solution for Linux


Please HELP!


how run the application on Linux without tell to user to install this and this.. a native Linux application!

  • What is the file format most be ? ELF, Bin.. ?
  • X11 is the native Linux GUI library ? or WxWidgets, QT, GTK+, gtkmm.. ???!!!
  • Can be run on Gnome and KDE ? or need a different code source ?
  • Any one know the solution for Linux ?

    ===================================



    The solution for Mac OS X

    Please HELP!


    I think the solution for Mac OS X is Cocoa in C++ with G++ ! but i'm note sure !

  • Can G++ build a native Mac OS application with Cocoa ??

  • Or Qt. Not 'native' but neither is MFC, WPF, Silverlight ....


    X11 has NO native GUI library. Learn wxWidgets and use it on all three platforms. It will handle the interface to Win32 and Quartz for you.


    Windows API:

    #undef  UNICODE
    #define UNICODE
    #include    <windows.h>
    
    int main()
    {
        MessageBox(
            0,
            L"اهلا بالعالم",
            L"Hello World in Arabic !",
            MB_ICONINFORMATION | MB_SETFOREGROUND
            );
    }
    

    Building with MinGW g++ (producing a.exe ):

    C:test> g++ --version | find "++" 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> _

    Building with Visual C++ (producing x.exe ):

    C:test> (cl /nologo- 2>&1) | find "++"
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 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> _

    I think this is fairly "complete", but it's unclear what "complete" means.

    Anyway, hth.

    链接地址: http://www.djcxy.com/p/95248.html

    上一篇: glmnet中的自动脱字符参数调整失败

    下一篇: 高级Unicode GUI用于Windows / Linux / Mac的C ++本机应用程序