Wednesday, March 3, 2010

Hide windows Task bar java JNI

See my previous post on javaJNI sample imlpementation for basic info.

Now how to hide the user menu in windows system, user functionalities are in user32.dll file of windows.

Hide task bar

1. write a java class for native method or dll loading

public class WindowLock {
   
    private native void HideTaskbarClick(boolean flag);
   
    static{
        System.loadLibrary("WindowLock");
    }
   
    public static void main(String[] args) {
       
        new WindowLock().HideTaskbarClick(true);
       
    }
}

2.  now compile this you will get a WindowLock .class file and generate .h(header file) for that class by using javah command

/* DO NOT EDIT THIS FILE - it is machine generated */
#include
/* Header for class WindowLock */

#ifndef _Included_WindowLock
#define _Included_WindowLock
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     WindowLock
 * Method:    HideTaskbarClick
 * Signature: (Z)V
 */
JNIEXPORT void JNICALL Java_WindowLock_HideTaskbarClick
  (JNIEnv *, jobject, jboolean);

#ifdef __cplusplus
}
#endif
#endif


3. Now you have a .h file use this to create a WindowLock.c file which is in form of c
it will look like this

 #define     WIN32_LEAN_AND_MEAN
 #define     _WIN32_WINNT 0x0400

 #include
 #include
 #include
 #include "WindowLock.h"

 #define     TASKBAR         "Shell_TrayWnd"        // Taskbar class name

  JNIEXPORT void JNICALL
  Java_WindowLock_HideTaskbarClick
  (JNIEnv *env, jobject obj, jboolean flag)
  {
    printf("Inside Task bar Lock ! \n");
    HWND    hWnd;

    hWnd = FindWindow(TASKBAR, NULL);

    ShowWindow(hWnd, flag ? SW_SHOW : SW_HIDE);
    UpdateWindow(hWnd);

  }



4.

Now the important step come in you need to download mingw software so that you can run gcc command

once you have this in place

you go to command prompt and follow these steps(depends upon where you install mingw)
C:\>Cd mingw\bin
C:\mingw\bin>

now you need to use following command to generate .o file(i show you how)

gcc -c -I"C:\program files\Java\jdk1.5.0\include" -I"C:\Program Files\Java\jdk1.5.0\include\win32" -o "C:\windowLock\WindowLock.o" "C:\windowLock\WindowLock.c"

you have to run this command on

C:\mingw\bin\>

this will create WindowLock.o file

-I"C:\program files\Java\jdk1.5.0\include" in this you need to mention your PATH of jdk in my case this is (C:\program files\Java\jdk1.5.0\include)

and in

-o "C:\windowLock\WindowLock.o"

you need to specify loc where you want to have this WindowLock.o file(You should include all the files in one directory in my case it is windowLock)

"C:\windowLock\WindowLock.c"

and this is the path of WindowLock.c file

After this you now have a .o file

5.
now you have to write WindowLock.def file like this

EXPORTS
Java_WindowLock_HideTaskbarClick

where WindowLock is the name of the class and _HideTaskbarClick is the native method name
save it in the same directory WindowLock in my case

now you have to create a new dll WindowLock.dll that will provide communication between java and other language

Use this command to generate a new dll

gcc -shared -o"C:\WindowLock\WindowLock.dll" "C:\WindowLock\WindowLock.o" "C:\WindowLock\WindowLock.def"

it will greate the new dll WindowLock.dll overwrite the previous one

6.  now run WindowLock.java class with parameter true/false to hide/show task bar ...

Window Lock Source Code 

Related Posts:

  • RESTful Web Service What Are RESTful Web Services? Representational State Transfer (REST) is an architectural style that specifies constraints, such as the uniform interface, that if applied to a web service induce desirable properties, such as… Read More
  • ClientAbortException Generally, you can just ignore it. This exception will be thrown when the client has abruptly aborted the HTTP request while the page is still loading or continuous requesting/clicking. This will occur when the client pres… Read More
  • Search Engine Optimization (SEO) Lot of time we come cross search engine (Google) results, wonder how search engine pull this information, here our idea is how to make our domain to be recognized by search engine, what we have to follow, its not like every … Read More
  • Hadoop ? What is Hadoop? Hadoop is a free, Java-based programming framework that supports the processing of large data sets in a distributed computing environment. It is part of the Apache project sponsored by the Apache Software Fo… Read More
  • Refactor package change on whole project (JAVA) or Change package/import of whole project Some times in our application development we will come across situation like changing the package structure of the project. As all classes present in the project are having the old package and import statement declaration, w… Read More

0 comments:

Post a Comment