|
Yes I found out that if you have a modeless dialog box which can be used to cancel the print preview and keep the message handling "alive", the CPrintPreview class does not like that very much. CPreviewView::OnPreviewClose()will destroy the window and so the DC of the preview window if you close the preview window during a paint operation. If the CPreviewView::OnDraw() returns from the Print call and performs the clean up it will crash because of the now invalid DC of the window.
But I find it very strange that the CDC class can not handle such situations if its window handles are NULL. The only way I can solve this if to do a try/catch block around the drawing functions .
An other way may be to overwrite the OnPreviewClose method and don't close/destroy the window if a draw operation is in progress and then close the window after the draw operation.
By the way, thanks for your MultiPage PrintPreview class, Roger. It helps me alot to understand the "secrets" of the hidden MFC print preview class
|
|
|
|
|
Stop using C files, and use iostreams instead ?
How are you reading them back in ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
thomask wrote:
the programm ist written in visual c++...
Yes, but you're not using C++ file handling, you're passing handles around, and calling C functions.
thomask wrote:
no i don't read them back in?
i don't need this!
So how do you know they are written wrong ? If you're just writing the bytes into a field, there is no decimal place stored in a float. You need to read them back as a float array to see if you're getting back floats. If you want the file to say 3.1415.... instead of what you're getting, I reiterate the need to use iostreams. That is to say, if there's a way of doing that in C, I don't know it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
thomask wrote:
i am using the c++ file handling ...
Look, I don't want to argue with you. Read my articles on iostreams, they are C++ file handing.
thomask wrote:
another problem is before i write the float values into the file i convert them into a binaryreal dimension....
I think the core problem is that you have an array of a datatype that you're dumping into a file via a program that has no idea what the data types are, and expecting to see the floating point numbers in your file. Am I right ? C++ file handling via iostreams will add 40k or something to your exe, but will make this a piece of cake. You certainly won't have any ugly HANDLEs to pass around, or structures to fill.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Yes, search the articles for 'iostream graus' and you'll find them. There are probably other articles that are better for basic use, so maybe just 'iostream' if mine don't help.
Christian
No offense, but I don't really want to encourage the creation of another VB developer.
- Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael
P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not
as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
|
hi,
this is what you are looking for..
Since Microsoft got rid of ClassWizard in VC++ 7, quite a lot of jobs have become much more difficult. This article shows how to hook up the normal click events for toolbars in VC7, and how to disable buttons programmatically, depending on context.
First, let us assume we have an SDI application created using AppWizard.
The buttons are called ID_TBRED, ID_TBGREEN, and ID_TBBLUE respectively.
Creating Event Functions for the Buttons
If we built the program above just by adding in the toolbar buttons, they would by default be disabled, which is not very useful. Now we want to add an event function to each button so they do something when clicked.
First, let's create the functions for each of them. If you are following my SDI example, it is likely you will want to define the functions in your view. Open the header file for your view (double-click the class name in Class View), this is CDisableToolbarView in the example.
Okay; we need to write the declarations for our three functions; these would be as so:
afx_msg void OnToolbarRedClick();
afx_msg void OnToolbarGreenClick();
afx_msg void OnToolbarBlueClick();
That's all we need in our header, so we can close that and open our cpp file.
For each of the three functions declared above, we need to create a function defintition like the one below.
void CDisableToolbarView::OnToolbarRedClick()
{
MessageBox("Red clicked");
}
We've now finished creating the event functions. As they stand, VC++ doesn't know what events to hook our functions up to, so we need to specify this.
Toward the top of the cpp file you will see a block of code starting with BEGIN_MESSAGE_MAP. Within these lines we can hook the click events up to our functions. Between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP lines, add the following three lines:
ON_BN_CLICKED(ID_TBRED,OnToolbarRedClick)
ON_BN_CLICKED(ID_TBGREEN,OnToolbarGreenClick)
ON_BN_CLICKED(ID_TBBLUE,OnToolbarBlueClick)
By building the application, you should now see the three buttons enabled, and clicking them should show the respective message box. That's all there is to it!
cheers
Himanshu
|
|
|
|
|
Himanshu, do you know you can do it with the Class Wizard ? So you need not to add all the MFC stuff "by hand"...
~RaGE();
|
|
|
|
|
what if there is no classwizard...boom...
have you seen it is vc++7 not 6..and it doesn't support class wizard..so you have to do it manually..
cheers
Himanshu
|
|
|
|
|
Great
thanx a lot
this was the what I was looking for
I have another question related to this:
how to add functions such as in VC++6 OnDraw() for SDI and MDI, InitInstance(),..
thanx.
|
|
|
|
|
I guess thats something like this..
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
public:
virtual BOOL InitInstance();
i guess that should work fine with your code..
cheers
Himanshu
|
|
|
|
|
I am designing a scripting engine for use in a student project, that has similar syntax to C++ but not quite all the power. I have recently come to one small problem. When you have an operation, like a+b, there needs to be a return type from that operation. (though this does have a lot to do with my engine, it also is a question as to how C++ works, since I havn't really enountered any material on this subject - maybe I'm just not looking hard enough).
Say we have:
float f = 1+1.0;
f gets the value 2.0 since we know we are storing to a float.
But, if I am not going to store to float, but rather do something like
cout << 1+1.1 << endl; (not in my code, but in C++)
That gets the value of 2.1 (tested in C++), but how does the compiler know to promote to a float? Seems simple enough, but the engine is designed so that types can be added, so I want to know whats the best way to know how to promote a variable to another type during an operator (specifically, a binary operator)? I guess a better way of putting it would be "How can you determine what the resulting type will be from an operator that is done on two different types"? Will the first operand have precidence, or the second?
|
|
|
|
|
|
Exactly what I was looking for, thanks!
|
|
|
|
|
Neither the first nor the second, but the you may make the precidence according to the type : in fact, memory sapce allocated for float is bigger than memory for int. According to this criteria, make a previdence list (like : double,float,long int,int,char) and promote all your operand to the best ranked in this list.
~RaGE();
|
|
|
|
|
Hi
I am creating a CObject-derived class by first creating a class with CDocument as base class, and then replacing all 'CDocument' with 'CObject' and then removing the below message maps functions from the source and header
files.
BEGIN_MESSAGE_MAP(CMyClass, CObject)
//{{AFX_MSG_MAP(CMyClass)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
and
// Generated message map functions
protected:
//{{AFX_MSG(CMyClass)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
I have no problem compiling the program but when i try to use the class wizard, an error dialog box appeared with:
"Cannot find the insert section "AFX_MSG" in file.Class wizard cannot import or edit this class."
Anyone with suggestions as to what i should do?
|
|
|
|
|
why did you remove those blocks of code?
they are (obviously) what the CW is looking for.
-c
Zzzzz...
|
|
|
|
|
because what i actually want is a CObject-derived class, not CDocument-derived. And CObject-derived classes has no no message mapping.(This method of deriving from CObject class is taught by someone)
Actually, why does it want to find the insert section for "AFX_MSG"?
thks thks
|
|
|
|
|
raner wrote:
Actually, why does it want to find the insert section for "AFX_MSG"?
MFC needs it for message mapping. Maybe you did not remove everything needed.
Actually, to derive a class from a CObject, you only need to add the class with the wizard, and say you want it to be derived from CObject.
~RaGE();
|
|
|
|
|
raner wrote:
Actually, why does it want to find the insert section for "AFX_MSG"?
Its a guess but:
Possibly becuase the CDocument object used the DECLARE_SERIAL() / IMPLEMENT_SERIAL() macros and you need to switch to DECLARE_DYNAMIC() / IMPLEMENT_DYNAMIC() ?
Roger Allen
Sonork 100.10016
This is a multiple choice question, choose wisely
Why did the hedgehog cross the road?
A: To show he had guts?
B: To see his flat mate?
|
|
|
|
|
i did not see the DECLARE_SERIAL() / IMPLEMENT_SERIAL() macros but i saw the DECLARE/IMPLEMENT_DYNCREATE macros pair...does it matter?
thks
|
|
|
|
|
a better question is: if you don't need message mapping, what do you need the CW for?
-c
Zzzzz...
|
|
|
|
|
actually i don't really need the class wizard for that class...but the error message appearing every time i activate the CW seem to mean that something is terribly wrong? So i thought if i don't fix it now, it's bound to give me problems someday?
was i wrong?
|
|
|
|
|
in that case, i think you were right to delete those sections. and, i think you should get rid of any //{{AFX_* comments in there (leave any delcarations, etc. - just get rid of the comment lines). those are all the places CW is scanning. also, you should delete the *.CLW file for your project, then re-run CW. hopefully, it won't try to re-parse your class.
-c
|
|
|
|
|
I'm using WM_MOUSEWHEEL message to provide zoom control in a window that has no scroll bars. Certain mice have an "enhanced scroll" option. If this is turned on, my window doesn't receive the WM_MOUSEWHEEL message at all (Spy doesn't show any messages when the wheel is turned). Other applications, such as IE, do receive the message (according to Spy). Any ideas?
-- Rubio
|
|
|
|
|