|
Having just finished up a C++ programming class, I'm making the
move to MFC and Windows programming. I expected to find
something (at least roughly) equivalent to the main() routine
found in console apps. After looking through numerous books,
I still don't know where my application code goes. I know
how to do initialization (e.g. the OnDraw function) but I
don't know where I would put some code to make GDI calls.
I don't want to respond to messages (at least yet), I just
want to make some GDI calls in my main program.
Does someone know where the equivalent of main() is for
MFC programs?
Thanks. BTW, I'm not using AppWizard.
Dave
|
|
|
|
|
If you're using Win32 calls (instead of MFC), your Windows main() entry point is WinMain() . If you're using MFC, AppWizard will generate the application instance for you. The framework calls methods in your application, allowing you to implement/customize the app's startup. The real main() function is buried in the Windows startup stub that gets linked into your app.
> BTW, I'm not using AppWizard.
Aieee! I would strongly advise using the AppWizard.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
Thanks for your input. Sounds like I should
use AppWizard. So I will. But I still don't
know where my application code goes. What are
the "application instances"? What is the
Windows startup stub? Can you help me with
the names of the classes that I should be
looking at? Are there some methods where
I would insert my application code?
Thanks again.
Dave
Dave
|
|
|
|
|
The class you want to look at is the one AppWizard derives from CWinApp , specifically the InitInstance() method. AppWizard peppers its generated code with comments which are reasonable helpful and will help you learn more about MFC's application framework.
I also suggest you look at some books on MFC/Windows programming to help you get started. I think you'll find the ones by Charles Petzold and Jeff Prosise to be a great read. You can likely buy them used for very little on EBay or Amazon.
And continue to post your Windows questions at CP!
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
I have 4 books on Visual C++ 6.0 and/or MFC programming but
not the ones you mention, which I'll pursue getting.
I used AppWizard to create my program and looked at InitInstance()
and it seems to be only for initialization. The comment in the
code says "Standard initialization".
So, I still don't know where my application code goes. As noted
above, I'll pursue getting the books but is it possible, in the
meantime, to let me know where my "regular application code"
goes -- not the initialization code but the code that will run after
initialization?
My "regular application code" will display graphics on an ongoing
and continuous basis, I just don't know where to put it. Can you
let me know?
Thanks.
|
|
|
|
|
A Windows app that exposes a user interface requires a main window, and optionally various child windows depending on the type of interface (dialog, SD, MDI, etc.).
For your purpose, it seems that a dialog based app will suffice. The graphics will be displayed within the dialog box. When you run AppWizard (to create an MFC Windows Application), select "Dialog Based" at the appropriate step.
When you build and run your app, a "main dialog window" will be displayed. If you click Esc (or the little x a the top right corner), the dialog will exit, control will eventually return to your CWinApp derived class, and your app will exit.
The actual displaying of graphics will likely occur within a custom control (chart, graph, whatever) you may choose to implement. This control will reside within the dialog. You can create a timer to update the control every "n" units of time. You may also want to add buttons and other widgets on the dialog to allow the user to control the app.
Hope this sheds some more light on "the big picture".
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Ravi,
Thanks for the further tip. I used AppWizard to create
a dialog application. So, now, I have the same question:
Where does my application code go? You mention that
the displaying of graphics will occur within a "custom
control". I don't know that this is -- I think what I'm
looking for is a function (method) that gets called to
run my code.
My goal (for now) is to draw a circle in the dialog window.
I want to do this is my main code section, *not* in the
initialization InitInstance() method. Can you let me
know where I would put this circle code?
I presume that my application code goes in a well-defined
and well-known location in the dialog window code, I'm just
trying to find out what this location is. Can you let me know?
Thanks again, sorry for not "getting it" quicker.
|
|
|
|
|
For a GUI application you need to think in terms of what you do to react to user input, not the classical main approach. As such, do not think of your dialog application as having a main code section - your application responds to messages from the Windows message system, and it is within the handlers for these messages that your application code is distributed as appropriate. In the case of drawing a circle in the window, then you would put that code within the handler for the WM_PAINT message, for example, which is called whenever the window needs to be redrawn. If you bring up the ClassWizard then it allows you to define a whole host of these functions to respond to most things. To stress, dont think of it in terms of having a main code section - Windows handles all that, you just respond to its messages.
|
|
|
|
|
Johnny is exactly right.
Windows (like any event driven GUI) requires your application to respond to events. Windows notifies your application when an event occurs by sending messages to its windows. Each message is identified by a WM_something constant. Examples of messages are:
-
WM_SIZE the user has just resized the dialog
-
WM_MOVE the user has moved the dialog
-
WM_QUERYENDSESSION Windows is shutting down and would like to terminate your application
-
WM_PAINT the user has moved a window, causing (part of) your window to need to be redrawn MFC conveniently provides predefined methods (that you can override) to customize your response to these messages. The one you probably want to handle is the last one. The handler for this message is OnPaint() .
My gut tells me you might be better off doing some reading before venturing into building your app. Once you get a better handle (pun intended) on MFC, you can decide where to inject your application's drawing code and perhaps add more bells and whistles to your app.
Good luck!
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Right now, I am doing quite bad in C++ programming class, and I really have no clue how to start this program. All I need is a kick in the rear (psuedocode), I obviously don't need anyone to type out the code for me.
http://www.cse.psu.edu/~cg103/NewHW/Pj2.pdf
A quick note: The due date is incorrect on there. It is due Tuesday November 18th.
Thanks for your help. I really, really appreciate it ^_^
|
|
|
|
|
You're just talking about setting up 2D arrays and passing over them, aren't you ? To flip, you swap values across one row or column at a time, and to add brightness, you need just add a value to each element, up to a maximum of the max grey specified in the header.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am a novice to C++. I am writing a program where I need to get today's date in this format (MM/DD/YY). I also need to know the day of the week (Sunday - Saturday). I have looked for this information on the CodeProject site, but all I found were things I do not understand. Is there a command, function, etc. I can use in my program that returns the information I want? Or do I have to learn more about C++ to understand the information contained on this web site. I hoped this would be easier. Thanks for you help in advance.
David Hoffman
|
|
|
|
|
|
Thanks Mike,
Sorry but I don't have a clue as to what you are saying. I have not worked with structures or classes, just functions. I have only been in a C++ classroom for about 3 months. In BASIC this was easy, DATE$ gave you the date and then you could manipulate it. I don't want you to write the code for me. Can I look at code that is already written and be able to understand it so I can then modify and use it in my program? Everything I have seen so far has been confusing because I have seen no explaination of what is happening. For example, I found this snippet of code in Visual Studio C++ that displays the information I need, but there are places in the program that I do not understand. Here it is.
#include <stdio.h><br />
#include <sys/timeb.h><br />
#include <time.h><br />
#include <iostream.h><br />
<br />
void main( void )<br />
{<br />
struct __timeb64 timebuffer;<br />
char *timeline;<br />
char wait;<br />
<br />
_ftime64( &timebuffer );<br />
timeline = _ctime64( & ( timebuffer.time ) );<br />
<br />
printf( "The time is %.19s.%hu %s", timeline, timebuffer.millitm, &timeline[20] );<br />
cin >> wait;
}
Would you explain this program to me so I can umderstand what is going on, or can you guide me to where I can read something that explains what is taking place? Thanks again.
David Hoffman
|
|
|
|
|
Easy (when you know how)
You need to look up the ftime and ctime functions in your IDE help.
The fact that you have _ftime64 and _ctime64 functions makes me think you're working on a 64-bit system, not a 32-bit one. How am I doing so far?
ftime retrieves the time, and then ctime converts it into a string (like DATE$).
The printf just splits the last part of the string off, so your output contains hundredths of a second.
Steve S
|
|
|
|
|
Hi,
I have a dialog in which I have a toolbar in the middle of the dialog window. I put the toolbar there with a
m_wndMiddleButtons.SetWindowPlacement(&wpl)
in OnInitDialog. m_wndMiddleButtons is a CToolBar and wpl is a WINDOWPLACEMENT structure.
I have to move this toolbar in the OnSize method of my dialog, but when I can (from OnSize)
m_wndMiddleButtons.SetWindowPlacement(&wpl) my app crashes. I can't call any method of m_wndMiddleButtons without a crash.
Anybody nows a method for solving this problem?
Thanks.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
Let's say the user didn't click the OK-button (or any other button) of the MessageBox dialog. Is there a way to define that MessageBox dialog is still running?
Or let's put in another way - for some reasons I need to show my application above all the other non-topmost windows, but I can't do this when the MessageBox/AfxMessageBox dialog is running - for example when the user didn't click on the OK button of the MessageBox dialog and has activated another application. What shall I do in order to show my application and the unclosed MessageBox dialog? Is there a way to define that MessageBox dialog is still running? Or is it possible to create a pointer to it? And what about AfxMessageBox dialog - can I create a pointer to this dialog?
|
|
|
|
|
|
Hi.
How can I Toggle views?
I use SplitterWnd (2x1), and want to toggle view in pane(0,0).
I made button for toggle, andthen, using flag for setting current-view state.
But, can't redraw view.(because that's Split-window?)
Followings: in this I use 2x1 and 1x2 splitterwnd.
CRect rect;
GetClientRect(rect);
if(!m_wndSplitter1.CreateStatic(this,2,1))
return FALSE;
m_wndSplitter2.CreateStatic(&this->m_wndSplitter1, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitter1.IdFromRowCol(1,0));
m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CDvMenu),CSize(rect.right,58),pContext);
m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CDvView),CSize(rect.right/2,rect.bottom),pContext);//pic viewer
if(flag != 0)//flag for current view state
m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CDvOpenGL),CSize(rect.right,rect.bottom),pContext);//opengl viewer
else
m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CDvView),CSize(rect.right,rect.bottom),pContext);//pic viewer
SetActiveView((CView*) m_wndSplitter2.GetPane(0,1));
return TRUE;
~~~
void CDvMenu::OnToggle()
{
// TODO: Add your control notification handler code here
CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
CDvDoc* pDoc = (CDvDoc *)pFrame->GetActiveDocument();
BOOL toggle = ((CMainFrame*)pFrame)->flag;
if(toggle)
((CMainFrame*)pFrame)->flag = 0;
else
((CMainFrame*)pFrame)->flag = 1;
-------------> Here, what should I do? plz, help.
}
|
|
|
|
|
You should call CFrameWnd::SetActiveView().
|
|
|
|
|
Hi.
I'm trying to write a program that would act like a banner. Here are the requirements:
. sit on a screen edge (top, bottom, left or right)
. restrict all other windows to the part of the screen not used by the banner
. run under Win98 and above
. should be written using Visual C++
I have no idea on how to limit the other programs to use the area of the screen not covered by the banner. Any help ?
thank you
Milonius
|
|
|
|
|
What you're thinking of is an app bar. Check out MSDN as there are a few pages on writing them. I've also seen articles in past MSDN magazines with MFC code for writing them too.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|
My project needs to split a 20 page pdf file to 20 single page pdf files, I don't have any clue in doing it, could anyone help me in accomplish it, thanks in advance.
|
|
|
|
|
or: is it a bug?
We develop with .net 2003 & develop services.
Services run a long time, and occasionally crash.
We are having a heck of a time getting DrWatson to work for us. He was our friend, before we moved onto C++ .NET2003 but seems not to like us anymore.
Anyhow, we're clueless on the matter.
I'd like to know your strategy for dealing with an application that needs to be up and running all the time, and when it crashes we need to record it and restart it.
Anyhow, once we started to use .net/2003 we lost this. We never used the first .net either.
We need to automagically record dump files and be able to interpret later.
Help!
Thanks in advance.
P.S. Ship day in 2 days.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|
|
|