Link to home
Start Free TrialLog in
Avatar of Harisha M G
Harisha M GFlag for India

asked on

C++ DOS --> C++ Windows ?

Hello =)

I am fairly good at C++, and want to learn programming for Windows.

I don't want to use MFC for this. Any good tutorial to start ?
SOLUTION
Avatar of Jose Parrot
Jose Parrot
Flag of Brazil image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Harisha M G

ASKER

> Programming for Microsoft Windows without Microsoft Foundation Class is impossible.

I know we can write a program only using Windows APIs. By MFC I mean VC++, sorry for the confusion.

I want a good tutorial to start, which starts from WinMain and covers most basic things.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>You'll need the Windows NT/2000 Native API Reference, by Gary Nebbett

... which addresses quite low-level aspects, but not the GUI?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, pressed "Submit" before ending...
http://www.relisoft.com/win32/, as stated by efn.
Seems to be exactly what you are looking for.
Simple tutorials on C++ coding, no MFC, start from "Hello word" until more advanced programs with dialogs. With your skills in C++ I think it will a fast learning curves.

When you stated "I don't want to use MFC" does it means you don't want to program MFC or you don't want use it, even with no direct coding MFC?
>> When you stated "I don't want to use MFC" does it mean...

I prefer Dev-C++, which is more generic, and is portable. The programs I write should be able to be compiled on VC++, C++ Builder, DevC++ or any other standard compiler for that matter, that can handle Win32 programs
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> all of these are cross-platform

I thought each OS has seperate method of creating dialog boxes, buttons etc.

If I write a program for Windows, and then compile the same under Linux, would it work ?
If you use WxWindows, yes.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Besides the wide range of technical options on should consider also the objectives. That is, we can't forget the most important: what is really better for mgh_mgharish objectives.

The objectives range from programming for pleisure to programming for business applications in a Systems Engineer department inside an industry.
My own experience includes a case where the chosen technology (VB.net, Crystal, Oracle) was opposite to the desired Java by most programmers and managers, imposed by the environment: partners, easy to find skilled people, legacy, dominant technology in the specific industry.

This is not a crithicism on our discussion, BTW rich on content, but a reminder for us not diverse on mgh_mgharish objectives.

Jose
Thank you everyone for your suggestions.

As I said, I am newbie to neither programming, nor C++ and not even to Windows programming.

I have coded a lot in VB, and hence I know the basics. What I want is a way to learn to code it in a way I like it.

Most IDEs give you the option to use the controls what they give. But the reason why I am trying to code on my own can be found out here: https://www.experts-exchange.com/questions/21890562/TreeView-TextBox.html
[ It is just an example, I have many more like that ;) ]

And the reason why I chose C++ is obvious... I want the power and control over the programs I write.

Now I am having exams going on (Yes, I am a student) and hence will not be able to check all the links given for some days. But don't stop ! Keep them coming.. as soon as I can see those, I will close the question.

Any good tutorial that makes you learn Windows programming using C++, (using code, of course, as the IDEs can't give you full power) please post it here :)

Thanks once again
>>Any good tutorial that makes you learn Windows programming using C++, (using code, of course, as
>>the IDEs can't give you full power) please post it here :)

Well, what is it now that you want? Windows programming is the Win32 API in the 1st place, "Windows programming using C++" means frameworks...
OK.. I will make it clear with a code.. :)

In DevC++, you'll find this code as an example:

_________________________________________

#include <windows.h>
#include <string.h>
#include <iostream>

LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton = 0;
static int cx, cy;
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
switch (nMsg)
{
case WM_CREATE:
{
TEXTMETRIC tm;

hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 30;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);

hwndButton = CreateWindow (
"button",
"Click Here",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
0, 0, cx, cy,
hwnd,
(HMENU) 1,
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}
case WM_DESTROY:
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);

rc.bottom = rc.bottom / 2;
DrawText (hdc, "Hello, World!", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_SIZE:
if (hwndButton &&
(wParam == SIZEFULLSCREEN ||
 wParam == SIZENORMAL)
   )
{
rc.left = (LOWORD(lParam) - cx) / 2;
rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
MoveWindow (
hwndButton,
rc.left, rc.top, cx, cy, TRUE);
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == 1 &&
    HIWORD(wParam) == BN_CLICKED &&
    (HWND) lParam == hwndButton)
{
DestroyWindow (hwnd);
}
return 0;
break;
}

return DefWindowProc (hwnd, nMsg, wParam, lParam);
}

int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain;
MSG msg;
WNDCLASSEX wndclass;
char*szMainWndClass = "WinTestWin";


memset (&wndclass, 0, sizeof(WNDCLASSEX));

wndclass.lpszClassName = szMainWndClass;

wndclass.cbSize = sizeof(WNDCLASSEX);

wndclass.style = CS_HREDRAW | CS_VREDRAW;

wndclass.lpfnWndProc = MainWndProc;

wndclass.hInstance = hInst;

wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);

wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);

RegisterClassEx (&wndclass);

hwndMain = CreateWindow (
szMainWndClass,
"Hello",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInst,
NULL
);

ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}

_________________________________________

I want to learn above type of programming, rather than putting a button on a dialog, double clicking it, and putting something like

    MsgBox("Hello World");

as the code...

Hope this clears my intensions
Ahh - the old Charles Petzold way of programming in Windows. I much prefer using a table of message ID and the associated function to be executed instead of the huge switch statement. In fact, this is how MFC handles the messages (remember - under all the OO constructs, it's still the Windows API).
>> remember - under all the OO constructs, it's still the Windows API

May be ! I don't know the details :(

>> I much prefer using a table of message ID and the associated function to be executed instead of the huge switch statement.

lol yeah, but it is written for demo I suppose

Does anybody know of a tutorial to learn this stuff ?
Well, that's plain C - and so is the Win32 API. When C++ enters the scene, we're talking about frameworks. It is your choice if you want to go that way, but you'll find that you are lost when it gets to more complex GUIs (and here I mean 'more complex than notepad.exe'). Anyway, that is covered at http://www.winprog.org/tutorial/ ("Welcome to Version 2.0 of theForger's Win32 API Tutorial" - quite in-depth). I'd suggest to take a look at http://www.relisoft.com/win32/index.htm ("Windows API Tutorial") which starts encapsuling Windows objects with classes, which IMHO is a better approach.
Thanks... (Points increased from 250 to 500)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks. Currently going through http://www.winprog.org/tutorial/ (jkr) and seems to be a good one..

Anyone know of anything else like that ?
Avatar of dark_archon
dark_archon

I should also thank you guys, because I've been looking for a straight-forward approach to Win32 programming in C, and theForger's tutorial looks very helpful.
> Thanks. Currently going through http://www.winprog.org/tutorial/ (jkr) and seems to be a good one..

Yes, that's why I suggested it two days, sixteen hours, and thirty-one minutes before jkr did.
https://www.experts-exchange.com/questions/21902809/C-DOS-C-Windows.html#17006833

As jkr has written:

"why are you repeating my post?"
https://www.experts-exchange.com/questions/20076682/error-LNK2001-unresolved-external-symbol-htons-4.html

"is there any apparent reason for repeating my comment?"
https://www.experts-exchange.com/questions/20366557/How-To-Register-Active-X-control.html

"So, why repeating it?"
https://www.experts-exchange.com/questions/20703053/cathing-key-events.html

Perhaps the answer is that his comments added value to the bare links I posted.

> Anyone know of anything else like that ?

You might check out http://www.relisoft.com/win32/index.htm, which has been recommended to you by JoseParrot, jkr, and me.
Oh, efn, right ! Once I clarified my intentions, I looked for the specific, and found jkr suggested it.

Don't worry.. you'll get your share :)
I think you're going about this the right way: once you understand how to do Windows stuff in C, you'll have abetter understanding of how the frameworks work. The problem I've always had with MFC is that the tooling makes it so easy that people don't bother to understand what each class actually does - try doing it by hand if you can, although I have to admit that can be pretty difficult.
> I think you're going about this the right way

Perhaps, if mastering the Windows API is the Holy Grail. I'm not convinced that it is now that we are in 2006.
> once you understand how to do Windows stuff in C, you'll have abetter understanding of how the frameworks work.

That's what my goal is.. once I finish the basics, I will play with it for some time, and my next target would be the frameworks.
efn,

>>You might check out http://www.relisoft.com/win32/index.htm, which has been recommended to you
>> by JoseParrot, jkr, and me.

sorry, I really missed that you mentioned that first.
>  Perhaps, if mastering the Windows API is the Holy Grail. I'm not convinced that it is now that we are in 2006.

Actually, I'd disagree strongly on this point. I increasingly meet new hires who don't understand basic computer functionality and who have never used the command line. This means that they are lacking in the fundamental information that underlies all computer technology. Similarly, all Windows programming, including C#,J#, VB, and MFC all ultimately refer back to the underlying APIs in the Windows DLLs. Understanding how these work provide a better understanding of how windows works and eventually a better understanding of how the programming languages work,
Thank you one and all !!

Split was a bit difficult.. and I managed it like this:

efn 200 + Accepted
jkr 100
JoseParrot 60
rstaveley 40
bpmurray e_tadeu trigger-happy dbkruger & cup 20 each

Hope it is acceptable to all of you :)

Thanks once again for your active collaboration