|
-
Aug 9th, 2012, 06:08 AM
#1
Thread Starter
New Member
beginner learn c++ windows application
hi, I want to learn C++, make windows application, but is it C++ only DOS application?
I known VB 6.0 is simple use GDI layout, is it C++ also provide that GDI?
first, how to choose C++ program? is it Devx or Microsoft, C++Builder?
and I want to simple use GDI, what program focus beginner?
and can give me sample, I want to build window application
as same as VB6,
make TextBox (two)
make commandbuttom (one)
Command1:
msgbox (Val(Text1) + val(Text2))
thanks~!
-
Aug 9th, 2012, 02:26 PM
#2
Re: beginner learn c++ windows application
 Originally Posted by fookma
hi, I want to learn C++, make windows application, but is it C++ only DOS application?
If you by DOS application (which is a family of operating systems) mean a console application, then no, C++ is not limited to console applications.
 Originally Posted by fookma
I known VB 6.0 is simple use GDI layout, is it C++ also provide that GDI?
The Win32 API is what provides VB6 (and any other language) with the ability to display graphical windows, buttons, lists.. you name it.
To do the same in C++, you would make use of the Win32 API.
 Originally Posted by fookma
first, how to choose C++ program? is it Devx or Microsoft, C++Builder?
The two most common compilers being used nowadays is Microsoft Visual C++ and GCC. If you want to use GCC for windows development, you'd need to look up MinGW.
I believe Dev-C++ is a bit dated by now.
 Originally Posted by fookma
and I want to simple use GDI, what program focus beginner?
I do not really understand what this means, can you elaborate?
 Originally Posted by fookma
and can give me sample, I want to build window application
as same as VB6,
make TextBox (two)
make commandbuttom (one)
Command1:
msgbox (Val(Text1) + val(Text2))
It takes a whole lot of more work to do this without the use of a framework of some sort. I threw this together for you, here you go:
Code:
#include <iostream>
#include <Windows.h>
#include <tchar.h>
int setupWindow(HINSTANCE, int);
int setupControls(HINSTANCE);
void calculateResult();
HWND hwnd;
HWND hwndText1;
HWND hwndText2;
HWND hwndButton;
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg,WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if(lParam == (LPARAM)hwndButton)
{
calculateResult();
}
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
if(!setupWindow(hInstance, nCmdShow))
{
return -1;
}
if(!setupControls(hInstance))
{
return -1;
}
// Message loop
MSG msg;
while(GetMessage(&msg, hwnd, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
int setupWindow(HINSTANCE hInstance, int nCmdShow)
{
WNDCLASSEX wndclass;
ZeroMemory(&wndclass, sizeof(wndclass));
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.hInstance = hInstance;
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclass.lpszClassName = L"vbfsampleclass";
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.lpfnWndProc = WndProc;
if(!RegisterClassEx(&wndclass))
{
DWORD err = GetLastError();
std::cerr << "RegisterClassEx failed with error code " << GetLastError << std::endl;
return 0;
}
hwnd = CreateWindowEx(
0,
L"vbfsampleclass",
L"VBForums Win32 sample",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(hwnd == NULL)
{
std::cerr << "CreateWindowEx failed with error code " << GetLastError() << std::endl;
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return 1;
}
int setupControls(HINSTANCE hInstance)
{
// Textbox 1
hwndText1 = CreateWindowEx(
0,
L"EDIT",
L"3",
ES_NUMBER | WS_CHILD | WS_VISIBLE | WS_BORDER,
16,
24,
100,
24,
hwnd,
(HMENU)101,
hInstance,
NULL);
if(hwndText1 == NULL)
{
std::cerr << "CreateWindowEx failed with error code " << GetLastError() << std::endl;
return 0;
}
// Textbox 2
hwndText2 = CreateWindowEx(
0,
L"EDIT",
L"5",
ES_NUMBER | WS_CHILD | WS_VISIBLE | WS_BORDER,
16,
60,
100,
24,
hwnd,
(HMENU)101,
hInstance,
NULL);
if(hwndText2 == NULL)
{
std::cerr << "CreateWindowEx failed with error code " << GetLastError() << std::endl;
return 0;
}
// Button 1
hwndButton = CreateWindowEx(
0,
L"BUTTON",
L"Calculate!",
BS_TEXT | BS_VCENTER | WS_CHILD | WS_VISIBLE | WS_BORDER,
16,
96,
100,
24,
hwnd,
0,
hInstance,
NULL);
if(hwndButton == NULL)
{
std::cerr << "CreateWindowEx failed with error code " << GetLastError() << std::endl;
return 0;
}
ShowWindow(hwndButton, SW_SHOW);
return 1;
}
void calculateResult()
{
TCHAR strValue1[64];
TCHAR strValue2[64];
TCHAR strResult[64];
int intValue1;
int intValue2;
GetWindowText(hwndText1, strValue1, 64);
GetWindowText(hwndText2, strValue2, 64);
intValue1 = _tstoi(strValue1);
intValue2 = _tstoi(strValue2);
_itot(intValue1 + intValue2, strResult, 10);
SetWindowText(hwndButton, strResult);
}
With all this said;
I am willing to bet that you had hoped it to be more simple than this. Without any framework to help you, it gets complicated quick. I would suggest you look into frameworks like Qt to make things easier for you.
Last edited by Atheist; Aug 9th, 2012 at 05:08 PM.
-
Aug 10th, 2012, 05:36 AM
#3
Thread Starter
New Member
Re: beginner learn c++ windows application
thanks, but is it same VB6, Icons for the main controls, drag-and-drop tool (textbox, Label, CommandButtom, List,...) to empty form1?
if need that "drag-and-drop tool to....", Devx provide it? or which is provide this simple GUI applications?
thanks!
http://en.wikipedia.org/wiki/Visual_Basic
-
Aug 10th, 2012, 06:23 AM
#4
Re: beginner learn c++ windows application
There are a number of tools that supplies a graphical "drag-and-drop" editor. One being Qt that I mentioned in by previous post. Theres also C++/CLI, but I would personally say that Qt is a better option.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|