How to access About, Preferences and Quit menus on carbon : WIN32 « SWT JFace Eclipse « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » SWT JFace Eclipse » WIN32Screenshots 
How to access About, Preferences and Quit menus on carbon


/*******************************************************************************
 * Copyright (c) 2000, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.snippets;

/*
 * How to access About, Preferences and Quit menus on carbon.
 * NOTE: This snippet uses internal SWT packages that are
 * subject to change without notice.
 
 * For a list of all SWT example snippets see
 * http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/dev.html#snippets
 */

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.carbon.*;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class Snippet178 {

  private static final int kHICommandPreferences = ('p' << 24('r' << 16)
      ('e' << 8'f';

  private static final int kHICommandAbout = ('a' << 24('b' << 16)
      ('o' << 8'u';

  private static final int kHICommandServices = ('s' << 24('e' << 16)
      ('r' << 8'v';

public static void main(String[] arg) {
  Display.setAppName("AppMenu")// sets name in Dock
  Display display = new Display();
  hookApplicationMenu(display, "About AppMenu");
  Shell shell = new Shell(display);
  shell.setText("Main Window");
  shell.open();
  while (!shell.isDisposed())
    if (!display.readAndDispatch())
      display.sleep();

  display.dispose();
}

static void hookApplicationMenu(Display display, final String aboutName) {
  // Callback target
  Object target = new Object() {
    int commandProc(int nextHandler, int theEvent, int userData) {
      if (OS.GetEventKind(theEvent== OS.kEventProcessCommand) {
        HICommand command = new HICommand();
        OS.GetEventParameter(theEvent, OS.kEventParamDirectObject,
            OS.typeHICommand, null, HICommand.sizeof, null,
            command);
        switch (command.commandID) {
        case kHICommandPreferences:
          return handleCommand("Preferences")//$NON-NLS-1$
        case kHICommandAbout:
          return handleCommand(aboutName);
        default:
          break;
        }
      }
      return OS.eventNotHandledErr;
    }

    int handleCommand(String command) {
      Shell shell = new Shell();
      MessageBox preferences = new MessageBox(shell, SWT.ICON_WARNING);
      preferences.setText(command);
      preferences.open();
      shell.dispose();
      return OS.noErr;
    }
  };

  final Callback commandCallback = new Callback(target, "commandProc"3)//$NON-NLS-1$
  int commandProc = commandCallback.getAddress();
  if (commandProc == 0) {
    commandCallback.dispose();
    return// give up
  }

  // Install event handler for commands
  int[] mask = new int[] { OS.kEventClassCommand, OS.kEventProcessCommand };
  OS.InstallEventHandler(OS.GetApplicationEventTarget(), commandProc,
      mask.length / 2, mask, 0null);

  // create About ... menu command
  int[] outMenu = new int[1];
  short[] outIndex = new short[1];
  if (OS.GetIndMenuItemWithCommandID(0, kHICommandPreferences, 1,
      outMenu, outIndex== OS.noErr
      && outMenu[0!= 0) {
    int menu = outMenu[0];

    int l = aboutName.length();
    char buffer[] new char[l];
    aboutName.getChars(0, l, buffer, 0);
    int str = OS.CFStringCreateWithCharacters(OS.kCFAllocatorDefault,
        buffer, l);
    OS.InsertMenuItemTextWithCFString(menu, str, (short00,
        kHICommandAbout);
    OS.CFRelease(str);

    // add separator between About & Preferences
    OS.InsertMenuItemTextWithCFString(menu, 0(short1,
        OS.kMenuItemAttrSeparator, 0);

    // enable pref menu
    OS.EnableMenuCommand(menu, kHICommandPreferences);

    // disable services menu
    OS.DisableMenuCommand(menu, kHICommandServices);
  }

  // schedule disposal of callback object
  display.disposeExec(new Runnable() {
    public void run() {
      commandCallback.dispose();
    }
  });
}
}

           
       
Related examples in the same category
1. Invoke the system text editor on autoexec.bat
2. Place an icon with a popup menu on the system trayPlace an icon with a popup menu on the system tray
3. SWT Ole FrameSWT Ole Frame
4. OLE and ActiveX example snippet
5. Word OLEWord OLE
6. Invoke an external batch fileInvoke an external batch file
7. Find the icon of the program that edits .bmp filesFind the icon of the program that edits .bmp files
8. Running a script within IE.Running a script within IE.
9. Reading and writing to a SAFEARRAY
10. Embed Word in an applet
11. OLE and ActiveX example: browse the typelibinfo for a program id
12. OLE and ActiveX example: get events from IE controlOLE and ActiveX example: get events from IE control
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.