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:

  • Hadoop Set Up on Ubuntu Linux (Single-Node Cluster)Running Hadoop on Ubuntu Linux (Single-Node Cluster) Hadoop is a framework written in Java, Incorporates features similar to those of the Google File System (GFS) and of the MapReduce computing paradigm. Hadoop’s HDFS is a… Read More
  • Elastic Search 2.x sample CRUD code What is ElasticSearch? Elasticsearch is an open-source, restful, distributed, search engine built on top of apache-lucene, Lucene is arguably the most advanced, high-performance, and fully featured search engine library i… Read More
  • Remove or Filter Stopping/Stemming words using java For the better indexing or searching the data in the big text chunk we need to filter the unwanted words from the data to get the better performance on the search by indexing only the logical words. What is Stopping Words?… Read More
  • error 10 cordova google plus login ionic Below are the reason for the error 10. Android key and web client id not used properly. Missing debug key in .android folder of windows system Missing SHA1 key in the fire base console. Apk not using the ge… Read More
  • guacd:"Error: Protocol Security Negotiation Failure"Guacamole server is unable to make rdp connection with windows system and guacd library will throw this exception because windows remote desktop setting is not enabled. Enable remote desktop setting: this will solve th… Read More

0 comments:

Post a Comment