1. Stuart Macandrew
  2. PowerBuilder
  3. Wednesday, 24 October 2018

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
0
Votes
Undo

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
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. Stuart Macandrew
  2. Wednesday, 31 October 2018
There are no comments made yet.
  1. Tuesday, 30 October 2018
  2. PowerBuilder
  3. # 1
Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

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

Comment
There are no comments made yet.
  1. Tuesday, 30 October 2018
  2. PowerBuilder
  3. # 2
Stuart Macandrew Accepted Answer Pending Moderation
0
Votes
Undo

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.
  1. Thursday, 25 October 2018
  2. PowerBuilder
  3. # 3
Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

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

Comment
There are no comments made yet.
  1. Thursday, 25 October 2018
  2. PowerBuilder
  3. # 4
Stuart Macandrew Accepted Answer Pending Moderation
0
Votes
Undo

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.
  1. Wednesday, 24 October 2018
  2. PowerBuilder
  3. # 5
Roland Smith Accepted Answer Pending Moderation
0
Votes
Undo

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
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. Stuart Macandrew
  2. Monday, 5 November 2018
Can you put together a demo app and post it.
  1. Roland Smith
  2. Monday, 5 November 2018
There are no comments made yet.
  1. Wednesday, 24 October 2018
  2. PowerBuilder
  3. # 6
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.