Solved

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

Posted on 2006-06-28
38
3,362 Views
Last Modified: 2010-05-18
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 ?
0
Comment
Question by:Harisha M G
  • 12
  • 6
  • 5
  • +8
38 Comments
 
LVL 18

Assisted Solution

by:JoseParrot
JoseParrot earned 60 total points
Comment Utility
Hi,

MFC stands for Microsoft Foundation Class. Programming for Microsoft Windows without Microsoft Foundation Class is impossible. The best you can is to use a third part API that makes the interface between your program and the MFC.

In my oppinion, Borland C++ Builder is the guy. The foundation is almost invisible to you, thus allowing you to concentrate your efforts in what you are looking for. To avoid high investments just to try this Builder, you find at ebay older versions (versions 3 or 4). Or, with luck, found a magazine with verison 6 Personal in the companion CD, for free and registrable at Borland. I have such version. You can also download the Enterprise version from Borland site, but I think is a huge tool for just trying.

Let me describe an example of Borland's Builder C++ effectiveness:
You want a Form with a Drivers ComboBox(A:, C:, D:, etc.) which opens the root directory of the selected disk in a FileList. You never will write a single line of code to do it. Borland writes all MFC to you. You just link the ComboBox to the FileList, compile and run the program. That's all.

Hope it is useful to you.

Jose
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
> 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.

0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
I want a good tutorial to start, which starts from WinMain and covers most basic things.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
Comment Utility
I'd suggest to start with stuff like

http://www.mdstud.chalmers.se/~md7amag/code/wintut/wtpart1.html ("Windows Programming Tutorial 1")

and

http://www.flipcode.com/articles/article_winprog01.shtml ("Introduction To Windows Programming")

which leaves out the framework part. But, be advised that without a framework, GUI programming is really a pain in the neck. Sooner or later youll have to pick one. If you want to stay portable and free, take a look at wxWidgets (www.wxwidgets.org), formerly known as wxWindows.
0
 
LVL 15

Accepted Solution

by:
efn earned 200 total points
Comment Utility
0
 
LVL 18

Assisted Solution

by:JoseParrot
JoseParrot earned 60 total points
Comment Utility
Hi,

You'll need the Windows NT/2000 Native API Reference, by Gary Nebbett,
or Windows NT Win32 API SuperBible by Richard Simon,  or equivalent.
I still use an old 1020 pages NT API Reference.

These aren't tutorials, are guide to the Windows API to be used as reference.

Soon you wiill perceive that need to construct a small toolkit, to avoid repeating coding and gain some productivity. Step by step it will change to a framework. Really I wish to you
      Good luck!

Jose
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>You'll need the Windows NT/2000 Native API Reference, by Gary Nebbett

... which addresses quite low-level aspects, but not the GUI?
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 40 total points
Comment Utility
You might be better off focusing on mastering .NET instead of the Windows API (with or without MFC) and you might even want to do that mastering in C#. Just a thought. The times, they are a-changing.
0
 
LVL 15

Assisted Solution

by:bpmurray
bpmurray earned 20 total points
Comment Utility
> Programming for Microsoft Windows without Microsoft Foundation Class is impossible
Rubbish! I was writing Windows programs long before MFC came along.

In fact, you can use cygwin to develop for Windows, using the gcc compiler and mingw libraries, so no Micro$oft tools are needed. See cygwin.com
0
 
LVL 4

Assisted Solution

by:e_tadeu
e_tadeu earned 20 total points
Comment Utility
I aggree with bpmurray. You can use cygwin or mingw, and for the gui you can use Qt (or GTK, and yes, there are perfect windows ports of these libraries).
But for beginners, I would advise to use Bloodshed Dev-C++... it's a very nice IDE built upon mingw.

Do not confuse MFC with Visual C++ with Windows API. They are three different things.

The windows API is the lowest level of interface of your programs with the MS Windows Operational System. There are a lot of functions covering not only GUI programming, but many things an OS should offer to you (IO, drivers, etc.).

The MFC are a set of 'higher level' classes built to help the programmer with utilities to interface with the API and other things.

Visual C++ is just an IDE (Integrated Development Environment) with a compiler, debugger, editor, libraries, etc.

If you want to run away of Windows API and Visual C++, I advise you to learn Qt or wxWindows. And they work on Linux too!
0
 
LVL 18

Expert Comment

by:JoseParrot
Comment Utility
0
 
LVL 18

Expert Comment

by:JoseParrot
Comment Utility
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?
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
>> 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
0
 
LVL 18

Assisted Solution

by:JoseParrot
JoseParrot earned 60 total points
Comment Utility
Maybe you already know wxDev-C++, a Borland Builder like IDE for Dev-c++. If, no, take a look, because you maintain Dev-c++ features in a IDE environment, which can be useful. http://wxdsgn.sourceforge.net/
0
 
LVL 14

Assisted Solution

by:trigger-happy
trigger-happy earned 20 total points
Comment Utility
I haven't done that much windows programming, but I can say that WTL (Windows Template Library) is a good library to create windows programs with. I'd also have to agree with the others when it comes to using gtk/qt/wxwindows since all of these are cross-platform and there's a good chance that if your program uses any of them, they could also work on other platforms like linux/mac.

--trigger-happy
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
> 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 ?
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
If you use WxWindows, yes.
0
 
LVL 11

Assisted Solution

by:dbkruger
dbkruger earned 20 total points
Comment Utility
I can put in a good word for GTK+. Though hard to get set up and configure, it's cleaner in my opinion to code than windows, and it runs on everything.
0
 
LVL 17

Assisted Solution

by:rstaveley
rstaveley earned 40 total points
Comment Utility
I'd be interested to see how GTK++, wxWindows and Qt compare from a developer's perspective especially with a view to porting projects to Win32 (i.e. doing what mgh_mgharish wants). Qt seemed to win out in the Slashdot lion's den back in November 2001 - see http://slashdot.org/askslashdot/01/11/21/0227206.shtml - but that's quite a while back; does anyone have a more recent comparison?
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 18

Expert Comment

by:JoseParrot
Comment Utility
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
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
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: http://www.experts-exchange.com/Q_21890562.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
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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...
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
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
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
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).
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
>> 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 ?
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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.
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
Thanks... (Points increased from 250 to 500)
0
 
LVL 11

Assisted Solution

by:cup
cup earned 20 total points
Comment Utility
An alternative search keyword is "Windows SDK".  That is what the non MFC interface is known as.  If you use "Windows API", you will get tons of hits, mostly not what you want.

There are  quite a few books on the subject but they are mostly out of print as the whole world drifted towards C++ after MS brought out a better compiler.  You may be able to pick one up (try Herb Sutter or something similar sounding) from a 2nd hand bookshop at a reasonable price (saw one a year ago for £2 - original price £45).

Another way of learning is to use WTL.  This is a 700K download from MS and it is free.  Build your program using the std GUI tools and see what is generated.  Then step into the templates and see how they are coded.  MS hasn't implemented the export keyword in C++ so they don't hide the template code and we can still look at it.  The templates are all coded in SDK.  It is quite a useful exercise in seeing how things are done.
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
Thanks. Currently going through http://www.winprog.org/tutorial/ (jkr) and seems to be a good one..

Anyone know of anything else like that ?
0
 

Expert Comment

by:dark_archon
Comment Utility
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.
0
 
LVL 15

Expert Comment

by:efn
Comment Utility
> 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.
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21902809.html#17006833

As jkr has written:

"why are you repeating my post?"
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20076682.html

"is there any apparent reason for repeating my comment?"
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20366557.html

"So, why repeating it?"
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20703053.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.
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
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 :)
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
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.
0
 
LVL 17

Expert Comment

by:rstaveley
Comment Utility
> 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.
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
> 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.
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
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.
0
 
LVL 15

Expert Comment

by:bpmurray
Comment Utility
>  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,
0
 
LVL 37

Author Comment

by:Harisha M G
Comment Utility
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
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now