コード例 #1
0
ファイル: cslist.cpp プロジェクト: tweimer/miranda-ng
void addProtoStatusMenuItem(char *protoName)
{
	PROTOACCOUNT *pdescr = Proto_GetAccount(protoName);
	if (pdescr == nullptr || pdescr->ppro == nullptr)
		return;

	HGENMENU hRoot = Menu_GetProtocolRoot(pdescr->ppro);
	if (hRoot == nullptr)
		return;

	char buf[200];
	mir_snprintf(buf, "CSList/ShowList/%s", protoName);
	if (!ServiceExists(buf))
		CreateServiceFunctionParam(buf, showList, (LPARAM)protoName);

	CMenuItem mi(g_plugin);
	mi.flags = CMIF_UNICODE;
	mi.hIcolibItem = forms[0].hIcoLibItem;
	mi.name.w = MODULENAME;
	mi.position = 2000040000;
	mi.pszService = buf;
	mi.root = hRoot;
	Menu_AddStatusMenuItem(&mi);

	RegisterHotkeys(buf, pdescr->tszAccountName, pdescr->iOrder);
}
コード例 #2
0
LRESULT CFloatingWindow::OnReloadSettings(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (!lParam)
		UnRegisterHotkeys();

	if (!wParam)
		Settings.LoadSettings();

	if (!lParam)
		RegisterHotkeys();
	return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: Jasu/HashTWM
void UpdateMousePos(HWND hwnd)
{
  POINT cursor;
  GetCursorPos(&cursor);

  if ((cursor.x < screen_x) || (cursor.x > screen_x + screen_width) || (cursor.y < screen_y) || (cursor.y > screen_y + screen_height)) {
    if (mouse_pos_out == 0) {
      mouse_pos_out = 1;
      UnregisterHotkeys(hwnd);
    }
  } else {
    if (mouse_pos_out == 1) {
      mouse_pos_out = 0;
      Sleep(500);
      RegisterHotkeys(hwnd);
    }
  }
}
コード例 #4
0
LRESULT CFloatingWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	/*int w = ::GetSystemMetrics(SM_CXSMICON);
	if ( w > 32 ) {
		w = 48;
	} else if ( w > 16 ) {
		w = 32;
	}
	int h = w;*/
	m_hIconSmall = GuiTools::LoadSmallIcon(IDR_MAINFRAME);
	SetIcon(m_hIconSmall, FALSE);

	RegisterHotkeys();
	InstallIcon(APPNAME, m_hIconSmall, /*TrayMenu*/ 0);
	NOTIFYICONDATA nid;
	ZeroMemory(&nid, sizeof(nid));
	nid.cbSize = NOTIFYICONDATA_V2_SIZE;
	nid.hWnd = m_hWnd;
	nid.uVersion = NOTIFYICON_VERSION;
	Shell_NotifyIcon(NIM_SETVERSION, &nid);
	return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: dubepaul/T-Clock
//================================================================================================
//--------------------------------------------------==-+++--> Entry Point of Program Using WinMain:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	WNDCLASS wndclass;
	HWND hwndMain;
	MSG msg;
	int updated;
	
	(void)hPrevInstance;
	(void)nCmdShow;
	
	#if defined(__GNUC__) && defined(_DEBUG)
	#	ifdef _WIN64
	#		define LoadExcHndl() LoadLibraryExA("dbg\\64\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
	#	else
	#		define LoadExcHndl() LoadLibraryExA("dbg\\exchndl", NULL, LOAD_WITH_ALTERED_SEARCH_PATH)
	#	endif
	#else
	#	define LoadExcHndl()
	#endif
	LoadExcHndl(); // LOAD_WITH_ALTERED_SEARCH_PATH works :P At least since Win2k
	
	g_instance = hInstance;
	if(LoadClockAPI("misc/T-Clock" ARCH_SUFFIX, &api)){
		MessageBox(NULL, "Error loading: T-Clock" ARCH_SUFFIX ".dll", "API error", MB_OK|MB_ICONERROR);
		return 2;
	}
	chdir(api.root); // make sure we've got the right working directory
	
	// Make sure we're running Windows 2000 and above
	if(!api.OS) {
		MessageBox(NULL,"T-Clock requires Windows 2000 or newer","old OS",MB_OK|MB_ICONERROR);
		return 1;
	}
	
	// make sure ObjectBar isn't running -> From Original Code/Unclear if This is Still a Conflict. (test suggested not really.. no crash but no clock either :P)
	if(FindWindow("ObjectBar Main","ObjectBar")) {
		MessageBox(NULL,"ObjectBar and T-Clock can't be run together","ObjectBar detected!",MB_OK|MB_ICONERROR);
		return 1;
	}
	
	// Load ALL of the Global Resources
	g_hIconTClock = LoadIcon(api.hInstance, MAKEINTRESOURCE(IDI_MAIN));
	g_hIconPlay = LoadImage(g_instance, MAKEINTRESOURCE(IDI_PLAY), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	g_hIconStop = LoadImage(g_instance, MAKEINTRESOURCE(IDI_STOP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	g_hIconDel  = LoadImage(g_instance, MAKEINTRESOURCE(IDI_DEL), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
	
//	FindTrayServer(hwndMain);
	
	// Make sure we're not running 32bit on 64bit OS / start the other one
	#ifndef _WIN64
	if(IsWow64()){
		hwndMain = FindWindow(g_szClassName, NULL);
		if(hwndMain) { // send commands to existing instance
			ProcessCommandLine(hwndMain,lpCmdLine);
		}else{ // start new instance
			char clock64[MAX_PATH];
			memcpy(clock64, api.root, api.root_len+1);
			add_title(clock64,"Clock" ARCH_SUFFIX_64 ".exe");
			api.Exec(clock64,lpCmdLine,NULL);
		}
		return 0;
	}
	#endif // _WIN64
	
	// Do Not Allow the Program to Execute Twice!
	updated = 25; /**< wait up to 5 sec in 1/5th seconds for other instance */
	do{
		HANDLE processlock=CreateMutex(NULL,FALSE,g_szClassName); // we leak handle here, but Windows closes on process exit anyway (so why do it manually?)
		if(processlock && GetLastError()==ERROR_ALREADY_EXISTS){
			CloseHandle(processlock);
			hwndMain = FindWindow(g_szClassName, NULL);
			if(hwndMain) { // This One Sends Commands to the Instance
				ProcessCommandLine(hwndMain,lpCmdLine); // That is Currently Running.
				return 0;
			}
			Sleep(200);
			continue;
		}
		break;
	}while(updated--);
	
	// Update settings if required and setup defaults
	if((updated=CheckSettings())<0){
		return 1;
	}
	CancelAllTimersOnStartUp();
	
	// Message of the taskbar recreating - Special thanks to Mr.Inuya
	g_WM_TaskbarCreated = RegisterWindowMessage("TaskbarCreated");
	
	// register a window class
	wndclass.style         = 0;
	wndclass.lpfnWndProc   = WndProc;
	wndclass.cbClsExtra    = 0;
	wndclass.cbWndExtra    = 0;
	wndclass.hInstance     = g_instance;
	wndclass.hIcon         = g_hIconTClock;
	wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(intptr_t)(COLOR_WINDOW+1);
	wndclass.lpszMenuName  = NULL;
	wndclass.lpszClassName = g_szClassName;
	g_atomTClock = RegisterClass(&wndclass);
	
	if(api.OS >= TOS_VISTA) { // allow non elevated processes to send control messages (eg, App with admin rights, explorer without)
		#define MSGFLT_ADD 1
		#define MSGFLT_REMOVE 2
		typedef BOOL (WINAPI* ChangeWindowMessageFilter_t)(UINT message,DWORD dwFlag);
		ChangeWindowMessageFilter_t ChangeWindowMessageFilter=(ChangeWindowMessageFilter_t)GetProcAddress(GetModuleHandle("user32"), "ChangeWindowMessageFilter");
		if(ChangeWindowMessageFilter){
			int msgid;
			ChangeWindowMessageFilter(g_WM_TaskbarCreated,MSGFLT_ADD);
			ChangeWindowMessageFilter(WM_COMMAND,MSGFLT_ADD);
			for(msgid=WM_MOUSEFIRST; msgid<=WM_MOUSELAST; ++msgid)
				ChangeWindowMessageFilter(msgid,MSGFLT_ADD);
			for(msgid=MAINMFIRST; msgid<=MAINMLAST; ++msgid)
				ChangeWindowMessageFilter(msgid,MSGFLT_ADD);
		}
	}
	
	// create a hidden window
	g_hwndTClockMain = hwndMain = CreateWindowEx(WS_EX_NOACTIVATE, MAKEINTATOM(g_atomTClock),NULL, 0, 0,0,0,0, NULL,NULL,g_instance,NULL);
	// This Checks for First Instance Startup Options
	ProcessCommandLine(hwndMain,lpCmdLine);
	
	RegisterHotkeys(hwndMain, 1);
	
	if(api.OS > TOS_2000) {
		if(api.GetInt("Desktop", "MonOffOnLock", 0))
			RegisterSession(hwndMain);
	}
	if(updated==1){
		PostMessage(hwndMain,WM_COMMAND,IDM_SHOWPROP,0);
	}
	while(GetMessage(&msg, NULL, 0, 0)) {
		if(!(g_hwndSheet && IsWindow(g_hwndSheet) && PropSheet_IsDialogMessage(g_hwndSheet,&msg))
		&& !(g_hDlgTimer && IsWindow(g_hDlgTimer) && IsDialogMessage(g_hDlgTimer,&msg))
		&& !(g_hDlgTimerWatch && IsWindow(g_hDlgTimerWatch) && IsDialogMessage(g_hDlgTimerWatch,&msg))
		&& !(g_hDlgSNTP && IsWindow(g_hDlgSNTP) && IsDialogMessage(g_hDlgSNTP,&msg))
		&& !(g_hDlgStopWatch && IsWindow(g_hDlgStopWatch) && IsDialogStopWatchMessage(g_hDlgStopWatch,&msg))){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	
	RegisterHotkeys(hwndMain, 0);
	
	UnregisterSession(hwndMain);
	
	EndNewAPI(NULL);
	
	return (int)msg.wParam;
}
コード例 #6
0
ファイル: main.c プロジェクト: Jasu/HashTWM
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
  WNDCLASSEX winClass;
  HWND hwnd;
  MSG msg;

  // Process command line
  LPWSTR *argv = NULL;
  int argc;
  int i;
  unsigned short tilingMode;

  argv = CommandLineToArgvW(GetCommandLineW(), &argc);

  for (i = 0; i < argc; i++) {
    char arg[128];
    wsprintfA(arg, "%S", argv[i]);

    if (i < (argc - 1)) {
      char nextarg[128];
      wsprintfA(nextarg, "%S", argv[i + 1]);

      if (!strcmp(arg, "-o")) {
        alpha = atoi(nextarg);
      } else if (!strcmp(arg, "-i")) {
        if (ignoreCount < MAX_IGNORE) {
          sprintf(ignoreClasses[ignoreCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-a")) {
        include_mode = 1; // Include mode instead of exclude

        if (includeCount < MAX_IGNORE) {
          sprintf(includeClasses[includeCount++], "%s", nextarg);
        }
      } else if (!strcmp(arg, "-m")) {
        int y;
        modkeys = 0;

        for (y = 0; y < strlen(nextarg); y++) {
          switch (nextarg[y])
          {
            case 'c':
              modkeys |= MOD_CONTROL;
              break;
            case 'a':
              modkeys |= MOD_ALT;
              break;
            case 's':
              modkeys |= MOD_SHIFT;
              break;
            case 'w':
              modkeys |= MOD_WIN;
              break;
          }
        }
      } else if (!strcmp(arg, "-t")) {
        tilingMode = atoi(nextarg);
      } else if (!strcmp(arg, "-left")) {
        screen_x = atoi(nextarg);
      } else if (!strcmp(arg, "-top")) {
        screen_y = atoi(nextarg);
      } else if (!strcmp(arg, "-width")) {
        screen_width = atoi(nextarg);
      } else if (!strcmp(arg, "-height")) {
        screen_height = atoi(nextarg);
      }
    }
    if (!strcmp(arg, "-v")) {
      MessageBox(NULL, VERSION, "Version", MB_OK);
      LocalFree(argv);
      return 1;
    } else if (!strcmp(arg, "-l")) {
      lockMouse = 1;
    } else if (!strcmp(arg, "-x")) {
      experimental_mouse = 1;
    } else if (!strcmp(arg, "--one-tag")) {
      one_tag_per_window = 1;
    }
  }

  // Initialize tags
  for (i = 0; i < TAGS; i++) {
    tags[i].nodes = NULL;
    tags[i].last_node = NULL;
    tags[i].current_window = NULL;
    tags[i].tilingMode = DEFAULT_TILING_MODE;
    tags[i].masterarea_count = 1;
  }

  LocalFree(argv);

  winClass.cbSize = sizeof(WNDCLASSEX);
  winClass.style = 0;
  winClass.lpfnWndProc = WndProc;
  winClass.cbClsExtra = 0;
  winClass.cbWndExtra = 0;
  winClass.hInstance = hInstance;
  winClass.hIcon = NULL;
  winClass.hIconSm = NULL;
  winClass.hCursor = NULL;
  winClass.hbrBackground = NULL;
  winClass.lpszMenuName = NULL;
  winClass.lpszClassName = NAME;

  if (!RegisterClassEx(&winClass)) {
    MessageBox(NULL, "Error Registering Window Class", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  hwnd = CreateWindowEx(0, NAME, NAME, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);

  if (!hwnd) {
    MessageBox(NULL, "Error Creating Window", "Error", MB_OK | MB_ICONERROR);
    return 0; // Bail
  }

  if (!screen_x && !screen_y && !screen_width && !screen_height) { // Screen options aren't being specified from the command line so set some defaults
    RECT workarea;
    SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);
    screen_x = workarea.left;
    screen_y = workarea.top;
    screen_width = workarea.right - workarea.left;
    screen_height = workarea.bottom - workarea.top;
  }

  RegisterHotkeys(hwnd);
  UpdateMousePos(hwnd);

  EnumWindows(EnumWindowsRestore, 0); // Restore windows on startup so they get tiled
  EnumWindows(EnumWindowsProc, 0);

  ArrangeWindows();

  // Get function pointer for RegisterShellHookWindow
  if ( RegisterShellHookWindow_ == NULL )
  {
    RegisterShellHookWindow_ = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle("USER32.DLL"), "RegisterShellHookWindow");
    if (RegisterShellHookWindow_ == NULL) {
      MessageBox(NULL, "Could not find RegisterShellHookWindow", "Error", MB_OK | MB_ICONERROR);
      return 0;
    }
  }

  RegisterShellHookWindow_(hwnd);
  shellhookid = RegisterWindowMessage("SHELLHOOK"); // Grab a dynamic id for the SHELLHOOK message to be used later

  while (GetMessage(&msg, NULL, 0, 0) > 0)
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }

  return msg.wParam;
}