[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppBuilderXWin32APIHelloWorld
Change this to:
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppBuilderXWin32APIHelloWorld
(C++ BuilderX) Hello World program, Win32 API
Similar to Win32 API Hello World program.- Do 'File | Close all'
- Do 'File | New | New GUI Application'
- In the popped-up window, do 'Next | Next', then check the box to add source code, then click 'Finish'
- Doubleclick 'Untitled1.cpp' (your source code)
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { return 0; }
- include <windows.h>
- ifdef __BORLANDC__
- pragma argsused
- endif
Change this to:
LRESULT CALLBACK myWndProc(HWND hWindow, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg==WM_PAINT) { PAINTSTRUCT ps; const HDC hDC = BeginPaint(hWindow,&ps); RECT rect; GetClientRect(hWindow,&rect); DrawText(hDC,TEXT("HELLO WORLD"),-1,&rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); EndPaint(hWindow,&ps); return 0; } else if (msg==WM_DESTROY) { PostQuitMessage(0); return 0; } return DefWindowProc(hWindow,msg,wParam,lParam); } int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { const static TCHAR appName[] = TEXT("Hello world"); WNDCLASSEX myWin; myWin.cbSize = sizeof(myWin); myWin.style = CS_HREDRAW | CS_VREDRAW; myWin.lpfnWndProc = myWndProc; myWin.cbClsExtra = 0; myWin.cbWndExtra = 0; myWin.hInstance = hInstance; myWin.hIcon = 0; myWin.hIconSm = 0; myWin.hCursor = 0; myWin.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); myWin.lpszMenuName = 0; myWin.lpszClassName = appName; //Register if (!RegisterClassEx(&myWin)) return 0; const HWND hWindow = CreateWindow( appName, appName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0); ShowWindow(hWindow,nCmdShow); UpdateWindow(hWindow); { MSG msg; while(GetMessage(&msg,0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } return 0; }
- include <windows.h>
- ifdef __BORLANDC__
- pragma argsused
- endif
'Hello world' links
- C
- C++
- C++ Builder, console
- C++ Builder, VCL
- C++ Builder, CLX
- C++ BuilderX, console
- C++ BuilderX, Win32 API
- C#
- PHP
- Prolog
- Turbo C++
- Visual Prolog
- Win32 API
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
