// ToDo: Changer le declenchement en mode auto: virer la ref. au screensaver // et monitorer directement les events clavier (et la charge CPU ?) // Affichage de XW stopped pas toujours correct... // long au demarrage // essayer de virer le passage par java pour Quit #define STRICT #define WIN32_LEAN_AND_MEAN #include #include #include #include #include #include "XWlaunchRes.h" #include "XWlaunch.h" // #ifdef XWSERVER // #define MAIN_CLASS "xtremweb/dispatcher/Dispatcher" // #define HC_CLASSPATH "../lib;xtremweb.jar;jcert.jar;jsse.jar,mm.mysql-2.0.2-bin.jar" // #define WNDCLASSNAME "XWServerWndClass" // #define WNDNAME "Xtremweb server" // #define CONFIG_FILE "./xtremweb.server.conf" // #endif #ifdef XWWORKER #define MAIN_CLASS "xtremweb/worker/Worker" #define HC_CLASSPATH "xtremweb.jar" #define WNDCLASSNAME "XWWorkerWndClass" #define WNDNAME "XWHEP worker" #define CONFIG_FILE "../conf/xtremweb.worker.conf" #define KEYSTORE "xwhepworker.keys" #endif #ifdef XWCLIENT #define MAIN_CLASS "xtremweb/client/Client" #define HC_CLASSPATH "xtremweb.jar" #define WNDCLASSNAME "XWClientWndClass" #define WNDNAME "XWHEP client" #define CONFIG_FILE "xtremweb.client.conf" #define KEYSTORE "xwhepclient.keys" #endif #ifndef MAIN_CLASS #error "Compile what? (use -DXWWORKER, or -DXWCLIENT, or -DXWSERVER)" #endif #define MAIN_METHOD "main" #define MAIN_METHOD_SIGNATURE "([Ljava/lang/String;)V" //#define JARFILE "XWDisp.jar;mm.mysql-2.0.2-bin.jar" // // local variables // static HINSTANCE hInstance; static HWND hScrWindow; static HMENU popupMenu = NULL; static NOTIFYICONDATA XWDispNid; static HICON XWDispIcon; static char XWstate[200]; typedef int (CALLBACK *FCTX)(JavaVM **pvm, JNIEnv **env, void *args); static FCTX ifn = NULL; // **************************************************************************** static void xwExit(int code) { // Shell_NotifyIcon (NIM_DELETE,&XWDispNid); DestroyWindow (hScrWindow); exit (code); } // ------------------------------------------------ // Handler // // Console Control Handler // // Ignore all attempts to shutdown the application. // // Arguments: // // dwCtrlType - control event type // // Return: // // TRUE (ignore event) // ------------------------------------------------ BOOL Handler (DWORD dwCtrlType) { return TRUE; } // **************************************************************************** static LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { switch (msg) { case WM_CREATE: return 0; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; case XW_ICONNOTIFY: //click icon in status area if (lParam==WM_RBUTTONDOWN) { if (popupMenu != NULL) return 0; popupMenu = CreatePopupMenu (); if (popupMenu == NULL) return 0; MENUITEMINFO menuItem; POINT pos; menuItem.cbSize = sizeof (MENUITEMINFO); menuItem.fMask = MIIM_DATA | MIIM_TYPE | MIIM_ID | MIIM_STATE; menuItem.fType = MFT_STRING; menuItem.fState = MFS_DEFAULT; menuItem.wID = IDQUIT; menuItem.hSubMenu = NULL; menuItem.hbmpChecked = NULL; menuItem.hbmpUnchecked = NULL; menuItem.dwItemData = 0; menuItem.dwTypeData = "Quit"; menuItem.cch = 4; InsertMenuItem (popupMenu, 0, TRUE, &menuItem); GetCursorPos (&pos); int cmd; cmd = (int)TrackPopupMenuEx(popupMenu, TPM_RETURNCMD, pos.x, pos.y, hScrWindow, NULL); DestroyMenu (popupMenu); popupMenu = NULL; switch (cmd) { case 0: /* char errStr[30]; sprintf (errStr, "cant track popup : %li", (long)GetLastError()); MessageBox(0, errStr, WNDNAME, MB_OK | MB_ICONWARNING); break; */ case IDQUIT: xwExit (0); } } break; default: return DefWindowProc(hwnd,msg,wParam,lParam); } // switch (msg) return 0; } //WindowProc() // **************************************************************************** void NidCreate() { XWDispIcon=(HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_XWD),IMAGE_ICON,16,16,0); XWDispNid.cbSize=sizeof(NOTIFYICONDATA); XWDispNid.hWnd=hScrWindow; XWDispNid.uID=1234; XWDispNid.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP; XWDispNid.uCallbackMessage=XW_ICONNOTIFY; XWDispNid.hIcon=XWDispIcon; lstrcpy(XWDispNid.szTip, WNDNAME); } //NidCreate() // **************************************************************************** #define MAX_KEY_LENGTH 255 #define MAX_VALUE_NAME 16383 TCHAR* findLastSubKey(HKEY hKey) { static TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name DWORD cbName; // size of name string TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name DWORD cchClassName = MAX_PATH; // size of class string DWORD cSubKeys=0; // number of subkeys DWORD cbMaxSubKey; // longest subkey size DWORD cchMaxClass; // longest class string DWORD cValues; // number of values for key DWORD cchMaxValue; // longest value name DWORD cbMaxValueData; // longest value data DWORD cbSecurityDescriptor; // size of security descriptor DWORD dwType = REG_SZ; FILETIME ftLastWriteTime; // last write time DWORD i, retCode; TCHAR achValue[MAX_VALUE_NAME]; DWORD cchValue = MAX_VALUE_NAME; // Get the class name and the value count. retCode = RegQueryInfoKey( hKey, // key handle achClass, // buffer for class name &cchClassName, // size of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time // Enumerate the subkeys, until RegEnumKeyEx fails. if (cSubKeys) { for (i=0; iNewObjectArray(2, env->FindClass("java/lang/String"), env->NewStringUTF ("")); if (str_array == NULL) { MessageBox(0, "Insufficient memory", "XWHEP error", MB_OK | MB_ICONWARNING); goto main1; } // For each command-line argument ... if ((jstr0 = env->NewStringUTF("--xwgui")) == 0) { MessageBox(0, "Can not allocate arguments", "XWHEP error", MB_OK | MB_ICONWARNING); goto main1; } // wsprintf (buffer2, "--xwconfig=%s", CONFIG_FILE); if ((jstr1 = env->NewStringUTF("--xwconfig=xtremweb.client.conf")) == 0) { MessageBox(0, "Can not allocate arguments", "XWHEP error", MB_OK | MB_ICONWARNING); goto main1; } env->SetObjectArrayElement(str_array, 0, jstr0); env->SetObjectArrayElement(str_array, 1, jstr1); if ((clazz = env->FindClass (MAIN_CLASS)) == 0) { MessageBox(0, "Can not locate java class", "XWHEP error", MB_OK | MB_ICONWARNING); goto main1; } // Attempt to locate the te class's main method. if ((mid = env->GetStaticMethodID(clazz, "main", "([Ljava/lang/String;)V")) == 0) { MessageBox(0, "Can not locate main method", "XWHEP error", MB_OK | MB_ICONWARNING); goto main1; } // Launch the main method. env->CallStaticVoidMethod(clazz, mid, str_array); // Check for and display any exception that may have been thrown. if (env->ExceptionOccurred()) { env->ExceptionDescribe(); goto main1; } // Attempt to detach the main thread from the JVM, so that this thread // will appear to have exited when the Java application's main method // terminates. All Java monitors held by this thread are released. All // Java threads waiting for this thread to die are notified. if (jvm->DetachCurrentThread() != 0) MessageBox(0, "Could not detach the main thread from the JVM", "XWHEP error", MB_OK | MB_ICONWARNING); main1: // Destroy the JVM instance. jvm->DestroyJavaVM(); main2: // Release the loaded JVM. FreeLibrary (hinstance); xwExit (0); } // RunJVM() // **************************************************************************** int WINAPI WinMain(HINSTANCE h,HINSTANCE,LPSTR,int) { DWORD ThreadID; HANDLE hThread; WNDCLASS wc; hInstance=h; wc.style = 0; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = WNDCLASSNAME; //are we alone ? if (FindWindow (WNDCLASSNAME, WNDNAME) != NULL) { MessageBox (0, "Already started", WNDNAME, MB_OK | MB_ICONWARNING); xwExit (1); } //create main window RegisterClass(&wc); lstrcpy(XWstate,"Initializing"); hScrWindow = CreateWindow(WNDCLASSNAME, WNDNAME, WS_SYSMENU, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); if (hScrWindow==NULL) { MessageBox (0, "Can't create window", WNDNAME, MB_OK | MB_ICONWARNING); xwExit (1); } //Boot JVM in a new Thread hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)RunJVM,NULL,0,&ThreadID); if (hThread==NULL) { MessageBox (0, "Can't create JVM thread", WNDNAME, MB_OK | MB_ICONWARNING); xwExit (1); } //load resources // NidCreate(); //Shell_NotifyIcon(NIM_ADD,&XWDispNid); //msg loop... MSG msg; while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; } //WinMain ()