Solved

Disabling printscreen

Posted on 1998-08-24
10
922 Views
Last Modified: 2010-04-04
Can anyone show me how to disable the print screen event.
There are two ways I guess, either through Application.OnMessage
or through theWMSysCommand(var message...

I'd like the second since the first would slow the application down.

Please anyone!
0
Comment
Question by:peed112097
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 1

Expert Comment

by:pjdb
ID: 1337514
I think that the print screen does not go to the application since it is handle by the system to copy all the screen.
The only way i see to do it is to hook to the clipboard to be notifyed of he changes and clear it if the content is a copy of the screen.
JDB
0
 

Author Comment

by:peed112097
ID: 1337515
Ok, maby I did'nt make my self clear. I'm not interested in disabling the printscreen, all I want is that when hitting the printscreen key, nothing in my application should be printed.

/Per
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337516
There is a component in the RXLibrary that can view the clipboard...it might be useful to you in some way ..

Regards,
Viktor Ivanov
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1337517
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337518
You might wanna hook the window with the the keyboard hook, and if that key is pressed then do nothing,,,,

Regards,
Viktor Ivanov
0
 

Author Comment

by:peed112097
ID: 1337519
Can you show me with an examle on the keyboard hook?
0
 
LVL 8

Accepted Solution

by:
ZifNab earned 50 total points
ID: 1337520
Hi peed,

a Win32 app can register the print key as a hotkey:

 RegisterHotKey (Self.Handle, idHOT_SNAPWINDOW,
                  0, // can use MOD flags here, see win32.hlp
                  VK_SNAPSHOT);

It has to unregister it when it terminates.

  UnRegisterHotKey (Self.Handle, idHOT_SNAPWINDOW);

 
Add a handler for WM_HOTKEY to your main form and you can do something like
this

procedure TForm_MnMain.WMHotKey (Var Message: TWMHotKey);
begin
  If message.HotKey = idHot_SnapWindow then
    MyPrintScreen;
end;

Regards, Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337521
function KeyBoardCallback (Code : Integer; WParam : Word;
   LParam : Longint) : LongInt;
   begin
     Result := 0;
     // Check to see if it's the hot key ..here is the secret to get the key
   if Lo(wParam) = VK_SNAPSHOT then
     begin
     //Do your code here.....
      ShowMessage('Hot key pressed');
   Result := 1;
   end;
   CallNextHookEx(gHook, code, Wparam, Lparam);
   end;
-==============To hook===============-
   gHook := SetWindowsHookEx(WH_KEYBOARD, @ClueCardKeyBoardCallback,
   HInstance, GetCurrentThreadId);
   If (gHook = 0) then ShowMessage('Not Hooked');
-==============To unhook===============-
   { This unhooks the hook }
   If not(UnHookWindowsHookEx(gHook)) then
   ShowMessage('Couldnt Unhook');
--------------
It would be something similar to this.....I hope it helps =)

Regards,
Viktor Ivanov

0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337522
Here's an example from borland.com:

The PrintScreen system key is not processed during the TForm
keydown event. The following example tests if the PrintScreen key has
been pressed by calling the Windows API function GetAsyncKeyState()
during the Application.OnIdle event.

Example:

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure AppIdle(Sender: TObject; var Done: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnIdle := AppIdle;
end;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
begin
  if GetAsyncKeyState(VK_SNAPSHOT) <> 0 then
  Form1.Caption := 'SnapShot';
  Done := True;
end;

/// John
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1337523
And here's another:

The following example demonstrates registering a hot key with the
system to globally trap the windows printscreen key.

Example:

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const id_SnapShot = 101;

procedure TForm1.WMHotKey (var Msg : TWMHotKey);
begin
  if Msg.HotKey = id_SnapShot then
  ShowMessage('GotIt');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RegisterHotKey(Form1.Handle,
    id_SnapShot,
    0,
    VK_SNAPSHOT
  );
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  UnRegisterHotKey (Form1.Handle, id_SnapShot);
end;

/// John

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question