MFC: #$@#$##$#@$#@

Started by
18 comments, last by FERNANDO-BRASIL 21 years, 7 months ago
Excellent. If you want to know where I derived my solution from, check out singleton patterns. Only instead of the class storing the pointer to it''s only initialization, the CWinApp class has a pointer the the MainFrame (CFrameWnd) object it created. AfxGetApp() will allow you to access any of the application class members.

Also, check out how MFC gets the CDocument in the CView class. You will find out that this is the same method I used. Leanring the Document/View archetecture was a speed bump for me until I learned the Singleton pattern, then it all made sence.

Cheers
-James
Advertisement
Or you can do:

MyFrame *pFrame = (MyFrame*)GetParentFrame();

or

MyFrame *pFrame = (MyFrame*)AfxGetMainWnd();

within view class.

View has easy access to document thru GetDocument(), Frame has access to document thru GetActiveDocument(), you can use AfxGetApp() or global pApp. I wrote from my memory.

Don''t forget the hierarchy chain thru which messages are passed around. Frame is first then view then frame then docs I think. MSDN has tons of useful mfc articles. Also check out knowledge base articles for mfc hints.
Also wanted to say that don''t get discouraged with mfc. I took two weeks off to read all the mfc info I could find and that has helped me a lot. Don''t forget once you get good at it you can use undocumented mfc functions to do what you want. But make sure you document them in your code. I had to resort to this type of thing to get at the filename before save as.. box got opened and replace it with different name. If something seems impossible to do in mfc then reading thru the mfc source can help.
Thank you guys!! You really helped me a lot!!!

I think I''m starting to love MFC now.. hehe

But, by the way, when using Win32API to do an application, we have to do our message handler by hand, like this:

loop {
PeekMessage()
TranslateMessage()
DispathMessage()
}

With MFC, this message handler disappear. But with my old win32 applications I used to put a call to a function there, like:

loop {
if (PeekMessage() == TRUE) {
PeekMessage()
TranslateMessage()
DispathMessage
} else {
Process();
}
}

Is there in MFC, an OnSomething function that I can use to put a call to a function like I used to put in my win32 applications?

THank you again guys!
In MFC I think the best way to handle that might be threads. You could make a looping thread that does your processing function. Otherwise you might have to do the OnTimer function which isn''t very accurate.

Check the MFC examples in the DX SDK, they should have a method layed out for that very thing.

Always remember, you''''re unique. Just like everyone else.
Always remember, you''re unique. Just like everyone else.Greven
the other day I decided I am finished with MFC. With .net coming out and DX samples not using it no use wasting brain power on it

DOWN WITH MFC!
http://www.mattherb.com now with CATCAM!
quote:Original post by angrytofu
the other day I decided I am finished with MFC.

I''m sure MFC will be devastated.
I''ve never done MFC, but maybe OnIdle is what your looking for?
Hi!

I tested it here, but it didn''t work the way I expected.

The help says that OnIdle function is called when the message queue is empty, and it''s true! I tested here, but I don''t know, it''s not perfect... There are sometimes that the function would be called, but its not.

BTW, can you guys could tell me why OnKeyUp and OnKeyDown don''t process VK_DOWN and VK_RIGHT messages? I tryed to get them, but I don''t know why, the dialog box only sends the VK_UP and VK_LEFT.

Thank you.
Hey! I did it!

I''m using OnIdle, but now I''m returning a nonzero value and the things are right.

I read the MSDN help about OnIdle, and didn''t understand very well why I have to return a nonzero value, but now it''s working.

This topic is closed to new replies.

Advertisement