Posts

Showing posts from 2011

Adding shortcut menu in the Windows Start menu

In relation to the previous article the simplest way to add a shortcut menu in the Windows Start menu is to add the shortcut menu into the similar folder below.. C:\Documents and Settings\earl\Start Menu\Programs\ That's it! =)

Adding desktop shortcut programmtically in Windows

I was tinkering of how I can put a desktop shortcut of my program and I thought this is one of those things I still have to learn. So, I wander into the internet to find a most simple example and read lots of articles and discussion and somehow I find it daunting to read all those codes where all I want is to create a simple desktop shortcut. After a lot of reading and experimentation I finally have the code below. #include<windows.h> #include<shlobj.h>  int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {     createShortcut();     return 0; } void createShortcut() {     HRESULT hr;     ::CoInitialize(NULL); IShellLink *pShellLink; hr = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_ALL,IID_IShellLink, (void**)&pShellLink); hr = pShellLink->SetPath("C:\\MyProjects\\OCXTest\\Debug\\OCXTest.exe");  // Path to the object we are referring to hr = pShellLink->SetDescription("This is a test!!&q

How to asynchronously update GUI in Java

Image
There are times an application needs to display feedback to the user that certain activity is going on like status of a progress perhaps. In Java an application cannot update the GUI asynchronously while you're also processing using the same thread. What normally happens is that your GUI will be updated only after the processing have completed which is not we want. So, to do what we want we need to use only the main application thread for GUI update while we will create a separate thread for processing in that way the GUI is updated asynchronously. Sample Code: public class ProgressDialog extends javax.swing.JDialog{     public ProgressDialog(java.awt.Frame parent, boolean modal) {         super(parent, modal);         initComponents();         worker = new Worker();     } private void StartActionPerformed(java.awt.event.ActionEvent evt) {         if(Start.getText().equals("Start"))         {             worker.Start();             Start.setText("St

Using javah to create JNI interfaces

There are times that you will need to interface with the underlying operating system APIs or you have a dynamic link libraries that needs to be called from Java. It can be done using JNI using the javah tool. First, you will need to create a java class that expose interfaces that you will implement in C. ////////////////////////////////// MyJavaInterfaces.java //////////////////////////////////// public class MyJavaInterfaces{     public MyJavaInterfaces(){     }     public native int MyFunction();     static{         System.loadLibrary("MyNativeInterfaces");     } } ////////////////////////////////////////////////////////////////////////////////////////////////////////// The declaration, public native int MyFunction(); is the native function that needs to be implemented in C. The call, System.loadLibrary("MyNativeInterfaces"); is the library that you will create and in it is your native function implementation. So, after creating your java class