[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 720
  • Last Modified:

New button in CPrintDialog

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
tko092397
Asked:
tko092397
  • 10
  • 5
1 Solution
 
tko092397Author Commented:
Edited text of question
0
 
ppeckCommented:
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
 
ppeckCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
tko092397Author Commented:
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
 
tko092397Author Commented:
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
 
tko092397Author Commented:
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
 
tko092397Author Commented:
I think

m_pd.hInstance = ???

must be the mother, i.e., the print dialog.
0
 
tko092397Author Commented:
Pleez, help me! I cant figure it out.

I am stucked with it...
0
 
ppeckCommented:
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
 
tko092397Author Commented:
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
 
tko092397Author Commented:
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
 
ppeckCommented:
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
 
tko092397Author Commented:
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
 
tko092397Author Commented:
Dear Patrik,

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

Tomas
0
 
ppeckCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 10
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now