Monday, January 19, 2009

Disable PrintScreen on C# without Keyboard Hooks


Yes, there is a simple solution to prevent grabbing information on your C# application screen with the keyboard's printscreen key without using keyboard hooks or calling COM interops. The solution makes use of Windows Forms Message Filter to trap keyboard events on your application window.

To trap keyboard events with Windows Message Filter, you need to implement the IMessageFilter interface and override the member PreFilterMessage(ref Message WM) method. This is the method called whenever a Form receives a keyboard or mouse event. You may want to read more about IMessageFilter.

The problem is that even though you have trapped the PrintScreen keypress event, the captured image will still persist to the clipboard. Therefore the simplest solution is to clear up the clipboard right after the PrintScreen is pressed on the keyboard.

This is how the overridden method will look like this:

public bool PreFilterMessage(ref Message WM)
{
Keys kCode = (Keys)(int)WM.WParam & Keys.KeyCode;

//block printscreen on KeyPress
if (kCode == Keys.Snapshot)
{
//remove the captured image from clipboard
Clipboard
.Clear();

MessageBox.Show("Printscreen not allowed.");

return true;

}

return false;

}

Another thing is that, if this method returns true, the Windows GDI Message will not be received by the Form.

Note: The PrintScreen event can only be captured if the Application window is active.


Enjoy!

Saturday, January 10, 2009

Fixing a Problematic Motorola L6

Few days after I have re-flashed my Motorola L6 phone, I encountered a problem with the firmware. It seems like the firmware cannot access the phone memory. When I select an item in the main menu, my phone just displays the message "Please Wait..." and does nothing after. The phone cannot be used in this current state and the only i see one option to fix this and it is to re-flash again with a newer firmware. Now the problem is that i will lose my contact database if i do this so i looked for way to back it up. I tried using Windows XP's hyper terminal to read the phone memory thru AT commands but got no success.



The good thing is that i made a backup of the whole application folder (Motorola Software Update) including the registry changes. I made a copy of the files inside the application folder right after it has backed up the personal data on the phone. So the temporary files were also copied unconsciously.

Restart the Motorola phone on Bootloader mode. This can be done by pressing the *, # and the power buttons together at the same time while the phone is turned off. The phone should display a black screen with white text indicating that the phone is on “Programmable Mode”.

Then run the Motorola Software Update. The software should detect the phone and will automatically commence the firmware upgrade. While update is in progress, copy the personal data temporary file from the temp folder of your backup and paste it to the temp folder under the application folder, usually “C:\Program Files\Motorola\Software Update\temp”. The filename is usually in this format ##############.dat

Wait for the update to finish. The phone will then restart after the update is completed and will then restart the restore process. The software will read from the backup file you placed in the temp folder. This backup file includes the phonebook. Presto!

All though the phone is now fixed, I do not guarantee that whole problem is fully fixed therefore I suggest that you start backing up your phonebook. You may do this by syncing your phone to you PC. Good Luck.

Popular