|
*Tom* wrote:
I think the problem here is the functions StretchBlt and BitBlt and how they works.
You have to note that StretchBlt and BitBlt are not supported by all device contexts. I think printer DCs will not support them.
You may want to use the GetDeviceCaps member function of the CDC class with the parameter RASTERCAPS to determine if your printer DC supports them. See MSDN Library for details.
|
|
|
|
|
CodeBrain wrote:
You have to note that StretchBlt and BitBlt are not supported by all device contexts
I have look in the MSDN but I´m just confused, isn´t there a easy way to do this.
|
|
|
|
|
CodeBrain wrote:
You have to note that StretchBlt and BitBlt are not supported by all device contexts
so if the device not support StretchBlt and BitBlt, then there is impossible to print a bmp picture?
|
|
|
|
|
There is a way!
Take a look at my article PrintingTricksAndTips.asp[^]in the printing section. You need to convert your bitmap to a DIB and use StretchDIBBits() to plot it on the output device.
Most of the code shown in the article should work for non MFC code as well.
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?
|
|
|
|
|
Thanks Roger for the comment. But I´m starting to realize that this forum is not for a beginner like me, and with beginner I mean really a beginner . I have read your code and a have a question about the first row in "how to implement..." and that is: What is iImage? , i´m using a bitmap as a resource or alternative from a file. I attach my code if you have the time to help me how to implement the functions so it will work for me.
-Tom
void CPrint::OnClickPrint()
{
UpdateData(TRUE);
CBitmap bitmapResource;
bitmapResource.LoadBitmap(IDB_MYBMP);
BITMAP bmResource;
bitmapResource.GetBitmap(&bmResource);
CDC memDC;
CClientDC dc(this);
memDC.CreateCompatibleDC(&dc);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject( bitmapResource );
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
if(dlgPrint.DoModal()==IDOK)
{
CDC dcPrint;
dcPrint.Attach(dlgPrint.GetPrinterDC());
DOCINFO myPrintJob;
myPrintJob.cbSize = sizeof(myPrintJob);
myPrintJob.lpszDocName = "myPrintJob";
myPrintJob.lpszOutput = NULL;
myPrintJob.lpszDatatype = NULL;
myPrintJob.fwType = NULL;
if(dcPrint.StartDoc(&myPrintJob)>=0)
{
dcPrint.StartPage();
dcPrint.SelectObject(&ArialFontHeader);
dcPrint.TextOut(...);
dcPrint.SelectObject(&ArialFont);
dcPrint.SelectObject(&ArialFontHeaderCard);
dcPrint.TextOut(...);
dcPrint.SelectObject(&ArialFont);
dcPrint.EndPage();
dcPrint.EndDoc();
}
dcPrint.DeleteDC();
}
}
|
|
|
|
|
someone knows how to convert from a bitmap to a DIB and use StretchDIBBits() DIB´s to use with the article PrintingTricksAndTips in the printing section.
- Tom
|
|
|
|
|
I have some problems with a CDC object if it has no valid hDCs.
In fact I have a print preview with a very long output. If I close the preview window using the X in the upper right corner of the window during the paint process I get a crash in my paint routine in some CDC member functions! The CDC pointer is still valid but the hDCs of the CDC objects are invalid (NULL). Is the CDC class so ugly developed that it crashes in every method if the hDCs are NULL?
How can I prevent this?
The only possibilities I see are:
* Check the hDCs of the CDC object before each call to a CDC method.
* Use a try/catch block around my printing funtion.
Are there any other possibilities?
Thanks in advance.
|
|
|
|
|
This seems to be a problem with the print preview code. After you hit the X, the OnPrint() function which gets the CDC object should not be called. Try putting in a breakpoint for the invalid case and see what is happening in the call stack to try and see why the OnPrint() function is being called when it should not be.
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?
|
|
|
|
|
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...
|
|
|
|
|