コード例 #1
0
HWND WinWindowCapture::FindHWND() {
  if( mHwnd && IsWindow( mHwnd ) ) {
    return mHwnd;
  }

  HWND hwnd = FindWindowW( NULL, L"Hearthstone" );

  if( !hwnd ) {
    // Fallback for localized
    HWND unityHwnd = FindWindowW( L"UnityWndClass", NULL );
    if( unityHwnd ) {
      DWORD procId;
      GetWindowThreadProcessId( unityHwnd, &procId );

      HANDLE handle = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, procId );
      TCHAR buffer[ MAX_PATH ] = { 0 };
      GetModuleFileNameEx( (HMODULE)handle, NULL, buffer, MAX_PATH );
      CloseHandle( handle );

      QString path = QString::fromWCharArray( buffer );
      if( path.contains( "Hearthstone" ) ) {
        hwnd = unityHwnd;
      }
    }
  }

  mHwnd = hwnd;
  return mHwnd;
}
コード例 #2
0
ファイル: msconfig.c プロジェクト: Strongc/reactos
BOOL Initialize(HINSTANCE hInstance)
{
    BOOL Success = TRUE;
    LPWSTR lpszVistaAppName = NULL;
    HANDLE hSemaphore;
    INITCOMMONCONTROLSEX InitControls;

    /* Initialize our global version flags */
    bIsWindows = TRUE; /* IsWindowsOS(); */ // TODO: Commented for testing purposes...
    bIsOSVersionLessThanVista = TRUE; /* IsOSVersionLessThanVista(); */ // TODO: Commented for testing purposes...

    /* Initialize global strings */
    szAppName = LoadResourceString(hInstance, IDS_MSCONFIG);
    if (!bIsOSVersionLessThanVista)
        lpszVistaAppName = LoadResourceString(hInstance, IDS_MSCONFIG_2);

    /* We use a semaphore in order to have a single-instance application */
    hSemaphore = CreateSemaphoreW(NULL, 0, 1, L"MSConfigRunning");
    if (!hSemaphore || GetLastError() == ERROR_ALREADY_EXISTS)
    {
        CloseHandle(hSemaphore);

        /*
         * A semaphore with the same name already exist. It should have been
         * created by another instance of MSConfig. Try to find its window
         * and bring it to front.
         */
        if ( (hSingleWnd && IsWindow(hSingleWnd))                         ||
             ( (hSingleWnd = FindWindowW(L"#32770", szAppName)) != NULL ) ||
             (!bIsOSVersionLessThanVista ? ( (hSingleWnd = FindWindowW(L"#32770", lpszVistaAppName)) != NULL ) : FALSE) )
        {
            /* Found it. Show the window. */
            ShowWindow(hSingleWnd, SW_SHOWNORMAL);
            SetForegroundWindow(hSingleWnd);
        }

        /* Quit this instance of MSConfig */
        Success = FALSE;
    }
    if (!bIsOSVersionLessThanVista) MemFree(lpszVistaAppName);

    /* Quit now if we failed */
    if (!Success)
    {
        MemFree(szAppName);
        return FALSE;
    }

    /* Initialize the common controls */
    InitControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
    InitControls.dwICC  = ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_UPDOWN_CLASS /* | ICC_PROGRESS_CLASS | ICC_HOTKEY_CLASS*/;
    InitCommonControlsEx(&InitControls);

    hInst = hInstance;

    return Success;
}
コード例 #3
0
ファイル: DllMain.cpp プロジェクト: vevix/FixWin10Taskbar
extern "C" __declspec(dllexport) LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam) {
	if (nCode >= HC_ACTION && wParam == WM_LBUTTONUP && lParam) {
		auto msg = reinterpret_cast<MOUSEHOOKSTRUCT*>(lParam);
		auto hWnd = FindWindowW(L"Shell_SecondaryTrayWnd", nullptr);
		if (msg->hwnd == hWnd) {
			SetForegroundWindow(FindWindowW(L"Shell_TrayWnd", nullptr));
		}
	}

	return CallNextHookEx(nullptr, nCode, wParam, lParam);
}
コード例 #4
0
static void WindowMonitorTask()
{
	LOG4CXX_DEBUG(NYDWE::gInjectLogger, "Monitor thread started.");

	try
	{
		std::string result;
		while (!WorldEditStrings("WESTRING_MODIFYTEXTURES", result))
		{
			boost::this_thread::sleep(boost::posix_time::milliseconds(125));
		}
		std::wstring text = ydwe::util::u2w(result);

		while (!gWindowMonitorShouldExit)
		{
			boost::this_thread::sleep(boost::posix_time::milliseconds(125));

			// Check dialog
			HWND dialog = FindWindowW(L"#32770", text.c_str());
			if (dialog && IsDlgButtonChecked(dialog, 0xC /* CheckBox */))
			{
				EnableWindow(GetDlgItem(dialog, 0x10 /* Delete style */), TRUE);
				EnableWindow(GetDlgItem(dialog, 0x11 /* Add style */), TRUE);
				EnableWindow(GetDlgItem(dialog, 0x12 /* Replace style */), TRUE);
			}
		}
	}
	catch (boost::thread_interrupted &) 
	{
		LOG4CXX_DEBUG(NYDWE::gInjectLogger, "Monitor thread interruppted.");
	}

	LOG4CXX_DEBUG(NYDWE::gInjectLogger, "Monitor thread ends.");
}
JNIEXPORT void JNICALL Java_org_jivesoftware_spark_plugin_flashing_FlashWindow_flash(JNIEnv * env, jobject obj, jstring windowTitle, jboolean flash)
{
	const wchar_t * utf16 = (wchar_t *)env->GetStringChars(windowTitle, NULL);	
	HWND hwnd = FindWindowW(NULL, utf16);	
	env->ReleaseStringChars(windowTitle, (jchar*)utf16);
	FlashWindow(hwnd, flash);
}
コード例 #6
0
	bool initIT()
	{
		try
		{
			if (!FindWindowW(L"iTunes", NULL))
			{
				// AfxMessageBox(L"iTunes not running");
				
				if (initialized) app.ReleaseDispatch();

				initialized = false;
				return false;
			}
		}
		catch(COleException * e) // in case we couldn't properly release the dispatch
		{
			return false;
		}

		if (!initialized)
		{
			COleException e;
			if(!app.CreateDispatch(L"iTunes.Application", &e)) {
			   /*CString str;
			   str.Format(L"CreateDispatch() failed w/err 0x%08lx", e.m_sc);
			   AfxMessageBox(str, MB_SETFOREGROUND);*/
			   return false;
			}
			initialized = true;
		}

		return true;
	}
コード例 #7
0
ファイル: unique.c プロジェクト: houzhenggang/gimp-painter
static gboolean
gimp_unique_win32_open (const gchar **filenames,
                        gboolean      as_new)
{
#ifndef GIMP_CONSOLE_COMPILATION

    /*  for the proxy window names  */
#include "gui/gui-unique.h"

    HWND  window_handle = FindWindowW (GIMP_UNIQUE_WIN32_WINDOW_CLASS,
                                       GIMP_UNIQUE_WIN32_WINDOW_NAME);

    if (window_handle)
    {
        COPYDATASTRUCT  copydata = { 0, };

        if (filenames)
        {
            gchar  *cwd   = g_get_current_dir ();
            GError *error = NULL;
            gint    i;

            for (i = 0; filenames[i]; i++)
            {
                gchar *uri;

                uri = gimp_unique_filename_to_uri (filenames[i], cwd, &error);

                if (uri)
                {
                    copydata.lpData = uri;
                    copydata.cbData = strlen (uri) + 1;  /* size in bytes   */
                    copydata.dwData = (long) as_new;

                    SendMessage (window_handle,
                                 WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);
                }
                else
                {
                    g_printerr ("conversion to uri failed: %s\n", error->message);
                    g_clear_error (&error);
                }
            }

            g_free (cwd);
        }
        else
        {
            SendMessage (window_handle,
                         WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);
        }

        return TRUE;
    }

#endif

    return FALSE;
}
コード例 #8
0
ファイル: CShellDispatch.cpp プロジェクト: Moteesh/reactos
HRESULT STDMETHODCALLTYPE CShellDispatch::ToggleDesktop()
{
    TRACE("(%p)\n", this);

    HWND hTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
    PostMessageW(hTrayWnd, WM_COMMAND, TRAYCMD_TOGGLE_DESKTOP, 0);

    return S_OK;
}
コード例 #9
0
ファイル: Window.c プロジェクト: xpika/winhugs
static void hugsprim_FindWindowW_25(HugsStackPtr hugs_root)
{
    HsPtr arg1;
    HsPtr arg2;
    HsPtr res1;
    arg1 = hugs->getPtr();
    arg2 = hugs->getPtr();
    res1 = FindWindowW(arg1, arg2);
    hugs->putPtr(res1);
    hugs->returnIO(hugs_root,1);
}
コード例 #10
0
ファイル: TextFunctions.cpp プロジェクト: Superxwolf/nModules
void TextFunctions::_Register() {
  RegisterDynamicTextFunction(L"Time", 0, Time, true);
  RegisterDynamicTextFunction(L"Time", 1, Time, true);

  RegisterDynamicTextFunction(L"WindowTitle", 1, [] (LPCWSTR /* name */, UCHAR /* numArgs */, LPWSTR* args, LPWSTR dest, size_t cchDest) -> size_t {
    HWND window = FindWindowW(args[0], nullptr);
    if (window) {
      return GetWindowTextW(window, dest, (int)cchDest);
    }
    return 0;
  }, true);
}
コード例 #11
0
ファイル: volume.c プロジェクト: amaneureka/reactos
static
VOID
SetSystrayVolumeIconState(BOOL bEnabled)
{
    HWND hwndTaskBar;

    hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
    if (hwndTaskBar == NULL)
        return;

    SendMessageW(hwndTaskBar, WM_USER + 220, 4, bEnabled);
}
コード例 #12
0
ファイル: xinerama.c プロジェクト: vindo-app/wine
static void query_desktop_work_area( RECT *rc_work )
{
    static const WCHAR trayW[] = {'S','h','e','l','l','_','T','r','a','y','W','n','d',0};
    RECT rect;
    HWND hwnd = FindWindowW( trayW, NULL );

    if (!hwnd || !IsWindowVisible( hwnd )) return;
    if (!GetWindowRect( hwnd, &rect )) return;
    if (rect.top) rc_work->bottom = rect.top;
    else rc_work->top = rect.bottom;
    TRACE( "found tray %p %s work area %s\n", hwnd,
           wine_dbgstr_rect( &rect ), wine_dbgstr_rect( rc_work ));
}
コード例 #13
0
ファイル: volume.c プロジェクト: amaneureka/reactos
static
BOOL
GetSystrayVolumeIconState(VOID)
{
    HWND hwndTaskBar;

    hwndTaskBar = FindWindowW(L"SystemTray_Main", NULL);
    if (hwndTaskBar == NULL)
    {
        return FALSE;
    }

    return (BOOL)SendMessageW(hwndTaskBar, WM_USER + 221, 4, 0);
}
コード例 #14
0
ファイル: DllMain.cpp プロジェクト: vevix/FixWin10Taskbar
extern "C" __declspec(dllexport) LRESULT CALLBACK RedrawProc(int nCode, WPARAM wParam, LPARAM lParam) {
	if (nCode >= HC_ACTION) {
		auto msg = reinterpret_cast<CWPSTRUCT*>(lParam);
		if ((msg->message == WM_WINDOWPOSCHANGING || msg->message == WM_WINDOWPOSCHANGED || msg->message == WM_NCPAINT)) {
			auto hWnd = FindWindowW(L"Shell_SecondaryTrayWnd", nullptr);
			hWnd = FindWindowExW(hWnd, nullptr, L"WorkerW", nullptr);

			if (msg->hwnd == hWnd) {
				SetWindowPos(hWnd, nullptr, 0, 0, 0, 0, 1);
			}
		}
	}

	return CallNextHookEx(nullptr, nCode, wParam, lParam);
}
コード例 #15
0
ファイル: main.c プロジェクト: nfglynn/emacs
INT CALLBACK WinMain(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR cmd_line, int cmd_show)
{
    LONG current_style = 0; /* Current style of the emacs window. */
    LONG style = 0; /* New style of the emacs window. */
    LONG style_ex = 0; /* New extended style of the emacs window. */
    HWND insert_after = NULL;
    HWND emacs_window = FindWindowW(EMACS_CLASS_NAME, NULL);
    BOOL topmost_requested = is_topmost_requested();

    if (emacs_window)
    {
        /* If window is in full-screen mode, then it will be maximized. Clear WS_MAXIMIZE bit and then compare styles. */
        current_style = GetWindowLongPtrW(emacs_window, GWL_STYLE);
        current_style ^= WS_MAXIMIZE;
        /* We will toggle between full-screen/windowed modes for Emacs */
        if (current_style == EMACS_FULLSCREEN_STYLE)
        {
            style = EMACS_WINDOWED_STYLE;
            style_ex = EMACS_WINDOWED_STYLE_EX;
            if (topmost_requested)
            {
                style_ex |= WS_EX_TOPMOST;
                insert_after = HWND_NOTOPMOST;
            }
        }
        else
        {
            style = EMACS_FULLSCREEN_STYLE;
            style_ex = EMACS_FULLSCREEN_STYLE_EX;
            if (topmost_requested)
            {
                style_ex |= WS_EX_TOPMOST;
                insert_after = HWND_TOPMOST;
            }
        }

        SetWindowLongPtrW(emacs_window, GWL_STYLE, style);
        SetWindowLongPtrW(emacs_window, GWL_EXSTYLE, style_ex);
        SetWindowPos(emacs_window, insert_after, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
        ShowWindowAsync(emacs_window, SW_MAXIMIZE);
    }
    else
    {
        MessageBoxW(NULL, L"Can not find emacs window.", L"Error", MB_OK | MB_ICONERROR);
    }

    return 0;
}
コード例 #16
0
ファイル: process.cpp プロジェクト: guneysu-arsiv/injectory
Process Process::findByWindow(wstring className, wstring windowName)
{
	HWND hwnd = FindWindowW(className.empty() ? nullptr : className.c_str(), windowName.empty() ? nullptr : windowName.c_str());
	if (!hwnd)
	{
		DWORD errcode = GetLastError();
		BOOST_THROW_EXCEPTION(ex_injection() << e_api_function("FindWindow") << e_text("could not find window class:'" + to_string(className) + "' title:'" + to_string(windowName) + "'") << e_last_error(errcode));
	}

	pid_t pid = 0;
	GetWindowThreadProcessId(hwnd, &pid);
	if (pid == 0)
		BOOST_THROW_EXCEPTION(ex_injection() << e_api_function("GetWindowThreadProcessId") << e_text("could not get process id for window class:'" + to_string(className) + "' title:'" + to_string(windowName) + "'"));

	return Process::open(pid);
}
コード例 #17
0
ファイル: inipara.c プロジェクト: Firef0x/pcxfirefox
void WINAPI refresh_tray(void)
{
    HWND hwnd ;          /* tray hwnd */
    RECT m_trayToolBar;
    int  x;
    hwnd = FindWindowW(L"Shell_TrayWnd", NULL);
    hwnd = FindWindowExW(hwnd, 0, L"TrayNotifyWnd", NULL);
    hwnd = FindWindowExW(hwnd, 0, L"SysPager", NULL);
    hwnd = FindWindowExW(hwnd, 0, L"ToolbarWindow32", NULL);
    GetClientRect(hwnd, &m_trayToolBar);
    for(x = 1; x < m_trayToolBar.right - 1; x++)
    {
        int y = m_trayToolBar.bottom / 2;
        PostMessage(hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
    }
}
コード例 #18
0
//*********************************************************************//
// IsAlreadyRunning
//	- check if another instance of this application is running
//	- set focus to the other instance if it exists
bool IsAlreadyRunning( void )
{
	// Is there another window with the same class name & title?
	HWND hOtherWnd = FindWindowW( WINDOW_CLASS_NAME, WINDOW_TITLE );
	if( hOtherWnd != 0 )
	{
		// Is it minimized?
		if( IsIconic( hOtherWnd ) == TRUE )
			ShowWindow( hOtherWnd, SW_RESTORE );

		// Bring it to the foreground
		SetForegroundWindow( hOtherWnd );
		return true;
	}

	// No other instances are running
	return false;
}
コード例 #19
0
ファイル: Utils.cpp プロジェクト: nakedboov/WinClipCursor
HWND FindRequiredWindow(const std::wstring& className, const std::wstring& title, unsigned int attemptCount)
{
	HWND requiredWindow = NULL;

	if (className.empty() && title.empty())
		return NULL;

	while (attemptCount-- > 0)
	{
		requiredWindow	= FindWindowW(className.c_str(), title.c_str());
		if (requiredWindow != NULL)
			break;
						
		Sleep(g_SleepTimeOut);
	}

	return requiredWindow;
}
コード例 #20
0
wchar_t *sendpraatW (void *display, const wchar_t *programName, long timeOut, const wchar_t *text) {
    wchar_t nativeProgramName [100];
#if xwin
    char *home, pidFileName [256], messageFileName [256];
    FILE *pidFile;
    long pid, wid = 0;
#elif win
    wchar_t homeDirectory [256], messageFileName [256], windowName [256];
    HWND window;
    (void) display;
    (void) timeOut;
#elif mac
    AEDesc programDescriptor;
    AppleEvent event, reply;
    OSErr err;
    UInt32 signature;
    (void) display;
#endif

    /*
     * Clean up from an earlier call.
     */
    errorMessageW [0] = '\0';

    /*
     * Handle case differences.
     */
    wcscpy (nativeProgramName, programName);
#if xwin
    nativeProgramName [0] = tolower (nativeProgramName [0]);
#else
    nativeProgramName[0] = toupper (nativeProgramName [0]);
#endif

    /*
     * If the text is going to be sent in a file, create its name.
     * The file is going to be written into the preferences directory of the receiving program.
     * On X Window, the name will be something like /home/jane/.praat-dir/message.
     * On Windows, the name will be something like C:\Documents and Settings\Jane\Praat\Message.txt,
     * or C:\Windows\Praat\Message.txt on older systems.
     * On Macintosh, the text is NOT going to be sent in a file.
     */
#if xwin
    if ((home = getenv ("HOME")) == NULL) {
        swprintf (errorMessageW, 1000, L"HOME environment variable not set.");
        return errorMessageW;
    }
    sprintf (messageFileName, "%s/.%ls-dir/message", home, programName);
#elif win
    if (GetEnvironmentVariableW (L"USERPROFILE", homeDirectory, 255)) {
        ;   /* Ready. */
    } else if (GetEnvironmentVariableW (L"HOMEDRIVE", homeDirectory, 255)) {
        GetEnvironmentVariableW (L"HOMEPATH", homeDirectory + wcslen (homeDirectory), 255);
    } else {
        GetWindowsDirectoryW (homeDirectory, 255);
    }
    swprintf (messageFileName, 256, L"%ls\\%ls\\Message.txt", homeDirectory, programName);
#endif

    /*
     * Write the message file (Unix and Windows only).
     */
#if xwin
    FILE *messageFile;
    if ((messageFile = fopen (messageFileName, "w")) == NULL) {
        swprintf (errorMessageW, 1000, L"Cannot create message file \"%s\" "
                  L"(no privilege to write to directory, or disk full).\n", messageFileName);
        return errorMessageW;
    }
    if (timeOut)
        fwprintf (messageFile, L"#%ld\n", getpid ());   /* Write own process ID for callback. */
    fwprintf (messageFile, L"\ufeff%ls", text);
    fclose (messageFile);
#elif win
    {   /* 20090401 [email protected] added braces to please visual studio */
        FILE *messageFile;
        if ((messageFile = _wfopen (messageFileName, L"w")) == NULL) {
            swprintf (errorMessageW, 1000, L"Cannot create message file \"%ls\" "
                      L"(no privilege to write to directory, or disk full).\n", messageFileName);
            return errorMessageW;
        }
        fwprintf (messageFile, L"\ufeff%ls", text);
        fclose (messageFile);
    } /* 20090401 [email protected] added braces to please visual studio */
#endif

    /*
     * Where shall we send the message?
     */
#if xwin
    /*
     * Get the process ID and the window ID of a running Praat-shell program.
     */
    sprintf (pidFileName, "%s/.%ls-dir/pid", home, programName);
    if ((pidFile = fopen (pidFileName, "r")) == NULL) {
        swprintf (errorMessageW, 1000, L"Program %ls not running (or a version older than 3.6).", programName);
        return errorMessageW;
    }
    if (fscanf (pidFile, "%ld%ld", & pid, & wid) < 1) {
        fclose (pidFile);
        swprintf (errorMessageW, 1000, L"Program %ls not running, or disk has been full.", programName);
        return errorMessageW;
    }
    fclose (pidFile);
#elif win
    /*
     * Get the window handle of the "Objects" window of a running Praat-shell program.
     */
    swprintf (windowName, 256, L"PraatShell1 %ls", programName);
    window = FindWindowW (windowName, NULL);
    if (! window) {
        swprintf (errorMessageW, 1000, L"Program %ls not running (or an old version).", programName);
        return errorMessageW;
    }
#elif mac
    /*
     * Convert the program name to a Macintosh signature.
     * I know of no system routine for this, so I'll just translate the two most common names:
     */
    if (! wcscmp (programName, L"praat") || ! wcscmp (programName, L"Praat") || ! wcscmp (programName, L"PRAAT"))
        signature = 'PpgB';
    else if (! wcscmp (programName, L"als") || ! wcscmp (programName, L"Als") || ! wcscmp (programName, L"ALS"))
        signature = 'CclA';
    else
        signature = 0;
    AECreateDesc (typeApplSignature, & signature, 4, & programDescriptor);
#endif

    /*
     * Send the message.
     */
#if xwin
    /*
     * Be ready to receive notification of completion.
     */
    if (timeOut)
        signal (SIGUSR2, handleCompletion);
    /*
     * Notify running program.
     */
    if (wid != 0) {   /* Praat shell version October 21, 1998 or later? Send event to window. */
        /*
         * Notify main window.
         */
        XEvent event;
        int displaySupplied = display != NULL;
        if (! displaySupplied) {
            display = XOpenDisplay (NULL);
            if (display == NULL) {
                swprintf (errorMessageW, 1000, L"Cannot open display %s.", XDisplayName (NULL));
                return errorMessageW;
            }
        }
        event. type = ClientMessage;
        event. xclient. serial = 0;
        event. xclient. send_event = True;
        event. xclient. display = display;
        event. xclient. window = (Window) wid;
        event. xclient. message_type = XInternAtom (display, "SENDPRAAT", False);
        event. xclient. format = 8;   /* No byte swaps. */
        strcpy (& event. xclient.data.b [0], "SENDPRAAT");
        if(! XSendEvent (display, (Window) wid, True, KeyPressMask, & event)) {
            if (! displaySupplied) XCloseDisplay (display);
            swprintf (errorMessageW, 1000, L"Cannot send message to %ls (window %ld). "
                      "The program %ls may have been started by a different user, "
                      "or may have crashed.", programName, wid, programName);
            return errorMessageW;
        }
        if (! displaySupplied) XCloseDisplay (display);
    } else {
        /*
         * Use interrupt mechanism.
         */
        if (kill (pid, SIGUSR1)) {
            swprintf (errorMessageW, 1000, L"Cannot send message to %ls (process %ld). "
                      "The program %ls may have been started by a different user, "
                      "or may have crashed.", programName, pid, programName);
            return errorMessageW;
        }
    }
    /*
     * Wait for the running program to notify us of completion,
     * but do not wait for more than 'timeOut' seconds.
     */
    if (timeOut) {
        signal (SIGALRM, handleTimeOut);
        alarm (timeOut);
        theTimeOut = timeOut;   /* Hand an argument to handleTimeOut () in a static variable. */
        errorMessageW [0] = '\0';
        pause ();
        if (errorMessageW [0] != '\0') return errorMessageW;
    }
#elif win
    /*
     * Notify the running program by sending a WM_USER message to its main window.
     */
    if (SendMessage (window, WM_USER, 0, 0)) {
        swprintf (errorMessageW, 1000, L"Program %ls returns error.", programName);   /* BUG? */
        return errorMessageW;
    }
#elif mac
    /*
     * Notify the running program by sending it an Apple event of the magic class 758934755.
     */
    AECreateAppleEvent (758934755, 0, & programDescriptor, kAutoGenerateReturnID, 1, & event);
    AEPutParamPtr (& event, 1, typeUnicodeText, text, wcslen (text) + 1);
#ifdef __MACH__
    err = AESendMessage (& event, & reply,
                         ( timeOut == 0 ? kAENoReply : kAEWaitReply ) | kAECanInteract | kAECanSwitchLayer,
                         timeOut == 0 ? kNoTimeOut : 60 * timeOut);
#else
    err = AESend (& event, & reply,
                  ( timeOut == 0 ? kAENoReply : kAEWaitReply ) | kAECanInteract | kAECanSwitchLayer,
                  kAENormalPriority, timeOut == 0 ? kNoTimeOut : 60 * timeOut, NULL, NULL);
#endif
    if (err != noErr) {
        if (err == procNotFound || err == connectionInvalid)
            swprintf (errorMessageW, 1000, L"Could not send message to program \"%ls\".\n"
                      L"The program is probably not running (or an old version).", programName);
        else if (err == errAETimeout)
            swprintf (errorMessageW, 1000, L"Message to program \"%ls\" timed out "
                      L"after %ld seconds, before completion.", programName, timeOut);
        else
            swprintf (errorMessageW, 1000, L"Unexpected sendpraat error %d.\nNotify the author.", err);
    }
    AEDisposeDesc (& programDescriptor);
    AEDisposeDesc (& event);
    AEDisposeDesc (& reply);
#endif

    /*
     * Notify the caller of success (NULL pointer) or failure (string with an error message).
     */
    return errorMessageW [0] == '\0' ? NULL : errorMessageW;
}
コード例 #21
0
ファイル: connect.c プロジェクト: Gaikokujin/WinNT4
/***************************************************************************\
* ConnectConv
*
* Description:
* Work function for all Connect cases.
*
* Method:
*
* To reduce the number of windows we use and to simplify how client
* windows handle multiple WM_DDE_ACK messages during initiation, a
* single client window can handle many conversations, each with
* a different server window.
*
* The client window is created and set to a initiation state via the
* GWL_CONVSTATE window word. Initiates are then sent to enumerated server
* window candidates.
* The GWL_CONVSTATE value is used by the DDEML mother windows
* to determine if only one or several ACKs are desired to minimize
* unnessary message traffic.
*
* The client window GWL_CONVCONTEXT? window words are also used by
* Event Windows to pass context information.
*
* Note that all client and server windows are children of the mother
* window. This reduces the number of top level windows that
* WM_DDE_INITIATES need to hit.
*
* Each WM_DDE_ACK that is received by a client window while in the
* initiation state causes it to create a CL_CONV_INFO structure,
* partially initialize it, and link it into its list of CL_CONV_INFO
* structures. The head of the list is pointed to by the GWL_PCI
* client window word.
*
* After each WM_DDE_INITIALIZE is sent, the GWL_PCI value is checked
* to see if it exists and needs initialization to be completed. If
* this is the case the init code knows that at least one ACK was
* received in response to the WM_DDE_INITIALIZE send. The
* initialization of each CL_CONV_INFO struct that needs it is then completed.
*
* Once the broadcasting of WM_DDE_INITIALIZE is done, the init code
* then sets the GWL_CONVSTATE value in the client window to indicate that
* initialization is complete.
*
* Returns:
* The head pci to the client window or NULL if no connections made it.
*
* History:
* 11-1-91 sanfords Created.
\***************************************************************************/
PCL_CONV_INFO ConnectConv(
    PCL_INSTANCE_INFO pcii,
    LATOM laService,
    LATOM laTopic,
    HWND hwndTarget, // 0 implies broadcast
    HWND hwndSkip, // 0 implies no skips - avoids self-connections.
    PCONVCONTEXT pCC,
    HCONVLIST hConvList,
    DWORD clst)
{
    INIT_ENUM ie;
    PCL_CONV_INFO pci;
    PCONV_INFO pcoi;
    GATOM gaService, gaTopic;

    CheckDDECritIn;

    if (hwndTarget && hwndTarget == hwndSkip) {
        return(NULL);
    }

    LeaveDDECrit;
    CheckDDECritOut;

    if (pcii->flags & IIF_UNICODE) {
        ie.hwndClient = CreateWindowW((LPWSTR)(gpsi->atomSysClass[ICLS_DDEMLCLIENTW]),
                                     L"",
                                     WS_CHILD,
                                     0, 0, 0, 0,
                                     pcii->hwndMother,
                                     (HMENU)0,
                                     (HANDLE)0,
                                     (LPVOID)NULL);
    } else {
        ie.hwndClient = CreateWindowA((LPSTR)(gpsi->atomSysClass[ICLS_DDEMLCLIENTA]),
                                     "",
                                     WS_CHILD,
                                     0, 0, 0, 0,
                                     pcii->hwndMother,
                                     (HMENU)0,
                                     (HANDLE)0,
                                     (LPVOID)NULL);
    }

    EnterDDECrit;

    if (ie.hwndClient == 0) {
        return (NULL);
    }

    if (pCC != NULL) {
        if (!NtUserDdeSetQualityOfService(ie.hwndClient, &(pCC->qos), NULL)) {
            SetLastDDEMLError(pcii, DMLERR_MEMORY_ERROR);
            goto Error;
        }
    }
    /*
     * Note that a pci will be created and allocated for each ACK recieved.
     */
    SetConvContext(ie.hwndClient, (LONG *)pCC);
    SetWindowLong(ie.hwndClient, GWL_CONVSTATE, clst);
    SetWindowLong(ie.hwndClient, GWL_SHINST, (LONG)pcii->hInstServer);
    SetWindowLong(ie.hwndClient, GWL_CHINST, (LONG)pcii->hInstClient);

    gaService = LocalToGlobalAtom(laService);
    gaTopic = LocalToGlobalAtom(laTopic);
    ie.lParam = MAKELONG(gaService, gaTopic);
    if (!hwndTarget) {
        ie.hwndSkip = hwndSkip;
        ie.laServiceRequested = laService;
        ie.laTopic = laTopic;
        ie.hConvList = hConvList;
        ie.clst = clst;
    }

    LeaveDDECrit;

    if (hwndTarget) {
        SendMessage(hwndTarget, WM_DDE_INITIATE, (DWORD)ie.hwndClient,
                ie.lParam);
    } else {
        /*
         * Send this message to the nddeagnt app first so it can start
         * the netdde services BEFORE we do an enumeration of windows.
         * This lets things work the first time.  NetDDEAgent caches
         * service status so this is the fastest way to do this.
         */
        HWND hwndAgent = FindWindowW(SZ_NDDEAGNT_CLASS, SZ_NDDEAGNT_TITLE);
        if (hwndAgent) {
            SendMessage(hwndAgent,
                WM_DDE_INITIATE, (WPARAM)ie.hwndClient, ie.lParam);
        }
        EnumWindows((WNDENUMPROC)InitiateEnumerationProc, (LONG)&ie);
    }

    EnterDDECrit;
    /*
     * hConvList may have been destroyed during the enumeration but we are
     * done with it now so no need to revalidate.
     */

#ifdef DEBUG
    {
        WCHAR sz[10];

        if (gaService && GlobalGetAtomName(gaService, sz, 10) == 0) {
            RIPMSG1(RIP_ERROR, "Bad Service Atom after Initiate phase: %lX", (DWORD)gaService);
        }
        if (gaTopic && GlobalGetAtomName(gaTopic, sz, 10) == 0) {
            RIPMSG1(RIP_ERROR, "Bad Topic Atom after Initiate phase: %lX", (DWORD)gaTopic);
        }
    }
#endif // DEBUG

    GlobalDeleteAtom(gaService);
    GlobalDeleteAtom(gaTopic);

    //
    // Get the first pci allocated when a WM_DDE_ACK was recieved.
    //
    pci = (PCL_CONV_INFO)GetWindowLong(ie.hwndClient, GWL_PCI);
    if (pci == NULL) {
Error:
        LeaveDDECrit;
        NtUserDestroyWindow(ie.hwndClient);
        EnterDDECrit;
        return (NULL);
    }

    SetWindowLong(ie.hwndClient, GWL_CONVSTATE, CLST_CONNECTED);
    if (hwndTarget) {
        /*
         * If hwndTarget was NULL, the enumeration proc took care of this.
         */
        pci->hwndReconnect = hwndTarget;
        UserAssert(pci->ci.next == NULL);
        pci->ci.laServiceRequested = laService;
        IncLocalAtomCount(laService); // pci copy
    }

    if (pcii->MonitorFlags & MF_CONV) {
        for (pcoi = (PCONV_INFO)pci; pcoi; pcoi = pcoi->next) {
            MONCONV(pcoi, TRUE);
        }
    }
    return (pci);
}
コード例 #22
0
ファイル: winamp.c プロジェクト: leeter/hexchat
static int
winamp(const char *const word[], const char *const word_eol[], void *userdata)
{

char current_play[2048], *p;
char p_esc[2048];
char cur_esc[2048];
char truc[2048];
HWND hwndWinamp = FindWindowW(L"Winamp v1.x",NULL);

    if (hwndWinamp)
	{
	    {
	        if (!stricmp("PAUSE", word[2]))
			{
			   if (SendMessageW(hwndWinamp,WM_USER, 0, 104))
				{
			   	   SendMessageW(hwndWinamp, WM_COMMAND, 40046, 0);
			
			       if (SendMessageW(hwndWinamp, WM_USER, 0, 104) == PLAYING)
			   	       hexchat_print(ph, "Winamp: playing");
			       else
                       hexchat_print(ph, "Winamp: paused");
				}
            }
			else
		        if (!stricmp("STOP", word[2]))
			    {
			       SendMessageW(hwndWinamp, WM_COMMAND, 40047, 0);
			       hexchat_print(ph, "Winamp: stopped");
			    }
			else
			    if (!stricmp("PLAY", word[2]))
			    {
			         SendMessageW(hwndWinamp, WM_COMMAND, 40045, 0);
			         hexchat_print(ph, "Winamp: playing");
			    }
        	else

			    if (!stricmp("NEXT", word[2]))
			    {
			         SendMessageW(hwndWinamp, WM_COMMAND, 40048, 0);
			         hexchat_print(ph, "Winamp: next playlist entry");
			    }
			else

                if (!stricmp("PREV", word[2]))
			    {
			         SendMessageW(hwndWinamp, WM_COMMAND, 40044, 0);
			         hexchat_print(ph, "Winamp: previous playlist entry");
			    }
		    else

                if (!stricmp("START", word[2]))
			    {
			         SendMessageW(hwndWinamp, WM_COMMAND, 40154, 0);
			         hexchat_print(ph, "Winamp: playlist start");
			    }

		    else

                if (!word_eol[2][0])
			    {
					GetWindowText(hwndWinamp, current_play, sizeof(current_play));

					if (strchr(current_play, '-'))
					{
	
					p = current_play + strlen(current_play) - 8;
					while (p >= current_play)
					{
						if (!strnicmp(p, "- Winamp", 8)) break;
							p--;
					}

					if (p >= current_play) p--;
	
					while (p >= current_play && *p == ' ') p--;
						*++p=0;
	
	
					p = strchr(current_play, '.') + 1;

 					song_strcpy(p_esc, p);
 					song_strcpy(cur_esc, current_play);
	
					if (p)
					{
						sprintf(truc, "me is now playing:%s", p_esc);
					}
					else
					{
						sprintf(truc, "me is now playing:%s", cur_esc);
					}
	
	   				hexchat_commandf(ph, truc);
	
				}
				else hexchat_print(ph, "Winamp: Nothing being played.");
			}
		    else
                hexchat_printf(ph, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START]\n");
         }

	}
	else
	{
       hexchat_print(ph, "Winamp not found.\n");
	}
	return HEXCHAT_EAT_ALL;
}
コード例 #23
0
ファイル: main.cpp プロジェクト: korha/SoundCardSwitch
//-------------------------------------------------------------------------------------------------
void FMain()
{
    if (const HWND hWnd = FindWindowW(g_wGuidClass, nullptr))
        PostMessageW(hWnd, WM_CLOSE, 0, 0);

    if (SUCCEEDED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)))
    {
        IMMDeviceEnumerator *immDeviceEnumerator;
        if (CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), reinterpret_cast<LPVOID*>(&immDeviceEnumerator)) == S_OK)
        {
            IMMDevice *immDeviceDefault;
            if (immDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &immDeviceDefault) == S_OK)
            {
                wchar_t *wIdDefaultOld;
                HRESULT hr = immDeviceDefault->GetId(&wIdDefaultOld);
                immDeviceDefault->Release();
                if (hr == S_OK)
                {
                    IMMDeviceCollection *immDeviceCollection;
                    hr = immDeviceEnumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &immDeviceCollection);
                    immDeviceEnumerator->Release();
                    if (hr == S_OK)
                    {
                        UINT iCount;
                        if (immDeviceCollection->GetCount(&iCount) == S_OK)
                        {
                            bool bFail = true;
                            for (UINT i = 0; i < iCount; ++i)
                            {
                                IMMDevice *immDevice;
                                if (immDeviceCollection->Item(i, &immDevice) == S_OK)
                                {
                                    wchar_t *wIdEnum;
                                    hr = immDevice->GetId(&wIdEnum);
                                    immDevice->Release();
                                    if (hr == S_OK)
                                    {
                                        if (FCompareMemoryW(wIdDefaultOld, wIdEnum))
                                        {
                                            bFail = false;
                                            if (++i >= iCount)
                                                i = 0;
                                            hr = immDeviceCollection->Item(i, &immDevice);
                                            immDeviceCollection->Release();
                                            if (hr == S_OK)
                                            {
                                                wchar_t *wIdDefaultNew;
                                                if (immDevice->GetId(&wIdDefaultNew) == S_OK)
                                                {
                                                    IPropertyStore *ipStore;
                                                    hr = immDevice->OpenPropertyStore(STGM_READ, &ipStore);
                                                    immDevice->Release();
                                                    if (hr == S_OK)
                                                    {
                                                        PROPVARIANT propFriendlyName;
                                                        PropVariantInitFix(&propFriendlyName);
                                                        PROPERTYKEY propKeyFriendlyName;
                                                        propKeyFriendlyName.fmtid.Data1 = 0xA45C254E;
                                                        propKeyFriendlyName.fmtid.Data2 = 0xDF1C;
                                                        propKeyFriendlyName.fmtid.Data3 = 0x4EFD;
                                                        FCopyMemory(propKeyFriendlyName.fmtid.Data4);
                                                        propKeyFriendlyName.pid = 14;
                                                        hr = ipStore->GetValue(propKeyFriendlyName, &propFriendlyName);
                                                        ipStore->Release();
                                                        if (SUCCEEDED(hr))
                                                        {
                                                            IPolicyConfig *pPolicyConfig;
                                                            if (CoCreateInstance(__uuidof(CPolicyConfigClient), nullptr, CLSCTX_ALL, (GetVersion() & 0xFF) >= 10 ? __uuidof(IPolicyConfigWin10) : __uuidof(IPolicyConfig), reinterpret_cast<LPVOID*>(&pPolicyConfig)) == S_OK)
                                                            {
                                                                hr = pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eConsole);
                                                                if (hr == S_OK)
                                                                {
                                                                    pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eMultimedia);
                                                                    pPolicyConfig->SetDefaultEndpoint(wIdDefaultNew, eCommunications);
                                                                }
                                                                pPolicyConfig->Release();
                                                                if (hr == S_OK)
                                                                {
                                                                    WNDCLASSEX wndCl;
                                                                    wndCl.cbSize = sizeof(WNDCLASSEX);
                                                                    wndCl.style = 0;
                                                                    wndCl.lpfnWndProc = WindowProc;
                                                                    wndCl.cbClsExtra = 0;
                                                                    wndCl.cbWndExtra = 0;
                                                                    wndCl.hInstance = GetModuleHandleW(nullptr);
                                                                    wndCl.hIcon = nullptr;
                                                                    wndCl.hCursor = nullptr;
                                                                    wndCl.hbrBackground = nullptr;
                                                                    wndCl.lpszMenuName = nullptr;
                                                                    wndCl.lpszClassName = g_wGuidClass;
                                                                    wndCl.hIconSm = nullptr;

                                                                    if (RegisterClassExW(&wndCl))
                                                                    {
                                                                        if (CreateWindowExW(WS_EX_NOACTIVATE | WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, g_wGuidClass, nullptr, WS_POPUP | WS_VISIBLE | WS_MAXIMIZE, 0, 0, 0, 0, nullptr, nullptr, wndCl.hInstance, propFriendlyName.pwszVal))
                                                                        {
                                                                            MSG msg;
                                                                            while (GetMessageW(&msg, nullptr, 0, 0) > 0)
                                                                                DispatchMessageW(&msg);
                                                                        }
                                                                        UnregisterClassW(g_wGuidClass, wndCl.hInstance);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        PropVariantClear(&propFriendlyName);
                                                    }
                                                    CoTaskMemFree(wIdDefaultNew);
                                                }
                                                else
                                                    immDevice->Release();
                                            }
                                            break;
                                        }
                                        CoTaskMemFree(wIdEnum);
                                    }
                                }
                            }
                            if (bFail)
                                immDeviceCollection->Release();
                        }
                        else
                            immDeviceCollection->Release();
                    }
                    CoTaskMemFree(wIdDefaultOld);
                }
                else
                    immDeviceEnumerator->Release();
            }
            else
                immDeviceEnumerator->Release();
        }
        CoUninitialize();
    }
}
コード例 #24
0
/***************************
 * CreateDlg
 ***************************/
SHVBool SHVMainThreadEventDispatcherConsole::CreateDlg()
{
SHVString16C title(SHVString16C::FromWin32(L"SHIVA Console"));
int titleLength = title.GetLength();
HLOCAL templateHandle;
void* dlgTemplate;
char* buffer;
int len = AlignDWord( sizeof(DLGTEMPLATE) + sizeof(WORD) * 4
	+ ((titleLength) ? ((titleLength+1)*2 + sizeof(WORD)) : 0)
	);

	HWND oldWindow = FindWindowW(NULL,title.GetSafeBufferWin32());
	///\todo add code to make sure the window is created with the same application as us
	if (oldWindow) 
	{
		// set focus to foremost child window
		// The "| 0x01" is used to bring any owned windows to the foreground and
		// activate them.
		SetForegroundWindow((HWND)((ULONG) oldWindow | 0x00000001));
		return SHVBool::False;
	}

	templateHandle = LocalAlloc(LHND, len);

	dlgTemplate = LocalLock(templateHandle);
	
	memset(dlgTemplate,0,len);

	LPDLGTEMPLATE temp = (LPDLGTEMPLATE)dlgTemplate;
	temp->x  = 0;
	temp->y  = 0;
	temp->cx = 240;
	temp->cy = 180;
	temp->cdit  = 0; // number of controls
	temp->style = WS_CAPTION | WS_SYSMENU | WS_POPUP | WS_OVERLAPPED;
	temp->dwExtendedStyle = WS_EX_DLGMODALFRAME;

	// skip the dlgtemplate data from buffer
	buffer = (char*)dlgTemplate;
	buffer += sizeof(DLGTEMPLATE);

	// set menu and skip
	*(WORD*)buffer = 0;
	buffer += sizeof(WORD);

	// set class and skip
	*(WORD*)buffer = 0;
	buffer += sizeof(WORD);

	// set title and skip
	if (titleLength)
	{
	WCHAR* titleWChar = (WCHAR*)buffer;

		wcscpy(titleWChar,title.GetSafeBufferWin32());
	}
	else
	{
		*(WORD*)buffer = 0;
		buffer += sizeof(WORD);
	}

#ifdef __SHIVA_POCKETPC
	memset (&s_sai, 0, sizeof(s_sai));
	s_sai.cbSize = sizeof(s_sai);
#endif

	wndConsole = CreateDialogIndirectW(GetModuleHandle(NULL), (LPDLGTEMPLATE)dlgTemplate, NULL, &SHVMainThreadEventDispatcherConsole::WinceDlgProc);

	LocalUnlock(templateHandle);
	LocalFree(templateHandle);


	SetWindowLongPtr(wndConsole,GWLP_USERDATA,(LONG_PTR)this);

#ifdef __SHIVA_POCKETPC
	{
	SHMENUBARINFO mbi;

		memset(&mbi, 0, sizeof(SHMENUBARINFO));
		mbi.cbSize     = sizeof(SHMENUBARINFO);
		mbi.hwndParent = wndConsole;
		mbi.nToolBarId = 100;
		mbi.hInstRes   = GetModuleHandle(NULL);
		mbi.nBmpId     = 0;
		mbi.cBmpImages = 0;
		mbi.dwFlags    = SHCMBF_EMPTYBAR;

		SHCreateMenuBar(&mbi);
		if (mbi.hwndMB)
		{
		RECT menubarRect, winRect;
			GetWindowRect(wndConsole, &winRect);
			GetWindowRect(mbi.hwndMB, &menubarRect);
			winRect.bottom -= (menubarRect.bottom - menubarRect.top);
			MoveWindow(wndConsole, winRect.left, winRect.top, winRect.right, winRect.bottom, FALSE);
		}
	}
#endif

	// font stuff
	{
	HDC dc = ::GetDC(NULL);
	int dcBackup = ::SaveDC(dc);
	SIZE sz;
	LOGFONTW lf;

#if defined(__SHIVA_WINCE) && (_WIN32_WCE < 500)
		///\todo Implement a way to get the real message font from the system on windows CE
		memset(&lf, 0, sizeof(LOGFONT));
		lf.lfWeight = FW_NORMAL;
		lf.lfHeight = 15; // reasonable size
#else
	HFONT stockFont = (HFONT)::GetStockObject(SYSTEM_FONT);

		///\todo Test if this method works for older wince's
	
		// do something!
		SHVVERIFY(::GDIGetObject(stockFont, sizeof(LOGFONT), &lf));
#endif
		lf.lfPitchAndFamily = FIXED_PITCH|FF_MODERN;
		wcscpy(lf.lfFaceName, L"MS Shell Dlg");
		Font = ::CreateFontIndirect(&lf);
		::SendMessage(wndConsole,WM_SETFONT,(WPARAM)Font,0);

		::SelectObject(dc,Font);
		
		SHVVERIFY(::GetTextExtentPointW(dc,L" ",1,&sz));
		fontHeight = sz.cy + 2;
		fontWidth = sz.cx;

		::RestoreDC(dc,dcBackup);
		::ReleaseDC(NULL,dc);

	}

	// edit box
	edtConsole = ::CreateWindowExW(0,L"EDIT", L"", ES_LEFT|ES_AUTOHSCROLL|WS_TABSTOP|WS_CHILD|WS_VISIBLE,
			0, 0, 0, fontHeight, wndConsole, NULL, GetModuleHandle(NULL), NULL);
	edtProc = (WNDPROC)GetWindowLongPtr(edtConsole,GWLP_WNDPROC);
	SetWindowLongPtr(edtConsole,GWLP_WNDPROC,(LONG_PTR)&SHVMainThreadEventDispatcherConsole::WinceEditProc);

	::SendMessage(edtConsole,WM_SETFONT,(WPARAM)Font,0);

	Resize();
	::ShowWindow(wndConsole,SW_SHOW);
	::UpdateWindow(wndConsole);

	return SHVBool::True;
}
コード例 #25
0
ファイル: unique.c プロジェクト: Distrotech/gimp
static gboolean
gimp_unique_win32_open (const gchar **filenames,
			gboolean      as_new)
{
#ifndef GIMP_CONSOLE_COMPILATION

/*  for the proxy window names  */
#include "gui/gui-unique.h"

  HWND  window_handle = FindWindowW (GIMP_UNIQUE_WIN32_WINDOW_CLASS,
				     GIMP_UNIQUE_WIN32_WINDOW_NAME);

  if (window_handle)
    {
      COPYDATASTRUCT  copydata = { 0, };

      if (filenames)
        {
          gchar  *cwd   = g_get_current_dir ();
          gint    i;

          for (i = 0; filenames[i]; i++)
            {
              GFile *file;
              file = g_file_new_for_commandline_arg_and_cwd (filenames[i], cwd);

              if (file)
                {
                  gchar *uri = g_file_get_uri (file);

                  copydata.lpData = uri;
                  copydata.cbData = strlen (uri) + 1;  /* size in bytes   */
                  copydata.dwData = (long) as_new;

                  SendMessage (window_handle,
                               WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);

                  g_free (uri);
                  g_object_unref (file);
                }
              else
                {
                  g_printerr ("conversion to uri failed for '%s'\n",
                              filenames[i]);
                }
            }

          g_free (cwd);
        }
      else
        {
          SendMessage (window_handle,
                       WM_COPYDATA, (WPARAM) window_handle, (LPARAM) &copydata);
        }

      return TRUE;
    }

#endif

  return FALSE;
}
コード例 #26
0
ファイル: clipbrd.c プロジェクト: JaredSmudde/reactos
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
    HACCEL hAccel;
    HWND hPrevWindow;
    WNDCLASSEXW wndclass;
    WCHAR szBuffer[MAX_STRING_LEN];

    hPrevWindow = FindWindowW(szClassName, NULL);
    if (hPrevWindow)
    {
        BringWindowToFront(hPrevWindow);
        return 0;
    }

    switch (GetUserDefaultUILanguage())
    {
        case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
            SetProcessDefaultLayout(LAYOUT_RTL);
            break;

        default:
            break;
    }

    ZeroMemory(&Globals, sizeof(Globals));
    Globals.hInstance = hInstance;

    ZeroMemory(&wndclass, sizeof(wndclass));
    wndclass.cbSize = sizeof(wndclass);
    wndclass.lpfnWndProc = MainWndProc;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIconW(hInstance, MAKEINTRESOURCEW(CLIPBRD_ICON));
    wndclass.hCursor = LoadCursorW(0, IDC_ARROW);
    wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndclass.lpszMenuName = MAKEINTRESOURCEW(MAIN_MENU);
    wndclass.lpszClassName = szClassName;

    if (!RegisterClassExW(&wndclass))
    {
        ShowLastWin32Error(NULL);
        return 0;
    }

    ZeroMemory(&Scrollstate, sizeof(Scrollstate));

    LoadStringW(hInstance, STRING_CLIPBOARD, szBuffer, ARRAYSIZE(szBuffer));
    Globals.hMainWnd = CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_ACCEPTFILES,
                                       szClassName,
                                       szBuffer,
                                       WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       CW_USEDEFAULT,
                                       NULL,
                                       NULL,
                                       Globals.hInstance,
                                       NULL);
    if (!Globals.hMainWnd)
    {
        ShowLastWin32Error(NULL);
        return 0;
    }

    ShowWindow(Globals.hMainWnd, nCmdShow);
    UpdateWindow(Globals.hMainWnd);

    hAccel = LoadAcceleratorsW(Globals.hInstance, MAKEINTRESOURCEW(ID_ACCEL));
    if (!hAccel)
    {
        ShowLastWin32Error(Globals.hMainWnd);
    }

    /* If the user provided a path to a clipboard data file, try to open it */
    if (__argc >= 2)
        LoadClipboardDataFromFile(__wargv[1]);

    while (GetMessageW(&msg, 0, 0, 0))
    {
        if (!TranslateAcceleratorW(Globals.hMainWnd, hAccel, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessageW(&msg);
        }
    }

    return (int)msg.wParam;
}
コード例 #27
0
ファイル: systray.cpp プロジェクト: Moteesh/reactos
/*************************************************************************
 * Shell_NotifyIconW            [SHELL32.298]
 */
BOOL WINAPI Shell_NotifyIconW(DWORD dwMessage, PNOTIFYICONDATAW pnid)
{
    BOOL ret = FALSE;
    HWND hShellTrayWnd;
    DWORD cbSize, dwValidFlags;
    TRAYNOTIFYDATAW tnid;
    COPYDATASTRUCT data;

    /* Find a handle to the shell tray window */
    hShellTrayWnd = FindWindowW(L"Shell_TrayWnd", NULL);
    if (!hShellTrayWnd)
        return FALSE; // None found, bail out

    /* Validate the structure size and the flags */
    cbSize = pnid->cbSize;
    dwValidFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
    if (cbSize == sizeof(NOTIFYICONDATAW))
    {
        dwValidFlags |= NIF_STATE | NIF_INFO | NIF_GUID /* | NIF_REALTIME | NIF_SHOWTIP */;
    }
    else if (cbSize == NOTIFYICONDATAW_V3_SIZE)
    {
        dwValidFlags |= NIF_STATE | NIF_INFO | NIF_GUID;
    }
    else if (cbSize == NOTIFYICONDATAW_V2_SIZE)
    {
        dwValidFlags |= NIF_STATE | NIF_INFO;
    }
    else // if cbSize == NOTIFYICONDATAW_V1_SIZE or something else
    {
        if (cbSize != NOTIFYICONDATAW_V1_SIZE)
        {
            WARN("Invalid cbSize (%d) - using only Win95 fields (size=%d)\n",
                cbSize, NOTIFYICONDATAW_V1_SIZE);
            cbSize = NOTIFYICONDATAW_V1_SIZE;
        }
    }

    /* Build the data structure */
    ZeroMemory(&tnid, sizeof(tnid));
    tnid.dwSignature = NI_NOTIFY_SIG;
    tnid.dwMessage   = dwMessage;

    /* Copy only the needed data, everything else is zeroed out */
    CopyMemory(&tnid.nid, pnid, cbSize);
    /* Adjust the size (the NOTIFYICONDATA structure is the full-fledged one) and the flags */
    tnid.nid.cbSize = sizeof(tnid.nid);
    tnid.nid.uFlags &= dwValidFlags;

    /* Be sure the szTip member (that could be cut-off) is correctly NULL-terminated */
    if (tnid.nid.uFlags & NIF_TIP)
    {
        if (cbSize <= NOTIFYICONDATAW_V1_SIZE)
        {
#define NIDV1_TIP_SIZE_W  (NOTIFYICONDATAW_V1_SIZE - FIELD_OFFSET(NOTIFYICONDATAW, szTip))/sizeof(WCHAR)
            tnid.nid.szTip[NIDV1_TIP_SIZE_W - 1] = 0;
#undef NIDV1_TIP_SIZE_W
        }
        else
        {
            tnid.nid.szTip[_countof(tnid.nid.szTip) - 1] = 0;
        }
    }

    /* Be sure the info strings are correctly NULL-terminated */
    if (tnid.nid.uFlags & NIF_INFO)
    {
        tnid.nid.szInfo[_countof(tnid.nid.szInfo) - 1] = 0;
        tnid.nid.szInfoTitle[_countof(tnid.nid.szInfoTitle) - 1] = 0;
    }

    /* Send the data */
    data.dwData = 1;
    data.cbData = sizeof(tnid);
    data.lpData = &tnid;
    if (SendMessageW(hShellTrayWnd, WM_COPYDATA, (WPARAM)pnid->hWnd, (LPARAM)&data))
        ret = TRUE;

    return ret;
}
コード例 #28
0
ファイル: displayfunc.cpp プロジェクト: rbrtribeiro/smalllux3
void keyFunc(unsigned char key, int x, int y) {
	switch (key) {
		case 'p': {
			session->SaveFilmImage();
			break;
		}
		case 27: { // Escape key
			delete session;

			SLG_LOG("Done.");
			exit(EXIT_SUCCESS);
			break;
		}
		case ' ': // Restart rendering
			session->Stop();
			session->Start();
			break;
		case 'a': {
			session->BeginEdit();
			session->renderConfig->scene->camera->TranslateLeft(MOVE_STEP);
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		}
		case 'd': {
			session->BeginEdit();
			session->renderConfig->scene->camera->TranslateRight(MOVE_STEP);
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		}
		case 'w': {
			session->BeginEdit();
			session->renderConfig->scene->camera->TranslateForward(MOVE_STEP);
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		}
		case 's': {
			session->BeginEdit();
			session->renderConfig->scene->camera->TranslateBackward(MOVE_STEP);
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		}
		case 'r':
			session->BeginEdit();
			session->renderConfig->scene->camera->Translate(Vector(0.f, 0.f, MOVE_STEP));
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		case 'f':
			session->BeginEdit();
			session->renderConfig->scene->camera->Translate(Vector(0.f, 0.f, -MOVE_STEP));
			session->renderConfig->scene->camera->Update(
				session->film->GetWidth(), session->film->GetHeight());
			session->editActions.AddAction(CAMERA_EDIT);
			session->EndEdit();
			break;
		case 'h':
			OSDPrintHelp = (!OSDPrintHelp);
			break;
		case 'n': {
			const unsigned int screenRefreshInterval = session->renderConfig->GetScreenRefreshInterval();
			if (screenRefreshInterval > 1000)
				session->renderConfig->SetScreenRefreshInterval(max(1000u, screenRefreshInterval - 1000));
			else
				session->renderConfig->SetScreenRefreshInterval(max(50u, screenRefreshInterval - 50));
			break;
		}
		case 'm': {
			const unsigned int screenRefreshInterval = session->renderConfig->GetScreenRefreshInterval();
			if (screenRefreshInterval >= 1000)
				session->renderConfig->SetScreenRefreshInterval(screenRefreshInterval + 1000);
			else
				session->renderConfig->SetScreenRefreshInterval(screenRefreshInterval + 50);
			break;
		}
		case 't':
			// Toggle tonemap type
			if (session->film->GetToneMapParams()->GetType() == TONEMAP_LINEAR) {
				Reinhard02ToneMapParams params;
				session->film->SetToneMapParams(params);
			} else {
				LinearToneMapParams params;
				session->film->SetToneMapParams(params);
			}
			break;
		/*case '0':
			config->SetRenderingEngineType(PATHOCL);
			glutTimerFunc(config->GetScreenRefreshInterval(), timerFunc, 0);
			break;*/
		case 'o': {
#if defined(WIN32)
			std::wstring ws;
			ws.assign(SLG_LABEL.begin (), SLG_LABEL.end());
			HWND hWnd = FindWindowW(NULL, ws.c_str());
			if (GetWindowLongPtr(hWnd, GWL_EXSTYLE) & WS_EX_TOPMOST)
				SetWindowPos(hWnd, HWND_NOTOPMOST, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
			else
				SetWindowPos(hWnd, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
#endif
			break;
		}

		default:
			break;
	}

	displayFunc();
}
コード例 #29
0
ファイル: winmain.c プロジェクト: rmallof/reactos
int WINAPI
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd)
{
    WNDCLASSEXW WndClass = {0};
    WCHAR szWindowClass[] = L"ROSAPPMGR";
    WCHAR szWindowName[MAX_STR_LEN];
    WCHAR szErrorText[MAX_STR_LEN];
    HANDLE hMutex = NULL;
    MSG Msg;

    switch (GetUserDefaultUILanguage())
  {
    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
      SetProcessDefaultLayout(LAYOUT_RTL);
      break;

    default:
      break;
  }

    hInst = hInstance;

    if (!IsUserAnAdmin())
    {
        LoadStringW(hInst, IDS_USER_NOT_ADMIN, szErrorText, sizeof(szErrorText) / sizeof(WCHAR));
        MessageBox(0, szErrorText, NULL, MB_OK | MB_ICONWARNING);
        return 1;
    }

    hMutex = CreateMutexW(NULL, FALSE, szWindowClass);
    if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
    {
        /* If already started, it is found its window */
        HWND hWindow = FindWindowW(szWindowClass, NULL);

        /* Activate window */
        ShowWindow(hWindow, SW_SHOWNORMAL);
        SetForegroundWindow(hWindow);
        return 1;
    }

    if (!LoadSettings())
    {
        FillDefaultSettings(&SettingsInfo);
    }

    InitLogs();

    InitCommonControls();

    /* Create the window */
    WndClass.cbSize        = sizeof(WNDCLASSEXW);
    WndClass.lpszClassName = szWindowClass;
    WndClass.lpfnWndProc   = MainWindowProc;
    WndClass.hInstance     = hInstance;
    WndClass.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN));
    WndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
    WndClass.lpszMenuName  = MAKEINTRESOURCEW(IDR_MAINMENU);

    if (RegisterClassExW(&WndClass) == (ATOM)0) goto Exit;

    LoadStringW(hInst, IDS_APPTITLE, szWindowName, sizeof(szWindowName) / sizeof(WCHAR));

    hMainWnd = CreateWindowExW(WS_EX_WINDOWEDGE,
                               szWindowClass,
                               szWindowName,
                               WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
                               CW_USEDEFAULT,
                               CW_USEDEFAULT,
                               680,
                               450,
                               NULL,
                               NULL,
                               hInstance,
                               NULL);

    if (!hMainWnd) goto Exit;

    /* Show it */
    ShowWindow(hMainWnd, SW_SHOW);
    UpdateWindow(hMainWnd);

    /* Message Loop */
    while (GetMessage(&Msg, NULL, 0, 0))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

Exit:
    if (hMutex) CloseHandle(hMutex);

    return 0;
}
コード例 #30
0
int DigitalWatchWindow::Create(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	char szWindowClass[100];
	char szTitle[100];

	sprintf((char *)&szWindowClass, "DIGITALWATCH_BDA");
	sprintf((char *)&szTitle, "DigitalWatch");

	g_pData->hWnd = FindWindowW(CA2W(szWindowClass), NULL);

	//LATER: Option for multiple instances
	if (g_pData->hWnd != NULL && !g_pData->settings.application.multiple)
	{
		(log << "An instance of Digital Watch is already running.\n  Bringing the existing instance to the foreground.\n").Write();
		SetForegroundWindow(g_pData->hWnd);
		return FALSE;
	}

//	if (g_pData->hWnd != NULL && g_pData->settings.application.multiple)
//		g_pData->values.application.multiple = g_pData->settings.application.multiple;

	HBRUSH br = CreateSolidBrush(0x00000000);

	WNDCLASSEXA wcex;
	wcex.cbSize = sizeof(WNDCLASSEXA);

	wcex.style			= CS_DBLCLKS;// | CS_HREDRAW | CS_VREDRAW;// | CS_NOCLOSE | CS_DBLCLKS;
	wcex.lpfnWndProc	= (WNDPROC)MainWndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= 0;
	wcex.hIcon			= LoadIcon(hInstance, (LPCTSTR)IDI_DIGITALWATCH);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= br;
	wcex.lpszMenuName	= 0;
	wcex.lpszClassName	= szWindowClass;
	wcex.hIconSm		= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	ATOM ar = RegisterClassExA(&wcex);

	USES_CONVERSION;
	g_pData->hWnd = CreateWindowA(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW/*WS_THICKFRAME*/, CW_USEDEFAULT, 0, 726, 435, NULL, NULL, NULL, NULL);
	if (!g_pData->hWnd)
	{
		__int64 err = GetLastError();
		//return_FALSE_SHOWMSG("Error creating window: " << err)
		return (log << "Error creating window: " << err << "\n").Show();
	}

	SetWindowLong(g_pData->hWnd, GWL_STYLE, GetWindowLong(g_pData->hWnd, GWL_STYLE) & (~(WS_CAPTION/* | WS_BORDER*/))); 

	if (g_pData->settings.window.startAtLastWindowPosition && g_pData->settings.loadedFromFile)
	{
		(log << "Restoring last window position. x=" << g_pData->values.window.position.x << " y=" << g_pData->values.window.position.y << " width=" <<g_pData->values.window.size.width << " height=" << g_pData->values.window.size.height << "\n").Write();
	}
	
	BOOL bFullscreen = g_pData->values.window.bFullScreen;
	g_pData->values.window.bFullScreen = FALSE;
	g_pTv->SetWindowPos(g_pData->values.window.position.x, g_pData->values.window.position.y, g_pData->values.window.size.width, g_pData->values.window.size.height, g_pData->settings.window.startAtLastWindowPosition && g_pData->settings.loadedFromFile, TRUE);
	g_pData->values.window.bFullScreen = bFullscreen;

	ShowWindow(g_pData->hWnd, nCmdShow);
	UpdateWindow(g_pData->hWnd);

	if (g_pData->settings.window.startFullscreen != 0)
	{
		(log << "Restoring fullscreen state\n").Write();
		g_pTv->Fullscreen();
	}
	if (g_pData->settings.window.startAlwaysOnTop != 0)
	{
		(log << "Restoring always on top\n").Write();
		g_pTv->AlwaysOnTop();
	}

	return TRUE;
}