Main Menu

News:

SyntaxBoom, now with pwetty syntax highlighted code boxes! \o/ 

https://www.syntaxboom.com/forum/index.php?topic=96

Shoutbox

Jackdaw

Today at 20:00:40
Going to have to try bourbon and beans. That should be an explosive combination.

Baggey

Today at 13:15:42
I sometimes mix a chicken vindaloo and a Tika Masala together. Awesome  :P

Dabzy

Today at 05:49:34
And doing the act was the realisation I went for an indian when out... 20mins I was in the thunderbox waiting for me back chaff to cool down!

Dabzy

Today at 05:48:11
When I was on my "Year On The Blur", aka drinking after getting divorced, I was minging one night, couldnt remember getting home. Anyway, next day, went to work, and needed a poo...

GfK

2025-10-15, 21:39:05
I overdosed on jelly babies once and my arse was like the shooty gun bit at the start of James Bond

Amon

2025-10-15, 20:16:38
lol

Jackdaw

2025-10-15, 19:40:48
Never had a Phall or a tinderloo. But I have heard that your backside feels like that map at the start of every episode of Bonanza.

GfK

2025-10-15, 19:22:25
Never confuse phall with phallus

Baggey

2025-10-15, 18:30:58
My mate ate a phall one night. Even that was to hot for me. I bet he suffered in the morning!  :-[

Dabzy

2025-10-15, 18:02:52
I like nice and toasty bit of fire in my bait as well, I used to eat really red hot gear, but nowadays if I do... Heartburn happens! :(

Members
Stats
  • Total Posts: 1,810
  • Total Topics: 224
  • Online today: 26
  • Online ever: 232 (Oct 08, 2025, 09:18 AM)
Users Online
  • Users: 1
  • Guests: 16
  • Total: 17
Welcome to SyntaxBoom. Please login or sign up.

Recent

MaxGUI - GadgetPrint()

Started by _PJ_, Sep 25, 2025, 01:50 PM

Previous topic - Next topic

_PJ_


GadgetPrint(  )
Does not seem to do anything:

Import maxgui.drivers
Local window:Tgadget=CreateWindow("Test",0,0,256,64)
Local gadget:Tgadget=CreateTextArea(0,0,128,16,window)
SetGadgetText(gadget,"testing")
GadgetPrint(gadget)

Does anyone else have issues?

Henri

#1
Hi,

all functionality in DoPrint method has been commented out (not sure why). If you want that functionality back, you have to make few modifications.

In 'maxgui.mod\win32maxguiex.mod\win32maxguiex.bmx' find line 4216, and add this inside Method DoPrint()

Local tmpTextSelLen = TextAreaSelLen(Self)
Local tmpPrintDialog:PRINTDLGW = New PRINTDLGW

tmpPrintDialog.flags = PD_RETURNDC | PD_HIDEPRINTTOFILE | PD_NOPAGENUMS
If Not tmpTextSelLen Then tmpPrintDialog.flags:|PD_NOSELECTION

tmpPrintDialog.hwndOwner = _hwnd

If Not PrintDlg( Byte Ptr tmpPrintDialog ) Then Return 0

Local hdcPrinter:Byte Ptr = tmpPrintDialog.hdc

Local tmpDoc:DOCINFOW = New DOCINFOW
Local tmpDocTitle:Short Ptr = AppTitle.ToWString()
tmpDoc.lpszDocName = tmpDocTitle

Local tmpSuccess = (StartDocW( hdcPrinter, Byte Ptr tmpDoc ) > 0)

If tmpSuccess Then

	Local _cursor:Byte Ptr = TWindowsGUIDriver._cursor

	SetPointer( POINTER_WAIT )

	SetMapMode( hdcPrinter, MM_TEXT )

	Local wPage = GetDeviceCaps( hdcPrinter, PHYSICALWIDTH )
	Local hPage = GetDeviceCaps( hdcPrinter, PHYSICALHEIGHT )
	Local xPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSX )
	Local yPPI = GetDeviceCaps( hdcPrinter, LOGPIXELSY )

	Local tmpTextLengthStruct[] = [GTL_DEFAULT,1200]
	Local tmpTextLength = SendMessageW (_hwnd, EM_GETTEXTLENGTHEX, WParam Byte Ptr tmpTextLengthStruct, 0)

	Local tmpTextPrinted, tmpFormatRange:FORMATRANGE = New FORMATRANGE

	tmpFormatRange.hdc = hdcPrinter
	tmpFormatRange.hdcTarget = hdcPrinter

	tmpFormatRange.rcPageRight = (wPage*1440:Long)/xPPI
	tmpFormatRange.rcPageBottom = (hPage*1440:Long)/yPPI

	tmpFormatRange.rcLeft = (1440*_pagemargin);tmpFormatRange.rcTop = (1440*_pagemargin)
	tmpFormatRange.rcRight = tmpFormatRange.rcPageRight - (2880*_pagemargin)
	tmpFormatRange.rcBottom = tmpFormatRange.rcPageBottom - (2880*_pagemargin)

	If tmpPrintDialog.flags & PD_SELECTION Then
		tmpTextPrinted = TextAreaCursor(Self)
		tmpFormatRange.CHARRANGE_cpMax = tmpTextPrinted+tmpTextSelLen
	Else
		tmpFormatRange.CHARRANGE_cpMax = tmpTextLength
	EndIf

	SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)

	While tmpSuccess And ( tmpTextPrinted < tmpFormatRange.CHARRANGE_cpMax )

		tmpFormatRange.CHARRANGE_cpMin = tmpTextPrinted

		tmpSuccess = (StartPage(hdcPrinter) > 0)
		If Not tmpSuccess Then Exit

		tmpTextPrinted = SendMessageW( _hwnd, EM_FORMATRANGE, True, Int Byte Ptr tmpFormatRange )

		tmpSuccess = (EndPage(hdcPrinter) > 0)

	Wend

	If tmpSuccess Then EndDoc( hdcPrinter ) Else AbortDoc( hdcPrinter )

	SendMessageW (_hwnd, EM_FORMATRANGE, False, 0)

	TWindowsGUIDriver._cursor = _cursor
	SetCursor _cursor

EndIf

GlobalFree( tmpPrintDialog.hDevMode )
GlobalFree( tmpPrintDialog.hDevNames )
DeleteDC( hdcPrinter )

MemFree tmpDocTitle

Return tmpSuccess


In 'C:\BlitzMaxNG\mod\maxgui.mod\win32maxguiex.mod\common.bmx' add these definitions:

Const PD_NOSELECTION:Int = $4
Const PD_DISABLEPRINTTOFILE:Int = $80000
Const PD_PRINTTOFILE:Int = $20
Const PD_RETURNDC:Int = $100
Const PD_RETURNDEFAULT:Int = $400
Const PD_RETURNIC:Int = $200
Const PD_SELECTION:Int = $1
Const PD_SHOWHELP:Int = $800
Const PD_NOPAGENUMS:Int = $8
Const PD_PAGENUMS:Int = $2
Const PD_ALLPAGES:Int = $0
Const PD_COLLATE:Int = $10
Const PD_HIDEPRINTTOFILE:Int = $100000

Type PRINTDLGW
	Field lStructSize:Int = SizeOf(Self)
	Field hwndOwner:Byte Ptr, hDevMode:Byte Ptr, hDevNames:Byte Ptr, hdc:Byte Ptr
	Field flags:Int, nFromPage:Short, nToPage:Short, nMinPage:Short, nMaxPage:Short, nCopies:Short

?X64
	Field hInstance:Byte Ptr
	Field lCustData:LParam
	Field lpfnPrintHook:Byte Ptr
	Field lpfnSetupHook:Byte Ptr
	Field lpPrintTemplateName:Byte Ptr
	Field lpSetupTemplateName:Byte Ptr
	Field hPrintTemplate:Byte Ptr
	Field hSetupTemplate:Byte Ptr
?X86
	Field padding:Short, padding2:Short, padding3:Short, padding4:Short, padding5:Short, padding6:Short
	Field padding7:Short, padding8:Short, padding9:Short, padding10:Short, padding11:Short, padding12:Short
	Field padding13:Short, padding14:Short, padding15:Short, padding16:Short
?
EndType

Type DOCINFOW
	Field cbSize:Int = SizeOf(Self)
	Field lpszDocName:Short Ptr, lpszOutput:Short Ptr, lpszDatatype:Short Ptr
	Field fwType:Int
EndType

Type FORMATRANGE
	Field hdc:Byte Ptr, hdcTarget:Byte Ptr
	Field rcLeft:Int, rcTop:Int, rcRight:Int, rcBottom:Int
	Field rcPageLeft:Int, rcPageTop:Int, rcPageRight:Int, rcPageBottom:Int
	Field CHARRANGE_cpMin:Int, CHARRANGE_cpMax:Int
EndType

-Henri

Baggey

I came up with this  :-X

SuperStrict

Import maxgui.drivers

Local window:Tgadget=CreateWindow("Test",0,0,256,256)
Local gadget:Tgadget=CreateTextArea(0,0,128,22,window)


SetGadgetLayout( gadget, 0, 0, 128, 16 )

	
ActivateGadget( gadget )

SetGadgetText(gadget,"testing")


While Not AppTerminate() And Not KeyDown(Key_Escape)


Wend
Running a Pc that just aint. Faster nough. I7-4Ghz, 32Gb Ram, 4Gb Nvidia, 2 x 1Tb SSD's, 2 x 24" LCD's

RETRO everything!

Jesus was only famous because of his Dad

_PJ_

#3
Thanks, Henri
I will give that a try and see how it goes.

I do appreciate that printer communication is an unwieldy beast due to years of back-compatibility and hardware/communication evolution over the decades so it doesn't surprise me if there are some issues - but luckily I'm only working in and compiling for Windows so that might simplify things for my case at least :)

[quick edit: ]
A lot of the "DoPrint method that waas commented out had the good old "cannot convert between Byte Pointer and "Int" handle so it maybe got removed with the move to NG or soon after.

_PJ_

Okay, so I made the changes as described.
Re-compiled the modules ( reported success )

I still don't see a print dialog appearing, though...

____________________

So I noticed the IDE has a "Print" option in its menu - clickign this DID bring up the Windows Printer dialog as expected, so I chaecked the src/maxide.bmx and found tthe line 2318:

GadgetPrint htmlview
_

Which couldnt be simpler, right?
So I thought that maybe - although the documentation suggests GadgetPrint only works for htmlview and textarea gadgets, maybe it's ONLY for htmlview?

quick test of
Import maxgui.drivers
Local window:Tgadget=CreateWindow("Test",0,0,256,64)
Local gadget:Tgadget=CreateHTMLView(0,0,128,16,window)
SetGadgetText(gadget,"testing")
GadgetPrint gadget
End
Also results in nothing...

So I figured I would probably need some more substantial test program with more content worth printing - so I'm looking into that now...

Henri

I'm guessing thats related to 32-bit vs. 64-bit compilation

Okay, I modified the PRINTDLGW type a bit. See if that fixes it.

Type PRINTDLGW
    Field lStructSize:Int = SizeOf(Self)
    Field hwndOwner:Byte Ptr, hDevMode:Byte Ptr, hDevNames:Byte Ptr, hdc:Byte Ptr
    Field flags:Int, nFromPage:Short, nToPage:Short, nMinPage:Short, nMaxPage:Short, nCopies:Short

?X64
    Field hInstance:Byte Ptr
    Field lCustData:LParam
    Field lpfnPrintHook:Byte Ptr
    Field lpfnSetupHook:Byte Ptr
    Field lpPrintTemplateName:Byte Ptr
    Field lpSetupTemplateName:Byte Ptr
    Field hPrintTemplate:Byte Ptr
    Field hSetupTemplate:Byte Ptr
?X86
    Field padding:Short, padding2:Short, padding3:Short, padding4:Short, padding5:Short, padding6:Short
    Field padding7:Short, padding8:Short, padding9:Short, padding10:Short, padding11:Short, padding12:Short
    Field padding13:Short, padding14:Short, padding15:Short, padding16:Short
?
EndType

-Henri

Dabzy

If it works for HTMLViews, could you not save the text area data to a temp file, then load it up into a hidden HTMLView gadget and go from there?

Never used the command, just a workaround idea.

Dabz
Intel i7-13620H, nVidia GerForce RTX 4060 Laptop GPU (8GB GDDR6), 16GB LPDDR5X, 1TB SSD, Windows 11 x64 piss flap of an OS!

Midimaster

Quote from: _PJ_ on Sep 25, 2025, 01:50 PMGadgetPrint(  )
Does not seem to do anything:




Are you interested in "Repairing the feature" or Printing something within your BlitzMax apps?

I ask, because there are better ways to get a high quality printout via Screenshot-, Clipboard- and PDF-Module in BlitzMax.



_PJ_

Quote from: Henri on Sep 29, 2025, 08:44 PMI'm guessing thats related to 32-bit vs. 64-bit compilation

Okay, I modified the PRINTDLGW type a bit. See if that fixes it.


Excellent! That seems to have done the trick!

Thanks, Henri. It all works for me now :)

_____________________________________________
Quote from: Dabzy on Sep 30, 2025, 05:47 AMIf it works for HTMLViews, could you not save the text area data to a temp file, then load it up into a hidden HTMLView gadget and go from there?

Never used the command, just a workaround idea.

Dabz
Good idea :)

The problem was that I couldn't get it to work at all - but now with Henri's fix, applying the necessary details to an htmlview gadget is what I am doing!

Quote from: Midimaster on Sep 30, 2025, 03:08 PMAre you interested in "Repairing the feature" or Printing something within your BlitzMax apps?

I ask, because there are better ways to get a high quality printout via Screenshot-, Clipboard- and PDF-Module in BlitzMax.

So the reason I wanted this function to work is because I am currently (very slowly) going through my old Blitz+ and Blitz3D projects and some of the "better" ones I want to convert to or recreate in BMax
One such project was for creating inserts and labels for CD/DVD/BluRay cases.

Thanks to some amazing work by asomeone from the old blitzbasic forums, there was a Printer.decls and DLL
But Printer device handling/architecture is a huge nightmare and way beyond my ability to build an Extern interface or such, so I was reaally glad to see that this printer functionality was 'built-in' to BMaxGUI

Midimaster

The advantage of the BlitzMax PDF-module is, that it enables you to define an exact document size (in millimeters). And it enables you to print (zoom) the coloured content of any TPixmap into this document.

Of course adding texts is also possible. In any size, font or direction...
The quality of prints from this PDF is awesome!

The use is very easy. I will write anyway a tutorial about "Using PDF-module" in the next days here.