screen tinter - vb.net

with the help of the stackoverflow community i have designed an app that colors the screen, and makes it look like you are wearing different color glasses.
i would also like to add the functionality of instead of coloring the whole screen, ONLY coloring the background of a document exactly like this program does:
http://www.thomson-software-solutions.com/html/screen_tinter.html
anyone have any clue how to do this in vb.net?

That's a pretty simple trick, it just replaces the system color that's used for window backgrounds. You'd change it by P/Invoking the SetSysColor() API function. Here's a sample Windows Forms app that demonstrates the technique. Start a new WF app and drop a button on the form. Then paste this code:
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
int oldcolor;
public Form1() {
InitializeComponent();
oldcolor = GetSysColor(COLOR_WINDOW);
this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
this.button1.Click += new EventHandler(button1_Click);
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
int element = COLOR_WINDOW;
SetSysColors(1, ref element, ref oldcolor);
}
private int Color2COLORREF(Color color) {
return color.R | (color.G << 8) | (color.B << 0x10);
}
private void button1_Click(object sender, EventArgs e) {
int element = COLOR_WINDOW;
int colorref = Color2COLORREF(Color.NavajoWhite);
SetSysColors(1, ref element, ref colorref);
}
private const int COLOR_WINDOW = 5;
[DllImport("user32.dll")]
private static extern bool SetSysColors(int one, ref int element, ref int color);
[DllImport("user32.dll")]
private static extern int GetSysColor(int element);
}
}

Offtopic a bit, but you can change Word to default to "White on Blue". Blue background, white text.

Related

Eclipse plugin - ColumnLabelProvider display only image

So I am developing an Eclipse plug-in and using ColumnLabelProvider to provide label for the columns of my tree viewer.
However, in one of the columns, I only intend to display an image and no text. However, in the final display, Eclipse reserves blank space for the text element even if I return a null.
Is there any way to make it display only image and in the full space provided?
Here is the code snippet:
column4.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
return null;
}
#Override
public Image getImage(Object element) {
/* Code to Display an image follows */
.....
}
});
ColumnLabelProvider will always leave space for the text.
You can use a class derived from OwnerDrawLabelProvider to draw the column yourself.
Something like:
public abstract class CentredImageCellLabelProvider extends OwnerDrawLabelProvider
{
protected CentredImageCellLabelProvider()
{
}
#Override
protected void measure(Event event, Object element)
{
}
#Override
protected void erase(final Event event, final Object element)
{
// Don't call super.erase() to suppress non-standard selection draw
}
#Override
protected void paint(final Event event, final Object element)
{
TableItem item = (TableItem)event.item;
Rectangle itemBounds = item.getBounds(event.index);
GC gc = event.gc;
Image image = getImage(element);
Rectangle imageBounds = image.getBounds();
int x = event.x + Math.max(0, (itemBounds.width - imageBounds.width) / 2);
int y = event.y + Math.max(0, (itemBounds.height - imageBounds.height) / 2);
gc.drawImage(image, x, y);
}
protected abstract Image getImage(Object element);
}

How do I implement a mouse event outside the Java frame?

I am trying to make a return program which will press the enter key when the left mouse key is clicked...
with courtesy of
http://www.java-tips.org/java-se-tips/java.awt/how-to-use-robot-class-in-java.html (for void typing method) and "thenewboston" I have gotten so far...
I am trying to make it so that it will function in other platforms, for example: Word, Note Pad and not just on a JFrame
This is what I have up till now...
import java.awt.event.MouseEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class MW3Tool
{
public static void main (String[] args)
{
Robot enter = new Robot();
int num;
return count = 0;
num = count * 3;
Control c = new Control();
for (int k = 1; k <= num; k++)
{System.out.println("H");}
/* try {
Robot robot = new Robot(); // Going to be used to electronically hit the enter key later.
robot.delay(5000);
robot.setSpeed(10);
for (int k = 1; k<= num; k ++)
robot.keyPress(KeyEvent.VK_ENTER);
}
catch (AWTException e) {
e.printStackTrace();
} } */
}
private class Control implements MouseListener
{
int count;
int useless;
int useless2;
public void mouseClicked(MouseEvent event)
{
count++;
}
public void mousePressed(MouseEvent event)
{
useless++;
}
public void mouseExited(MouseEvent event)
{
useless2++;
}
}
}
My errors:
----jGRASP exec: javac -g MW3Tool.java
MW3Tool.java:20: cannot return a value from method whose result type is void
return count = 0;
^
MW3Tool.java:22: cannot find symbol
symbol : variable count
location: class MW3Tool
num = count * 3;
^
MW3Tool.java:35: non-static variable this cannot be referenced from a static context
Control c = new Control();
^
MW3Tool.java:60: MW3Tool.Control is not abstract and does not override abstract method mouseEntered(java.awt.event.MouseEvent) in java.awt.event.MouseListener
private class Control implements MouseListener
^
4 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Sorry for my inefficient methods (newly affiliated with Java)
Any help will be appreciated... thank you...
First error: Are you trying to initialize an Integer? Wrong syntax. Use
int count = 0;
Second error: Solving the first error will solve this error.
Third error: Instead of saying
private class Control implements MouseListener { ... }
Say
private static class Control implements MouseListener { ... }
Last error:
See the MouseListener Javadocs:
Method Summary
void mouseClicked(MouseEvent e)
Invoked when the mouse button has been clicked (pressed and released) on a component.
void mouseEntered(MouseEvent e)
Invoked when the mouse enters a component.
void mouseExited(MouseEvent e)
Invoked when the mouse exits a component.
void mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a component.
void mouseReleased(MouseEvent e)
Invoked when a mouse button has been released on a component.
You MUST override all of these methods in the Control class for your program to work.
Hope this helps!

Java - pressing a direction key and having it move smoothly

When I press a direction key to move the object in that direction, it moves once, pauses momentarily, then moves again. Kind of like how if I want to type "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", I would hold "a" key down, but after the first "a" there is a pause then the rest of the "a"'s are typed. How do I remove that pause in KeyListener? Thank you.
This is the key repetition feature that the OS provides, so there is no way around the pauses.
The way most games gets around this is to keep an array of the current state of all required keys and check periodically on them (for example in the game loop) and act on that (e.g move).
public class KTest extends JFrame implements KeyListener {
private boolean[] keyState = new boolean[256];
public static void main(String[] args) {
new KeyTest();
int xVelocity = 0;
int x = 0;
while(1) {
xVelocity = 0;
if(keyState[KeyEvent.VK_LEFT]) {
xVelocity = -5;
}
x += xVelocity;
}
}
KTest() {
this.addKeyListener(this);
}
void keyPressed(KeyEvent e) {
key_state[e.getKeyCode()] = true;
}
void keyReleased(KeyEvent e) {
key_state[e.getKeyCode()] = false;
}
}
Base class taken from: http://content.gpwiki.org/index.php/Java:Tutorials:Key_States

Trying to get HorizontalOffset, always returns 0

I am writing an app with C#/xaml for Windows8 Metro.
I have a Scrollviewer and would like to get the horizontaloffset.
I tryed it with this:
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(GetValue(ScrollViewer.HorizontalOffsetProperty));
}
but i is always 0, althrough in the debugger it shows me an offset of 221.09 and i scrolled down!
Michael
If you scrolled down - your horizontal offset wouldn't change unless you scrolled horizontally.
Perhaps your event handler isn't on the ScrollViewer itself and if that's the case - you would need to call GetValue on the SV itself, e.g.
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(myScrollViewer.GetValue(ScrollViewer.HorizontalOffsetProperty));
}
or better yet just do this:
private void ScrollViewer_ViewChanged_1(object sender, ScrollViewerViewChangedEventArgs e)
{
int i = Convert.ToInt32(myScrollViewer.HorizontalOffset);
}

defining event handler for Tick event of DispatcherTimer in windows 8 app

I am developing an application in windows 8 Visual studio 11, and I want to define an event handler for a DispatcherTimer instance as below:
public sealed partial class BlankPage : Page
{
int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += new EventHandler(HandleTick);
}
private void HandleTick(object s,EventArgs e)
{
timecounter--;
if (timecounter ==0)
{
//disable all buttons here
}
}
.....
}
But I get the following Error :
Cannot implicitly convert type 'System.EventHandler' to 'System.EventHandler<object>'
I am a novice developer to widows 8 apps.
Would you please help me ?
almost had it :) You don't need to instantiate a new eventhandler object, you only need to point to the method that handles the event. Hence, an eventhandler.
int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += timer_Tick;
}
protected void timer_Tick(object sender, object e)
{
timecounter--;
if (timecounter == 0)
{
//disable all buttons here
}
}
Try to read up on delegates to understand events Understanding events and event handlers in C#
Your code is expecting HandleTick to have two Object params. Not an object param and an EventArg param.
private void HandleTick(object s, object e)
NOT
private void HandleTick(object s,EventArgs e)
This is a change that took place for Windows 8.
WinRT makes use of Generics more than the standard .NET Runtime. DispatcherTimer.Tick as defined in WinRT is here:
public event EventHandler<object> Tick
While the WPF DispatcherTimer.Tick is here
public event EventHandler Tick
Also note that you don't have to use the standard named method to create an Event Handler. You can use a lambda to do it in place:
int timecounter = 10;
DispatcherTimer timer = new DispatcherTimer();
public BlankPage()
{
this.InitializeComponent();
timer.Tick += (s,o)=>
{
timecounter--;
if (timecounter == 0)
{
//disable all buttons here
}
};
}