3

I am working on the assignment to write a Virtual Printer with C# and NTDDK.

I have created a test printer driver and I am able to print .ps documents(redirected to C:\test\test.ps always) using it. But now I have to write a small application that will popup a messagebox saying "Print is done" using C# but I am not able to figure out how to do it?

Can anyone help me in this?

Thanks in advance!

Hiren
  • 341
  • 1
  • 4
  • 17
  • nice question but very vertical scope, can you show a snippet of the code, for example when you start printing, is everything written in pure managed .NET / C# ? – Davide Piras Mar 16 '11 at 08:44
  • I have not started anything in c# as yet. I was wondering how to check whether print is done ? I am pure c++ dev and new to c#. – Hiren Mar 16 '11 at 08:48
  • Why not just write a batch file with commands to echo something or send a message over the network to the particular ip address using `Net Send %COMPUTERNAME% mymessage` or something similar.. – Robin Maben Mar 16 '11 at 08:49
  • @conqenator - I have to popup a messagebox on my local system and my printer is not in a network. – Hiren Mar 16 '11 at 08:50

1 Answers1

0

Use the endprint event...that is something like, in the designer code put:

/////////////// something.EndPrint += new PrintEventHandler(endingclass); //////////////

in the form constructor, or anywhere in the program/form where you can call the method put:

private void endingclass(object sender, PrintEventArgs e)

{

MessageBox.Show("wazaaaaaaaaaaaaaaaaa");

}

//////// Obviously, you need to make some...arrangements in the code above - but I believe they are self evident. In case you have problems, googl the endprint event, it will 100% has some examples associated with it.

//// On a side note...if you're really bored you can think of asynchronous process which checks the process every....1/10 of a second :). It will work, but it's a bizarre way to accomplish such a thing. Since you're a c++ developer, c# should be easy to you, you'll like it, it's more powerfull than c++ anyway.

johny
  • 49
  • 3
  • C# is indeed more powerful than c++ – Hiren Mar 16 '11 at 09:25
  • nice answer wasted completely with the comment C# is more powerful than C++, I believe it's actually the opposite but let's don't start a fight :) – Davide Piras Mar 16 '11 at 09:27
  • @johny Thanks for the answer. I want to write my C# app such that it should be visible only when the print is done.I thought of writing a thread/process which looks for every second to see if test.ps is changed/edited/modified/deleted (C# has one such class which can help me in this) but this ain't gonna help since I have to make sure that my app is running all the time which as you said this is bizzare way. Now I am looking to put a hook in driver code for C# app to pop-up window. and yes C# is indeed more powerful than c++. – Hiren Mar 16 '11 at 09:31
  • @Davide For Application programming, yes C# has so many in-built classes that is why it seems more powerful and of course c++ is the best language if you know where to find supporting libraries :) anyways as you said lets not fight over that matter :) – Hiren Mar 16 '11 at 09:34
  • Well...I really like c++, but the advantages of c# can't be overlooked most of the time: the big .net library and let's not forget that it allows unsafe code, so all of the c++ features of memory management and stack manipulation aren't so...unreachable in c#. Let alone the visual controls of visual studio, intellisense, garbage collection, code highlighting....even the foreach statement if you will :). What i don't like in c# is how type safe it is, the variable shadowing, bool not for classes etc. On topic: user662104 - you can use easily: this.show() OR this.hide() to show/hide the form. – johny Mar 16 '11 at 09:51
  • @johny Is there anything like I can register my app in Windows such that app will be run whenever print is triggered to my printer? – Hiren Mar 16 '11 at 10:05