Solved

New button in CPrintDialog

Posted on 1998-07-28
15
676 Views
Last Modified: 2013-11-20
Dear someone!

The problem is simple: Set an extra button on default print dialog window.
It works for CFileDialog, but I cant get it to work with CPrintDialog.
I have created a resource named IDD_DIALOG1 with only the extra button
on it. Please help me. I have tryed every possible way I can think of.
Sorry for including a lot of code, but there is the problem.

One possible solution could be:
m_pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);
In the document, for CFileDialog, you may use MAKEINTRESOURCE, but
it is not mentioned for CPrintDialog.
As it is now, no dialog appears. If taking avay PD_ENABLEPRINTTEMPLATE
from the flags, the print dialog appears.

I tryed with CColorDialog, and than my IDD_DIALOG1 object appeared in the
main window area! And the color dialog dont appeared.

Tomas

//hello.cpp
#include <afxwin.h>
#include <afxext.h>
#include "resource.h"

class CHelloApp : public CWinApp
{
public:            
  virtual BOOL InitInstance();
};

// Create an instance of the application class
CHelloApp HelloApp;

// Declare the main window class
class CHelloWindow : public CFrameWnd
{            
  CStatic* cs;
public:            
  CHelloWindow();
  afx_msg void OnLButtonUp(UINT,CPoint);
  DECLARE_MESSAGE_MAP()
};



class CSpecialFileDialog : public CPrintDialog
{
public:
      CSpecialFileDialog(BOOL bPrintSetupOnly,
                 DWORD dwFlags,
                 CWnd* pParentWnd);

      enum { IDD = IDD_DIALOG1 };
};


BEGIN_MESSAGE_MAP(CHelloWindow, CFrameWnd)
   ON_WM_LBUTTONUP()
END_MESSAGE_MAP()


CSpecialFileDialog::CSpecialFileDialog(BOOL bPrintSetupOnly,
                                       DWORD dwFlags,
                                                         CWnd* pParentWnd)
      : CPrintDialog(bPrintSetupOnly, dwFlags, pParentWnd)
{
      //m_pd.Flags |= PD_DISABLEPRINTTOFILE | PD_ENABLEPRINTTEMPLATE;
      m_pd.Flags |= PD_DISABLEPRINTTOFILE;
    m_pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);
}


BOOL CHelloApp::InitInstance()
{            
  m_pMainWnd = new CHelloWindow();            
  m_pMainWnd->ShowWindow(m_nCmdShow);            
  m_pMainWnd->UpdateWindow();            
  return TRUE;
}

void CHelloWindow::OnLButtonUp(UINT nFlags, CPoint point)
{
    CSpecialFileDialog dlgFile(FALSE, NULL, NULL);
    int nModal = dlgFile.DoModal();
}


CHelloWindow::CHelloWindow()
{                  
  Create(NULL, "Hello World!", WS_OVERLAPPEDWINDOW, CRect(0,0,800,800));            
}
0
Comment
Question by:tko092397
  • 10
  • 5
15 Comments
 

Author Comment

by:tko092397
ID: 1319822
Edited text of question
0
 
LVL 1

Expert Comment

by:ppeck
ID: 1319823
tko,

It is not enough to import the print dialog from prnsetup.dlg
(which I think you did). You also have to copy the resource ids
from dlgs.h to your resource.h file:

#define ctlFirst                        0x0400
#define psh1                            0x0400
#define psh2                            0x0401
#define psh3                            0x0402
#define psh4                            0x0403
#define psh5                            0x0404
#define psh6                            0x0405
#define psh7                            0x0406
#define psh8                            0x0407
#define psh9                            0x0408
#define psh10                           0x0409
#define psh11                           0x040a
#define psh12                           0x040b
#define psh13                           0x040c
#define psh14                           0x040d
#define psh15                           0x040e
#define psh16                           0x040f
#define chx1                            0x0410
#define chx2                            0x0411
#define chx3                            0x0412
#define chx4                            0x0413
#define chx5                            0x0414
#define chx6                            0x0415
.

If this does not help, post the result of 'CommDlgExtendedError()'
(which you call immediately after DoModal()).

Patrick

0
 
LVL 1

Expert Comment

by:ppeck
ID: 1319824
Sorry, from the above it is not clear what resource ids have to be included.
But if you include all the ids between 0x0400 (ctlFirst) and 0x04ff (ctlLast) you
should be on the safe side :-)

Patrick

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:tko092397
ID: 1319825
Helo!

I tryed #include <dlgs.h> both in resource.h and in my main program, but no difference.
I also tryed to copy the dlgs.h texts into resource.h but no difference.
The result of CommDlgExtendedError is the number 4
In my private dialog, that I want to merge with print dialog, there is nothing! I toke away
the button, so there is only a big gray area.

 If I define the following:
m_pd.hInstance = AfxGetInstanceHandle();

then I get my dialog ( a big gray rectangle area ) to appear in my main window, and
wherewver I click with mouse it pingles. I must kill the process to quit the program.

It seems that I must set hInstance to point to my app..??

Please help.

Tomas

0
 

Author Comment

by:tko092397
ID: 1319826
My dialog resource:

Style: child
Border: none
Clip sliblings
Visible

If I change these to POPUP and DIALOGFRAME, then my dialog appears as a
real dialog, not inbedded in my main window. So, the problem is to merge my
bialog with print dialog.
0
 

Author Comment

by:tko092397
ID: 1319827
I think my dialog must be set to child! Then, it's mother must be the print dialog!
Thats it! But how can I set my dialog's mother to be the print dialog?
0
 

Author Comment

by:tko092397
ID: 1319828
I think

m_pd.hInstance = ???

must be the mother, i.e., the print dialog.
0
 

Author Comment

by:tko092397
ID: 1319829
Pleez, help me! I cant figure it out.

I am stucked with it...
0
 
LVL 1

Expert Comment

by:ppeck
ID: 1319830
Tomas,

have you imported the print dialog resource from prnsetup.dlg ?
Having done this, you can edit the print dialog in the resource
editor and add your custom buttons there. There is - at least to
my knowledge - no way of extending the print dialog by another
dialog.

So, the three steps are:
1) add the print dialog resource 'PRINTDLGORD' from prnsetup.dlg to resource.h
2) add the print dialog control ids from dlgs.h to resource.h
3) customize the print dialog using the resource editor
4) in your program, set the m_pd.flags and m_pd.hInstance members

Good luck,

Patrick

0
 

Author Comment

by:tko092397
ID: 1319831
Helo again,

What is the difference between CFileDialog and CPrintDialog? The program included
above works with CFileDialog.

I dont think it is possible to include the print dialog so that you can edit it. Either way,
I dont succeed to edit it in resource editor.

Sorry, I reopen it. Please write a mail to me if I am wrong.  tko@kcs.se

My files in FileView are:

hehe.cpp
resource.h
Script1.rc

Here follows my resource.h  :

==============================================
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Script1.rc
//
#define PRINTDLGORD                     1538


#define IDD_DIALOG1                     101

// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif

0
 

Author Comment

by:tko092397
ID: 1319832
Here is the minimal program that should work...   :(

//hello.cpp
#include <afxwin.h>
#include <afxext.h>
#include <dlgs.h>
#include "resource.h"

class CHelloApp : public CWinApp
{
public:            
  virtual BOOL InitInstance();
};

// Create an instance of the application class
CHelloApp HelloApp;

// Declare the main window class
class CHelloWindow : public CFrameWnd
{            
  CStatic* cs;
public:            
  CHelloWindow();
  afx_msg void OnLButtonUp(UINT,CPoint);
  DECLARE_MESSAGE_MAP()
};


BEGIN_MESSAGE_MAP(CHelloWindow, CFrameWnd)
   ON_WM_LBUTTONUP()
END_MESSAGE_MAP()


BOOL CHelloApp::InitInstance()
{            
  m_pMainWnd = new CHelloWindow();            
  m_pMainWnd->ShowWindow(m_nCmdShow);            
  m_pMainWnd->UpdateWindow();            
  return TRUE;
}

void CHelloWindow::OnLButtonUp(UINT nFlags, CPoint point)
{
    CPrintDialog* pp = new CPrintDialog(FALSE, NULL, NULL);
      pp->m_pd.hInstance = AfxGetInstanceHandle();
      pp->m_pd.Flags |= PD_DISABLEPRINTTOFILE | PD_ENABLEPRINTTEMPLATE;
      pp->m_pd.lpPrintTemplateName = MAKEINTRESOURCE(IDD_DIALOG1);
      //pp->m_pd.hwndOwner = NULL;
      pp->DoModal();
}


CHelloWindow::CHelloWindow()
{                  
  Create(NULL, "Hello World!", WS_OVERLAPPEDWINDOW, CRect(0,0,800,800));            
}

0
 
LVL 1

Expert Comment

by:ppeck
ID: 1319833
Tomas,

I'm sorry, it was my fault (I wrote that comment before going to sleep :-) )

In step 1, you have to add the print dialog resource to your .rc file, of course, not
to the resource.h file. Then you should be able to edit it in the resource editor.
Steps 2-4 remain unchanged.

Again: I know of no other way of extending the print dialog, and the solution I
suggested works (tried & tested).

Good luck,

Patrick

0
 

Author Comment

by:tko092397
ID: 1319834
Helo!

Thanks for the correction. I belive you, that it can be done only that way.
Now, the final problem is, how can I put the print dialog recource 'PRINTDLGORD'
into my .rc file ? Should I put the following line into .rc file  ??
#define PRINTDLGORD           xxxx
If so, where? I dont thin it is so simple to do that. So, how do you done that?
Do you use some Studio function to do that, "to edit the .rc file" ?

Thanks for your kind helping...  :)


Tomas

===============

My .rc file  :


//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32

/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 418, 283
STYLE WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS
FONT 8, "MS Sans Serif"
BEGIN
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
    IDD_DIALOG1, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 411
        TOPMARGIN, 7
        BOTTOMMARGIN, 276
    END
END
#endif    // APSTUDIO_INVOKED


#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE
BEGIN
    "resource.h\0"
END

2 TEXTINCLUDE DISCARDABLE
BEGIN
    "#include ""afxres.h""\r\n"
    "\0"
END

3 TEXTINCLUDE DISCARDABLE
BEGIN
    "\r\n"
    "\0"
END

#endif    // APSTUDIO_INVOKED

#endif    // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


0
 

Author Comment

by:tko092397
ID: 1319835
Dear Patrik,

Finally, I succeded to be able to edit the print dialog in resource editor.
Thanks for your help!

Tomas
0
 
LVL 1

Accepted Solution

by:
ppeck earned 100 total points
ID: 1319836
Tomas,

I'm happy you succeeded at last. If you think I have now answered
your question, please grade this dummy answer.

Thank you,

Patrick

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question