SRL Archive - Help and Support

Printing Text on a Form


gerauchert

2013-05-28 23:53:10

From my searches, I have not found anything related to printing text on a form for simba (opening up Print Dialog menu and physically printing it out). I remember SCAR had TRichEdit, which allowed me to do this before, but Simba does not support TRichEdit or TPrintDialog.

Two questions:

Is there another type that allows printing on simba forms?

Would it be difficult to implement TRichEdit into simba? Or what would go into making simba forms printing-compatible by alternative means? (perhaps a plugin? Idk…lol)

Any feedback would be most appreciated. I REALLY need to get a print option going on this program that I am making.

Brandon

2013-05-29 02:57:10

http://msdn.microsoft.com/en-us/library/ms646940(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/ms646937(v=vs.85).aspx

Can put those two into a plugin easily and print any document or image or device context. Not sure about any native Simba functionality but through a plugin (or possibly an extension too), its more than possible. I know for sure a plugin can do it. But yeah I'm not sure if Simba has a form control that can do it.

gerauchert

2013-05-29 10:20:00

@Brandon: Thanks for the reply, and I am happy that this is possible through a plugin. However, my skills are lacking in other languages aside from pascal… and I have never once attempted to make a plugin.

All I want the script to be able to do is print the text that is recorded in a TMemo. From the links you provided, it looks like C++ is your suggestion for the plugin. As I would probably be more familiar to FreePascal (and since there is a plugin tutorial w/ fpc example), would there be an advantage to using C++ over fpc?

Brandon

2013-05-29 12:46:39

From: gerauchert
@Brandon: Thanks for the reply, and I am happy that this is possible through a plugin. However, my skills are lacking in other languages aside from pascal… and I have never once attempted to make a plugin.

All I want the script to be able to do is print the text that is recorded in a TMemo. From the links you provided, it looks like C++ is your suggestion for the plugin. As I would probably be more familiar to FreePascal (and since there is a plugin tutorial w/ fpc example), would there be an advantage to using C++ over fpc?



There isn't much "Advantage" when it comes to plugins but when it comes to re-usability and use in other projects or languages, then my vote would go to C++. Also note that the API is a C api.

For ME, Cpp just happens to be the easiest language and has pretty good docs so yeah.. Its up to you which language you write it in really.


Exporting the following code to a Simba plugin would be trivial. Also making it show a small preview of the page to print or a Page-Setup is trivial as well.


Small sample:




void Print(HWND WindowHandle)
{
PRINTDLGEX PrintStruct = {0};
char RangeBuffer[10 * sizeof(PRINTPAGERANGE)];

PrintStruct.lStructSize = sizeof(PRINTDLGEX);
PrintStruct.hwndOwner = WindowHandle;
PrintStruct.hDevMode = nullptr;
PrintStruct.hDevNames = nullptr;
PrintStruct.hDC = nullptr;
PrintStruct.Flags = PD_RETURNDC | PD_COLLATE;
PrintStruct.Flags2 = 0;
PrintStruct.ExclusionFlags = 0;
PrintStruct.nPageRanges = 0;
PrintStruct.nMaxPageRanges = 10;
PrintStruct.lpPageRanges = reinterpret_cast<LPPRINTPAGERANGE>(&RangeBuffer[0]);
PrintStruct.nMinPage = 1;
PrintStruct.nMaxPage = 1000;
PrintStruct.nCopies = 1;
PrintStruct.hInstance = nullptr;
PrintStruct.lpPrintTemplateName = nullptr;
PrintStruct.lpCallback = nullptr;
PrintStruct.nPropertyPages = 0;
PrintStruct.lphPropertyPages = nullptr;
PrintStruct.nStartPage = START_PAGE_GENERAL;
PrintStruct.dwResultAction = 0;

LRESULT hResult = PrintDlgEx(&PrintStruct);

if (PrintStruct.dwResultAction == PD_RESULT_PRINT && hResult == S_OK)
{
LPDEVMODE pDevInfo = reinterpret_cast<LPDEVMODE>(PrintStruct.hDevMode);
}

if (PrintStruct.hDC)
{
DeleteDC(PrintStruct.hDC);
}

if (PrintStruct.hDevMode)
{
GlobalFree(PrintStruct.hDevMode);
}

if (PrintStruct.hDevNames)
{
GlobalFree(PrintStruct.hDevNames);
}
}

gerauchert

2013-05-29 16:14:10

@Brandon: Thank you for the info, but I must remind you of my *cough* challenged nature, when it comes to doing anything other than scar/simba coding. If this is a trivial thing to accomplish, would it be too much to ask if you could create the plugin for me? Or provide some detailed steps for converting the C++ code you posted into the plugin? (I don't mind doing the work, it will just take too long for me to figure out… and ill probably end up making a new help thread)

Brandon

2013-05-29 16:41:41

From: gerauchert
@Brandon: Thank you for the info, but I must remind you of my *cough* challenged nature, when it comes to doing anything other than scar/simba coding. If this is a trivial thing to accomplish, would it be too much to ask if you could create the plugin for me? Or provide some detailed steps for converting the C++ code you posted into the plugin? (I don't mind doing the work, it will just take too long for me to figure out… and ill probably end up making a new help thread)




[ATTACH]21504[/ATTACH]


{$loadlib Printer.dll}

var
frmMain: TForm;
Closed: Boolean;
Params: TVariantArray;

procedure OnClose(Sender: TObject; var Action: TCloseAction);
begin
Closed := True;
end;

procedure InitializeForm;
begin
frmMain := TForm.Create(nil);
frmMain.ONCLOSE := @OnClose;
frmMain.Show;
end;

begin
ThreadSafeCall('InitializeForm', Params);
PrintDialog(FrmMain.Handle, 'Simba Printer', 'Hello Brandon', 500, 500);

repeat
Sleep(500);
Until(Closed);

frmMain.Close;
frmMain.Free;
end.

Results of printing to a file rather than my actual printer (that works too):

gerauchert

2013-05-29 18:50:43

Thanks dude, this is a lifesaver for me. Much appreciated :)


EDIT: and yeah, can't figure it out. Do I need to download a c++ interpreter and run something in that folder to make the Printer.dll?

Brandon

2013-05-29 19:28:33

From: gerauchert
Thanks dude, this is a lifesaver for me. Much appreciated :)


EDIT: and yeah, can't figure it out. Do I need to download a c++ interpreter and run something in that folder to make the Printer.dll?



If you want to compile it yourself then just stick the source in any c++ compiler and run it. If you want to just use the binary file then copy bin/release/Printer.dll to Simba/Plugins.


Up to you.

gerauchert

2013-05-29 19:54:51

From: Brandon
If you want to compile it yourself then just stick the source in any c++ compiler and run it. If you want to just use the binary file then copy bin/release/Printer.dll to Simba/Plugins.


Up to you.


Thanks man, I think the first download was corrupted or something because there was no Printer.dll. Redownloaded and all is well :)

EDIT:
@Brandon: The print dialog works great, no errors or anything. For some reason, however, it will only print the memo as one line of text. Ex:

Procedure PrintTheMemo(Sender: TObject);
var
i: Integer;
PrintText: String;
begin
if PrintMemo.Text = '' then Exit;
for i := 0 to PrintMemo.LINES.Count-1 do
PrintText := PrintText + ''+ #13#10+ '' +PrintMemo.LINES[i] ;
Writeln(PrintText);
//PrintDialog(Simplicity.Handle,ActiveTab[MainPage.PageIndex].Caption,PrintText,0,0);
end;
{The Writeln results in:
one
two
three
four
five
BUT it physically prints:
onetwothreefourfive}
Even when I put in the carriage return char and assign to a separate string, it still prints one line, despite what writeln outputs. I am assuming that it is because I am inputting a simple String, the print dialog requires something else to organize it into its proper format? Is there something that can be done on the C++ end to alleviate this issue? I dl'ed devC++ and took a look through the source of what you provided me, but I don't know what the hell I am doing lol.