Implementing my own print preview? - c++

I have developed my own Report Control which is simply nothing but drawing text on a CDC of the control window's client DC. I have got the printing function to work too. The report output is sent to the printer directly. However I want to let the user know the output before the report is actually printed.
I cannot do this using MFC's print preview architecture as my project is not using the doc/view architecture. Is it possible for me to create a print preview window myself ? How does MFC handle this ? Are there any special processing need to be done or keep in mind when showing the printer output on screen ? I've read that MFC used 2 DCs for print preview purposes. Do I need to do this as well if Im goin for a custom print preview ?
Your input is highly appreciated !
tia.
P.S. i use Visual Studio 6 and there is no option to change this to a newer version just as there is no way for me to add doc/view support.

Print preview isn't that special. It just means that you have to render to screen (or bitmap) what you'd otherwise would render to the printer DC. This primarly means using the page size, and providing a UI control for the prev/next page.

I had tweeked this code in order to compile it as static lib. It is for dialog based applications.If you don't need special functionality it will work ok for you.
I had to dig through MFC mechanisms to add extra functionality but at the end I dropped it. If you know other programming languages, try to find a print preview control in that language, make it a dll and use it from your MFC application.
For example, I found the NicePreview control for Delphi and it worked, for me, beautifully !

if you managed to print your output to a file in an RTF format and displayed it on screen would this solve the problem?

There is a class CPreviewView in MFC. Maybe you can find a way to instantiate it without MDI structure.
Otherwise, you can simply paint on screen whatever you are painting on the printer DC. Just remember that you will probably need to scale it down for lower dpi.

Related

Why is my listbox not resizing? (Dynamically resizing dialog components)

My app is Win32; I'm using VS 2015. I have a dialog box that contains a listbox. I set the listbox to be dynamically resized, but it does not change when the dialog is resized.
Here are the listbox' attributes:
The listbox is owner-drawn:
This is the default size of the dialog:
This is what the dialog looks like when I stretch in Test mode in the Resource Workshop Dialog Editor. Notice the inside listbox expands too, exactly as hoped:
However, when it's actually running, stretching the dialog does not increase the size of the listbox:
Why is this not working? Is there some additional voodoo I have to invoke to get it to actually work? Does this only work in MFC? What is the Win32 equivalent of CWnd::ExecuteDlgInit?
Note: I have already looked at https://msdn.microsoft.com/en-us/library/mt270148.aspx and http://mariusbancila.ro/blog/2015/07/27/dynamic-dialog-layout-for-mfc-in-visual-c-2015/, wherein I did not find an answer.
Does this only work in MFC?
Indeed, this only works when using MFC1.
What is the Win32 equivalent of CWnd::ExecuteDlgInit?
MFC is a library built on top of the Windows API. The windowing system in the Windows API does not provide any sort of layout management. If you want to see the Windows API equivalent, it's literally what is implemented in MFC.
So, why is this supported in the graphical resource editor then? Because that is where the layout information is generated. It's ultimately placed into a custom resource of type AFX_DIALOG_LAYOUT, where MFC picks it up to do its magic. If you aren't using MFC, that resource is simply ignored.
That's not to say that - in theory - you wouldn't be able to implement your own solution that reads the generated resource. As long as you can find documentation for the custom resource used by MFC. I didn't, but a look into the MFC source revealed, that it's pretty simple (a version WORD, followed by pairs of WORDs for horizontal and vertical move and size settings).
1 Or a library that understands the implementation details, such as the WTL.
This functionality is also supported in Windows Template Library!
https://sourceforge.net/p/wtl/git/ci/master/tree/Include/atlframe.h
If you have a look at the CDynamicDialogLayout class you can see how it works, and if you are using WTL you can even use the functionality yourself.
For the record, I was looking for the solution to this as well, when I resized a control on my dialog all of the dynamic resizing stopped working, although it worked fine in the Test Mode.
To fix it, in the the second link you posted there's a section on adding a function:
void CMFCDynLayoutDemoDlg::SetupDynamicLayout()
Where you re-setup the Dynamic Layout manager
Once I did this, it started working in the live version for me.
Very similar answer is in this post too:
Recalculate dynamic layout properties

Trying to write a c++ console program to change a setting controlled by a windows checkbox

Is it possible to create a keyboard shortcut to switch between the monitor and portion selection of this wacom preferences window, via a c++ console program?
Sorry if this is poorly worded, I've had trouble trying to find the right words to search for ways to do it.
I think it should be possible, although a bit tedious. You should be able to use the Windows API, and try to EnumWindows/EnumDesktopWindows to identify the respective application Window, and its respective controls (which are also Windows).
You should identify the window title, and class ids, for the app window, and the checkbox button controls, then when you enumerate through all the desktop windows, you can identify the ones you are interested in.
Then you can use the SendMessage() API to send messages to the controls (Windows) of interest to manipulate them.
It's a bit tedious, but sounds possible.
An example of use here to get an idea:
http://www.cplusplus.com/forum/windows/25280/

Is it possible to embed a command prompt in a win32 app?

In linux and when installing packages etc. There are some installers that have a progress bar and a dos window which shows the files being extracted etc. How can i add this window to my C++ Win32 programs so that i can have it showing the tasks im doing? I cannot find any documentation on MSDN.
Question: How can i add a console window (if that's what its called, sure looks like one) in my program to show the details of the task at hand being done?
Here is a window with what i am asking.. (personal info so I erased the details. :]
You cannot embed a real console window inside another window (although a windowed process can have a separate console window). While it looks like a console window / command prompt, it is just a matter of appearances. What you want to do is create a sub-window/control with similar characteristics as a console window and then redirect the console output from the application(s) being run to append to that sub-window. For more information on how to do redirect the console output in Windows, see http://support.microsoft.com/kb/190351.
That "dos window" is a regular edit control: CreateWindow(ES_MULTILINE, EDIT, ...
However, it has the font set to a fixed-width one (Looks like courier). This is done by sending WM_SETFONT to the edit control.
#user995048 says "You cannot embed a real console window inside another window". But "cannot" is a strong word! I can run an entire virtualized computer in a window if I wish. :) So one can quite reasonably intuit that there are ways of doing what you say.
Sure, it is true that what you've seen are almost certainly cases of output redirection into a custom widget, designed to mimic the simple appearance of a terminal. However...if you want to embed one application's window inside another, there are things you can look into which might fit. Cooperative methods exist like GtkPlug, for instance:
http://developer.gnome.org/gtk/2.24/GtkPlug.html
To actually capture a not-designed-to-cooperate app's window and throw it in your app would be trickier. But possible, just as screen captures and virtual machines are possible. Probably best to avoid that sort of thing unless there's really a cause for it, though...
Try this
http://www.codeguru.com/cpp/misc/misc/article.php/c277/
link. I think the solution provided is what you need.
I tried it many years ago and it worked. I have not tried it in newer versions of windows though.

Get text from a windowsless control

I was wondering how can I read text of a control that doesn't have an HWND. For instance, the print dialog in office 2007 doesn't have HWND on all of its controls (only a few).
Is there anyway to get the text from these controls?
I believe they're simply drawn on the window and react using HITTEST, but I'm not sure, so I'm asking you guys :-).
Thanks for your help!
Generally, there is no guaranteed way to do that. However, chances are you can get the text (and other info about the controls) using the IAccessible interface. Most Microsoft products implement this interface on most of the UI elements: this is how screen readers for disabled people work
For a generic windowless control, all you can assume is that the text exists only as pixels on the screen, so the only way to read it is with OCR.
If you can learn more information about the specific controls you want to inspect, then you might learn that the windowless control has a parent window that handles messages on its behalf, or that the control has a COM object you can manipulate, or that the control honors the Windows accessibility API. If you don't know anything else about the control, then all you have are the pixels.

MFC maximize window feature

I have tried to make the fullscreen feature of a SDI application with splitter windows by following the forum link. However, my status bar, system menu as well as the title bar of the application have disappeared. Do you have any suggestions on any easy ways of getting these back (or if I have to use different method of making the application maximized during startup instead of fullscreen)? Thanks in advance.
I got rid of any manipulations on the cs structure in the PreCreateWindow handler and used a ShowWindow(SW_MAXIMIZE) function call in the OnCreate function implementation of my MainFrame function, and it works quite well.
It sounds like you just want the window to be maximized. Take a look at the SetWindowPlacement function or ShowWindow.