|
But using Win 8 for development.
|
|
|
|
|
You are right. I missed that.
|
|
|
|
|
That's OK, I missed the XP bit. 
|
|
|
|
|
|
Bram van Kampen wrote: The XPS File I got was,in Binary. As you would expect, since it also includes formatting information about the content. I have used this to test printing in my applications, and never had a problem. I guess you need to look at your actual printing code.
|
|
|
|
|
Well,
The Binary I get refuses to open.
Here is my Printing Code:-
void CConfirmOrdersStep1Dlg::OnPrint()
{
if(CreateViewForPrinting()==false){
AfxMessageBox("No Orders have been Marked for Printing");
return;
}
CDC dc;
CPrintDialog printDlg(FALSE);
<pre>
if (printDlg.DoModal() == IDCANCEL) return;
dc.Attach(printDlg.GetPrinterDC()); dc.m_bPrinting = TRUE;
CString strTitle="Old Orders";
// strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);
DOCINFO di;
memset(&di, 0,sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;
BOOL bPrintingOK = dc.StartDoc(&di);
CPrintInfo Info;
Info.m_rectDraw.SetRect(0,0,
dc.GetDeviceCaps(HORZRES),
dc.GetDeviceCaps(VERTRES));
OnBeginPrinting(&dc, &Info);
UINT page;
for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
dc.StartPage();
Info.m_nCurPage = page;
PrintPage(&dc, &Info);
bPrintingOK = (dc.EndPage() > 0);
}
OnEndPrinting(&dc, &Info);
if (bPrintingOK)
dc.EndDoc();
else
dc.AbortDoc();
dc.DeleteDC();
}
// As from Chris Mauder.
// Instead of Global I made it a member
//
// m_pView (Type COrderPageView) contains a list of PageFragments
// The Fragment at index 0 is the header, to be printed at the Top
// of each Page (Customer Details, etc)
// CondensePages() does Nothing for Now.
//
// Anyways, This Works, as I can successfully print the Page to a Text
// File.
void CConfirmOrdersStep1Dlg::OnBeginPrinting(CDC * pDC, CPrintInfo * pInfo)
{
// Set the Font to "CourierNew"
CFont PrinterFont;
if(!PrinterFont.CreatePointFont(
100,
"Courier New",
pDC)){
ASSERT(NULL);
return;
}
CSize Size=pDC->GetTextExtent("AAAA",4);
m_nCurrentPrintRectWidth=Size.cx*10;
m_nCurrentLineHeight=Size.cy;
int PageHeight=pInfo->m_rectDraw.Height();
m_nLinesPerPage=PageHeight/m_nCurrentLineHeight;
m_pView->CondensePages(m_nLinesPerPage);
}
/////////////////////////////////////////////////////////////////
//
// This is where we print, First the Header, and thereafter the Page Content
void CConfirmOrdersStep1Dlg::PrintPage(CDC * pDC, CPrintInfo * pInfo)
{
int PageNumber=pInfo->m_nCurPage;
m_nCurrentPrintRectTop=0;
COrderPageView* pView=(COrderPageView*)m_pView->GetDataFromIndex(0);
PrintDocFragment(pView,pDC);
COrderPageView* pOrder=(COrderPageView*)m_pView->GetDataFromIndex(PageNumber);
PrintDocFragment(pOrder,pDC);
}
void CConfirmOrdersStep1Dlg::OnEndPrinting(CDC * pDC, CPrintInfo * pInfo)
{
}
// We Create a List of Set of lists of 40 char wide strings
// The First Item in this List is the Header, specifying the
// Customer Details
// The remaining items contain Order Details for the Same Customer
// This Part Works, As is shown by 'DumpToTextFile()'
bool CConfirmOrdersStep1Dlg::CreateViewForPrinting()
{
delete m_pView;
m_pView=new COrderPageList();
int i;
int ItemCount=0;
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)="=1)ItemCount++;
" }
="" if(itemcount="=0)return" false;
="" tag_str_customer*="" pcust="m_pNode-">pCustomer;
COrderPageView* pPageHeader=new COrderPageView(NULL,40);
pPageHeader->m_pCustomer=m_pNode->pCustomer;
pPageHeader->PrintPageHeader();
m_pView->AddReference(pPageHeader);
for(i=0;i<m_clist.getcount();i++){
if(m_clist.getcheck(i)!="1)continue;
" int="" index="((int)m_cList.GetItemData(i))-BIAS;
" lpstr_order="" po="(LPSTR_ORDER)m_pOrderList-">GetDataFromIndex(Index);
COrderPageView* pPageView=new COrderPageView(pO,40);
pPageView->PrintOrderBody();
m_pView->AddReference(pPageView);
}
ifdef _DEBUG
m_pView->DumpToTextFile();
endif
return true;
}
///////////////////////////////////////////////////////////////////////////////
//
// THIS IS WHERE THE RUBBER MEETS THE ROAD!
//
// We Are Committing a Set of Lines of Text in an Incrementing
// List of adjusting Rectangles.
int CConfirmOrdersStep1Dlg::PrintDocFragment(COrderPageView * pView, CDC * pDC)
{
ASSERT(pView);
ASSERT(pDC);
int i;
for(i=0;i<pview->GetItemCount();i++){
RECT DrawingRect;
DrawingRect.left=0;
DrawingRect.top=m_nCurrentPrintRectTop;
m_nCurrentPrintRectTop+=m_nCurrentLineHeight;
DrawingRect.right=m_nCurrentPrintRectWidth;
DrawingRect.bottom=m_nCurrentPrintRectTop-1;
LPCSTR DrawingText=(LPCSTR)pView->GetDataFromIndex(i);
pDC->DrawText(DrawingText,-1,&DrawingRect,DT_LEFT);
}
return i;
}
Getting Desparate at this stage. I Guess I am doing something trivial wrong.
Thanks + Regards,
Bram van Kampen
|
|
|
|
|
Well I just Notice, I forgot to Select the Font into the Printer Device Context.
That would of course have an impact!
Can anyone spot other errors?
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: The Binary I get refuses to open. Not sure what that means, or what is missing. If you do not select the font into the DC then it will just use a default, so you should still see some output. Given that this is Chris's original code, you may want to try talking to him.
|
|
|
|
|
Wel,
I get a Binary File not recognised by the XPS Reader.
I can open it as Binary in a HexVieuwer, and get nothing recognisable.
Bram van Kampen
|
|
|
|
|
When I look at an XPS print file it looks something like:
PK µC'I Metadata/Job_PT.xmlíW]s¢H}ߪý)Þ' &Ùh%NÝ4ZÁØ }Cè`|
´¢óë÷¶ã̬‰™™§éòš{Îážþ¸póqGgK–<Mn•ʹ¦œ±ÄOž„·Š3l¸V>6ÿþë&+žƒœ'bÈý9gKŠöÞ*3!²†ªþŒÅ^qs?O‹ôIœûi¬–< Ò²P«šVSµk5"H¾=Øbžr/fešÏ•íªà{Ú²,ÏËÚyš‡’£¢>š÷öõ'…🽠‚·QÊA²ÏÀ¤Ð°žÈ•ŠŸÿJdÎÖ˜FP¨{è*
which is fine, and the XPS reader opens it OK.
As to why you cannot read yours is a total mystery. If you are using all the standard APIs (or their MFC equivalents) to create your print files, then they should at least be readable.
Try changing the extension from .xps to .zip and have a look at the content then.
|
|
|
|
|
Hi, Richard,
Well, if it opens in your machine , there is evidently something wrong with my reader, and nothing wrong with the code I wrote to generate same.
I'm away on a break for a few days. I had my 62nd Birthday 3 weeks ago, but, were unable to escape. We are trying enjoy life in semi retirement, with a small important money spinning business running in the background, powered by my software.
I appreciate your comment, and will try changing the XPS ext to ZIP when I'm back.
I Think that you know that I write software for Laundrettes and Dry-Cleaners, specifically for our own chain.
There are No Trade or Other secrets buried in the Text Example I Sent. It is a Fictitious Customer with a Fictitious ancient Order. (The Bane of a laundrette is people not coming back to pay and collect, It Clogs up the shop, the work is done, but, the Till does not ring. )
The Program I am writing now, is a concerted attempt to attack this, by contacting customers. The First step there is, to ensure that ancient Orders that appear on the database, are still present in the shop. Whereas we Trust our staff, an order could have been given out, without the order being rang in, the staff pocketing the sale, and the Item remaining on the Database. At any rate, we do not want to contact customers over long forgotten items, when we no longer poses them, for whatever reason.
It also gives staff an other activity at quiet Times. Instead of drinking cups of tea, they have a Screen of alternative, and More Productive activity. Making Phone Calls, and finding People's goods. If people's goods can not be found, then there is no point in ringing the customer. Let sleeping dogs lie, and Management writes the item off. We tried it manually, and got things like "Oh I forgot about that, I will collect it next Saturday" Saturday came and went, we all forgot, order still here. This new program will pursue only say 10 old orders at the time, but these orders will be pursued vigorously.
Items Promised to be Collected By a date, will disappear of the ToDo List, but, will re-appear there after that date, if at that stage not collected and paid.
The Interface is being designed so that Junior Staff can handle it, kicking major decisions back upstairs. The Document I tried to print was a form, for staff to go around the shop, and find the goods. The First Step.
When you Opened the XPS File, could you read the Text as Follows:-
Finding Old Orders in the Shop
Printed by <????> on 01 09 16 - 23:40:14
Customer:-
TONY LOUGHLIN
If The Item(s) are Found you should
Update the Computer Record, and
Destroy this Page!
Otherwise Inform Management of the
Discrepancies, by Returning this Page
Marked Up Accordingly!
Order Nr 214058
Received on: 27/07/12 - 13:18:21
Not Confirmed Present since Completion
Qty Description Amount
1 lb Wash +Dry £11.00
========
Total For Order £11.00
Due for This Order £11.00
Packaging:- -1Wb
========================================
<pre>
Actually Found:-
Hangers Pastics Flatpacks WashBags
+-+ +-+ +-+ +-+
| | | | | | | |
| | | | | | | |
| | | | | | | |
+-+ +-+ +-+ +-+
========================================
Please let me know If you Did.
It means in that case: "Programming Problem Solved"
Thanks and Regards,
Bram van Kampen
|
|
|
|
|
Hi Bram, well I'm a few years older than you, so in theory I should have more knowledge locked in my brain. But you know what they say about theory and practice.
When I said I could open the XPS file, I meant one that I generated here. If you can send me the one you generate I could have a look at it for you. Send me a private email and I can give you an address, or put it up on one of the public staging sites.
|
|
|
|
|
I am not sure that you should be calling CView::OnBeginPrinting[^] in your code. That function will be called by the framework when printing is initiated.
|
|
|
|
|
I have a custom rotary slider control inheriting from CSliderCtrl. Its own behaviour is fine, it displays as I want, responds to mouse dragging and rotates just as it should. Then I want to interact with it from its parent dialog and the problems start.
I had imagined that I would just have to trap the ON_VSCROLL message to obtain its value as it changes. (It is set up with Orientation: Vertical though I have tried Horizontal too.) I can't trap ON_VSCROLL or ON_HSCROLL with either setting. I have tried catching NM_RELEASEDCAPTURE and can't get that either. I have:
BEGIN_MESSAGE_MAP(CNewPatchDlg, CDialog)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_VOLUME, OnReleasedCapture)
END_MESSAGE_MAP()
in my dialog message map and
void CNewPatchDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
void CNewPatchDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
void CGm36NewPatchDlg::OnReleasedCapture(NMHDR* pNMHDR, LRESULT* pResult)
declared and defined in my dialog .h and .cpp files. They exist as temporary function stubs with a little junk code in there to just see whether I can hit breakpoints in the functions. None get hit.
In the dialog editor the wizard shows only four control events available for the control, NM_CUSTOMDRAW, NM_OUTOFMEMORY, NM_RELEASEDCAPTURE, NM_THEMECHANGED. I expected to see more than that! I would have thought at least I could have accessed ON_VSCROLL via the wizard though a standard CSliderCtrl shows the same four options.
I know sometimes these controls can be a little eccentric but I thought this would be pretty plain sailing. I've dug around and found a couple of suggestions that I'm not the only person to have this issue with a Custom slider but no one seems to have a solution, only to use ON_HSCROLL or ON_VSCROLL which I can't seem to do. This must be something very simple I am seeing wrong. Can anyone suggest what I am missing?
|
|
|
|
|
|
I found that Richard, MSDN is the first thing I go to. There is a wealth of stuff with examples (that actually are only part complete) in there. None of it seems to work!
From your link:
Quote: A slider control notifies its parent window of user actions by sending the parent WM_HSCROLL or WM_VSCROLL messages, depending on the orientation of the slider control. To handle these messages, add handlers for the WM_HSCROLL and WM_VSCROLL messages to the parent window. The OnHScroll and OnVScroll member functions will be passed a notification code, the position of the slider, and a pointer to the CSliderCtrl object.
It just seems to back up everything I have done so far. I am trying unsuccessfully to catch the ON_HSCROLL and ON_VSCROLL messages in the parent wiondow just as MS says. I know I can parse out the info once I have caught the message, it's getting the message to land that I can't do even though I seem to be doing exactly what they say.
|
|
|
|
|
AlbertB wrote: MSDN is the first thing I go to Unfortunately so many of our posters do not.
Looking at CDialog, it does not look like it implements the OnXScroll methods, so one wonders whether it just ignores scroll messages. I'm not sure quite how to get round that (years since I did MFC), but in Win32 I would probably subclass the Dialog control and use my own message handler.
|
|
|
|
|
I seem to have at least found a way of doing what I want, even though it does not explain to me what I am really doing wrong here. I have defined a custom message and can send this on to the dialog from within the custom slider at an opportune point. I pass the ID and the value I want as its parameters. I can then catch the custom message in my dialog message handler just as I should be able to and process it from there.
I would still like to know why I can't get to grips with the ON_VSCROLL way of doing this as every link I find tells me I should be able to do this as the standard method. I take your point that CDialog doesn't seem to support OnXScroll, but it's a mystery as to why everyone seems to tell you that is the way to do it. Thanks for your time and efforts Richard, even though we still seem to have only half a picture it's greatly appreciated.
|
|
|
|
|
Interesting,
Can you give us fragments of the Code that resolved it, so that we all may learn?
Regards,
Bram van Kampen
|
|
|
|
|
In stdafx.h:
#define IDM_SLIDER_CHANGE WM_USER+8
In the derived CRotarySlider class at a relevant point in my positioning calculation:
int iID = ::GetDlgCtrlID(::GetFocus());
GetParent()->SendMessage(IDM_SLIDER_CHANGE, iID, nPos);
In the Dialog class that the control is used in:
Added to the message map:
ON_MESSAGE(IDM_SLIDER_CHANGE, OnSliderChange)
And handler function:
LRESULT CGm36NewPatchDlg::OnSliderChange(WPARAM wParam, LPARAM lParam)
{
switch (wParam)
{
case IDC_VOLUME:
{
break;
}
case IDC_GAIN:
{
break;
}
}
LRESULT lr = 0;
return lr;
}
There are still aspects to tidy up which may not be best coding practice but that works at the moment.
|
|
|
|
|
As you are getting right down and dirty and away from the MFC framework there are more possibilities inside the Win32 API.
If you look at the WM_PARENTNOTIFY message
WM_PARENTNOTIFY message (Windows)[^]
If you are compiling for windows > VISTA you can actually stop the message going to the dialog at all and directly handle it within the slider using the extended flag WS_EX_NOPARENTNOTIFY style. Useful for making owner draw (skinned) sliders.
It isn't clear to me if you are trying to get the slider to change something directly on it's control (owner draw skin) or if you are changing something in the dialog viewport so it may or may not be useful depending what you are doing.
I know for example that WinTweaks has its thumb part of it's scrollbar animated, I used to love the flame one
A basic example of owner draw in MFC is on the site and it isn't simple (How to skin CListCtrl including scrollbars and column headers[^])
In vino veritas
modified 29-Aug-16 5:20am.
|
|
|
|
|
Thanks Leon that's great advice. What I'm actually doing is to replace the linear slider appearance with a custom rotary knob within my CRotarySlider class (inheriting from CSliderCtrl and based on simple bitmaps for the background, knob and marker dot). As usual, the user grabs and drags to reposition the knob. That part works absolutely fine. I then needed to handle the change of knob position in the dialog class so was trying to catch the VSCROLL, which as you know I can't seem to do.
As I now have it, the calculations to do with conversion from mouse position to control value are taken care of in the CRotarySlider class itself and the finalised control value needs to be passed out to the Dialog class. As I said I have managed to do this with a custom message.
I have used the basic DDX setup in the past but it was so long ago I couldn't accurately remember the ins and outs of it but it does occur to me that I may be missing something glaringly obvious in that direction.
I'll certainly look into your suggestions, thanks for the heads up, they are greatly appreciated.
|
|
|
|
|
Okay so the thing you are trying to make is a Radial Control or sometimes called a radial gauge (although gauge tends to imply display only)
Can't you just push out the messages as standard scrollbar messages using PostMessage with the handle being your parent window. I mean in standard native Win32 I would do this if I wanted to FAKE a WM_VSCROLL or WM_HSCROLL lets assume your dial is handle is hwnd and a position pos.
HWND myParent = GetParent(hwnd);
PostMessage(myParent, WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, pos), (LPARAM)hwnd);
As we are faking it I wouldn't use SendMessage as it might go re-entrant (you post off to the dialog and it posts back and around in circles it would go).
I can't see how MFC could get that wrong as there message pump is still using PeekMessage from the standard windows queue.
In vino veritas
|
|
|
|
|
I'd use spy and verify the window hierarchy is as you expect. Perhaps the dialog is not a direct parent of the slider.
Steve
|
|
|
|
|
Agree with Steve.
I use VS98 with MFC42, which is badly documented on advance features. However, it gets me trough most issues. Spy can show you which function dumps your message into the 'BitBin' underneath your Desk.
You are apparently of a generation that is un-aware of the Windows SDK.
In the SDK, messages were handled in the Actual Window Procedure, or, bounced to the Parent or Child Window Procedure.
This was reflected in that Unhandled Messages were referred to the 'DefaultWndProc(...)'
That Parent-Child relation is Similar To, but Incompatible with, the CPP Inheritance Model.
MFC Simplifies all this with thin but, powerful wrappers.
These Wrappers do as much of the hard work, as can be expected.
Now, when things go wrong, VS98 was provided with Powerful Tools.'Spy' is just One of them. Do Not forget, At One stage these compilers and Tools were used by Microsoft to develop code for the various Windows Versions.
In order to use MFC correctly, I suggest reading books about the Windows SDK.
Regards, and Success,
Bram van Kampen
|
|
|
|
|