|
|
Hi,
I'm having some trouble with an sdi app. I want to have multiple child windows reflecting the contents of a single document (I'm trying to stay away from an mdi app). I've created some CFrameWnd objects as children of the main view (main view is that created by visual cpp 6.0 sdi app wizard) but they are always in an inactived state - even when clicked on. They move, minimize, etc fine but the title bar never changes color to show activation . This is also the case when I create my frames as children of the main (top level) frame. Do I need to redirect messages from my main frame at all, or is there some initialisation I'm missing - or something else altogether ?
Any help would be greatly appreciated.
Thanks,
Ben
|
|
|
|
|
What window styles are you using for the child windows?
Mark
|
|
|
|
|
I'm using WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW for the child frame windows.
|
|
|
|
|
|
Hi everyone,
I made a program which can draw some graphs using memory device, now I wanna print the graph. Unfortunately what I did doesnt work! In print preview, the graph is reversed and the size can't be controled which means the graph is not magnified proportionally.
could you please tell me how can I make it? Thank you very much and look forward to hearing from you!
In OnDraw function, I coded as follow:
void CMyView::OnDraw(CDC* pDC)<br />
{<br />
<pre><br />
CMyDoc* pDoc = GetDocument();<br />
ASSERT_VALID(pDoc);<br />
CBitmap* pOldBitmap = m_pMemDC->SelectObject(m_pBitmap);<br />
<br />
if(pDC->IsPrinting())<br />
{<br />
pDC->SetMapMode(MM_LOENGLISH);<br />
pDC->StretchBlt(0,-950,pDC->GetDeviceCaps(LOGPIXELSX),pDC->GetDeviceCaps <br />
(LOGPIXELSY),m_pMemDC, 0,0, 6*m_nMaxX/5,m_nMaxY,SRCCOPY);<br />
<br />
}<br />
else<br />
pDC->BitBlt(0,0,m_nMaxX,m_nMaxY, m_pMemDC,0,0,SRCCOPY);<br />
<br />
m_pMemDC->SelectObject(pOldBitmap);<br />
</pre> }<br />
where,
m_nMaxX = GetSystemMetrics(SM_CXSCREEN);
m_nMaxY = GetSystemMetrics(SM_CYSCREEN);
used for defining the boudary of drawing
|
|
|
|
|
|
thanks for your help.
Acutally, my program wants to show the graph without scrollview, so I get the m_nMaxX and m_nMaxY and try to draw the graph dynamically according to the resolution of the computer. On the other hand, I use the memory device to draw the graph, so in "OnDraw" function, the function "StretchBlt" and "BitBlt" are used seperately for printing and screen view. I think that is the point, and that is what confuses me for a long time. How can I get the correct porporation when I use "StretchBlt" function for print preview?
Hope you can help me on this issue. thanks again!
|
|
|
|
|
My intent was to demonstrate MM_ISOTROPIC which allows your document to be defined in some arbitrary world coordinate system. (i.e 100x200, 1200x2000, 3000x3000, etc...). Your graphics don't have to be shuffled around or resized when printing to different devices or viewed via the screen. Instead you adjust the ViewPort extent to adjust the output to fit the device you are rendering to. Remove the scrollview stuff if you need.
Your blit's should work just fine. Don't lock yourself into a mapping mode like MM_LOENGLISH, MM_HIMETRIC, etc... since your going to have to adjust your output anyway to fit different devices in a proportional manner. MM_ISOTROPIC will preserve your aspect ratio when MM_ANISOTRIPC will allow you to have any aspect ratio you want. However, MM_ANISOTROPIC will distort output at any ratio than the original so it is of little practical value in production apps unless your intent is to distort the output.
Try this, make a document that is 1000x1000. Do your blitting so your image is at some location in this grid and try the sample. You will see that the image is always in the same relative position to the document and any other drawing output in OnDraw. You don't need to change the position of the items being drawn. The sample will ensure it is adjusted for you.
I hope I'm understanding the problem correctly. If not, I apologize
|
|
|
|
|
A simpler sample would be to first create an app with the sample code in the appropriate places. In the OnDraw, draw a simple line, rectangle, or some drawing primitive with coordinates that fall within the documents bounding box that is defined in the sample.
Resize the window, do a print preview in portrait, landscape, set different paper sizes before the print preview, change the screen resolution. You'll see how the document always fits itself.
Then once you see what it's doing, then try putting the blitting code in the OnDraw. All the code that determines if your printing or not is in the OnPrepareDC method so you only need the code for the blitting in the OnDraw.
|
|
|
|
|
Thank you very much
I will try to understand what you taught me and then more questions
|
|
|
|
|
I added following codes in OnDraw function
if(pDC->IsPrinting())<br />
{<br />
<pre>pDC->SetMapMode(MM_ISOTROPIC);<br />
pDC->StretchBlt(100,-100,pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES),<br />
m_pMemDC,0,0, 6*m_nMaxX/5,m_nMaxY,SRCCOPY);<br />
</pre>}
and in OnPrepareDC function, codes has been added as follow:
if(pDC->IsPrinting())<br />
{<br />
<pre>pDC->SetMapMode(MM_ISOTROPIC);<br />
<br />
int nPageWidth = pDC->GetDeviceCaps(PHYSICALWIDTH); <br />
int nPageHeight = pDC->GetDeviceCaps(PHYSICALHEIGHT); <br />
<br />
CSize size = CSize(nPageWidth, nPageHeight); <br />
pDC->SetWindowExt(size);<br />
<br />
pDC->SetViewportExt(pDC->GetDeviceCaps(HORZRES),-pDC->GetDeviceCaps(VERTRES));</pre><br />
}
Now, I can get the correct view in print preview!
Thank you very much!
By the way, I think I am still confused in print issue, such as mapping, the difference between the window and view, etc. Could you please recommend some literatures for me?
|
|
|
|
|
Glad to hear it's working.
As far as literature is concerned for mapping modes, viewports, etc...
I would have to say Ivor Horton does a superb job of taking anyone from A to Z. He goes through the process of building a drawing program in the second half of the book. The first half of the book is dedicated to C++ so the book is probably one of the best values out there.
For Visual C++ 6.0 (or 2003) get
Ivor Horton
Beginning Visual C++ 6
For Visual C++ 2005 get
Ivor Horton
Beginning Visual C++ 2005
(I flipped through this at the bookstore and it's basically the same as the previous book with some updates for 2005.)
|
|
|
|
|
Hi,
I am trying to make MSN client using VC++.NET. I am using socket for this. But I get “WSAETIMEDOUT (10060) Connection timed out ” error when I am connecting to messenger.hotmail.com server at port number 1863. Can I know what is wrong with this code? Thanks in advance. Priyank
WORD version;
WSADATA wsaData;
int rVal=0;
version = MAKEWORD(1,1);
WSAStartup(version,(LPWSADATA)&wsaData);
LPHOSTENT hostEntry;
//store information about the server
hostEntry = gethostbyname("messenger.hotmail.com");
if(!hostEntry)
{
::MessageBox(NULL,"Failed gethostbyname()","Test",MB_OK);
return false;
}
//create the socket
SOCKET theSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if(theSocket == SOCKET_ERROR)
{
::MessageBox(NULL,"Failed socket()","Test",MB_OK);
return false;
}
//Fill in the sockaddr_in struct
SOCKADDR_IN serverInfo;
serverInfo.sin_family = AF_INET;
serverInfo.sin_port = 1863;
serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
rVal=connect(theSocket,(LPSOCKADDR)&serverInfo,sizeof(serverInfo));
if(rVal==SOCKET_ERROR)
{
int errCode = ::WSAGetLastError();
::MessageBox(NULL,"Failed connect()","Test",MB_OK);
return false;
}
closesocket(theSocket);
WSACleanup();
MessageBox(NULL, "Connection was made", "SOCKET", MB_OK);
-- modified at 11:52 Tuesday 31st October, 2006
|
|
|
|
|
priyank_ldce wrote: serverInfo.sin_port = 1863;
try
serverInfo.sin_port = ::htons(1863);
|
|
|
|
|
Thanks it works
|
|
|
|
|
Well, i finnaly got the app to read from a file, anyways, it only reads up to a space, then it stops (unless you read from the file again, in a loop or something - of course each time its like a new line)
Anyways, im sure y'all already know that, and you may have guessed the question, how do a read a whole line upto an newline constant of some kind, rather that a space?
|
|
|
|
|
The Undefeated wrote: ...how do a read a whole line upto an newline constant of some kind, rather that a space?
Use the getline() method.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
That'd do it, thanks. Didn't i tell you it was an easy question.
|
|
|
|
|
use std::ifstream::getline()
|
|
|
|
|
Thanks for you help at first!
I'm a chinese student and my english isn't very well! A I really want your can give me some help on my english and computer courses(I'm very interesting in Visual C++)!
I'm a tenderfoot about C++ language!
I'm confusing by the question as follows:
there is parts of my code:
int a=10;
int* ap=&a;
char c='b';
char* cp=&c;
when I want to get the vaule of the Pointers point to;
cout<
|
|
|
|
|
Yeah, i got garbage as well, except i had a whole array of chars (an entire 7) to get round the problem, i had to write out each character at a time, a bit much effort really
|
|
|
|
|
you get garbage values after the character 'b' because the operator << is overloaded for a code char* parameter, to be a C-style string.
such a string is supposed to be NUL terminated (with '\0' ), so it read from the beginning (the 'b' character) until it finds a '\0' character in the memory after the 'b' , even if it is not yours.
if you want to see the address of the pointer, do this :
cout << (const void*)cp;
-- modified at 12:01 Tuesday 31st October, 2006
|
|
|
|
|
wanlim0817 wrote: ...Is there some differences between the int* type and cahr* type?
Of course. One points to an int and the other points to a char .
wanlim0817 wrote: And why there are some garbage gets when I use "cout<<cp"!< blockquote="">
Did you look to see what << operator was being called?
cout << (const void *) cp;
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
David, just a personal wondering, but here, is there a reason to use (const void*) more than the non-const (void*) cast ?
i don't see anything serious, so maybe you could light me up...
|
|
|
|
|