Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with GetDrawingSurface() call in JNI

843829Jul 15 2004 — edited Jul 16 2004
Hello,

I'm trying to implement a flashing alert in the taskbar via JNI (and in Windows). I've hit a brick wall however. The problem is that the awt.GetDrawingSurface() call seems to always return NULL no matter what I try.

Here's the C++ code...pretty standard stuff...
JNIEXPORT void JNICALL Java_flash_WindowUtil_flashInTaskBar
  (JNIEnv *env, jobject canvas, jobject component, jboolean flash)
{
	JAWT awt;
	JAWT_DrawingSurface* ds;
	JAWT_DrawingSurfaceInfo* dsi;
	JAWT_Win32DrawingSurfaceInfo* dsi_win;
	jboolean result;

	jint lock;

	// Get the AWT
	awt.version = JAWT_VERSION_1_3;
	result = JAWT_GetAWT(env, &awt);
	assert(result != JNI_FALSE);

	// Get the drawing surface
	ds = awt.GetDrawingSurface(env, component);
	if(ds == NULL)
		return;

	// Lock the drawing surface
	lock = ds->Lock(ds);
	assert((lock & JAWT_LOCK_ERROR) == 0);

	// Get the drawing surface info
	dsi = ds->GetDrawingSurfaceInfo(ds);

	// Get the platform-specific drawing info
	dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;

	FlashWindow(dsi_win->hwnd, flash);

	// Free the drawing surface info
	ds->FreeDrawingSurfaceInfo(dsi);
	// Unlock the drawing surface
	ds->Unlock(ds);
	// Free the drawing surface
	awt.FreeDrawingSurface(ds);
}

--------------------------------------------------------------
Here's my main java class:
public class Main {
    static JFrame f1, f2;
    
    public static void main(String[] args) {
        f1 = new JFrame("frame 1");
        f1.setBounds(20, 20, 400, 400);
        f2 = new JFrame("frame 2");
        f2.setBounds(50, 50, 400, 400);
        
        JButton butt = new JButton("Flash");
        f1.getContentPane().add(butt);
        
        butt.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                WindowUtil wu = new WindowUtil();
                wu.flash(f2, 500, 500, 10);
            }
        });
        
        f1.show();
        f2.show();
    }
}

--------------------------------------------------------------
Here's my WindowUtil class:
public class WindowUtil extends Canvas {
    static { System.load("C:\\docs\\flash\\WinUtil.dll"); }
    public native void flashInTaskBar(Component c, boolean flash);
    
    public void flash(final JFrame frame, final int intratime, final int intertime, final int count) {
        new Thread(new Runnable() {
            public void run() {
                try {
                    // flash on and off each time
                    for(int i=0; i<count; i++) {
                        flashInTaskBar(frame,true);
                        Thread.sleep(intratime);
                        flashInTaskBar(frame,true);
                        Thread.sleep(intertime);
                    }
                    // turn the flash off
                    flashInTaskBar(frame,false);
                } catch (Exception ex) {
                    System.out.println(ex.getMessage());
                }
        }}).start();
    }    
}

--------------------------------------------------------------
I've tried this on both Win2k and WinXP and get the same behaviour. Thanks in advance for any help! :)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2004
Added on Jul 15 2004
2 comments
224 views