Proposed Extra Methods for User32.java

Richard Peters <[email protected]> Wed, 27 Jul 2005 19:32:33 -0400
Newsgroups gmane.comp.windows.devel.jawin
Message-ID <LISTSERV%[email protected]>
I have been using Jawin for the last couple of weeks and have a suggestion
for extra functionality to be added to the org.jawin.donated.win32.User32
class.

The extra functionality allow for the following
  a opened window to be bought to the foreground (setForegroundWindow).
  a opened window to have the close button disabled.

However at the moment the line of code
enableMenuItem.invoke("III:I", 12, nbs, null, ReturnFlags.CHECK_NONE);
allways throws an exception and I don't know why, BUT the close button in
the opened window is disabled.

Functions as follows:

public static void setForegroundWindow(int windowHandle) throws
COMException {
   new FuncPtr("USER32.DLL", "SetForegroundWindow").invoke_I(windowHandle,
ReturnFlags.CHECK_NONE);
}


public static void disableCloseButtonOnWindow(int windowHandle) throws
COMException, IOException {
   FuncPtr getSystemMenu = new FuncPtr("USER32.DLL", "GetSystemMenu");
   FuncPtr enableMenuItem = new FuncPtr("USER32.DLL", "EnableMenuItem");

   // for the windows handle for IE obtain the GetSystemMenu
   int menuHndle = getSystemMenu.invoke_I(windowHandle, 0,
ReturnFlags.CHECK_HRESULT);

   // create a NakedByteStream for the serialization of Java variables
   // wrap it in a LittleEndianOutputStream
   // and then write the Java arguments
   NakedByteStream nbs = new NakedByteStream();
   LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
   leos.writeInt(menuHndle);
   leos.writeInt(61536);
   leos.writeInt(1);

   // call the generic invoke, with the NakedByteStream
   // and parameters describing how to deserialize the
   // NakedByteStream byte-array on the native side
   try {
      enableMenuItem.invoke("III:I", 12, nbs, null, ReturnFlags.CHECK_NONE);
   } catch (COMException e) {
      //ignore
   }
}