|
...using the ATL OLEDB consumer templates.
Does this mean that I'll have to manage versions of mdac_typ on client's machine?
To avoid this, I didn't switch to ADO....
Anyway, thanks for answering to question #1! I hope there will be other answers too! I'm curious what's considered to by the right way in this field.
cheers,
_____________
stefan bornuz
|
|
|
|
|
What's wrong with the 'printing pictures without MFC' article ? How are you stuck ? What is happening ?
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
|
|
|
|
|
wow, that was a really fast answer.
I have tried the article "How to print a bmp.." but i find the code very confusing.
CDC memDC;
CClientDC dc(this);
int bmpWidth = 1600;
int bmpHeight = 500;
memDC.CreateCompatibleDC( &dc );
CBitmap * bitmap = new CBitmap();
bitmap->CreateCompatibleBitmap(&dc,bmpWidth, bmpHeight);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject( bitmap );
comment: i want to load a resource bmp.
comment: what does thi mean, I don´t knoe how to draw...
I just want the part that prints the actual picture, i already can print text, lines etc. dcPrint.TextOut(...) ...
I think the problem here is the functions StretchBlt and BitBlt and how they works. I´m realy greatful for help on this
I´m a beginner, but I`m trying...
|
|
|
|
|
*Tom* wrote:
comment: i want to load a resource bmp.
OK, so you need to load a resource bitmap instead, ::LoadImage will do that for you, I believe.
*Tom* wrote:
comment: what does thi mean, I don´t knoe how to draw...
You need to use StretchBlt, BitBlt will leave the image too small. You also need to SetStretchBltMode to COLORONCOLOR. I may have the funtion name wrong, but that is the value you need to stop the image looking awful when stretched.
*Tom* wrote:
I think the problem here is the functions StretchBlt and BitBlt and how they works.
Sounds like you're half way there. StretchBlt stretches an image from one DC to another, and BitBlt draws it without stretching. You need to create a DC, select the image into it after loading, then use StretchBlt to draw it onto the print DC. Then you need to unselect the image ( when you select an image into a DC, the old image is returned, that's what the CBitmap * pOldBitmap line is above. You select that one back into the DC, and so free your other one, which needs deleting ).
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
|
|
|
|
|
Thanks that really explained a lot how it works , I think the problem as you say is the coping between the dc´s, here is my code that I use now:
CBitmap bitmapResource;
bitmapResource.LoadBitmap(IDB_PRINTLOGGA);
BITMAP bmResource;
bitmapResource.GetBitmap(&bmResource);
CClientDC dc(this);
CDC memClientDC;
memClientDC.CreateCompatibleDC(&dc);
CBitmap *pOldBitmapResource = (CBitmap *)memClientDC.SelectObjectbitmapResource);
if (pOldBitmapResource == NULL)
{
memClientDC.DeleteDC();
return ;
}
CPrintDialog dlgPrint(FALSE,PD_ALLPAGES,this);
if(dlgPrint.DoModal()==IDOK)
{
CDC dcPrint;
dcPrint.CreateCompatibleDC(&memClientDC);
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(0,0,"Membercard");
...more printing text code...
dcPrint.BitBlt(1600,5500,1500,1500, &memClientDC, 0,0, SRCCOPY);
dcPrint.EndPage();
dcPrint.EndDoc();
}
dcPrint.DeleteDC();
}
feel free to comment, note this code does not print the picture as I want it
|
|
|
|
|
*Tom* wrote:
CBitmap *pOldBitmapResource = (CBitmap *)memClientDC.SelectObjectbitmapResource);
I presume this usually ends SelectOBject(&bitmapResource) ?
*Tom* wrote:
if (pOldBitmapResource == NULL){ memClientDC.DeleteDC(); return ;}
I reckon this will almost always fail, I thought you got NULL back in the first instance on a new DC. Have you traced it ?
*Tom* wrote:
dcPrint.CreateCompatibleDC(&memClientDC); dcPrint.Attach(dlgPrint.GetPrinterDC());
I think the first line is redundant, the Attach will delete the Created DC internally.
*Tom* wrote:
dcPrint.BitBlt(1600,5500,1500,1500, &memClientDC, 0,0, SRCCOPY);
This should print a postage stamp sized bitmap somewhere on your page.
I have not written printing code for a long time, so I can't comment directly. I'd be inclined to trace into this and see where it goes and what the values of various things are on the way through.
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
|
|
|
|
|
*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
|
|
|
|
|