コード例 #1
0
ファイル: systray.c プロジェクト: Moteesh/reactos
static void test_cbsize(void)
{
    NOTIFYICONDATAA nidA;
    BOOL ret;

    if (pShell_NotifyIconW)
    {
        NOTIFYICONDATAW nidW;

        ZeroMemory(&nidW, sizeof(nidW));
        nidW.cbSize = NOTIFYICONDATAW_V1_SIZE;
        nidW.hWnd = hMainWnd;
        nidW.uID = 1;
        nidW.uFlags = NIF_ICON|NIF_MESSAGE;
        nidW.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
        nidW.uCallbackMessage = WM_USER+17;
        ret = pShell_NotifyIconW(NIM_ADD, &nidW);
        ok(ret, "NIM_ADD failed!\n");
        /* using an invalid cbSize does work */
        nidW.cbSize = 3;
        nidW.hWnd = hMainWnd;
        nidW.uID = 1;
        ret = pShell_NotifyIconW(NIM_DELETE, &nidW);
        ok( ret || broken(!ret), /* nt4 */ "NIM_DELETE failed!\n");
        /* as icon doesn't exist anymore - now there will be an error */
        nidW.cbSize = sizeof(nidW);
        ok(!pShell_NotifyIconW(NIM_DELETE, &nidW) != !ret, "The icon was not deleted\n");
    }

    /* same for Shell_NotifyIconA */
    ZeroMemory(&nidA, sizeof(nidA));
    nidA.cbSize = NOTIFYICONDATAA_V1_SIZE;
    nidA.hWnd = hMainWnd;
    nidA.uID = 1;
    nidA.uFlags = NIF_ICON|NIF_MESSAGE;
    nidA.hIcon = LoadIconA(NULL, (LPSTR)IDI_APPLICATION);
    nidA.uCallbackMessage = WM_USER+17;
    ok(Shell_NotifyIconA(NIM_ADD, &nidA), "NIM_ADD failed!\n");

    /* using an invalid cbSize does work */
    nidA.cbSize = 3;
    nidA.hWnd = hMainWnd;
    nidA.uID = 1;
    ret = Shell_NotifyIconA(NIM_DELETE, &nidA);
    ok(ret, "NIM_DELETE failed!\n");
    /* as icon doesn't exist anymore - now there will be an error */
    nidA.cbSize = sizeof(nidA);
    ok(!Shell_NotifyIconA(NIM_DELETE, &nidA) != !ret, "The icon was not deleted\n");
}
コード例 #2
0
ファイル: main.c プロジェクト: commshare/civet-webserver
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) {
  WNDCLASSA cls;
  HWND hWnd;
  MSG msg;

  init_server_name();
  memset(&cls, 0, sizeof(cls));
  cls.lpfnWndProc = (WNDPROC) WindowProc;
  cls.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  cls.lpszClassName = server_name;

  RegisterClassA(&cls);
  hWnd = CreateWindowA(cls.lpszClassName, server_name, WS_OVERLAPPEDWINDOW,
                      0, 0, 0, 0, NULL, NULL, NULL, NULL);
  ShowWindow(hWnd, SW_HIDE);

  TrayIcon.cbSize = sizeof(TrayIcon);
  TrayIcon.uID = ID_TRAYICON;
  TrayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  TrayIcon.hIcon = LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
                             IMAGE_ICON, 16, 16, 0);
  TrayIcon.hWnd = hWnd;
  snprintf(TrayIcon.szTip, sizeof(TrayIcon.szTip), "%s", server_name);
  TrayIcon.uCallbackMessage = WM_USER;
  Shell_NotifyIconA(NIM_ADD, &TrayIcon);

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

  // Return the WM_QUIT value.
  return msg.wParam;
}
コード例 #3
0
void DockWnd::quit()
{
#ifdef WIN32
    if (_Shell_NotifyIconW && IsWindowUnicode(winId())){
        NOTIFYICONDATAW notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = 0;
        notifyIconData.hWnd = winId();
        memset(notifyIconData.szTip, 0, sizeof(notifyIconData.szTip));
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = 0;
        notifyIconData.uID = 0;
        _Shell_NotifyIconW(NIM_DELETE, &notifyIconData);
    }else{
        NOTIFYICONDATAA notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = 0;
        notifyIconData.hWnd = winId();
        memset(notifyIconData.szTip, 0, sizeof(notifyIconData.szTip));
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = 0;
        notifyIconData.uID = 0;
        Shell_NotifyIconA(NIM_DELETE, &notifyIconData);
    }
#endif
}
コード例 #4
0
void DockWnd::setTip(const QString &tip)
{
#ifdef WIN32
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    strncpy(notifyIconData.szTip, tip.local8Bit(), sizeof(notifyIconData.szTip));
    notifyIconData.uCallbackMessage = 0;
    notifyIconData.uFlags = NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_MODIFY, &notifyIconData);
#else
    if (wharfIcon == NULL){
        if (isVisible()){
            QToolTip::remove(this);
            QToolTip::add(this, tip);
        }
    }else{
        if (wharfIcon->isVisible()){
            QToolTip::remove(wharfIcon);
            QToolTip::add(wharfIcon, tip);
        }
    }
#endif
}
コード例 #5
0
bool QSystemTrayIconSys::showMessageA(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon type, uint uSecs)
{
#if NOTIFYICON_VERSION>=3
    NOTIFYICONDATAA tnd;
    memset(&tnd, 0, notifyIconSizeA);
    Q_ASSERT(testAttribute(Qt::WA_WState_Created));

    setIconContentsA(tnd);
#if defined(Q_OS_WINCE)
    strncpy(tnd.szInfo, message.toLocal8Bit().constData(), qMin(message.length() + 1, 256));
    strncpy(tnd.szInfoTitle, title.toLocal8Bit().constData(), qMin(title.length()+1, 64));
#else
    lstrcpynA(tnd.szInfo, message.toLocal8Bit().constData(), qMin(message.length() + 1, 256));
    lstrcpynA(tnd.szInfoTitle, title.toLocal8Bit().constData(), qMin(title.length() + 1, 64));
#endif
    tnd.uID = q_uNOTIFYICONID;
    tnd.dwInfoFlags = iconFlag(type);
    tnd.cbSize = notifyIconSizeA;
    tnd.hWnd = winId();
    tnd.uTimeout = uSecs;
    tnd.uFlags = NIF_INFO;
    return Shell_NotifyIconA(NIM_MODIFY, &tnd);
#else
    Q_UNUSED(title);
    Q_UNUSED(message);
    Q_UNUSED(type);
    Q_UNUSED(uSecs);
    return false;
#endif
}
コード例 #6
0
BOOL CBisonClickerDlg::SetNotifyIcon(HICON NewIcon)
{
	nid.hIcon = NewIcon;
	BOOL Result = Shell_NotifyIconA(NIM_MODIFY, &nid);
	UpdateWindow();
	UpdateData();
	return Result;
}
コード例 #7
0
void RunAsWindow()
{
	// Create an invisible window
	HWND hwnd = ::CreateWindowA("static", "AllSrv", WS_OVERLAPPED,
		0, 0, 0, 0, NULL, NULL, ::GetModuleHandle(NULL), NULL);

	// Load the small application icon
	HICON hIcon = reinterpret_cast<HICON>(::LoadImage(::GetModuleHandle(NULL),
		MAKEINTRESOURCE(ICO_FEDSRV), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON),
		::GetSystemMetrics(SM_CYSMICON), 0));

	// Set the taskbar icon
	const UINT wm_ShellNotifyIcon = WM_APP;
	NOTIFYICONDATAA nid = { sizeof(nid), hwnd, 0, NIF_ICON | NIF_MESSAGE | NIF_TIP,
	  wm_ShellNotifyIcon, hIcon, "Allegiance Server" };
	Shell_NotifyIconA(NIM_ADD, &nid);

	// Enter a message loop
	while (true)
	{
		DWORD dwWait = ::MsgWaitForMultipleObjects(1, &g.hKillReceiveEvent,
			false, INFINITE, QS_ALLINPUT);
		if (WAIT_OBJECT_0 == dwWait)
			break;

		MSG msg;
		while (::PeekMessage(&msg, NULL, 0, 0, true))
		{
			::TranslateMessage(&msg);
			switch (msg.message)
			{
			case WM_QUIT:
				::SetEvent(g.hKillReceiveEvent);
				break;
			default:
				::DispatchMessage(&msg);
			}
		}
	}

	// Remove the taskbar icon
	Shell_NotifyIconA(NIM_DELETE, &nid);

	// Shutdown the application
	FedSrv_Terminate();
}
コード例 #8
0
ファイル: clisttray.cpp プロジェクト: martok/miranda-ng
int fnCListTrayNotify(MIRANDASYSTRAYNOTIFY* msn)
{
	if (msn == NULL)
		return 1;

	if (msn->cbSize != sizeof(MIRANDASYSTRAYNOTIFY) || msn->szInfo == NULL || msn->szInfoTitle == NULL)
		return 1;

	if (cli.trayIcon == NULL)
		return 2;

	UINT iconId = 0;
	if (msn->szProto) {
		for (int j = 0; j < cli.trayIconCount; j++) {
			if (cli.trayIcon[j].szProto != NULL) {
				if (!strcmp(msn->szProto, cli.trayIcon[j].szProto)) {
					iconId = cli.trayIcon[j].id;
					break;
				}
			}
			else if (cli.trayIcon[j].isBase) {
				iconId = cli.trayIcon[j].id;
				break;
			}
		}
	}
	else iconId = cli.trayIcon[0].id;

	if (msn->dwInfoFlags & NIIF_INTERN_UNICODE) {
		NOTIFYICONDATAW nid = { 0 };
		nid.cbSize = (cli.shellVersion >= 5) ? NOTIFYICONDATAW_V2_SIZE : NOTIFYICONDATAW_V1_SIZE;
		nid.hWnd = cli.hwndContactList;
		nid.uID = iconId;
		nid.uFlags = NIF_INFO;
		mir_wstrncpy(nid.szInfo, msn->tszInfo, SIZEOF(nid.szInfo));
		mir_wstrncpy(nid.szInfoTitle, msn->tszInfoTitle, SIZEOF(nid.szInfoTitle));
		nid.szInfo[SIZEOF(nid.szInfo) - 1] = 0;
		nid.szInfoTitle[SIZEOF(nid.szInfoTitle) - 1] = 0;
		nid.uTimeout = msn->uTimeout;
		nid.dwInfoFlags = (msn->dwInfoFlags & ~NIIF_INTERN_UNICODE);
		return Shell_NotifyIconW(NIM_MODIFY, &nid) == 0;
	}
	else {
		NOTIFYICONDATAA nid = { 0 };
		nid.cbSize = (cli.shellVersion >= 5) ? NOTIFYICONDATAA_V2_SIZE : NOTIFYICONDATAA_V1_SIZE;
		nid.hWnd = cli.hwndContactList;
		nid.uID = iconId;
		nid.uFlags = NIF_INFO;
		strncpy_s(nid.szInfo, msn->szInfo, _TRUNCATE);
		strncpy_s(nid.szInfoTitle, msn->szInfoTitle, _TRUNCATE);
		nid.uTimeout = msn->uTimeout;
		nid.dwInfoFlags = msn->dwInfoFlags;
		return Shell_NotifyIconA(NIM_MODIFY, &nid) == 0;
	}
}
コード例 #9
0
ファイル: MinimizeToTray.c プロジェクト: embassy/AkelPad
void Hide()
{
  EDITINFO ei;
  const wchar_t *wpFileName=NULL;

  //Get tip
  if (SendMessage(hMainWnd, AKD_GETEDITINFO, (WPARAM)NULL, (LPARAM)&ei))
  {
    if (*ei.wszFile)
      wpFileName=GetFileName(ei.wszFile, -1);
  }
  xprintfW(wszBuffer, L"%s%s%s", wpFileName, wpFileName?L" - ":NULL, L"AkelPad");

  if (bOldWindows)
  {
    NOTIFYICONDATAA nid;

    //Set tip
    WideCharToMultiByte(CP_ACP, 0, wszBuffer, -1, nid.szTip, 64, NULL, NULL);
    nid.szTip[63]='\0';

    //Add notify icon
    nid.cbSize=sizeof(nid);
    nid.hWnd=hMainWnd;
    nid.uID=0;
    nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
    nid.uCallbackMessage=nMinimizeToTrayMessage;
    nid.hIcon=(HICON)hMainSmallIcon;
    Shell_NotifyIconA(NIM_ADD, &nid);
  }
  else
  {
    NOTIFYICONDATAW nid;

    //Set tip
    xstrcpynW(nid.szTip, wszBuffer, 64);

    //Add notify icon
    nid.cbSize=sizeof(nid);
    nid.hWnd=hMainWnd;
    nid.uID=0;
    nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
    nid.uCallbackMessage=nMinimizeToTrayMessage;
    nid.hIcon=(HICON)hMainSmallIcon;
    Shell_NotifyIconW(NIM_ADD, &nid);
  }

  if (!bCmdShow)
  {
    //Hide main window
    ShowWindow(hMainWnd, SW_MINIMIZE);
    ShowWindow(hMainWnd, SW_HIDE);
  }
}
コード例 #10
0
void DockWnd::setIcon(const char *icon)
{
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon){
        wharfIcon->set(m_state, bBlink ?  m_unread : NULL);
	repaint();
	return;
    }
#endif
#endif
    drawIcon = Pict(icon);
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (!inTray){
        repaint();
        return;
    }
#endif
#endif
#ifdef WIN32
    QWidget::setIcon(drawIcon);
    if (IsWindowUnicode(winId())){
        __NOTIFYICONDATAW notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uFlags = NIF_ICON;
        Shell_NotifyIconW(NIM_MODIFY, (NOTIFYICONDATAW*)&notifyIconData);
    }else{
        __NOTIFYICONDATAA notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uFlags = NIF_ICON;
        Shell_NotifyIconA(NIM_MODIFY, (NOTIFYICONDATAA*)&notifyIconData);
    }
#else
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon)
        return;
#endif
    // from PSI:
    // thanks to Robert Spier for this:
    // for some reason the repaint() isn't being honored, or isn't for
    // the icon.  So force one on the widget behind the icon
    erase();
    QPaintEvent pe( rect() );
    paintEvent(&pe);
#endif
}
コード例 #11
0
void DockWnd::setTip(const char *text)
{
    m_tip = text;
    QString tip = m_unreadText;
    if (tip.isEmpty()){
        tip = i18n(text);
		tip = tip.replace(QRegExp("\\&"), "");
	}
#ifdef WIN32
    if (_Shell_NotifyIconW && IsWindowUnicode(winId())){
        NOTIFYICONDATAW notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        memset(notifyIconData.szTip, 0, sizeof(notifyIconData.szTip));
        unsigned size = tip.length();
        if (size >= sizeof(notifyIconData.szTip) / sizeof(wchar_t))
            size = sizeof(notifyIconData.szTip) / sizeof(wchar_t) - 1;
        memcpy(notifyIconData.szTip, tip.unicode(), size * sizeof(wchar_t));
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = NIF_TIP;
        notifyIconData.uID = 0;
        _Shell_NotifyIconW(NIM_MODIFY, &notifyIconData);
    }else{
        NOTIFYICONDATAA notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        strncpy(notifyIconData.szTip, tip.local8Bit(), sizeof(notifyIconData.szTip));
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = NIF_TIP;
        notifyIconData.uID = 0;
        Shell_NotifyIconA(NIM_MODIFY, &notifyIconData);
    }
#else
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon == NULL){
        if (isVisible()){
#endif
            QToolTip::remove(this);
            QToolTip::add(this, tip);
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
        }
    }else{
        if (wharfIcon->isVisible()){
            QToolTip::remove(wharfIcon);
            QToolTip::add(wharfIcon, tip);
        }
    }
#endif
#endif
}
コード例 #12
0
DockWnd::~DockWnd()
{
#ifdef WIN32
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = 0;
    notifyIconData.hWnd = winId();
    memset(notifyIconData.szTip, 0, sizeof(notifyIconData.szTip));
    notifyIconData.uCallbackMessage = 0;
    notifyIconData.uFlags = 0;
    notifyIconData.uID = 0;
    int i = Shell_NotifyIconA(NIM_DELETE, &notifyIconData);
#endif
}
コード例 #13
0
void cConsole::notifyServerState( enServerState newstate )
{
	// Required ugly stuff
#if !defined (NIF_INFO)
# define NIF_INFO   	 0x00000010
#endif
#if !defined(NIIF_INFO)
# define NIIF_INFO  	 0x00000001
#endif

	icondata.uFlags = NIF_ICON;

	if ( newstate == RUNNING )
	{
		icondata.hIcon = iconGreen;
	}
	else
	{
		icondata.hIcon = iconRed;
	}

#if (_WIN32_IE >= 0x0500)
	qstrcpy( icondata.szInfoTitle, "Wolfpack Server Status" );
	// Startup has finished
	if ( Server::instance()->getState() == STARTUP && newstate == RUNNING )
	{
		icondata.uFlags |= NIF_INFO;
		icondata.uTimeout = 2500;
		icondata.dwInfoFlags = NIIF_INFO;
		qstrcpy( icondata.szInfo, "Wolfpack has started up and is now ready to use." );
	}
	else if ( Server::instance()->getState() == SCRIPTRELOAD && newstate == RUNNING )
	{
		icondata.uFlags |= NIF_INFO;
		icondata.uTimeout = 2500;
		icondata.dwInfoFlags = NIIF_INFO;
		qstrcpy( icondata.szInfo, "Wolfpack has finished reloading the scripts." );
	}
	else if ( newstate == SHUTDOWN )
	{
		icondata.uFlags |= NIF_INFO;
		icondata.uTimeout = 2500;
		icondata.dwInfoFlags = NIIF_INFO;
		qstrcpy( icondata.szInfo, "Wolfpack is now shutting down." );
	}
#endif

	Shell_NotifyIconA( NIM_MODIFY, ( PNOTIFYICONDATAA ) & icondata );
}
コード例 #14
0
void DockWnd::setIcon(const char *icon)
{
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon)
        wharfIcon->set(icon, NULL);
#endif
#endif
    drawIcon = Pict(icon);
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (!inTray){
        repaint();
        return;
    }
#endif
#endif
#ifdef WIN32
    QWidget::setIcon(drawIcon);
    if (_Shell_NotifyIconW && IsWindowUnicode(winId())){
        NOTIFYICONDATAW notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.szTip[0] = 0;
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = NIF_ICON;
        notifyIconData.uID = 0;
        _Shell_NotifyIconW(NIM_MODIFY, &notifyIconData);
    }else{
        NOTIFYICONDATAA notifyIconData;
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.szTip[0] = 0;
        notifyIconData.uCallbackMessage = 0;
        notifyIconData.uFlags = NIF_ICON;
        notifyIconData.uID = 0;
        Shell_NotifyIconA(NIM_MODIFY, &notifyIconData);
    }
#else
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon)
        return;
#endif
    repaint();
#endif
}
コード例 #15
0
void DockWnd::setIcon(const QPixmap &p)
{
    drawIcon = p;
#ifdef WIN32
    QWidget::setIcon(p);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = 0;
    notifyIconData.uFlags = NIF_ICON;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_MODIFY, &notifyIconData);
#else 
    repaint();
#endif
}
コード例 #16
0
void DockWnd::quit()
{
#ifdef WIN32
    if (IsWindowUnicode(winId())){
        __NOTIFYICONDATAW notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hWnd = winId();
        Shell_NotifyIconW(NIM_DELETE, (NOTIFYICONDATAW*)&notifyIconData);
    }else{
        __NOTIFYICONDATAA notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hWnd = winId();
        Shell_NotifyIconA(NIM_DELETE, (NOTIFYICONDATAA*)&notifyIconData);
    }
#endif
}
コード例 #17
0
void DockWnd::setIcon(const char *icon)
{
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon)
        wharfIcon->set(icon, NULL);
#endif
#endif
    drawIcon = Pict(icon);
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (!inTray){
        repaint();
        return;
    }
#endif
#endif
#ifdef WIN32
    QWidget::setIcon(drawIcon);
    if (IsWindowUnicode(winId())){
        __NOTIFYICONDATAW notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uFlags = NIF_ICON;
        Shell_NotifyIconW(NIM_MODIFY, (NOTIFYICONDATAW*)&notifyIconData);
    }else{
        __NOTIFYICONDATAA notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uFlags = NIF_ICON;
        Shell_NotifyIconA(NIM_MODIFY, (NOTIFYICONDATAA*)&notifyIconData);
    }
#else
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    if (wharfIcon)
        return;
#endif
    repaint();
#endif
}
コード例 #18
0
bool QSystemTrayIconSys::trayMessageA(DWORD msg)
{
#if !defined(Q_OS_WINCE)
    NOTIFYICONDATAA tnd;
    memset(&tnd, 0, notifyIconSizeA);
    tnd.uID = q_uNOTIFYICONID;
    tnd.cbSize = notifyIconSizeA;
    tnd.hWnd = winId();
    Q_ASSERT(testAttribute(Qt::WA_WState_Created));

    if (msg != NIM_DELETE) {
        setIconContentsA(tnd);
    }
    return Shell_NotifyIconA(msg, &tnd);
#else
    Q_UNUSED(msg);
    return false;
#endif
}
コード例 #19
0
    // the unavoidable A/W versions. Don't forget to keep them in sync!
    bool trayMessageA( DWORD msg )
    {
		NOTIFYICONDATAA tnd;
		ZeroMemory( &tnd, sizeof(NOTIFYICONDATAA) );
		tnd.cbSize		= sizeof(NOTIFYICONDATAA);
 		tnd.hWnd		= winId();
		tnd.uID = 1; // michalj

 		if ( msg != NIM_DELETE ) {
 			tnd.uFlags		= NIF_MESSAGE|NIF_ICON|NIF_TIP;
			tnd.uCallbackMessage= WM_NOTIFYICON;
 			tnd.hIcon		= hIcon;
 			if ( !iconObject->toolTip().isNull() ) {
				// Tip is limited to 63 + NULL; lstrcpyn appends a NULL terminator.
				QString tip = iconObject->toolTip().left( 63 ) + QChar();
				lstrcpynA(tnd.szTip, (const char*)tip.local8Bit(), QMIN( tip.length()+1, 64 ) );
 			}
 		}

		return Shell_NotifyIconA(msg, &tnd);
    }
コード例 #20
0
ファイル: MinimizeToTray.c プロジェクト: embassy/AkelPad
void Show()
{
  NOTIFYICONDATAA nid;

  //Delete notify icon
  nid.cbSize=sizeof(nid);
  nid.hWnd=hMainWnd;
  nid.uID=0;
  Shell_NotifyIconA(NIM_DELETE, &nid);

  //Show main window
  if (bCmdShow)
  {
    ShowWindow(hMainWnd, (dwMainStyle == WS_MAXIMIZE)?SW_SHOWMAXIMIZED:SW_SHOW);
    if (dwCmdShow != SW_SHOWNORMAL) ShowWindow(hMainWnd, dwCmdShow);
    SetForegroundWindow(hMainWnd);
    bCmdShow=FALSE;
  }
  else
  {
    ShowWindow(hMainWnd, SW_SHOW);
    ShowWindow(hMainWnd, SW_RESTORE);
  }
}
コード例 #21
0
ファイル: KeyborDlg.cpp プロジェクト: gnleaf/Keybor
BOOL CKeyborDlg::OnInitDialog()
{
	
	CDialog::OnInitDialog();
 
	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	m_tab.InsertItem(0," 基本设置 "); //添加参数一选项卡 
    m_tab.InsertItem(1," 快捷映射 "); //添加参数二选项卡 
	m_tab.InsertItem(2," 计划任务 "); 
	m_tab.InsertItem(3," 扩展应用 ");
    m_tab.InsertItem(4," 关于 "); //添加结果选项卡 

	//关联对话框,并且将IDC_TAB控件设为父窗口 
	dlg1.Create(IDD_DIALOG1,GetDlgItem(IDC_TAB)); 
	dlg2.Create(IDD_DIALOG2,GetDlgItem(IDC_TAB)); 
	dlg4.Create(IDD_DIALOG4,GetDlgItem(IDC_TAB)); 
	dlg5.Create(IDD_DIALOG5,GetDlgItem(IDC_TAB));
	dlg3.Create(IDD_DIALOG3,GetDlgItem(IDC_TAB)); 

	//获得IDC_TABTEST客户区大小 
	CRect rs; 
	m_tab.GetClientRect(&rs ); 
	//调整子对话框在父窗口中的位置 
	rs.top+=22; 
	rs.bottom+=30; 
	//rs.left+=1; 
	//rs.right-=2; 

	//设置子对话框尺寸并移动到指定位置 
	dlg1.MoveWindow(&rs); 
	dlg2.MoveWindow(&rs); 
	dlg3.MoveWindow(&rs); 
	dlg4.MoveWindow(&rs);
	dlg5.MoveWindow(&rs);

	//分别设置隐藏和显示  
	dlg1.ShowWindow(true);
	dlg2.ShowWindow(false); 
	dlg3.ShowWindow(false); 
	dlg4.ShowWindow(false); 
	dlg5.ShowWindow(false);

	//设置默认的选项卡 
	m_tab.SetCurSel(0);

    CString m_good;
	CTime ct = CTime::GetCurrentTime();
	int hour = ct.GetHour();
	if(hour>=0 && hour<6)
		m_good="凌晨好,熬夜?强悍!注意休息!";
	else if(hour>=6 && hour<8)
		m_good="早上好,这个时候得看书啊!";
	else if(hour>=8 && hour<11)
		m_good="上午好,现在清净啊,呵呵!";
	else if(hour>=11 && hour<13)
		m_good="中午好,现在是休息时间咯!";
	else if(hour>=13 && hour<19)
		m_good="下午好,嘿嘿";
	else if(hour>=19)
		m_good="晚上好,别玩太晚了,早点睡觉lo!";

	notifydata.cbSize=sizeof(NOTIFYICONDATA);
	notifydata.hWnd=this->m_hWnd;
	notifydata.uCallbackMessage=WM_NOTIFYICON;
	notifydata.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP;
	notifydata.uID=IDI_ICON1;
	notifydata.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));
	strcpy_s(notifydata.szTip," Keybor for you");
	Shell_NotifyIconA(NIM_ADD,&notifydata);

	if(GetPrivateProfileIntA("System","Balloon",1,CAfx::filepath))
	{
		ShowBalloonTip("尊敬的客户"+m_good,"Keybor", 3000, 1);//弹出气泡提示
	}

//*******************************获取对话框坐标*********************************//
	RECT rect;
	rect.left=GetPrivateProfileIntA("System","PosX",0,CAfx::filepath);
	rect.top=GetPrivateProfileIntA("System","PosY",0,CAfx::filepath);
	rect.right=rect.left+473;
	rect.bottom=rect.top+362;
	MoveWindow(&rect);

    UpdateWindow();

	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
コード例 #22
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL)
{
#ifndef WIN32
    wharfIcon = NULL;
#endif
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showPopup(QPoint)));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pClient, SIGNAL(messageRead(ICQMessage*)), this, SLOT(messageRead(ICQMessage*)));
    connect(pClient, SIGNAL(messageReceived(ICQMessage*)), this, SLOT(messageReceived(ICQMessage*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bool bWMDock = false;
#ifndef WIN32
    Atom r_type;
    int r_format;
    unsigned long count, bytes_remain;
    unsigned char *prop = NULL, *prop2 = NULL;
    Atom _XA_WIN_SUPPORTING_WM_CHECK = XInternAtom(qt_xdisplay(), XA_WIN_SUPPORTING_WM_CHECK, False);
    int p = XGetWindowProperty(qt_xdisplay(), qt_xrootwin(), _XA_WIN_SUPPORTING_WM_CHECK,
                               0, 1, False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop);

    if (p == Success && prop && r_type == XA_CARDINAL &&
            r_format == 32 && count == 1)
    {
        Window n = *(long *) prop;

        p = XGetWindowProperty(qt_xdisplay(), n, _XA_WIN_SUPPORTING_WM_CHECK, 0, 1,
                               False, XA_CARDINAL, &r_type, &r_format,
                               &count, &bytes_remain, &prop2);

        if (p == Success && prop2 && r_type == XA_CARDINAL &&
                r_format == 32 && count == 1)
            bWMDock = true;
    }

    if (prop)
        XFree(prop);
    if (prop2)
        XFree(prop2);

#endif
#ifdef USE_KDE
    log(L_DEBUG, "WM props? %u", bWMDock);
    if (!bWMDock)
        KWin::setSystemTrayWindowFor( winId(), main->topLevelWidget()->winId());
#endif
    needToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    if (!bWMDock){
        setBackgroundMode(X11ParentRelative);
        setIcon(Pict(pClient->getStatusIcon()));
#ifdef USE_KDE
        show();
#else
    hide();
#endif
    }else{
        wharfIcon = new WharfIcon(this);
        Display *dsp = x11Display();
        WId win = winId();
        XWMHints *hints;
        XClassHint classhint;
        classhint.res_name  = (char*)"sim";
        classhint.res_class = (char*)"sim";
        XSetClassHint(dsp, win, &classhint);
        hints = XGetWMHints(dsp, win);
        hints->initial_state = WithdrawnState;
        hints->icon_x = 0;
        hints->icon_y = 0;
        hints->icon_window = wharfIcon->winId();
        hints->window_group = win;
        hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
        XSetWMHints(dsp, win, hints);
        XFree( hints );
        XSetCommand(dsp, winId(), _argv, _argc);
        resize(64, 64);
        show();
    }
#endif
    loadUnread();
    reset();
}
コード例 #23
0
ファイル: MinimizeToTray.c プロジェクト: embassy/AkelPad
LRESULT CALLBACK NewEditParentProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  if (uMsg == AKDN_MAIN_ONSTART_PRESHOW)
  {
    if (bMinimizeToTrayNowOnStart)
    {
      NMAINSHOW *nms=(NMAINSHOW *)lParam;

      dwMainStyle=*nms->dwStyle;
      dwCmdShow=*nms->dwShow;
      nms->bProcess=FALSE;
      bCmdShow=TRUE;
    }
  }
  else if (uMsg == AKDN_MAIN_ONSTART_FINISH)
  {
    bMinimizeToTrayNowOnStart=FALSE;
  }
  else if (uMsg == WM_SYSCOMMAND)
  {
    if (hWnd == hMainWnd)
    {
      if (wParam == SC_MINIMIZE)
      {
        if (bMinimizeToTrayAlways)
        {
          Hide();
          return TRUE;
        }
      }
    }
  }
  else if (uMsg == nMinimizeToTrayMessage)
  {
    if (lParam == WM_RBUTTONUP)
    {
      POINT pt;
      int nCmd;

      GetCursorPos(&pt);
      SetForegroundWindow(hMainWnd);

      if (nCmd=TrackPopupMenu(hMenuList, TPM_NONOTIFY|TPM_RETURNCMD|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, pt.x, pt.y, 0, hMainWnd, NULL))
      {
        if (nCmd == IDC_ITEM_RESTORE)
        {
          Show();
        }
        else if (nCmd == IDC_ITEM_EXIT)
        {
          NOTIFYICONDATAA nid;

          //Delete notify icon
          nid.cbSize=sizeof(nid);
          nid.hWnd=hMainWnd;
          nid.uID=0;
          Shell_NotifyIconA(NIM_DELETE, &nid);

          SendMessage(hMainWnd, WM_COMMAND, IDM_FILE_EXIT, 0);
        }
      }
      return TRUE;
    }
    else if (lParam == WM_LBUTTONUP)
    {
      Show();
      return TRUE;
    }
  }
  else if (uMsg == AKDN_ACTIVATE ||
           uMsg == AKDN_MESSAGEBOXBEGIN)
  {
    if (!bMinimizeToTrayNowOnStart)
    {
      if (!IsWindowVisible(hMainWnd))
        Show();
    }
  }

  //Call next procedure
  if (hWnd == hMainWnd)
    return NewMainProcData->NextProc(hWnd, uMsg, wParam, lParam);
  else
    return NewFrameProcData->NextProc(hWnd, uMsg, wParam, lParam);
}
コード例 #24
0
DockWnd::DockWnd(QWidget *main)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop)
{
    setMouseTracking(true);
    connect(this, SIGNAL(toggleWin()), main, SLOT(toggleShow()));
    connect(this, SIGNAL(showPopup(QPoint)), main, SLOT(showDockPopup(QPoint)));
    connect(this, SIGNAL(doubleClicked()), main, SLOT(dockDblClicked()));
    connect(pClient, SIGNAL(event(ICQEvent*)), this, SLOT(processEvent(ICQEvent*)));
    connect(pMain, SIGNAL(iconChanged()), this, SLOT(reset()));
    connect(pMain, SIGNAL(msgChanged()), this, SLOT(reset()));
    m_state = 0;
    showIcon = State;
    QTimer *t = new QTimer(this);
    connect(t, SIGNAL(timeout()), this, SLOT(timer()));
    t->start(800);
    bNoToggle = false;
#ifdef WIN32
    QWidget::hide();
    QWidget::setIcon(Pict(pClient->getStatusIcon()));
    gDock = this;
    oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    if (oldDockProc == 0)
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
    NOTIFYICONDATAA notifyIconData;
    notifyIconData.cbSize = sizeof(notifyIconData);
    notifyIconData.hIcon = topData()->winIcon;
    notifyIconData.hWnd = winId();
    notifyIconData.szTip[0] = 0;
    notifyIconData.uCallbackMessage = WM_DOCK;
    notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    notifyIconData.uID = 0;
    Shell_NotifyIconA(NIM_ADD, &notifyIconData);
#else
    setMinimumSize(22, 22);
    resize(22, 22);
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    if (bEnlightenment){
        wharfIcon = NULL;
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(pMain->getDockX(), pMain->getDockY());
        reset();
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        show();
        return;
    }

    wharfIcon = new WharfIcon(this);

    setBackgroundMode(X11ParentRelative);
    const QPixmap &pict = Pict(pClient->getStatusIcon());
    setIcon(pict);

    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );
    XSetCommand(dsp, win, _argv, _argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
    show();
#endif
    reset();
}
コード例 #25
0
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
	Q_UNUSED( hPrevInstance );
	Q_UNUSED( nShowCmd );
#if defined(_DEBUG)
	/*	AllocConsole();
		CONSOLE_SCREEN_BUFFER_INFO coninfo;
		GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
		coninfo.dwSize.Y = 500;
		SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
		int hConHandle;
		long lStdHandle;
		FILE *fp;
		lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
		hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
		fp = _fdopen( hConHandle, "w" );
		*stdout = *fp;
		setvbuf( stdout, NULL, _IONBF, 0 );
		lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
		hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
		fp = _fdopen( hConHandle, "w" );
		*stderr = *fp;
		setvbuf( stderr, NULL, _IONBF, 0 );
		QString consoleTitle = QString("%1 %2 %3 - Debug Console").arg(productString()).arg(productBeta()).arg(productVersion());
		SetConsoleTitle(consoleTitle.latin1());*/
#endif

	INITCOMMONCONTROLSEX initex;
	initex.dwICC = ICC_WIN95_CLASSES;
	initex.dwSize = sizeof( INITCOMMONCONTROLSEX );
	InitCommonControlsEx( &initex );
#pragma comment(lib, "comctl32.lib") // needed for InitCommonControlsEx call
	appInstance = hInstance;
	guiThread = GetCurrentThreadId();

	// Try to load riched20.dll
	HMODULE hRiched = LoadLibrary( "riched20.dll" );

	if ( !hRiched )
	{
		MessageBox( 0, "The riched20.dll library could not be found on your system.\nPlease install Microsoft Internet Explorer 4.0 or later.", "Missing DLL", MB_OK | MB_ICONERROR );
		return 1;
	}

	hbSeparator = CreateSolidBrush( RGB( 0xAF, 0xAF, 0xAF ) );
	hbBackground = CreateSolidBrush( RGB( 0, 64, 38 ) );
	iconGreen = ( HICON ) LoadImage( appInstance, MAKEINTRESOURCE( IDI_ICONGREEN ), IMAGE_ICON, 16, 16, 0 );
	iconRed = ( HICON ) LoadImage( appInstance, MAKEINTRESOURCE( IDI_ICONRED ), IMAGE_ICON, 16, 16, 0 );

	// Create the WindowClass
	WNDCLASSEX wpClass;
	ZeroMemory( &wpClass, sizeof( WNDCLASSEX ) );
	wpClass.cbSize = sizeof( WNDCLASSEX );
	wpClass.hInstance = hInstance;
	wpClass.lpfnWndProc = wpWindowProc;
	wpClass.hCursor = LoadCursor( NULL, MAKEINTRESOURCE( IDC_ARROW ) );
	wpClass.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_ICON1 ) );
	wpClass.hbrBackground = hbBackground;
	wpClass.lpszClassName = WOLFPACK_CLASS;
	wpClass.hIconSm = iconRed;
	wpClass.style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW;

	if ( !RegisterClassEx( &wpClass ) )
	{
		MessageBox( 0, "Couldn't register Window Class.", "Window Class", MB_OK | MB_ICONERROR );
		return 1;
	}

	// Create the Window itself
	hmMainMenu = LoadMenu( appInstance, MAKEINTRESOURCE( IDR_MAINMENU ) );
	mainWindow = CreateWindow( WOLFPACK_CLASS, "Wolfpack", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, hmMainMenu, hInstance, NULL );

	if ( mainWindow == 0 )
	{
		MessageBox( 0, QString( "Couldn't create the window: " + getErrorString() ).latin1(), "Wolfpack", MB_OK | MB_ICONERROR );
		return 1;
	}

	ShowWindow( mainWindow, SW_NORMAL );

	// Create the System Tray Icon
	ZeroMemory( &icondata, sizeof( icondata ) );
	icondata.cbSize = sizeof( icondata );
	icondata.hWnd = mainWindow;
	icondata.uID = 0;
	icondata.uFlags = NIF_MESSAGE | NIF_ICON;
	icondata.hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_ICON1 ) );
	icondata.uCallbackMessage = WM_TRAY_NOTIFY;

#if !defined(TTS_BALLOON)
# define TTS_BALLOON			 0x40
#endif

	// This is "ported" from MFC
	tooltip = CreateWindowEx( WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, mainWindow, NULL, hInstance, NULL );

	if ( tooltip )
	{
		TOOLINFO info;
		info.cbSize = sizeof( info );
		info.uFlags = TTF_TRANSPARENT | TTF_CENTERTIP;
		info.hwnd = mainWindow;
		info.uId = 0;
		info.hinst = 0;
		info.lpszText = LPSTR_TEXTCALLBACK;
		GetClientRect( mainWindow, &info.rect );
		SendMessage( tooltip, TTM_ADDTOOL, 0, ( LPARAM ) & info );
	}
	Shell_NotifyIconA( NIM_ADD, ( PNOTIFYICONDATAA ) & icondata );

	cServerThread serverThread( lpCmdLine );
	serverThread.start();

	MSG msg;

	while ( GetMessage( &msg, 0, 0, 0 ) > 0 )
	{
		if ( msg.message == WM_CHAR && msg.hwnd == inputWindow && msg.wParam == '\r' )
		{
			if ( Server::instance()->getState() == RUNNING )
			{
				char command[512] =
				{
				0,
				};
				GetWindowText( inputWindow, command, 512 );
				SetWindowText( inputWindow, "" );

				// We are in a different Thread. Remember that.
				Console::instance()->queueCommand( command );
			}

			continue;
		}
		else if ( msg.message == WM_TIMER )
		{
			char message[512];

			unsigned int seconds, minutes, hours, days;
			days = Server::instance()->time() / 86400000;
			hours = ( Server::instance()->time() % 86400000 ) / 3600000;
			minutes = ( ( Server::instance()->time() % 86400000 ) % 3600000 ) / 60000;
			seconds = ( ( ( Server::instance()->time() % 86400000 ) % 3600000 ) % 60000 ) / 1000;

			sprintf( message, "Uptime: %u:%02u:%02u:%02u", days, hours, minutes, seconds );
			SetWindowText( lblUptime, message );

			// Update the icon
			static unsigned int lastState = 0xFFFFFFFF;

			if ( lastState != Server::instance()->getState() )
			{
				if ( Server::instance()->getState() == RUNNING )
				{
					SendMessage( mainWindow, WM_SETICON, ICON_SMALL, ( WPARAM ) iconGreen );
					SendMessage( statusIcon, STM_SETIMAGE, IMAGE_ICON, ( LPARAM ) iconGreen );
				}
				else
				{
					SendMessage( mainWindow, WM_SETICON, ICON_SMALL, ( WPARAM ) iconRed );
					SendMessage( statusIcon, STM_SETIMAGE, IMAGE_ICON, ( LPARAM ) iconRed );
				}
			}
			lastState = Server::instance()->getState();
		}

		TranslateMessage( &msg );
		DispatchMessage( &msg );
	}

	Shell_NotifyIconA( NIM_DELETE, ( PNOTIFYICONDATAA ) & icondata );

	Server::instance()->cancel();

	serverThread.wait();

	return serverThread.returnValue();
}
コード例 #26
0
ファイル: main.c プロジェクト: commshare/civet-webserver
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
                                   LPARAM lParam) {
  static SERVICE_TABLE_ENTRYA service_table[] = {
    {server_name, (LPSERVICE_MAIN_FUNCTIONA) ServiceMain},
    {NULL, NULL}
  };
  int service_installed;
  char buf[200], *service_argv[] = {__argv[0], NULL};
  POINT pt;
  HMENU hMenu;

  switch (msg) {
    case WM_CREATE:
      if (__argv[1] != NULL &&
          !strcmp(__argv[1], service_magic_argument)) {
        start_mongoose(1, service_argv);
        StartServiceCtrlDispatcherA(service_table);
        exit(EXIT_SUCCESS);
      } else {
        start_mongoose(__argc, __argv);
      }
      break;
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        case ID_QUIT:
          mg_stop(ctx);
          Shell_NotifyIconA(NIM_DELETE, &TrayIcon);
          PostQuitMessage(EXIT_SUCCESS);
          break;
        case ID_EDIT_CONFIG:
          edit_config_file(ctx);
          break;
        case ID_INSTALL_SERVICE:
        case ID_REMOVE_SERVICE:
          manage_service(LOWORD(wParam));
          break;
      }
      break;
    case WM_USER:
      switch (lParam) {
        case WM_RBUTTONUP:
        case WM_LBUTTONUP:
        case WM_LBUTTONDBLCLK:
          hMenu = CreatePopupMenu();
          AppendMenuA(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, server_name);
          AppendMenuA(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
          service_installed = manage_service(0);
          snprintf(buf, sizeof(buf), "NT service: %s installed",
                   service_installed ? "" : "not");
          AppendMenuA(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, buf);
          AppendMenuA(hMenu, MF_STRING | (service_installed ? MF_GRAYED : 0),
                     ID_INSTALL_SERVICE, "Install service");
          AppendMenuA(hMenu, MF_STRING | (!service_installed ? MF_GRAYED : 0),
                     ID_REMOVE_SERVICE, "Deinstall service");
          AppendMenuA(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
          AppendMenuA(hMenu, MF_STRING, ID_EDIT_CONFIG, "Edit config file");
          AppendMenuA(hMenu, MF_STRING, ID_QUIT, "Exit");
          GetCursorPos(&pt);
          SetForegroundWindow(hWnd);
          TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL);
          PostMessage(hWnd, WM_NULL, 0, 0);
          DestroyMenu(hMenu);
          break;
      }
      break;
    case WM_CLOSE:
      mg_stop(ctx);
      Shell_NotifyIconA(NIM_DELETE, &TrayIcon);
      PostQuitMessage(EXIT_SUCCESS);
      return 0;  // We've just sent our own quit message, with proper hwnd.
  }

  return DefWindowProc(hWnd, msg, wParam, lParam);
}
コード例 #27
0
DockWnd::DockWnd(DockPlugin *plugin, const char *icon, const char *text)
        : QWidget(NULL, "dock",  WType_TopLevel | WStyle_Customize | WStyle_NoBorder | WStyle_StaysOnTop),
        EventReceiver(LowPriority)
{
#ifndef WIN32
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    wharfIcon = NULL;
#endif
#endif
    m_plugin = plugin;
    setMouseTracking(true);
    bNoToggle = false;
    bBlink = false;
    m_state = icon;
    blinkTimer = new QTimer(this);
    connect(blinkTimer, SIGNAL(timeout()), this, SLOT(blink()));
#ifdef WIN32
    m_bBalloon = false;
    hShell = NULL;
    setIcon(icon);
    QWidget::hide();
    gDock = this;
    WM_DOCK = RegisterWindowMessageA("SIM dock");
    if (IsWindowUnicode(winId())){
        oldDockProc = (WNDPROC)SetWindowLongW(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
/*
        OSVERSIONINFOA osvi;
        osvi.dwOSVersionInfoSize = sizeof(osvi);
        GetVersionExA(&osvi);
        if ((osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) && (osvi.dwMajorVersion > 4))
            m_bBalloon = true;
*/
        __NOTIFYICONDATAW notifyIconData;
        if (m_bBalloon){
            memset(&notifyIconData, 0, sizeof(notifyIconData));
            notifyIconData.cbSize = sizeof(notifyIconData);
            notifyIconData.uVersion = NOTIFYICON_VERSION;
            Shell_NotifyIconW(NIM_SETVERSION, (NOTIFYICONDATAW*)&notifyIconData);
        }
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        Shell_NotifyIconW(NIM_ADD, (NOTIFYICONDATAW*)&notifyIconData);
    }else{
        oldDockProc = (WNDPROC)SetWindowLongA(winId(), GWL_WNDPROC, (LONG)DockWindowProc);
        __NOTIFYICONDATAA notifyIconData;
        memset(&notifyIconData, 0, sizeof(notifyIconData));
        notifyIconData.cbSize = sizeof(notifyIconData);
        notifyIconData.hIcon = topData()->winIcon;
        notifyIconData.hWnd = winId();
        notifyIconData.uCallbackMessage = WM_DOCK;
        notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
        Shell_NotifyIconA(NIM_ADD, (NOTIFYICONDATAA*)&notifyIconData);
    }
#else
    setMinimumSize(22, 22);
    resize(22, 22);
#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    bInit = false;
    inTray = false;
    inNetTray = false;

    Display *dsp = x11Display();
    WId win = winId();

    bool bEnlightenment = false;
    QWidget tmp;
    Atom enlightenment_desktop = XInternAtom(dsp, "ENLIGHTENMENT_DESKTOP", false);
    WId w = tmp.winId();
    Window p, r;
    Window *c;
    unsigned int nc;
    while (XQueryTree(dsp, w, &r, &p, &c, &nc)){
        if (c && nc > 0)
            XFree(c);
        if (! p) {
            log(L_WARN, "No parent");
            break;
        }
        unsigned char *data_ret = NULL;
        Atom type_ret;
        int i_unused;
        unsigned long l_unused;
        if ((XGetWindowProperty(dsp, p, enlightenment_desktop, 0, 1, False, XA_CARDINAL,
                                &type_ret, &i_unused, &l_unused, &l_unused,
                                &data_ret) == Success) && (type_ret == XA_CARDINAL)) {
            if (data_ret)
                XFree(data_ret);
            bEnlightenment = true;
            log(L_DEBUG, "Detect Enlightenment");
            break;
        }
        if (p == r) break;
        w = p;
    }

    if (bEnlightenment){
        bInit = true;
        resize(48, 48);
        setFocusPolicy(NoFocus);
        move(m_plugin->getDockX(), m_plugin->getDockY());
        MWMHints mwm;
        mwm.flags = MWM_HINTS_DECORATIONS;
        mwm.functions = 0;
        mwm.decorations = 0;
        mwm.inputMode = 0;
        mwm.status = 0;
        Atom a = XInternAtom(dsp, "_MOTIF_WM_HINTS", False);
        XChangeProperty(dsp, win, a, a, 32, PropModeReplace,
                        (unsigned char *)&mwm, sizeof(MWMHints) / 4);
        XStoreName(dsp, win, "SIM");
        XClassHint *xch = XAllocClassHint();
        xch->res_name  = (char*)"SIM";
        xch->res_class = (char*)"Epplet";
        XSetClassHint(dsp, win, xch);
        XFree(xch);
        XSetIconName(dsp, win, "SIM");
        unsigned long val = (1 << 0) /* | (1 << 9) */ ;
        a = XInternAtom(dsp, "_WIN_STATE", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = 2;
        a = XInternAtom(dsp, "_WIN_LAYER", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        val = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 5);
        a = XInternAtom(dsp, "_WIN_HINTS", False);
        XChangeProperty(dsp, win, a, XA_CARDINAL, 32, PropModeReplace,
                        (unsigned char *)&val, 1);
        win_name = "SIM";
        win_version = VERSION;
        win_info = "";
        while (!comms_win)
        {
            ECommsSetup(dsp);
            sleep(1);
        }
        char s[256];
        snprintf(s, sizeof(s), "set clientname %s", win_name);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set version %s", win_version);
        ECommsSend(s);
        snprintf(s, sizeof(s), "set info %s", win_info);
        ECommsSend(s);
        ESYNC;

        set_background_properties(this);

        setIcon(icon);
        show();
        return;
    }

    wharfIcon = new WharfIcon(this);
#endif
    setBackgroundMode(X11ParentRelative);
    setIcon(icon);

#if !defined(QT_MACOSX_VERSION) && !defined(QT_MAC)
    XClassHint classhint;
    classhint.res_name  = (char*)"sim";
    classhint.res_class = (char*)"Wharf";
    XSetClassHint(dsp, win, &classhint);

    Screen *screen = XDefaultScreenOfDisplay(dsp);
    int screen_id = XScreenNumberOfScreen(screen);
    char buf[32];
    snprintf(buf, sizeof(buf), "_NET_SYSTEM_TRAY_S%d", screen_id);
    Atom selection_atom = XInternAtom(dsp, buf, false);
    XGrabServer(dsp);
    Window manager_window = XGetSelectionOwner(dsp, selection_atom);
    if (manager_window != None)
        XSelectInput(dsp, manager_window, StructureNotifyMask);
    XUngrabServer(dsp);
    XFlush(dsp);
    if (manager_window != None){
        inNetTray = true;
        if (!send_message(dsp, manager_window, SYSTEM_TRAY_REQUEST_DOCK, win, 0, 0)){
            inNetTray = false;
        }
    }

    Atom kde_net_system_tray_window_for_atom = XInternAtom(dsp, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);

    long data[1];
    data[0] = 0;
    XChangeProperty(dsp, win, kde_net_system_tray_window_for_atom, XA_WINDOW,
                    32, PropModeReplace,
                    (unsigned char*)data, 1);

    XWMHints *hints;
    hints = XGetWMHints(dsp, win);
    hints->initial_state = WithdrawnState;
    hints->icon_x = 0;
    hints->icon_y = 0;
    hints->icon_window = wharfIcon->winId();
    hints->window_group = win;
    hints->flags = WindowGroupHint | IconWindowHint | IconPositionHint | StateHint;
    XSetWMHints(dsp, win, hints);
    XFree( hints );

    Event eArgc(EventArgc);
    int argc = (int)eArgc.process();
    Event eArgv(EventArgv);
    char **argv = (char**)eArgv.process();
    XSetCommand(dsp, win, argv, argc);

    if (!inNetTray){
        move(-21, -21);
        resize(22, 22);
    }
#endif
    show();
#endif
    setTip(text);
    reset();
}