|
Start a new app from AppWizard, and check "Pinting", this enable print and print preview to your CView.
Then draw your bitmap on the OnDraw method of your view. That's all.
// PrintTestView.cpp
BEGIN_MESSAGE_MAP(CPrintTestView, CView)
//{{AFX_MSG_MAP(CPrintTestView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
void CPrintTestView::OnDraw(CDC* pDC)
{
CPrintTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);
// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;
// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
}
}
/////////////////////////////////////////////////////////////////////////////
// CPrintTestView printing
BOOL CPrintTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
|
|
|
|
|
Hi, I have a very simple problem here deciding whether to use an STL
vector or an STL list.
The list is a list of std::string
Basically, this how I am going to use this list:
1) Populate once, then leave untouched
2) Check if a string exists in the list
Does anyone know if I should use vector<string> or list<string> ?
Thanks!
Jeremy
"Hey man, Taliban, Tali me Banana."
|
|
|
|
|
1) Populate once, then leave untouched
So list doesn't have any advantages over vector in this case - use vector or map if you're going to frequently check if string exists.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I wouldn't use a vector or a list for this task. Use a vector for containing items where random access to the items is important, and there is a definite order to them. Use a list where you plan on accessing the items sequentially, and the order of insertion is maintained.
If you want to keep container of strings and you want to check later whether or not a string exists, consider using a set. The items in the set will be maintained in sorted order (not in order of insertion), only unique items will exist in the set (you won't be able to "Bob" in there twice). Use a set if the order in which you inserted the items into the container is not important. Use the set::find method to determine if an item already exists in the set. This will save you the trouble of traversing the entire container to find out if an item exists in the set. Also, since sets store their contents in a tree, determining if an items already exists in the set is less computationally expensive than determining if an items exists in a linear sequence (like a list or vector).
|
|
|
|
|
With list or vector you can perform only linear search . With set (which is a balanced binary tree) you use binary search, and that is a lot faster.
I vote pro drink
|
|
|
|
|
Others have already mentioned set, so I won't repeat them.
However, for future reference, the advantage of list is that it allows easy insertion/deletion in the middle, vector would need to reallocate the entire array to do this. The down side is that list cannot be randomly accessed - you need to start at the top and work your way through to find a particular location.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Thanks a lot guys! I found your suggestions very, very helpful.
Jeremy.
"Hey man, Taliban, Tali me Banana."
|
|
|
|
|
I'm writing a DLL that uses DirectShow to capture some video off a firewire (WDM) device, and I'm having a small problem.
We have an MFC app that creates the view in the EXE, and then passes a pointer to the view to the DLL so that we can put the preview window into the view. If the preview window consumes all of the client rectangle, I can't get the veiew to respond to mouse clicks. If I maximize the view window, I get a border of unused area around the preview window that responds to mouse clicks.
Can anyone provide any clues,documentation, books, magazines, help from aliens, anything?
|
|
|
|
|
Can you call SetCapture() in your view ? That's how I usually get around those sort of problems, although I often find it's tricky to get the code to a state where the mouse actually responds as you'd expect.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I basically can't change the exe. Anything I do has to be done in the DLL since we support many different DLL which perform similar functionality, using WDM instead of Video For Windows.
|
|
|
|
|
I've got myself a treeview (yeah!). When I select a node, the tvitem structure I get with the message doesn't contain the image (TVI_IMAGE) attribute. Is there a way of finding out what image the selection has? I'd like to use the image as a way of knowing what type of object was selected.
Thanks,
WAVK
|
|
|
|
|
You'll have to call CTreeCtrl::GetItem, passing HTREEITEM from NMTREEVIEW. Don't forget about TVIF_IMAGE flag.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I need to know when my parent gets WM_SIZE and WM_MOVE messages (i am a CButton derived control )
any help?
|
|
|
|
|
Your parent must co-operate and call some method exposed by button. There's no built-in notification going from parent to child during move/size operations.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hello, the codegurus around the world.;)
We can put the code likes SendMessage with the user-defined message or some Get function
from Dialog (or button) in WM_SIZE and WM_MOVE of the parent's message handler.
The only issue is how we get CWnd of the child dialog or the button of its dialog.
There are many ways to do this.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
How can I force all buttons, edit- boxes and list-boxes to be resized when resize the application window ? Objects should be smaller but still at the same location within the application window.
Hans
|
|
|
|
|
If you're using MFC you may have a look at ResizableLib on this site.
If using plain Win32 APIs, that same article can give you some ideas.
Paolo
------
"airplane is cool, but space shuttle is even better" (J. Kaczorowski)
|
|
|
|
|
this is the easiest way to place an icon on a button:
// Button = m_SafeButton
// Icon = IDI_FLOPPY
m_SafeButton.SetIcon(AfxGetApp()->LoadIcon(IDI_FLOPPY));
m_SafeButton.EnableWindow( true);
that´s all.
Hans
|
|
|
|
|
i am using NtQuerySystemInformation() from NTDLL.
my worry is whether this function will be supported in future versions of Windows.
isn't XP the next version of Win2k and ME that of Win9x??
i am unfamiliar with Windows Architecture...could someone help me out??
|
|
|
|
|
I want to control word through the interface the word provided. But I found some problems. I found not all the controls such as buttons, comboboxs are window control. They don't have the window handles. But I want to process some messages it sended. you can found this through spyxx.What can I do?
thanks to all the programmers who have helped me.
|
|
|
|
|
How on earth do you presume to have found that a button or combobox in Word does not have a HWND associated with it ? I believe Word does not use MFC, ( so no CWnd ), but I can't see how it could possibly show you a button without it being a window, with a handle.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
How on earth do you presume to have found that a button or combobox in Word does not have a HWND associated with it
He's probably thinking about Word toolbars - the comboboxes and buttons you can see there aren't real tax-paying, HWND-having windows.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I want to use my own dialog to control word. for example, I want to control the "insert -> index and content" dialog in my code. So I can send a message to set the checkboxes status. But i can't get the checkboxs' window handle now.
thanks to all the programmers who have helped me.
|
|
|
|
|
What are you trying to make Word do? Which controls/windows are you trying to control?
You seem to be approaching this from a strange angle. What do you want to achieve?
Michael
|
|
|
|
|
to be simple, I want to create a word document with my own format. And I will provide some dialogs to let people coustomize the format. so have to use some word's automation interface. But when a dialog of word do modaled, I can't get the status untile the dialog ended. for example, in the dialog "insert -> index and content" there are some check boxes, and i want to set the check boxes' status in my code. what can I do?
thanks to all the programmers who have helped me.
|
|
|
|