|
:|I am still having trouble trying to print in landscape. Below is my latest code which does not print or change the page to landscape. Any suggestion would be appreciated. I think I feel like a mouse going around in circles.
The code seems to give me a new device context but it does not seem to print.
void CLogbookView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
pDC = SetLandscape(pDC);
pDC->TextOut(100,100,"test");
}
CDC* CLogbookView::SetLandscape(CDC* pDC)
{
BOOL bStdSetUpDlg = TRUE;
CWnd *pWnd = this;
CPrintDialog pPrintDialog(bStdSetUpDlg,PD_USEDEVMODECOPIES ,pWnd);
pPrintDialog.GetDefaults();
LPDEVMODE pDEVMODE = pPrintDialog.GetDevMode();
pDEVMODE->dmOrientation = DMORIENT_LANDSCAPE;
pDC->m_hDC = pPrintDialog.CreatePrinterDC();
return pDC;
}
Desmond Mardle
|
|
|
|
|
Take a look at my article www.codeproject.com/printing/printerselect.asp
It covers switch landscape/portatit mode and a host of other features
If your still stuck, e-mail me direct.
Roger Allen
Sonork 100.10016
If I had a quote, it would be a very good one.
|
|
|
|
|
I have
_variant_t tempkeyValue = new _variant_t[20];
but when I go to do
delete[] tempkeyValue;
I get the error:
C:\Trainer\DB2\DbClass.cpp(204) : error C2440: 'delete' : cannot convert from 'class _variant_t' to ''.Ambiguous user-defined-conversion.
How can I get rid of the pointer fter I'm through with it?
Thanks,
ns
|
|
|
|
|
You need a pointer variable :
_variant_t *tempkeyValue = new _variant_t[20];
Sonork 100.15206;PavelK
|
|
|
|
|
Oops!So I did. The weird thing is. my code actually worked without declaring it a pointer, except for the delete.
Now I have:
_variant_t *tempkeyValue = new _variant_t[20];
*tempkeyValue = m_pRecordset->Fields->GetItem (key)->Value;
strcpy(keyValue,(char *) (_bstr_t)*tempkeyValue);
AfxMessageBox((char *) (_bstr_t)*tempkeyValue);
AfxMessageBox((char *) (_bstr_t)m_pRecordset->Fields->GetItem (key)->Value);
delete[] tempkeyValue;
which is fine, but I had:
_variant_t tempkeyValue = new _variant_t[20];
tempkeyValue = m_pRecordset->Fields->GetItem (key)->Value;
strcpy(keyValue,(char *) (_bstr_t)tempkeyValue);
AfxMessageBox((char *) (_bstr_t)tempkeyValue);
AfxMessageBox((char *) (_bstr_t)m_pRecordset->Fields->GetItem (key)->Value);
and it gave the right values in both messageboxes.
Is that to be expected or some weird coincidence?
Apprecite your reply tremendously. I was starting to thing _variant_t varaiables were a different beast as far as delete goes...
ns
|
|
|
|
|
This is a side-effect of conversions (1 argument) constructors and conversions operators...
A _variant_t can be converted to a VARIANT * implicitly by the defined conversion operator and this allows some misuse to go undetected...
Conversion operators are cool in general but very dangerous particulary when the returns pointers to internal data.
Philippe Mori
|
|
|
|
|
a how can I respond Enter Event in a editbox?
I have a editbox,and I want to make it do sth. like this: when the Enter key was press,other controls in the dialog can get the value in it,then the editbox clean up the value,nd wait the next input.
how can I make this ? Anyone can give me a clear answer?Thanks.
YES, I am here.
|
|
|
|
|
Here is one solution.
-create editbox
-add a button
-set button as default button
-when the user presses Enter, the button is press
-now you can do whatever you want including clear editbox
Kuphryn
|
|
|
|
|
I know this solution,but that's it,I don't want to add a button.I just want to respond the Enter Key.so...
YES, I am here.
|
|
|
|
|
You can derive your own edit control from CEdit and overide handling of keyboard messages. Then You can send a custom notification message to the parent window (dialog, form). See the edit control section here at CP for inspiration.
Sonork 100.15206;PavelK
|
|
|
|
|
Hello, the codegurus around the world.;)
This is one of the famous questions in MFC.
If you push Enter key, the dialog will be closed.
One solution is that you can trap Enter key message by PreTranslateMessage
before Enter Key message sends to the dialog.
And you can check if EditBox actually get the input focus in PreTranslateMessage.
Also, Paul Deliacia(?) posts his article in this question in MSDN magazine.
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
I always do stuff like that in my OnOK() function.
void CMyDialog::OnOK
{
if (GetFocus() == c_MyEditControl)
{
}
else
CDialog::OnOK();
}
CPUA 0x5041
Sonork 100.11743 Chicken Little
"So it can now be written in stone as a testament to humanities achievments "PJ did Pi at CP"." Colin Davies
Within you lies the power for good - Use it!
|
|
|
|
|
That's a neat tip!
|
|
|
|
|
Hi,
I have the problem that the below code
LOGFONT lf;
CFont font;
m_pWndOutput->ResetContent();
CFontDialog dlg;
if (dlg.DoModal()==IDOK)
{
dlg.GetCurrentFont(&lf);
if (font.CreateFontIndirect(&lf))
{
m_pWndOutput->SetFont(&font);
OutputAllItemsAgain();
}
}
which is a message handler of the Change Font button,
does not change the font itself in the ListBox (m_pWndOutput), it only changes the ListBox item height according to the font size specified in CFontDialog.
I tried this instead of a ListBox with a ListCtrl but experienced the same.
Could somebody please enlighten me?
Thanks
R.
|
|
|
|
|
Here is on solution.
// This should be in the class contructor.
-----
LOGFONT fontLog;
CDC dc;
memset(&fontLog, 0, sizeof(LOGFONT));
// set font size
fontLog.lfHeight = -MulDiv(11, GetDeviceCaps(dc, LOGPIXELSY), 72);
// set font type
strcpy(fontLog.lfFaceName, "Microsoft Sans Serif");
CFont *myFont;
myFont = new CFont();
myFont->CreateFontIndirect(&m_MsgLogFont);
-----
// This should be in the function you use to set the font.
-----
myFont->CreateFontIndirect(&m_MsgLogFont);
// Assuming this is a listview
GetEditCtrl().SetFont(myFont);
-----
Kuphryn
|
|
|
|
|
See the VC forum FAQ. The short answer is the CFont objec is a local variable and gets destroyed as soon as the function returns.
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
I'm doing a program in serial communication and have some questions:
1.When does the EV_CTS events take place?
do I need to monitor it? Can you give me an example?
2.If I use the MSComm control in SDI document,how can I add it to the project, and monitor the comm event? Thanx!
|
|
|
|
|
Search in the MSDN for:
1. Serial Communications in Win32 Allen Denver Microsoft Windows Developer Support
2. "VCTERM: Uses the Microsoft Communications ActiveX Control"
Read on then post!
Papa
Murex Co.
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
hi,
i have a situation where i use a frameless doc to do background processing and later i have to save it.how can i do that? also how can i save a different doc created in its own frame and view,all registered with a template?
|
|
|
|
|
Hi.I'm writing a dialog based aplication with support for sockets.I created my own derived class from CAsyncSocket.Whenever a client sends the string "cat <file>" to the server (where file is an ascii text file), the server responds sending the contents of the specified file to the client.The problem is that, most of the times, the server just sends about half of the contents of the file to the server.Here is the code I created to do this :
//on the server side:
//loop to read the contents of the file, f is a CFile object
//nbytes an UINT variable
//PacketSend(..) is my function to send the buffer to the client
while ( (nbytes = f.Read(buf,512)) )
PacketSend(buf,nbytes);
f.Close();
//PacketSend(..) function
void CConversarDlg::PacketSend(void *buffer,const int &length)
{
int total = sizeof(int) + length;
int sent;
int bufpos = 0;
BYTE *buf = new BYTE[sizeof(int) + length];
memcpy(buf,&length,sizeof(int));
memcpy((void *) (buf+sizeof(int)),buffer,length);
do
{
sent = ClientSocket->Send(buf+bufpos,total);
if ( sent == SOCKET_ERROR ) break;
total -= sent;
bufpos += sent;
if ( total > 0 ) Sleep(20);
} while ( total > 0 );
delete [] buf;
}
//on the client side:
//I call the funtion ReceivePacket on the overridable CAsyncSocket::OnReceive(int)
//PacketReceive(..) function
void CXploreDlg::PacketReceive(unsigned char **buffer)
{
unsigned char *buf;
int length;
int recv;
int bufpos = 0;
//clientsocket is an object of the derived CAsyncSocket Class I created
recv = clientsocket.Receive(&length,sizeof(int));
if ( recv != sizeof(int) || recv == SOCKET_ERROR ) return;
buf = new unsigned char[length + 1]; //+1 for the NULL character
do
{
recv = clientsocket.Receive(buf+bufpos,length);
if ( recv == SOCKET_ERROR ) break;
length -= recv;
bufpos += recv;
if ( length > 0 ) Sleep(20);
} while ( length > 0 );
*(buf + bufpos) = NULL;
*buffer = buf;
}
On the begining of each packet, I use 4 bytes (int value) for the client aplication to know the length of the packet,the rest is the contents of the ascii file specified....
I'm new to sockets, so I would apreciate a lot a little help...
I'm also trying to write code for downloading and uploading files, but i got exactly the same problem I mencioned before....
Thanks.
Portugal.
Filipe David Manana
|
|
|
|
|
Which platform you are interested in ???? If you are ready to bound to Win 2000 and later OSs, then use the APIs like TransmitFile and TransmitBuffers
Imran Farooqui
|
|
|
|
|
Hello, the codegurus around the world.;)
When you try to transfer the file by CAsyncSocket class, you need some kind
of CFile class process to read or write some part of the files to the buffer.
And this buffer will be sent or received in the server or client respectively.
I didn't find this process, so I'm wondering how you create this buffer.
Or you insert whole file to the buffer only one time?
If so, this approach seems not to be good.
Or while the process inserts the data to the buffer, you may call PacketSend.
You may need some code to check if the buffer includes exact buffer
before PacketSend is called?
Please, don't send me your email about your questions directly.
Have a nice day!
Sonork - 100.10571:vcdeveloper
-Masaaki Onishi-
|
|
|
|
|
Sure this sounds silly considering the plethora of available RDBMS out there but does anything like the subject would suggest actually exist...???
Basically an advanced CFile w/ like Hybrid SQL support or something? That doesn't require any third party libs, drivers, dll's or anything...???
Just curious....
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
|
Hi, all
Some problems about ATL Com:
1.I have create two ATL Object: CStudent and CTeacher .
The simple source code listed as follow: (some code auto generated by ATL have been skiped)
class CStudent
{
private:
long m_age;
public:
CStudent():m_age(10)
{
}
//...other code auto generated by ATL
};
class CTeacher
{
private:
IStudent* m_aStudent;
public:
CTeacher()
{
//create an instance of the com
CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_aStudent);
}
//...other code auto generated by ATL
}
2.Then I add a "IStudent * OneStudent" property for ITeacher ,to access the m_aStudent.
The implemention of the property are listed as below:
STDMETHODIMP CTeacher::get_OneStudent(IStudent *pVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*pVal = * m_aStudent;
return S_OK;
}
STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// TODO: Add your implementation code here
*m_aStudent = *newVal ;
return S_OK;
}
3.Now I type some VB code to test the com ,but some compiler errors occurrs.
VB Code:
Dim s As Student
Dim t As New Teacher
s = t.OneStudent
the last sentence "s = t.OneStudent" have compiler errors.
Errors:function or interface marked as restricted ,or the function use an Automation type not supported in Visual Basic
I guess the errors caused by the type dismatch between IStudnet and CStudent.But I did not know how to resolve it .
So who can tell me how to return the m_aStudent that can be supproted in vb??
thx.
Regards.
|
|
|
|