Ive been looking a some tuts on MFC. And they all use the Appwizard. Can you make an MFC app with out using the appwizard? Are there any tutorials like this?
One question...why? The AppWizard creates so much boilerplate code for you that you'd end up duplicating yourself. Plus you need to get all the comments right as well since the IDE uses them to find where to put the ClassWizard-generated entries.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Cuz then your not learning anything. When ever your earning a new language you should not let something create the code for you. 4 or 5 tuts on the appWizard and i havent learned a thing.
Ok im starting to pick up MFC without the AppWizard. I got a question though. Im making a window using the CFrameWnd class, but when i create it, it displays with the client edge sunken in. Like WS_EX_CLIENTEDGE was specified without me knowing. How do i stop this?
I tried this a few months ago but gave up since I couldn't see where the whole CWinApp::InitInstance (or whatever) fitted in to the just wanting to create a normal window.
So I gave up and wrote my own classes I will admit though, that MFC makes Windows programs piss-easy to make - with very little C++ knowledge I made something pretty complicated. But understanding it was a lot harder...maybe that's one of the provisos of MFC (don't bother understanding it, just hope it does what the docs say).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Well, what ive learned i understand really well. I just cant seem to get any farther now. I cant for the life of me figure how to create a button on a window.
After about 30 deep dives into the MFC source (I would be totally lost if it weren't supplied) I get a feeling what this thing is all about. But don't even try to understand the CString class.
MFC can be really good once you get into it, but the question is if it's worth the effort.
Parksie: basically in InitInstance you create a new CFrameWnd derived object and store it in m_pMainWnd. Then you call it's Create method. And you need a document template. I'd rather let the app wizard to it for me (although by now I think I can do it myself, but it's not worth the time).
Chimp: Get a good book. "Programming Windows with MFC" or something like that. A search on amazon.com will give you a good amount of titles.
To create a button, add a CButton member to your view. In InitialUpdate (a virtual function that you need to override) you call the button's Create method (look it up in the reference). You need to specify WS_VISIBLE as style and supply your view as parent.
To create an MFC app without the wizard, do the following:
create classes derived from
1) CWinApp
This one needs the function
BOOL InitInstance();
where it creates a document template and the main window. The document template is not necessary for a simple window.
2) CDocument
This one stores your data. If you just want an empty window, you don't need it.
3) CFrameWnd
This is your main window's frame. It needs to register a window class in it's constructor.
4) CView
This is your window's client area. You need to override OnDraw at least.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Shawn: yeah, this is even simpler, but not extendable. You should at least keep the frame/view paradigm, it simplifies programming in the long run. Document/View is also not bad because you then get better support from the framework.
Chimp: You usually don't make buttons in the main window. This is the duty of dialogs. But you could for instance try to make a small vector draw app. (This is the example that is followed troughout MY MFC book.) The application should be able to draw ellipses, rectangles and lines, filled and/or stroked, in different colors. It should be able to save and load. This is quite a task and may keep you busy for a while.
Important classes for you:
CDC (CPaintDC and CClientDC)
CDialog
CControlBar and derived (especially CToolBar)
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Im learning mfc because it is used alot. And i need to quickly write an editor that meets my high standards. Every free editor ive seen sucks. Except pfe. Its good but its not being updated.
Two questions. When you create the window and you pass it the CRect, how do you make it use CW_USEDEFAULT? And how do you get the application title string? Like when you use...
For the Win32API theres a help file that has alot of info. Is there something like that for MFC? I know about MSDN but i cant download that to my computer.
Originally posted by ChimpFace9000 For the Win32API theres a help file that has alot of info. Is there something like that for MFC? I know about MSDN but i cant download that to my computer.
For Win32 you should be using the Platform SDK (identical to parts of MSDN, but you can download it). That old .hlp file is chronically outdated.
Isn't there MFC documentation with Visual C++?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
I fear the only documentation of MFC is in MSDN. Usually there is an extract of MSDN (the parts that contain MFC documentation, Win32 SDK documentation etc.) distributed with VC++.
parksie: but what IS .NET? Is it a class library? COM library? API?
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
What happens is, everything gets compiled down to the CLR (Common Language Runtime) which is analogous to Java bytecodes. Unlike Java, when you run it it is fully compiled for the host, with proper optimisation (like VC++ would do) so that its just as fast as compiling it directly.
VB.NET has had a fairly striking overhaul, and is almost a different language. The way cool thing you can do with the CLR is you can use VB to derive from a C++ (if you use the managed extensions) class
So not only is it theoretically platform-independent, its language-independent (as long as they support most of OOP) as well
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
I'll stay with the old things nevertheless. Maybe just because nobody buys VC7 for me and I don't want to do it myself.
Is there (will there be) a student's version of it?
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
besides your strange variable naming (you really shouldn't give a variable a name that looks like a class name), use Create and add WS_BORDER to the styles.
All the buzzt CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
--------------------Configuration: Editor - Win32 Debug--------------------
Compiling...
main.cpp
wndmain.cpp
d:\Development\editor\Editor\wndmain.cpp(5) : error C2440: 'static_cast' : cannot convert from 'void (CWndMain::*)(LPCREATESTRUCT)' to 'int (CWnd::*)(LPCREATESTRUCT)'
None of the functions with this name in scope match the target type
Error executing cl.exe.
Editor.exe - 1 error(s), 0 warning(s)
Will try and fix it...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
The reason that it won't give a real window is because you should have given it a class name (such as "EDIT"). I haven't worked out why it's crashing though:
I actually changed it to see if it would avoid it crashing. It's not a pointer anymore, its just on the stack as a normal class member.
I'm using Win98, and it crashes on both VC++5 and VC++7. That is, in debug mode you get the little window because the assertion failed...if you hit "Ignore" it runs fine.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Ok i got another question. Theres a member function called PreCreateWindow that lets you change some attributes for when it gets created. Is there a function like that for when it registers the class? I want make the hbrBackground = NULL.