-
windows and c++
Hello,
I am a complete idiot in programming. I was using cprogramming.com, but was wondering if someone could tell me how you learn how to do things for windows apps (eg. internet explorer, ZoneAlarm), as when I do the tutorials on cprogramming.com, everything is always in a dos window.
Thanks,
Jeff
-
-
>>> I am a complete idiot in programming
It is because the tutorials you are using are trying to address this point. They are programming tutorials, not Win32 API tutorials. If you cannot program, believe me, you can't program the Win32 API. You will need to be able to reasonably fluent with your language before you try otherwise, you will just get confused and be back here asking why "X" doesn't work, when you are simply doing it wrong.
Walk before you run, learn the alphabet before you start on poetry, the language, before the applications.
This is just about the simplest Windows program you can write.
Code:
#include <windows.h>
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR Args, int WinMode)
{
HWND hWnd;
MSG Message;
WNDCLASSEX WinClass;
WinClass.cbSize = sizeof(WNDCLASSEX);
WinClass.hInstance = hThisInst;
WinClass.lpszClassName = "Window";
WinClass.lpfnWndProc = WindowFunc;
WinClass.style = 0;
WinClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WinClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
WinClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WinClass.lpszMenuName = NULL;
WinClass.cbClsExtra = 0;
WinClass.cbWndExtra = 0;
WinClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
if(!RegisterClassEx(&WinClass)) return 0;
hWnd = CreateWindow("Window",
"Window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hThisInst,
NULL);
ShowWindow(hWnd,
WinMode);
UpdateWindow(hWnd);
while(GetMessage(&Message,
NULL,
0,
0))
{
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hWnd,UINT Message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT PaintStruct;
HDC hDC;
switch(Message)
{
case WM_PAINT:
hDC = BeginPaint(hWnd,
&PaintStruct);
TextOut(hDC,
10,
10,
"Hello Windows",
14);
EndPaint(hWnd,
&PaintStruct);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,
Message,
wParam,
lParam);
}
return 0;
}
-
[pointless]
Hmm, you could completely cut out the window procedure, change WNDCLASSEX to WNDCLASS and initialize it to [0] (except with curly braces instead of square ones) and cut out half the filling-in, use WS_VISIBLE instead of ShowWindow(), and cut out UpdateWindow(). That comes to less than 1/2 the code :D Actually, you could cut out the entire thing and just stick a MessageBox(), then return!
[/pointless]
JefWic:
>>I am a complete idiot in programming.
Then I agree with adrianxw, you probably shouldn't try Windows programming, unless, you're just being excessively modest :)
-
Shorter:
Code:
#include <windows.h>
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
MessageBox(NULL, "I am teh 1337!!!", "Message!", MB_OK);
}
:)
-
Thanks for implementing my suggestion in code Magos :)
-
The reason my tutorial code is the way it is is because it tries to explain the reason behind things as well as the simple mechanics. The programs are written with beginners in mind who aim to go on to produce more then just the very basic "Hello World" program.
The full tutorial develops this program over several pages, I just clipped and posted the end result.
It then goes on to demonstrate why it is rubbish, and suggests the next tutorial - (back buffering)!