⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systray4j.cpp

📁 这是linux下ssl vpn的实现程序
💻 CPP
字号:
/*********************************************************************************
                                   systray4j.cpp
                                   -------------
    author               : Tamas Bara
    copyright            : (C) 2002-2004 by SnoozeSoft
    email                : snoozesoft@compuserve.de
 *********************************************************************************/

/*********************************************************************************
 *                                                                               *
 *   This library is free software; you can redistribute it and/or               *
 *   modify it under the terms of the GNU Lesser General Public                  *
 *   License as published by the Free Software Foundation; either                *
 *   version 2.1 of the License, or (at your option) any later version.          *
 *                                                                               *
 *   This library is distributed in the hope that it will be useful,             *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of              *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           *
 *   Lesser General Public License for more details.                             *
 *                                                                               *
 *   You should have received a copy of the GNU Lesser General Public            *
 *   License along with this library; if not, write to the Free Software         *
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   *
 *                                                                               *
 *********************************************************************************/

#include "stdafx.h"
#include "systray4j.h"
#include "systraymanager.h"

static HINSTANCE g_instance = 0;

// entry and exit point
BOOL APIENTRY DllMain( HINSTANCE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved )
{
    if( ul_reason_for_call == DLL_PROCESS_ATTACH ) g_instance = hModule;
    else if( ul_reason_for_call == DLL_PROCESS_DETACH ) SysTrayManager::destroy();

    return TRUE;
}

// initialize manager
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_initNative( JNIEnv* pEnv,
                                                   jobject obj,
                                                   jstring version )
{
    jboolean isCopy;
    LPCWSTR jarVersion = pEnv->GetStringChars( version, &isCopy );
    SysTrayManager::init( g_instance, pEnv, jarVersion ); 
    pEnv->ReleaseStringChars( version, jarVersion );
}

// add a new icon to the system tray, create the associated menu and return
// the its id
JNIEXPORT jint JNICALL
Java_snoozesoft_systray4j_NativeSysTray_addMainMenuNative( JNIEnv* pEnv,
                                                          jobject obj,
                                                          jobject menuObj,
                                                          jstring iconFileName,
                                                          jstring toolTip )
{
    jboolean isCopy;

    // extract the tooltip and the file name
    LPCWSTR tip = pEnv->GetStringChars( toolTip, &isCopy );
    LPCWSTR fileName = pEnv->GetStringChars( iconFileName, &isCopy );

    // pass all data to the manager and receive the assigned menu id
    UINT id = SysTrayManager::addMainMenu( menuObj, fileName, tip );

    // clean up
    pEnv->ReleaseStringChars( iconFileName, fileName );
    pEnv->ReleaseStringChars( toolTip, tip );

    return id;
}

// create a new submenu and return its id 
JNIEXPORT jint JNICALL
Java_snoozesoft_systray4j_NativeSysTray_addSubMenuNative( JNIEnv* pEnv,
                                                         jobject obj,
                                                         jobject menuObj )
{
    // pass the menu object and receive the assigned menu id
    UINT id = SysTrayManager::addSubMenu( menuObj );

    return id;
}

// change the tooltip displayed over the icon
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_setToolTipNative( JNIEnv* pEnv,
                                                         jobject obj,
                                                         jint menuId,
                                                         jstring toolTip )
{
    jboolean isCopy;
    LPCWSTR tip = pEnv->GetStringChars( toolTip, &isCopy );

    SysTrayManager::setToolTip( menuId, tip ); 
    
    pEnv->ReleaseStringChars( toolTip, tip );
}

// show/hide the icon in the system tray
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_showIconNative( JNIEnv* pEnv,
                                                       jobject obj,
                                                       jint menuId,
                                                       jboolean show )
{
    SysTrayManager::showIcon( menuId, show );
}

// change the icon shown in the system tray
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_setIconNative( JNIEnv* pEnv,
                                                      jobject obj,
                                                      jint menuId,
                                                      jstring iconFileName )
{
    jboolean isCopy;
    LPCWSTR fileName = pEnv->GetStringChars( iconFileName, &isCopy );
    SysTrayManager::setIcon( menuId, fileName ); 
    pEnv->ReleaseStringChars( iconFileName, fileName );
}

// enable/disable an item
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_enableItemNative( JNIEnv* pEnv,
                                                         jobject obj,
                                                         jint menuId,
                                                         jint itemIndex,
                                                         jboolean enable )
{
    SysTrayManager::enableItem( menuId, itemIndex, enable );
}

// check/uncheck an item
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_checkItemNative( JNIEnv* pEnv,
                                                        jobject obj,
                                                        jint menuId,
                                                        jint itemIndex,
                                                        jboolean check )
{
    SysTrayManager::checkItem( menuId, itemIndex, check );
}

// change the label of the specified item
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_setItemLabelNative( JNIEnv* pEnv,
                                                          jobject obj,
                                                          jint menuId,
                                                          jint itemIndex,
                                                          jstring itemLabel )
{
    jboolean isCopy;
    LPCWSTR label = pEnv->GetStringChars( itemLabel, &isCopy );

    SysTrayManager::setItemLabel( menuId, itemIndex, label );

    pEnv->ReleaseStringChars( itemLabel, label );
}

// insert an item to the menu at the specified position
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_addItemNative( JNIEnv* pEnv,
                                                      jobject obj,
                                                      jint menuId,
                                                      jint itemIndex,
                                                      jstring itemLabel,
                                                      jboolean checkable,
                                                      jboolean checked,
                                                      jboolean enabled )
{
    jboolean isCopy;
    LPCWSTR label = pEnv->GetStringChars( itemLabel, &isCopy );

    SysTrayManager::addItem( menuId, itemIndex, label, checkable, checked, enabled ); 
    
    pEnv->ReleaseStringChars( itemLabel, label );
}

// remove the specified item from the menu
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_removeItemNative( JNIEnv* pEnv,
                                                         jobject obj,
                                                         jint menuId,
                                                         jint itemIndex )
{
    SysTrayManager::removeItem( menuId, itemIndex );
}

// change the whole menu by replacing all items
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_removeAllNative( JNIEnv* pEnv,
                                                        jobject obj,
                                                        jint menuId )
{
    SysTrayManager::removeAll( menuId );
}

// detach our thread from the JVM
JNIEXPORT void JNICALL
Java_snoozesoft_systray4j_NativeSysTray_disposeNative( JNIEnv* pEnv, jobject obj )
{
    SysTrayManager::dispose();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -