CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    2

    How can i print a tab page?

    In my visual studio c++ application (Windows form application) there is one tab control with 3 tab pages.

    I want to press a button and to print the first tab page if i am in the 1st tab page, the second if i am in the 2nd tab page and the third tab page if i am in the 3rd page.

    How can i print the entire application screen?

    Thank you, for your help!

  2. #2
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Smile Re: How can i print a tab page?

    Hi, i couldnt exactly understood your requirement... whether it is to print from an Edit or likewise control in the Tab... or Print the Entire Tab window...

    Anyway, i hardly believes that you need to do my second assumption.. to print the Whole Tab window(Window region)...

    If you want to print Just the text or drawings in some controls, you may go for MSDN Doumentation of PrintDlg() or PrintDlgEx() API's,.. there is a pretty good example code also shown in the MSDN page... Also, look for StartDoc() and EndDoc() API's...


    if, you need to print the Entire window..., i think its not Directly posssible... or no API's available to directly to do it...

    Instead, you can try something... I've done this with a Treecontrol some time before and suceeded....

    First, get the printer DC from PrintDlg() API... Nextly get teh client rctangle of your Tab window (m_TabWin)

    Code:
    RECT rc;
    	GetClientRect(m_TabWin,&rc);//for eg: i used m_TabWin
    Nextly, get the rectangular Bounds of you Tabbed WIndow region with RECT Structure... and get the DC of your Window(Tabbed) with GetDC() API..

    now create a DC and Bitmap in memory...

    Code:
    HDC hMemDC = CreateCompatibleDC( hDC ); //hDC is your Windowhandle
    	HBITMAP hbitmap = CreateCompatibleBitmap( hDC, cx, cy); //cx, cy is the width and height of rect area of your Tabbed Window
    	ReleaseDC( m_TabWin, hDC );
    if ( hbitmap )
    	{
    		SelectObject( hMemDC, hbitmap); 
    		ShowScrollBar( m_TabWin, SB_BOTH, FALSE ); // Hide the ugly scrolbars
    		SendMessage( m_TabWin, WM_PAINT, (WPARAM)hMemDC, 0 );

    After this, Initialize the DOCINFO Structure... and call StartDoc() to flag start the printing job...

    Call StartPage()... StretchBlt() the Bitmap in Memory to the Printer DC... and after that, call EndPage()

    After all, delete all DC's and DeletObject(hbitmap)...

    I've given a basic outline or idea... this will work... for sure, and if u cant get me, please Refer the documentations of thse API's in MSDN and try for urself...
    "I studied everything but never topped. Today, toppers of the world's best universities are my employees"

    -William Henry Gates (Bill Gates)

  3. #3
    Join Date
    Dec 2008
    Posts
    114

    Re: How can i print a tab page?

    Quote Originally Posted by CoolPG View Post
    Call StartPage()... StretchBlt() the Bitmap in Memory to the Printer DC
    Not for printer DC (DIB)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured