示例#1
0
// Entry point
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
	g_hinst = hInst;

	// Look for previous instance
	HWND previnst = FindWindow(APP_NAME, NULL);
	if (previnst != NULL) {
		SendMessage(previnst, WM_COMMAND, SWM_FIND, 0);
		return 0;
	}

	// Create window
	WNDCLASSEX wnd = {sizeof(WNDCLASSEX), 0, WindowProc, 0, 0, hInst, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL, APP_NAME, NULL};
	wnd.hCursor = LoadImage(hInst, L"find", IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);
	RegisterClassEx(&wnd);
	g_hwnd = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_EX_LAYERED, wnd.lpszClassName, APP_NAME, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
	SetLayeredWindowAttributes(g_hwnd, 0, 1, LWA_ALPHA); // Almost transparent

	// Tray icon
	InitTray();
	UpdateTray();

	// Hook mouse
	if ((GetAsyncKeyState(VK_SHIFT)&0x8000)) {
		HookMouse();
	}

	// Message loop
	MSG msg;
	while (GetMessage(&msg,NULL,0,0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
示例#2
0
void InitTrayWindow(TrayWindow *trayWindow)
{
    FcitxClassicUI *classicui = trayWindow->owner;
    Display *dpy = classicui->dpy;
    int iScreen = classicui->iScreen;
    char   strWindowName[] = "Fcitx Tray Window";
    if (!classicui->bUseTrayIcon || classicui->isSuspend)
        return;

    InitTray(dpy, trayWindow);

    XVisualInfo* vi = TrayGetVisual(dpy, trayWindow);
    if (vi && vi->visual) {
        Window p = DefaultRootWindow(dpy);
        Colormap colormap = XCreateColormap(dpy, p, vi->visual, AllocNone);
        XSetWindowAttributes wsa;
        wsa.background_pixmap = 0;
        wsa.colormap = colormap;
        wsa.background_pixel = 0;
        wsa.border_pixel = 0;
        trayWindow->window = XCreateWindow(dpy, p, -1, -1, 1, 1,
                                           0, vi->depth, InputOutput, vi->visual,
                                           CWBackPixmap | CWBackPixel | CWBorderPixel | CWColormap, &wsa);
    } else {
        trayWindow->window = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
                             -1, -1, 1, 1, 0,
                             BlackPixel(dpy, DefaultScreen(dpy)),
                             WhitePixel(dpy, DefaultScreen(dpy)));
        XSetWindowBackgroundPixmap(dpy, trayWindow->window, ParentRelative);
    }
    if (trayWindow->window == (Window) NULL)
        return;

    XSizeHints size_hints;
    size_hints.flags = PWinGravity | PBaseSize;
    size_hints.base_width = trayWindow->size;
    size_hints.base_height = trayWindow->size;
    XSetWMNormalHints(dpy, trayWindow->window, &size_hints);

    if (vi && vi->visual)
        trayWindow->cs_x = cairo_xlib_surface_create(dpy, trayWindow->window, trayWindow->visual.visual, 200, 200);
    else {
        Visual *target_visual = DefaultVisual(dpy, iScreen);
        trayWindow->cs_x = cairo_xlib_surface_create(dpy, trayWindow->window, target_visual, 200, 200);
    }
    trayWindow->cs = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);

    XSelectInput(dpy, trayWindow->window, ExposureMask | KeyPressMask |
                 ButtonPressMask | ButtonReleaseMask | StructureNotifyMask
                 | EnterWindowMask | PointerMotionMask | LeaveWindowMask | VisibilityChangeMask);

    ClassicUISetWindowProperty(classicui, trayWindow->window, FCITX_WINDOW_DOCK, strWindowName);

    TrayFindDock(dpy, trayWindow);
}
示例#3
0
HRESULT  CluiLoadModule()
{
	CreateServiceFunction(MS_CLUI_GETCAPS,CLUIGetCapsService);

	InitDisplayNameCache();
	hookSystemShutdown_CListMod  = ModernHookEvent(ME_SYSTEM_SHUTDOWN,CListMod_ContactListShutdownProc);
	hookOptInitialise_CList      = ModernHookEvent(ME_OPT_INITIALISE,CListOptInit);
	hookOptInitialise_Skin       = ModernHookEvent(ME_OPT_INITIALISE,SkinOptInit);

	CreateServiceFunction("ModernSkinSel/Active", SvcActiveSkin);
	CreateServiceFunction("ModernSkinSel/Preview", SvcPreviewSkin);
	CreateServiceFunction("ModernSkinSel/Apply", SvcApplySkin);
	
	hookContactAdded_CListSettings = ModernHookEvent(ME_DB_CONTACT_ADDED,ContactAdded);	
	CreateServiceFunction(MS_CLIST_TRAYICONPROCESSMESSAGE,cli_TrayIconProcessMessage);
	CreateServiceFunction(MS_CLIST_PAUSEAUTOHIDE,TrayIconPauseAutoHide);
	CreateServiceFunction(MS_CLIST_CONTACTCHANGEGROUP,ContactChangeGroup);
	CreateServiceFunction(MS_CLIST_TOGGLEHIDEOFFLINE,ToggleHideOffline);

	CreateServiceFunction(MS_CLIST_TOGGLEGROUPS,ToggleGroups);
	CreateServiceFunction(MS_CLIST_TOGGLESOUNDS,ToggleSounds);
	CreateServiceFunction(MS_CLIST_SETUSEGROUPS,SetUseGroups);


	CreateServiceFunction(MS_CLIST_GETCONTACTICON,GetContactIcon);

	MySetProcessWorkingSetSize=(BOOL (WINAPI*)(HANDLE,SIZE_T,SIZE_T))GetProcAddress(GetModuleHandle(TEXT("kernel32")),"SetProcessWorkingSetSize");
	hCListImages = ImageList_Create(16, 16, ILC_MASK|ILC_COLOR32, 32, 0);
	InitCustomMenus();
	InitTray();
	{
		HINSTANCE hUser = GetModuleHandleA("USER32");
		MyMonitorFromPoint  = ( pfnMyMonitorFromPoint )GetProcAddress( hUser,"MonitorFromPoint" );
		MyMonitorFromWindow = ( pfnMyMonitorFromWindow )GetProcAddress( hUser, "MonitorFromWindow" );
		#if defined( _UNICODE )
			MyGetMonitorInfo = ( pfnMyGetMonitorInfo )GetProcAddress( hUser, "GetMonitorInfoW");
		#else
			MyGetMonitorInfo = ( pfnMyGetMonitorInfo )GetProcAddress( hUser, "GetMonitorInfoA");
		#endif
	}
	CLUI::InitClui();
	
	return S_OK;
}
示例#4
0
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
	_In_opt_ HINSTANCE hPrevInstance,
	_In_ LPTSTR    lpCmdLine,
	_In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	// TODO: 在此放置代码。
	MSG msg;
	HACCEL hAccelTable;

	// 初始化全局字符串
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_SCREENSHOT, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// 执行应用程序初始化:
	if (!InitInstance(hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_SCREENSHOT));

	InitTray(hInstance, hWnd);			//实例化托盘 
	SetTimer(hWnd, 3, 1000, NULL);		//定时发消息,演示气泡提示功能 




	// 主消息循环:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int)msg.wParam;
}
示例#5
0
int LoadContactListModule(void)
{
	/*	HANDLE hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDFIRST, 0, 0);
	while (hContact!=NULL) {
	DBWriteContactSettingString(hContact, "CList", "StatusMsg", "");
	hContact = (HANDLE) CallService(MS_DB_CONTACT_FINDNEXT, (WPARAM) hContact, 0);
	}
	*/
	HookEvent(ME_SYSTEM_SHUTDOWN,ContactListShutdownProc);
	HookEvent(ME_SYSTEM_MODULESLOADED,ContactListModulesLoaded);
	HookEvent(ME_OPT_INITIALISE,CListOptInit);
	HookEvent(ME_OPT_INITIALISE,SkinOptInit);
	hSettingChanged=HookEvent(ME_DB_CONTACT_SETTINGCHANGED,ContactSettingChanged);
	HookEvent(ME_DB_CONTACT_ADDED,ContactAdded);
	HookEvent(ME_DB_CONTACT_DELETED,ContactDeleted);
	hProtoAckHook=(HANDLE)HookEvent(ME_PROTO_ACK,ProtocolAck);
	hContactDoubleClicked=CreateHookableEvent(ME_CLIST_DOUBLECLICKED);
	hStatusModeChangeEvent=CreateHookableEvent(ME_CLIST_STATUSMODECHANGE);
	hContactIconChangedEvent=CreateHookableEvent(ME_CLIST_CONTACTICONCHANGED);
	CreateServiceFunction(MS_CLIST_CONTACTDOUBLECLICKED,ContactDoubleClicked);
	CreateServiceFunction(MS_CLIST_CONTACTFILESDROPPED,ContactFilesDropped);
	CreateServiceFunction(MS_CLIST_SETSTATUSMODE,SetStatusMode);
	CreateServiceFunction(MS_CLIST_GETSTATUSMODE,GetStatusMode);
	CreateServiceFunction(MS_CLIST_GETSTATUSMODEDESCRIPTION,GetStatusModeDescription);
	CreateServiceFunction(MS_CLIST_GETCONTACTDISPLAYNAME,GetContactDisplayName);
	CreateServiceFunction(MS_CLIST_INVALIDATEDISPLAYNAME,InvalidateDisplayName);
	CreateServiceFunction(MS_CLIST_TRAYICONPROCESSMESSAGE,TrayIconProcessMessage);
	CreateServiceFunction(MS_CLIST_PAUSEAUTOHIDE,TrayIconPauseAutoHide);
	CreateServiceFunction(MS_CLIST_CONTACTSCOMPARE,CompareContacts);
	CreateServiceFunction(MS_CLIST_CONTACTCHANGEGROUP,ContactChangeGroup);
	CreateServiceFunction(MS_CLIST_SHOWHIDE,ShowHide);
	CreateServiceFunction(MS_CLIST_SETHIDEOFFLINE,SetHideOffline);
	CreateServiceFunction(MS_CLIST_TOGGLEHIDEOFFLINE,ToggleHideOffline);

	CreateServiceFunction(MS_CLIST_DOCKINGPROCESSMESSAGE,Docking_ProcessWindowMessage);
	CreateServiceFunction(MS_CLIST_DOCKINGISDOCKED,Docking_IsDocked);
	CreateServiceFunction(MS_CLIST_HOTKEYSPROCESSMESSAGE,HotkeysProcessMessage);
	CreateServiceFunction(MS_CLIST_GETCONTACTICON,GetContactIcon);
	MySetProcessWorkingSetSize=(BOOL (WINAPI*)(HANDLE,SIZE_T,SIZE_T))GetProcAddress(GetModuleHandle(TEXT("kernel32")),"SetProcessWorkingSetSize");
	hCListImages = ImageList_Create(16, 16, ILC_MASK|ILC_COLOR32, 32, 0);

	InitDisplayNameCache(&lContactsCache);
	InitCListEvents();
	InitCustomMenus();
	InitGroupServices();	
	InitTray();

	{	CLISTMENUITEM mi;
	ZeroMemory(&mi,sizeof(mi));
	mi.cbSize=sizeof(mi);
	CreateServiceFunction("CList/DeleteContactCommand",MenuItem_DeleteContact);
	mi.position=2000070000;
	mi.flags=0;
	mi.hIcon=LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_DELETE));
	mi.pszContactOwner=NULL;    //on every contact
	mi.pszName=Translate("De&lete");
	mi.pszService="CList/DeleteContactCommand";
	CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi);
	CreateServiceFunction("CList/AddToListContactCommand",MenuItem_AddContactToList);
	mi.position=-2050000000;
	mi.flags=CMIF_NOTONLIST;
	mi.hIcon=LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ADDCONTACT));
	mi.pszName=Translate("&Add permanently to list");
	mi.pszService="CList/AddToListContactCommand";
	CallService(MS_CLIST_ADDCONTACTMENUITEM,0,(LPARAM)&mi);
	}


	HookEvent(ME_SKIN_ICONSCHANGED,CListIconsChanged);
	CreateServiceFunction(MS_CLIST_GETICONSIMAGELIST,GetIconsImageList);
	ImageList_AddIcon(hCListImages, LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_BLANK)));
	{	int i;
	for(i=0;i<sizeof(statusModeList)/sizeof(statusModeList[0]);i++)
		ImageList_AddIcon(hCListImages, LoadSkinnedIcon(skinIconStatusList[i]));
	}
	//see IMAGE_GROUP... in clist.h if you add more images above here
	ImageList_AddIcon(hCListImages, LoadSkinnedIcon(SKINICON_OTHER_GROUPOPEN));
	ImageList_AddIcon(hCListImages, LoadSkinnedIcon(SKINICON_OTHER_GROUPSHUT));

	//InitGroupMenus();

	return 0;
}
示例#6
0
// Entry point
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow) {
  g_hinst = hInst;

  // Get ini path
  GetModuleFileName(NULL, inipath, ARRAY_SIZE(inipath));
  PathRemoveFileSpec(inipath);
  wcscat(inipath, L"\\"APP_NAME".ini");
  wchar_t txt[10];

  // Convert szCmdLine to argv and argc (max 10 arguments)
  char *argv[10];
  int argc = 1;
  argv[0] = szCmdLine;
  while ((argv[argc]=strchr(argv[argc-1],' ')) != NULL) {
    *argv[argc] = '\0';
    if (argc == ARRAY_SIZE(argv)) break;
    argv[argc++]++;
  }

  // Check arguments
  int i;
  int elevate=0;
  for (i=0; i < argc; i++) {
    if (!strcmp(argv[i],"-elevate") || !strcmp(argv[i],"-e")) {
      // -elevate = create a new instance with administrator privileges
      elevate = 1;
    }
  }

  // Check if elevated if in >= Vista
  OSVERSIONINFO vi = { sizeof(OSVERSIONINFO) };
  GetVersionEx(&vi);
  vista = (vi.dwMajorVersion >= 6);
  if (vista) {
    HANDLE token;
    TOKEN_ELEVATION elevation;
    DWORD len;
    if (OpenProcessToken(GetCurrentProcess(),TOKEN_READ,&token) && GetTokenInformation(token,TokenElevation,&elevation,sizeof(elevation),&len)) {
      elevated = elevation.TokenIsElevated;
    }
  }

  // Register some messages
  WM_UPDATESETTINGS = RegisterWindowMessage(L"UpdateSettings");

  // Check AlwaysElevate
  if (!elevated) {
    GetPrivateProfileString(L"Advanced", L"AlwaysElevate", L"0", txt, ARRAY_SIZE(txt), inipath);
    if (_wtoi(txt)) {
      elevate = 1;
    }

    // Handle request to elevate to administrator privileges
    if (elevate) {
      wchar_t path[MAX_PATH];
      GetModuleFileName(NULL, path, ARRAY_SIZE(path));
      int ret = (INT_PTR) ShellExecute(NULL, L"runas", path, NULL, NULL, SW_SHOWNORMAL);
      if (ret > 32) {
        return 0;
      }
    }
  }

  // Create window
  WNDCLASSEX wnd = { sizeof(WNDCLASSEX), 0, WindowProc, 0, 0, hInst, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL, APP_NAME, NULL };
  wnd.hCursor = LoadImage(hInst, L"kill", IMAGE_CURSOR, 0, 0, LR_DEFAULTCOLOR);
  RegisterClassEx(&wnd);
  g_hwnd = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_EX_LAYERED, wnd.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
  SetLayeredWindowAttributes(g_hwnd, 0, 1, LWA_ALPHA); // Almost transparent

  // Tray icon
  InitTray();
  UpdateTray();

  // Hook keyboard
  HookKeyboard();

  // TimerCheck
  GetPrivateProfileString(L"General", L"TimerCheck", L"0", txt, ARRAY_SIZE(txt), inipath);
  if (_wtoi(txt)) {
    SetTimer(g_hwnd, CHECKTIMER, CHECKINTERVAL, NULL);
  }

  // Message loop
  MSG msg;
  while (GetMessage(&msg,NULL,0,0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return msg.wParam;
}
示例#7
0
// Entry point
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, char *szCmdLine, int iCmdShow) {
    g_hinst = hInst;
    IsWow64Process(GetCurrentProcess(), &x64);

    // Get ini path
    GetModuleFileName(NULL, inipath, ARRAY_SIZE(inipath));
    PathRemoveFileSpec(inipath);
    wcscat(inipath, L"\\"APP_NAME".ini");
    wchar_t txt[10];

    // Convert szCmdLine to argv and argc (max 10 arguments)
    char *argv[10];
    int argc = 1;
    argv[0] = szCmdLine;
    while ((argv[argc]=strchr(argv[argc-1],' ')) != NULL) {
        *argv[argc] = '\0';
        if (argc == ARRAY_SIZE(argv)) break;
        argv[argc++]++;
    }

    // Check arguments
    int i;
    int elevate=0, quiet=0, config=-1, multi=0;
    for (i=0; i < argc; i++) {
        if (!strcmp(argv[i],"-hide") || !strcmp(argv[i],"-h")) {
            // -hide = do not add tray icon, hide it if already running
            hide = 1;
        }
        else if (!strcmp(argv[i],"-quiet") || !strcmp(argv[i],"-q")) {
            // -quiet = do nothing if already running
            quiet = 1;
        }
        else if (!strcmp(argv[i],"-elevate") || !strcmp(argv[i],"-e")) {
            // -elevate = create a new instance with administrator privileges
            elevate = 1;
        }
        else if (!strcmp(argv[i],"-config") || !strcmp(argv[i],"-c")) {
            // -config = open config (with requested page)
            config = (i+1 < argc)?atoi(argv[i+1]):0;
        }
        else if (!strcmp(argv[i],"-multi")) {
            // -multi = allow multiple instances, used internally when elevating via config window
            multi = 1;
        }
    }

    // Check if elevated if in >= Vista
    OSVERSIONINFO vi = { sizeof(OSVERSIONINFO) };
    GetVersionEx(&vi);
    vista = (vi.dwMajorVersion >= 6);
    if (vista) {
        HANDLE token;
        TOKEN_ELEVATION elevation;
        DWORD len;
        if (OpenProcessToken(GetCurrentProcess(),TOKEN_READ,&token) && GetTokenInformation(token,TokenElevation,&elevation,sizeof(elevation),&len)) {
            elevated = elevation.TokenIsElevated;
        }
    }

    // Register some messages
    WM_UPDATESETTINGS = RegisterWindowMessage(L"UpdateSettings");
    WM_OPENCONFIG = RegisterWindowMessage(L"OpenConfig");
    WM_CLOSECONFIG = RegisterWindowMessage(L"CloseConfig");
    WM_ADDTRAY = RegisterWindowMessage(L"AddTray");
    WM_HIDETRAY = RegisterWindowMessage(L"HideTray");

    // Look for previous instance
    GetPrivateProfileString(L"Advanced", L"MultipleInstances", L"0", txt, ARRAY_SIZE(txt), inipath);
    if (!_wtoi(txt) && !multi) {
        HWND previnst = FindWindow(APP_NAME, NULL);
        if (previnst != NULL) {
            if (quiet) {
                return 0;
            }
            PostMessage(previnst, WM_UPDATESETTINGS, 0, 0);
            PostMessage(previnst, (hide && !config?WM_CLOSECONFIG:WM_OPENCONFIG), config, 0);
            PostMessage(previnst, (hide?WM_HIDETRAY:WM_ADDTRAY), 0, 0);
            return 0;
        }
    }

    // Check AlwaysElevate
    if (!elevated) {
        GetPrivateProfileString(L"Advanced", L"AlwaysElevate", L"0", txt, ARRAY_SIZE(txt), inipath);
        if (_wtoi(txt)) {
            elevate = 1;
        }

        // Handle request to elevate to administrator privileges
        if (elevate) {
            wchar_t path[MAX_PATH];
            GetModuleFileName(NULL, path, ARRAY_SIZE(path));
            int ret = (INT_PTR) ShellExecute(NULL, L"runas", path, (hide?L"-hide":NULL), NULL, SW_SHOWNORMAL);
            if (ret > 32) {
                return 0;
            }
        }
    }

    // Language
    memset(&l10n_ini, 0, sizeof(l10n_ini));
    UpdateLanguage();

    // Create window
    WNDCLASSEX wnd = { sizeof(WNDCLASSEX), 0, WindowProc, 0, 0, hInst, NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL, APP_NAME, NULL };
    RegisterClassEx(&wnd);
    g_hwnd = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TOPMOST|WS_EX_LAYERED, wnd.lpszClassName, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInst, NULL);
    SetLayeredWindowAttributes(g_hwnd, 0, 1, LWA_ALPHA); // Almost transparent

    // Tray icon
    InitTray();
    UpdateTray();

    // Hook system
    HookSystem();

    // Add tray if hook failed, even though -hide was supplied
    if (hide && !keyhook) {
        hide = 0;
        UpdateTray();
    }

    // Check for update
    GetPrivateProfileString(L"Update", L"CheckOnStartup", L"0", txt, ARRAY_SIZE(txt), inipath);
    if (_wtoi(txt)) {
        CheckForUpdate(0);
    }

    // Open config if -config was supplied
    if (config != -1) {
        PostMessage(g_hwnd, WM_OPENCONFIG, config, 0);
    }

    // Message loop
    MSG msg;
    while (GetMessage(&msg,NULL,0,0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}