|
I am writing a graphic design tool. I am using a device context to produce the image on screen. Now I want to be able to print the image to the printer. What I am doing so far is:
Create the screen device context : CDC *m_pDC = CreateDC ();
Do all kinds of weird and wonderful things to produce the image (all of this works, since I do get the image I want on screen)
When the user presses the Print option from the menu, I use the CPrintDialog class to select the printer, and subsequently I get a HDC by “CPrintDialog Print.CreatePrinterDC ();”
Then I calculate the size on paper by the following piece of code:
POINT point;
POINT start;
point.x = GetDeviceCaps (hDC, PHYSICALWIDTH);
start.x = GetDeviceCaps (hDC, PHYSICALOFFSETX);
point.x -= (start.x*2);
point.y = GetDeviceCaps (hDC, PHYSICALHEIGHT);
start.y = GetDeviceCaps (hDC, PHYSICALOFFSETY);
point.y -= (start.y*2);
DPtoLP (hDC, &point, 1);
DPtoLP (hDC, &start, 1);
I already have a POINT named “Source”, that holds the size of the screen DC.
Then I call:
if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY))
And this is where all goes wrong! This fails, and the error message (as obtained by FormatMessage and GetLastError) says: “The parameter is incorrect”
As far as I can see, the size on paper is correct, since I also write a (test) rectangle with these positions: Rectangle (hDC, start.x, start.y, point.x, point.y); and this produces a rectangle on paper with the size and position as I would expect.
Can anyone help me out here.
William
-- modified at 7:29 Thursday 17th August, 2006
|
|
|
|
|
|
Sarath,
Thanks for the tip. I checked the link, but it does not solve my problem, since it does not refer to sending the captured image to the printer. I do have a device context with a valid image. However, when I try to copy this image into a printer device context (using StretchBlt), I get an error message.
William
|
|
|
|
|
Before using stretchblt, i think you need to set SetStretchBltMode
printing to DC is not a big deal. it's same as using CDC
|
|
|
|
|
some devices cannot handle large bitmaps (see GetDeviceCaps(...RASTERCAPS), so you have to do your output in bands. some devices cannot do StretchBlt or StretchDIBits (again, see GetDeviceCaps)
|
|
|
|
|
Engberts wrote: if (!StretchBlt (hDC, start.x, start.y, point.x, point.y, m_pDC->GetSafeHwnd (), 0, 0, Source.x, Source.y, SRCCOPY))
6th parameter of API is HDC,whats is m_pDC->GetSafeHwnd () ?
I guess you are passing incorrect type of parameter. It should HDC(source).
|
|
|
|
|
Sorry, this is a typing error, I of course used GetSafeHdc () and not GetSafeHwnd ().
Meanwhile however, I think I found the solution. Since I am copying bitmaps between diferrent devices, I cannot directly BitBlt or StretchBlt between them. I am now using GetDIBits to get the device independant bits out of the screen's device context and then use StretchDIBits to move them into the printer's device context. This does require a lot of programming, but it does result in the required image on paper.
Thanks to you all for your efforts!
William
|
|
|
|
|
Never mind. Importantly, you shared your solution, that's great !
|
|
|
|
|
Hi! i want to write a '.txt' file getting data from a 'multiline edit box'. when i want to go to the next line in an edit box do i press ctrl+enter key? when i use this it gives an extra space character (" ") which spoils the format in the text file i am writing in.
i have also used 'endl;' in the instruction for writing to a file.
outfile << testdata << endl;
if i dont give endl; it gives me two line spaces in between each line in the text file, which again ruins the required file format. does anyone know what i can do to overcome this problem?
thanks!
meriawaz
|
|
|
|
|
Hi,
You need to create the editbox with the "Want return" style. This can either be done from the dialog design (if your application is dialog based) by selecting the "Want return" option on the "Styles" tab. Otherwise, you need to specify the "ES_WANTRETURN" style when creating the editbox.
Success,
William
|
|
|
|
|
Hi,
I am getting one char name from my program..For ex:
char szTemp[10];
szTemp is "DESIGN"..
With the same name i have folder in my drive like c:\Model\DESIGN..
I have to check whether the folder is present in that drive from my code...Pls any one help is there anyway to do this..I think but i didn't get any idea...
If the folder is present then i will do some functionalaties otherwise i return one messagebox that the folder is not there...
Anu
|
|
|
|
|
|
I used that but it shows error as
'PathFileExists' : undeclared identifier.. so that i include
#include "Shlwapi.h" as i found in MSDN but again it shows error as"
unresolved external symbol __imp__PathFileExistsA@4
.\WinDebug/InstructorStation.exe : fatal error LNK1120: 1 unresolved externals"
Why it occurs like this..
Anu
|
|
|
|
|
link Shlwapi.lib using project setting
|
|
|
|
|
|
You need to include header and import library
|
|
|
|
|
Look at the doc here[^]. At the bottom of the page, it shows you which header file you need to include and to which library your program needs to be linked to. So, you have to link to shlwapi.lib (check in your project settings for that).
|
|
|
|
|
Can anybody tell me how to get the Scrollbar's thumb coordinates? Not its thumb position, but its coordinates (CRect).
Plzzzz, help me.
|
|
|
|
|
You cannot ... directly.
I've never thought of that, but isn't the thumb a child window of the scrollbar? I think it is. If it is so, then you could enumerate the children, identify the one representing the thumb, then ask for its rect.
SkyWalker
|
|
|
|
|
1. some articles are [unedited], but some are not.
what is different between them?
2. some updated articles are displayed on front page of code-project. but why my articles are not displayed there after I modified them? what is policy about this? are they updated to front-page automatically or manually by web-masters?
hope someone kown my questions.
|
|
|
|
|
|
thx mate,
I post the 2 Qs on that forum...
I haven't used other frums so far except the VC one.
I guess one of my articles had been loaded to front-page after I updated it - but I am not sure, I just saw many traffic from code-project to my site on the second day after modification.
|
|
|
|
|
includeh10 wrote: I just saw many traffic from code-project to my site on the second day after modification.
thats Great!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Mr includeh10, you know CP very well, then you know this is not the right forum for such a question.
anyway, the articles in the unedited readers contribution are those which where submited with the article Wizard (instead of the mail submission). they will remain in this state as long as they are not poped from the stack by one of the CP editors (and believe me, the stack is very long ! lol)
the articles on the CP front page are the latest one which were newly submited or just updated.
|
|
|
|
|
I have a program taht must connect to a database to get a value, in a dialog class, I have entered the necessary code when (OnBnClickedButton1) ,then I copied un existing code "CDatabase _database;
if (!_database.Open("eChessDBSourceName"))........"
in compilation, many errors appears :
'CDatabase' : undecalred identifier
'_database' : undecalred identifier
salem ,c wiem.
|
|
|
|