|
Great - don't save it, just get the co-ordinates of the window and print only that part of it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
thank u.
can u help me check out my code,please?
CDC *pDC=GetWindowDC();
CBitmap bm;CRect rc;GetWindowRect(rc);
int Width=rc.Width();//GetSystemMetrics(SM_CXSCREEN);
int Height=rc.Height();//GetSystemMetrics(SM_CYSCREEN);
bm.CreateCompatibleBitmap(pDC,Width,Height);
CDC tdc;tdc.CreateCompatibleDC(pDC);
CBitmap*pOld=tdc.SelectObject(&bm);
tdc.BitBlt(0,0,Width,Height,pDC,0,0,SRCCOPY);
tdc.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
//
//here. btm can be save as BMP file
dc.StartPage(); // begin new page
Info.m_nCurPage = page;
CDC MemDC;
MemDC.CreateCompatibleDC(&dc);
pOld=MemDC.SelectObject(&bm); ///
dc.BitBlt(rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,&MemDC,0,0,SRCCOPY);
///but here .
//not be printed . the printer only print the bits,too.and the size of printer document is big!
//
|
|
|
|
|
This all looks right, I don't get what the problem is. What are the bounds of the bitmap ? Have you tried blting it to the screen ?
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
yes.
i have tested it.it can be bited to the screen.
my printer is canon lbp_800.
it's my printer's problem?
|
|
|
|
|
It's odd, because in theory if you send a 800x600 bitmap to a printer, you should expect to get a very small bitmap, because most printers have at least 600 dots per inch. IF the bitmap is fine, and the printer driver is hanging with a large amount of data passing through, then the problem is most certainly the print code.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
then,
how can i do?
save as BMP file,and print it with MS paint?
please
|
|
|
|
|
No, that would clearly be a hack. Print some text to your printer, then create a small bitmap programatically and print that. Build your way up until you work out where it is failing, and fix it ( naturally ask questions if you're confused or stuck, and provide whatever info you manage to find on the way ).
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
thanks a lot.
i have printed it.
this is my code
CDC memDC;
CWindowDC dc(this);
CRect rcrc;GetWindowRect(rcrc);
int bmpWidth = rcrc.Width();
int bmpHeight = rcrc.Height();
memDC.CreateCompatibleDC( &dc );
CBitmap * bitmap = new CBitmap();
bitmap->CreateCompatibleBitmap(&dc,bmpWidth, bmpHeight);
CBitmap * pOldBitmap = (CBitmap *) memDC.SelectObject(bitmap);
if (pOldBitmap == NULL) // if bitmap is very big, better check this !
{
memDC.DeleteDC();
delete bitmap;
AfxMessageBox("Not enough resource for the bitmap. Either reduce the bitmap dimension or \nswitch to lower screen setting (e.g. 256-color mode), and try again.");
return;
}
//draw bitmap here, or it can be done in another function
//
memDC.BitBlt(0,0,bmpWidth,bmpHeight,&dc,0,0,SRCCOPY);
// memDC.Ellipse(0, 0, bmpWidth - 1, bmpHeight - 1);
CDC prtDC;
CPrintInfo printInfo;
CSize size;
DOCINFO di;
CString szPortName, szAppName, szPrintError;
szAppName.LoadString(AFX_IDS_APP_TITLE);
szPrintError = "";
CSize paper_size; //printer paper size in mm
int xLogPPI = 0;
int yLogPPI = 0;
if( AfxGetApp()->GetPrinterDeviceDefaults(&printInfo.m_pPD->m_pd) )
{
HDC hDC = printInfo.m_pPD->m_pd.hDC;
if (hDC == NULL)
hDC = printInfo.m_pPD->CreatePrinterDC();
if(hDC !=NULL)
{
prtDC.Attach(hDC);
paper_size.cx = prtDC.GetDeviceCaps(HORZSIZE);
paper_size.cy = prtDC.GetDeviceCaps(VERTSIZE);
xLogPPI = prtDC.GetDeviceCaps(LOGPIXELSX);
yLogPPI = prtDC.GetDeviceCaps(LOGPIXELSY);
}
else
{
AfxMessageBox("Can not find printer. Please check installed/default printers.");
return;
}
}
int scr_xLogPPI = dc.GetDeviceCaps(LOGPIXELSX);
int scr_yLogPPI = dc.GetDeviceCaps(LOGPIXELSY);
int paper_width = (int) ((double) paper_size.cx * (double) xLogPPI / 25.4); //width of a printed page in pixels
int paper_height = (int) ((double) paper_size.cy * (double) yLogPPI / 25.4);
double ratio_x = (double) xLogPPI / (double) scr_xLogPPI;
double ratio_y = (double) yLogPPI / (double) scr_yLogPPI;
//pop up printer dialog
CPrintDialog prtDlg(FALSE, PD_PAGENUMS);
prtDlg.m_pd.nMinPage = 1;
prtDlg.m_pd.nMaxPage = 1;
prtDlg.m_pd.nFromPage = 1;
prtDlg.m_pd.nToPage = 1;
if(prtDlg.DoModal() == IDOK )
{
memset(&di, 0, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = szAppName;
szPortName = prtDlg.GetPortName();
di.lpszOutput = szPortName;
prtDC.m_bPrinting = TRUE;
}
else
return; //Cancel button pressed, don't forget this!
if(prtDC.StartDoc(&di) == -1)
{
AfxMessageBox("Printing error occured. Unable to find printer.");
prtDC.Detach();
prtDC.DeleteDC();
return;
}
prtDC.SetMapMode(MM_TEXT);
prtDC.StartPage();
prtDC.StretchBlt(0, 0, bmpWidth * ratio_x, bmpHeight* ratio_y, &memDC,
0, 0, bmpWidth, bmpHeight, SRCCOPY);
prtDC.EndPage();
memDC.SelectObject(pOldBitmap);
delete bitmap;
memDC.DeleteDC();
prtDC.EndDoc();
prtDC.Detach();
prtDC.DeleteDC();
return;
|
|
|
|
|
I want to display outlook:Inbox (which should open outlook to the Inbox folder). It works but the problem is that if Outlook is already openend, it will open a new Outlook instance. Id there a way that ShellExecute (or another function) won't open a new instance and use the one already running?
Thanks!
---------------
Concentrating on Ideas
http://www.edovia.com
|
|
|
|
|
Simply find the Outlook window using ::FindWindow(...) and activate it. If the findow has not been found then start Outlook with ShellExecute as you already do
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Use COM instead, I did this with Word some years ago.
Works great and you have a lot of control through the automation interface.
|
|
|
|
|
|
|
I am writing code and I am trying to use the simple TextOut(); function and I want to create a dynamic way to get the size of the LPCTSTR string rather than try to hard code it. I have tried sizeof() but that doesn't work any suggestions?
|
|
|
|
|
try "strlen" and its cousins.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
Probably another simple queston.
I have used the same code in other dialog boxes, (with different variables)and it works.
Thanks for the help.
I get the following ASSERT at the line containing m_BeginStr.ResetContent();
_AFXWIN_INLINE void CComboBox::ResetContent()
{ ASSERT(::IsWindow(m_hWnd)); ::SendMessage(m_hWnd, CB_RESETCONTENT, 0, 0); }
void CDlgOffset::OnButtonBrowse()
{
FILE *StrFile;
CWnd* pWnd;
CString sStrName;
double E;
double S;
CFileDialog dlg( TRUE, "txt", NULL, OFN_FILEMUSTEXIST, "Text Files (*.txt)||\0" ,NULL );
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
m_StrFile = dlg.GetPathName();
pWnd = GetDlgItem( IDC_EDIT2 );
pWnd->SetWindowText( m_StrFile );
// Load the Combo Boxes
StrFile = fopen( m_StrFile, "r+");
fseek( StrFile, 0L, SEEK_SET );
m_BeginStr.ResetContent();
m_EndingStr.ResetContent();
while( fscanf( StrFile, "%s %lf %lf", sStrName, &E, &S ) != EOF )
{
m_BeginStr.AddString( sStrName );
m_EndingStr.AddString( sStrName );
}
fclose( StrFile );
}
}
|
|
|
|
|
has m_BeginStr been initialized? chances are that it isn't yet a "window" (and the ::IsWindow test is failing). make sure you're either DDX'ing the control or SubClassing it (ie. attaching an actual control to the variable)
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
it has CCombobox attached to it in the member varibles.
|
|
|
|
|
look in the DoDataExchange function of your dialog. do you see a line that looks something like this:
DDX_Control(pDX, IDC_MY_COMBOS_ID, m_BeginStr);
?
if not, it needs one. otherwise, the member variable is never actually attached to the control.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
It is there.
void CDlgO::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgOffset)
DDX_Control(pDX, IDC_COMBO_END_STR, m_EndingStr);
DDX_Control(pDX, IDC_COMBO_BEG_STR, m_BeginStr);
|
|
|
|
|
hmmm.
can you put a breakpoint on that DDX line and step into the DDX_Control code to see if anything fails?
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|
it fails before it gets there.
Kevin
|
|
|
|
|
This question concerns the various C++ and corresponding header files that you would normally combine into a single project workspace folder. I'm somewhat mystified (but, I'm new to C++ and Visual C++,...everything is mysterious) as to the reasoning behind creating numerous separate files (both C/C++ and the definition headers) for a given project, except maybe convenience. As a novice to C++ programming, I find it much more educational to review the actual code than to read descriptive textbook style explanations of the various objects and functions. Currently, I am reading through Petzold's Programming Windows, which is excellent for a beginner like myself, but, I am curious as to why so many separate code files are necessary in a small, simple project as are presented in Petzold's book.
My main assumption is that for code and object re-use, it is convenient to have files that can be just added with an #include directive. I am wondering if in some circumstances it is preferred to have a definition header or series of such files for some specific configuration (I can't imagine what). Do I sound confused? I'm not even sure how to phrase to question.
Also, is it critical as to what order these various files are added to the project file? I am unclear as to what operations that compiler actually performs on these files besides scanning the syntax and creating a hierarchy of elements and instructions.
Anyone that could please just recommend an article that I could refer to, or a subject listing in the MSDN library, I would appreciate it hugely. Thanks.
|
|
|
|
|
you mentioned both of the answers:
1. code resue. you can't really reuse a class in another project, if it's definition is hidden away in a .CPP somewhere.
2. convenience. if your project gets much past the HelloWorld stage, you'll start to end up with classes and modules that have logical distinctions. for your own sanity, it's best to move those into separate files to keep the parts as manageable as possible.
no, it the order in which you add them to the project doesn't matter. VC will scan them and determine the dependencies automatically so that they are built in the right order.
-c
“losinger is a colorizing text edit control”
-- googlism
|
|
|
|
|