1. Stuart Macandrew
  2. PowerBuilder
  3. Wednesday, 24 October 2018 20:42 PM UTC

I have an ActiveX control which I need to render to a report. The control has a method which accepts a device context handle. So I think I can do this using the PRP_GetDC() function of PSHR170.DLL, something like this;

 

long ll_printjob

ulong lul_hdc

 

ll_printjob = PrintOpen( "Print Test" )

lul_hdc = PRP_GetDC( ll_printjob )

ole_map.OutputMap( lul_hdc, ... )

PrintClose( ll_printjob )

 

However when I test this, the print-page is rendered blank. 

My declaration of PRP_GetDC() is this;

 FUNCTION ulong PRP_GetDC (long printjob) library "PBSHR170.dll"

 I have attempted to render a bitmap using StretchBlt() to the print page  based on code that I know works, and that also seems to be rendered blank. So at this point I suspect that my hDC value is not valid, or the way I am using it is not valid. However the value  is non-zero, and reasonable values seem to be returned by from calls to get attributes of the hDC using GetDeviceCaps()  e.g.

 

constant long LOGPIXELSX  = 88

long LOGPIXELSY  = 90

GetDeviceCaps( lul_hdc ,LOGPIXELSX)

 

Does anyone have any pointers on getting this working?

(I am using Powerbuilder 2017R3)

Arthur Hefti Accepted Answer Pending Moderation
  1. Tuesday, 30 October 2018 04:53 AM UTC
  2. PowerBuilder
  3. # 1

Hi 

PRP_GetDC is working, I use this to change the printer orientation during a print job.

The problem is, that the coordinate system is not as you expect. Change li_Y in your sample to -3000 and you will have a flipped image on the top left of the page.

So with the help of a bit math you can place the data where you would like.

Regards

Arthur

Comment
  1. Stuart Macandrew
  2. Wednesday, 31 October 2018 04:43 AM UTC
Aaah ... the Y axis is negative - who would have known!



I think that answers my question and I can crack on with what I actually need to do.
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 30 October 2018 01:52 AM UTC
  2. PowerBuilder
  3. # 2

Can you render stuff to a window and then use the window's built in Print function?

Comment
There are no comments made yet.
Stuart Macandrew Accepted Answer Pending Moderation
  1. Thursday, 25 October 2018 23:01 PM UTC
  2. PowerBuilder
  3. # 3

Thanks for the suggestions Roland.

The nub of my question is whether I can draw to the DC returned by the (undocumented) PB function PRP_GetDC(long printjob).

I have attached a simple test application (printrender.zip) to illustrate this. This has a function to load a bitmap and then draw it to a DC passed in as an argument. The window has two buttons - one renders the bitmap onto the window, the other button renders the bitmap onto a print job (rendering a bitmap is not what I need to achieve in the end - it is just a test case to verify I have a valid DC to draw to).

If I pass a DC for the window, this code works - a test bitmap is rendered on the window as expected. The DC is obtained like this;

GetDC ( Handle(window) )

However if I use the same function to attempt to draw on a print-page, I get a blank page. The DC is obtained like this;

ll_job = printOpen()
PRP_GetDC (ll_job)

So my current conclusion is the DC returned by PRP_GetDC() is invalid. Or I am using it wrong?

 

Attachments (1)
Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 25 October 2018 13:24 PM UTC
  2. PowerBuilder
  3. # 4

If you can save the image in the control to a file, the PrintBitmap function will work.

Comment
There are no comments made yet.
Stuart Macandrew Accepted Answer Pending Moderation
  1. Wednesday, 24 October 2018 21:34 PM UTC
  2. PowerBuilder
  3. # 5

Yes it does have a print method(). However I need to add additional elements - bitmaps, text and boxes - to the page,  which I think I can do by with Powerbuilder printBitmap(), printText() etc.

 

This is actually a re-factor of existing code which had another activeX control handling the printing. What I am trying to do is remove that printing activeX control and substitute Powerbuilder "print" functionality. I thought it would be straight-forward ;-)

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 24 October 2018 20:52 PM UTC
  2. PowerBuilder
  3. # 6

The control doesn't have a print method?

I have two examples that use related Windows API functions:

Capture a control to a bitmap

http://www.topwizprogramming.com/freecode_bitmap.html

Custom Picture control:

http://www.topwizprogramming.com/freecode_canvas.html

 

Comment
  1. Stuart Macandrew
  2. Monday, 5 November 2018 23:00 PM UTC
For anyone's future reference the final resolution is as follows.

The cause of the issue I experienced is that PB printing uses Windows GDI map-mode MM_HIENGLISH ("Each logical unit is mapped to 0.001 inch. Positive x is to the right; positive y is up.").

To resolved this I used the SetMapMode() GDI function to set the map-mode of my drawing-context (hdc) to the default map mode of MM_TEXT ( "Each logical unit is mapped to one device pixel. Positive x is to the right; positive y is down." ).

I could then call the method of my ActiveX control to render using the map mode it was expecting.

This allowed me to mix PB PrintText(), PrintLine() etc. statements on the same print page as my ActiveX control drew to.
  1. Helpful
  1. Roland Smith
  2. Monday, 5 November 2018 23:57 PM UTC
Can you put together a demo app and post it.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.