|
What's the problem ? Is the bitmap really tiny ? If so, you need to get the size of the printer DC and stretchblt your image onto it.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
No, the image size is ok and the print preview works quite well, but it did not appear on the actual paper (bitmap lost).
|
|
|
|
|
What`s the code? What`s the problem? You couldn`t use the same CDC for printing bitmap with the CDC for printing lines and words.
<italic>Work hard and a bit of luck is the key to success. You don`t need to be genius, to be rich.
|
|
|
|
|
I expect that the bitmap is tiny on the print out? is this what is happening?
if so it is because you are drawing the bitmap into a printing device context, in which case a much higher resolution is used, you need to use the CDC function
StretchBlt() to draw the bitmap into a resolution equivalent rectangle which you will need to work out. So look up StretchBlt()on MSDN its is very simple.!! this
function simply stretches the bits in the bitmap accordingly.
Print preview probably works because it uses a screen DC just like what you are drawing on.
P.S. I hope this is the problem you are getting, if not soz!!
|
|
|
|
|
Soz!,other replies were not there when I replied, Im just not quick enough, well I was eating lunch!!
|
|
|
|
|
I do use the StretchBlt to copy bitmap from memory dc to the actual dc I got from CPrintDlg::CreateDC(), I think may be the problem is the image I want to print is colored, and the device is just only a black-white printer.
|
|
|
|
|
Hi,
I thought this was solved but there happens to be so mnay ways in which these two functions can fail
Here is the scenerio.
I need to connect to the server to find out if winzip command line utilities are installed or not. I use brute force method of connecting to the server running a dummy command using CreateProcess to run the command like c:\progra~1\winzip\wzzip.exe file.zip file.txt (assume file.txt exist).
It turns out to be faster than checking for presence of exes and dependencies.
It works like charm most of the times accept for one scenerio.
This deals with connection problems rather than createprocess etc.
I can do that only if I have valid access to drive c: on server to run the wzzip.exe.
So, I use WNetAddConnection2 to connect to the \\servername\c$ with proper administrative rights ( administrative usernames and password to the server, server is on LAN). After completing processing I dc using WNetCancelConnection2 .
The problem is if i go to winexplorer type in \\servername\c$, it prompts me for username and password. I enter the info and do what i do on c: of server and close the explorer. Now somehow windows remeber this connection and even a call to WNetCancelConnection2 fails to delete it. So when i call WNetAddConnection2 it returns the erro saying the credentials provided conflict with existing crediantls. But if i restart the computer and then run the app it conencts fine and do what it is suposed to do.
Is there a way I can make windows forget the connection (it's not even mapped ).
WNetCancelConnection2 is supposed to delete all non persistent conenctions liekt his, but It does not seem to be doing so.
Does anyone has an idea what's going on here???
Thankyou in advance
P.S. :can provide sample code, thought should explain teh scenerio first.
|
|
|
|
|
A clip from an older project. Deletes all connections. Modify to suite your needs.
Hope this helps.
/+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
// DeleteAllConnections()
// Purpose: Delete all network connections
// Added : 4/06/04
//+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
void TestDlg::DeleteAllConnections()
{
DWORD dwResult;
HANDLE hEnum;
DWORD cbBuffer = 16384;
DWORD cEntries = 0xFFFFFFFF;
LPNETRESOURCE lpnrDrv;
#if _DEBUG
return;
#endif
dwResult = WNetOpenEnum( RESOURCE_CONNECTED, RESOURCETYPE_ANY,0,NULL,&hEnum );
if (dwResult != NO_ERROR)
{
GetErrorMsg(dwResult);
return;
}
// start enumerating all the connections
while( dwResult != ERROR_NO_MORE_ITEMS )
{
lpnrDrv = (LPNETRESOURCE) GlobalAlloc( GPTR, cbBuffer );
dwResult = WNetEnumResource( hEnum, &cEntries, lpnrDrv, &cbBuffer);
if (dwResult == NO_ERROR)
{
for( DWORD ii = 0; ii < cEntries; ii++ )
{
if( lpnrDrv[ii].lpLocalName != NULL )
dwResult=WNetCancelConnection(lpnrDrv[ii].lpLocalName, TRUE );
else
dwResult=WNetCancelConnection(lpnrDrv[ii].lpRemoteName,TRUE );
GetErrorMsg(dwResult);
}
}
}
// cleanup
GlobalFree( (HGLOBAL) lpnrDrv );
WNetCloseEnum(hEnum);
}
Erik
|
|
|
|
|
Ok this is a just a remake of the piece of source that has the problem..
char somthing[200];
char somthing2[200];
cin>>somthing;
cin>>somthing2;
cout<
|
|
|
|
|
Works for me. the only thing is that because you are not outputting newlines the output was "hellohi", as expected.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Given the following:
string Part = “*(-2)”
char buf[5] = “10”
string Result = buf after arithmetic defined in Part is performed
I need to isolate the value after “-“ in Part and perform the arithmetic on buf (knowing in advance that this is a subtraction): For example, using the string values above (pseudo-code):
1- Isolate the “2” in string Part
[actually isolate everything between the “-“ and “)”]
2- Perform the subtraction buf – 2
3- Store result in Result string
Therefore the result should be Result = 8 (10 – 2 = 8)
I need a way to perform these steps….
Any clues or help would be greatly appreciated.
Thanks,
|
|
|
|
|
|
[actually isolate everything between the “-“ and “)”]
If this is exactly what you want, and you don't expect variations, then the following should do:
int x;
sscanf(Part.c_str(),"*(-%d",&x);
But if you wish your program to handle reasonably arbitrary arithmetic expressions the task is not that easy, you'll be basically building an expression parser.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Given string Part = “*(X2)” [multiplication]
I use the following code to extract the “2” into integer arith:
scanf(Part.c_str(),"*(X%d",&arith);
For the addition [“*(+2)”] and subtraction [“*(-2)”] this works perfectly.
However with the multiplication [“*(X2)”] arith is evaluated to be 0 instead of the expected “2”. I also tried using Part = “*(*2)” [this was my first choice] and it does the same thing. Any clues or recommendation?
The exact same problem occurs when trying to implement the Divide [Part = “*(|2)”].
Arith is evaluated to be 0 instead of the expected 2.
Why does it only work for my add [+] and subtract [-] and not my multiply [*] and divide [|]?
|
|
|
|
|
I am trying to always print in Landscape mode regardless of what user chooses. This is my code:
PRINTDLG pd;
LPDEVMODE pDevMode;
pDevMode=NULL;
pDevMode = (LPDEVMODE)::GlobalLock(pd.hDevMode);
// set orientation to landscape
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
pd.hDevMode = pDevMode;//Not needed
::GlobalUnlock(pd.hDevMode);
But it is not working. It always prints whatever user sets in PRINTDLG.
Any help will be appreciated.
Thanks to all.
Joe,
|
|
|
|
|
First off, this is a bad idea. If you want to always print in landscape then you are better off using a custom template and removing the portrait/landscape option from the dialog. Your users will get very PO'd if they choose portrait and it comes out landscape.
Now for your problem: Where have you inserted this code, because I do not see where you call the PrintDlg function. You should set the orientation to what you want after the dialog has been called and returned, if you call it before, then the dialog will override whatever settings you set.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Thanks for repsonding.
I did call it right after it had returned:
memset( &pd, 0, sizeof(PRINTDLG) );
// other init stuff
//then
if( !PrintDlg(&pd)) return 1;
// then I had here that code here...
// landscape mode .. etc
Joe,
|
|
|
|
|
The next thing is does the printer support landscape printing, and if it does, is the DM_ORIENTATION bit flag of the dmFields member set?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
I did check this: pDevMode->dmOrientation, and its value is =2 which is the value of DMORIENT_LANDSCAPE.
I know that pd.hDevMode is local but this is why I had this line:
pd.hDevMode = pDevMode;
Joe,
|
|
|
|
|
Anonymous wrote:
pd.hDevMode = pDevMode;
I think that is your problem, remove that line. You are assigning a pointer to a handle and that does not work.
If removing that line does not help, then post the entire code for the function. The initialization of the PRINTDLG structure, the call to PrintDlg, your changing the orientation, and how you access the PRINTDLG structure when you do the actual printing. Somewhere in there you are making a mistake, and I can not figure it out with the limited information you have given so far.
ps. I have to go, so it will be several hours before I will get back to this. Others feel free to help;)
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Here is the code:
static LPDEVMODE pDevMode;
static PRINTDLG pd; // for PrintDlg()
static DOCINFO di;
// Set Up PRINTDLG Structure For PrintDlg()
memset( &pd, 0, sizeof(PRINTDLG) ); // Clear It
pd.lStructSize = sizeof(PRINTDLG); // Size
pd.hwndOwner = this->GetSafeHwnd();
pd.nFromPage = 1;
pd.nToPage = 1000;
pd.nMinPage = 1;
pd.nMaxPage = 1000;
pd.Flags = PD_RETURNDC | PD_PAGENUMS | PD_NOSELECTION | PD_HIDEPRINTTOFILE;
if( !PrintDlg(&pd)) return 1;
// landscape mode
pDevMode=NULL;
pDevMode = (LPDEVMODE)::GlobalLock(pd.hDevMode);
// set orientation to landscape
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
//pd.hDevMode = pDevMode;//Not needed
// Here is code for stuff to print...
// At end is the clean-up
::GlobalUnlock(pd.hDevMode);
Maybe the problem is that pDevMode is local variable, maybe I need to change some global variable, I just do not know what or how.
By the way I commented that line and it had no effect.
Thanks.
Joe,
|
|
|
|
|
Anonymous wrote:
// Here is code for stuff to print...
Ok, that's cool, but this doesn't help me any.
How are you applying your changes to the printer device context? You are using the PD_RETURNDC flag, so I am assuming that you are using the hDC member of the PRINTDLG structure as your printer DC. After you change the orientation, are you calling ::ResetDC(pd.hDC, pDevMode); ? If so, what is the return value, does ResetDC succeed?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
Call pDC->ResetDC(pDevMode) after pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
Lisoft
|
|
|
|
|
I added: dc.ResetDC(pDevMode);
and it still prints portrait instead of landscape.
Joe,
|
|
|
|
|
The ResetDC() will not run properly on Windows 98 or lower version of windows
try Windows 2000 or later.
|
|
|
|