Exemplo n.º 1
0
// Function mostly compatible with the normal EnumChildWindows,
// except it lists in Z-Order and it doesn't ensure consistency
// if a window is removed while enumerating
void EnumWindowsZOrder(WNDENUMPROC callback, LPARAM lParam)
{
    HWND hwnd, hwndOwner;
    WCHAR szClass[64];
    DWORD ExStyle;

    for (hwnd = GetTopWindow(NULL); hwnd; hwnd = GetWindow(hwnd, GW_HWNDNEXT))
    {
        if (!IsWindowVisible(hwnd))
            continue;

        // check special windows
        if (!GetClassNameW(hwnd, szClass, _countof(szClass)) ||
            wcscmp(szClass, L"Shell_TrayWnd") == 0 ||
            wcscmp(szClass, L"Progman") == 0)
        {
            continue;
        }

        ExStyle = GetWindowLongPtrW(hwnd, GWL_EXSTYLE);
        if (ExStyle & WS_EX_TOOLWINDOW)
            continue;

        hwndOwner = GetWindow(hwnd, GW_OWNER);
        if ((ExStyle & WS_EX_APPWINDOW) || !IsWindowVisible(hwndOwner))
        {
            if (!callback(hwnd, lParam))
                break;

            continue;
        }
    }
}
Exemplo n.º 2
0
static BOOL CALLBACK find_top_window(HWND hwnd, LPARAM lParam)
{
    WCHAR str[1024];
    HWND* pwindow;

    if (!GetClassNameW(hwnd, str, ARRAY_LENGTH(str)) ||
        lstrcmpiW(str, g_window_class))
        return TRUE;

    if (!GetWindowTextW(hwnd, str, ARRAY_LENGTH(str)) ||
        lstrcmpiW(str, g_window_title))
        return TRUE;

    /* Check that the window is visible and active */
    if (!g_disabled)
    {
        DWORD style = GetWindowStyle(hwnd);
        if (!(style & WS_VISIBLE) || (style &  WS_DISABLED))
            return TRUE;
    }

    /* See if we find the control we want */
    if (g_control_class)
    {
        HWND control = NULL;
        EnumChildWindows(hwnd, find_control, (LPARAM)&control);
        if (!control)
            return TRUE;
        hwnd=control;
    }

    pwindow = (HWND*)lParam;
    *pwindow = hwnd;
    return FALSE;
}
Exemplo n.º 3
0
BOOL is_mozclass(HWND hwnd)
{
	WCHAR m_temp[VALUE_LEN+1] = {0};
	GetClassNameW(hwnd,m_temp,VALUE_LEN);
	return ( _wcsnicmp(m_temp,L"MozillaWindowClass",VALUE_LEN) ==0 ||
			 _wcsnicmp(m_temp,L"MozillaDialogClass",VALUE_LEN) ==0 ) ;
}
Exemplo n.º 4
0
static BOOL CALLBACK find_control(HWND hwnd, LPARAM lParam)
{
    WCHAR str[1024];
    HWND* pcontrol;

    if (!GetClassNameW(hwnd, str, ARRAY_LENGTH(str)) ||
        lstrcmpiW(str, g_control_class))
        return TRUE;

    if (g_control_caption)
    {
        if (!GetWindowTextW(hwnd, str, ARRAY_LENGTH(str)) ||
            !my_strstriW(str, g_control_caption))
            return TRUE;
    }
    if (g_control_id && g_control_id != GetWindowLong(hwnd, GWL_ID))
        return TRUE;

    /* Check that the control is visible and active */
    if (!g_disabled)
    {
        DWORD style = GetWindowStyle(hwnd);
        if (!(style & WS_VISIBLE) || (style &  WS_DISABLED))
            return TRUE;
    }

    pcontrol = (HWND*)lParam;
    *pcontrol = hwnd;
    return FALSE;
}
Exemplo n.º 5
0
// this is a helper function that takes the logic of determining window classes and puts it all in one place
// there are a number of places where we need to know what window class an arbitrary handle has
// theoretically we could use the class atom to avoid a _wcsicmp()
// however, raymond chen advises against this - http://blogs.msdn.com/b/oldnewthing/archive/2004/10/11/240744.aspx (and we're not in control of the Tab class, before you say anything)
// usage: windowClassOf(hwnd, L"class 1", L"class 2", ..., NULL)
int windowClassOf(HWND hwnd, ...)
{
// MSDN says 256 is the maximum length of a class name; add a few characters just to be safe (because it doesn't say whether this includes the terminating null character)
#define maxClassName 260
    WCHAR classname[maxClassName + 1];
    va_list ap;
    WCHAR *curname;
    int i;

    if (GetClassNameW(hwnd, classname, maxClassName) == 0)
        xpanic("error getting name of window class in windowClassOf()", GetLastError());
    va_start(ap, hwnd);
    i = 0;
    for (;;) {
        curname = va_arg(ap, WCHAR *);
        if (curname == NULL)
            break;
        if (_wcsicmp(classname, curname) == 0) {
            va_end(ap);
            return i;
        }
        i++;
    }
    // no match
    va_end(ap);
    return -1;
}
Exemplo n.º 6
0
	inline std::string get_class_name( HWND hwnd )
	{
		wchar_t tmp[256];

		if( !GetClassNameW( hwnd, tmp, std::extent< decltype( tmp ) >::value ) ) {
			return{};
		}

		return winapi::widechar_to_multibyte( tmp, CP_UTF8 );
	}
Exemplo n.º 7
0
BOOL CheckWindowClass(HWND hwnd, PCWSTR className)
{
    ULONG size = (wcslen(className) + 1)* sizeof(WCHAR);
    PWCHAR buffer = (PWCHAR)malloc(size);
    if (GetClassNameW(hwnd, buffer, size ) == 0)
    {
        free(buffer);
        return FALSE;
    }
    int res = wcscmp(buffer, className);
    free(buffer);
    return res == 0;
}
static HWND clone_window(HWND hWnd, LPVOID lpParam)
{
	int count;

	SetLastError(NO_ERROR);

	DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
	WIN32_CHK(GetLastError() == NO_ERROR);

	WCHAR lpClassName[100] = L"";
	count = GetClassNameW(hWnd, lpClassName, sizeof(lpClassName));
	WIN32_CHK(count != 0);

	WCHAR lpWindowName[100] = L"";
	count = GetWindowTextW(hWnd, lpWindowName, sizeof(lpWindowName));
	WIN32_CHK(count != 0);

	DWORD dwStyle = GetWindowLong(hWnd, GWL_STYLE);
	WIN32_CHK(GetLastError() == NO_ERROR);

	RECT rect;
	GetWindowRect(hWnd, &rect);
	WIN32_CHK(GetLastError() == NO_ERROR);

	HWND hWndParent = (HWND)GetWindowLongPtr(hWnd, GWLP_HWNDPARENT);
	WIN32_CHK(GetLastError() == NO_ERROR);

	HMENU hMenu = GetMenu(hWnd);
	WIN32_CHK(GetLastError() == NO_ERROR);

	HINSTANCE hInstance = (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
	WIN32_CHK(GetLastError() == NO_ERROR);

	HWND hwndCloned = CreateWindowExW(
	        dwExStyle,
	        lpClassName,
	        lpWindowName,
	        dwStyle,
	        rect.left,
	        rect.top,
	        rect.right - rect.left,
	        rect.bottom - rect.top,
	        hWndParent,
	        hMenu,
	        hInstance,
	        lpParam);

	WIN32_CHK(hwndCloned != NULL);

	return hwndCloned;
}
Exemplo n.º 9
0
static BOOL CALLBACK
RefreshBrowsersCallback(HWND hWnd, LPARAM msg)
{
    WCHAR ClassName[100];
    if (GetClassNameW(hWnd, ClassName, _countof(ClassName)))
    {
        if (!wcscmp(ClassName, L"Progman") ||
            !wcscmp(ClassName, L"CabinetWClass") ||
            !wcscmp(ClassName, L"ExploreWClass"))
        {
            PostMessage(hWnd, WM_COMMAND, FCIDM_DESKBROWSER_REFRESH, 0);
        }
    }
    return TRUE;
}
Exemplo n.º 10
0
bool MainContext::CheckWindow(HWND hWnd)
{
	std::unique_ptr<wchar_t[]> className(new wchar_t[MAX_PATH]);
	std::unique_ptr<wchar_t[]> windowName(new wchar_t[MAX_PATH]);

	GetClassNameW(hWnd, className.get(), MAX_PATH);
	GetWindowTextW(hWnd, windowName.get(), MAX_PATH);

	PrintLog("HWND 0x%p: ClassName \"%ls\", WindowName: \"%ls\"", hWnd, className.get(), windowName.get());

	bool class_found = config.GetWindowClass().compare(className.get()) == 0;
	bool window_found = config.GetWindowName().compare(windowName.get()) == 0;
	bool force = config.GetAllWindows();

	return class_found || window_found || force;
}
Exemplo n.º 11
0
BOOL CALLBACK EnumerateCallback(HWND window, LPARAM lParam)
{
   HICON hIcon;

   UNREFERENCED_PARAMETER(lParam);

   if (!IsWindowVisible(window))
            return TRUE;

   GetClassNameW(window,windowText,4095);
   if ((wcscmp(L"Shell_TrayWnd",windowText)==0) ||
       (wcscmp(L"Progman",windowText)==0) )
            return TRUE;
      
   // First try to get the big icon assigned to the window
   hIcon = (HICON)SendMessageW(window, WM_GETICON, ICON_BIG, 0);
   if (!hIcon)
   {
      // If no icon is assigned, try to get the icon assigned to the windows' class
      hIcon = (HICON)GetClassLongPtrW(window, GCL_HICON);
      if (!hIcon)
      {
         // If we still don't have an icon, see if we can do with the small icon,
         // or a default application icon
         hIcon = (HICON)SendMessageW(window, WM_GETICON, ICON_SMALL2, 0);
         if (!hIcon)
         {
            // If all fails, give up and continue with the next window
            return TRUE;
         }
      }
   }

   windowList[windowCount] = window;
   iconList[windowCount] = CopyIcon(hIcon);

   windowCount++;

   // If we got to the max number of windows,
   // we won't be able to add any more
   if(windowCount == MAX_WINDOWS)
      return FALSE;

   return TRUE;
}
Exemplo n.º 12
0
void print_window_infos(HWND hwnd) {
  OutputDebugStringW(L"---------------------------------------------------------\n");
  wchar_t window_name[255];
  GetWindowText(hwnd, window_name, sizeof(window_name));
  print(L"window title:\n\t%s\n", window_name);

  wchar_t class_name[255];
  GetClassNameW(hwnd, class_name, sizeof(class_name));
  print(L"window class name:\n\t%s\n", class_name);

  RECT geometry;
  GetWindowRect(hwnd, &geometry);
  OutputDebugString(L"Geometrie:\n");
  print(L"\tx1: %li,\t y1: %li\n", geometry.left, geometry.top);
  print(L"\tx2: %li,\t y2: %li\n", geometry.right, geometry.bottom);

  OutputDebugStringW(L"---------------------------------------------------------\n\n");
}
Exemplo n.º 13
0
static BOOL WINAPI IsConsoleWindow(HWND hWnd)
{
	static const WCHAR ConsoleWindowClass[] = L"ConsoleWindowClass";

	HideConsoleTrace(L"hWnd=%1!p!", hWnd);

	WCHAR ClassName[20];
	INT32 ClassNameCch = GetClassNameW(hWnd, ClassName, ARRAYSIZE(ClassName));

	if (ClassNameCch == 0)
	{
		HideConsoleTraceLastError(L"GetClassNameW");
		return FALSE;
	}

	if (ClassNameCch != ARRAYSIZE(ConsoleWindowClass) - 1)
	{
		HideConsoleTrace(
			L"hWnd=%1!p! ClassName=%2 Result=FALSE",
			hWnd,
			ClassName
		);

		return FALSE;
	}

	INT32 CompareResult = CompareStringW(
		LOCALE_INVARIANT,
		0,
		ClassName,
		ClassNameCch,
		ConsoleWindowClass,
		ARRAYSIZE(ConsoleWindowClass) - 1
	);

	HideConsoleTrace(
		L"hWnd=%1!p! ClassName=%2 Result=%3",
		hWnd,
		ClassName,
		(CompareResult == CSTR_EQUAL) ? L"TRUE" : L"FALSE"
	);

	return (CompareResult == CSTR_EQUAL);
}
Exemplo n.º 14
0
int winapi_GetClassNameW(lua_State* L)
{
  HWND hwnd;
  size_t size;
  char buffer[2048];
  LUASTACK_SET(L);

  hwnd = lua_toWindow(L, 1);

  size = GetClassNameW(hwnd, (LPWSTR)&buffer, sizeof(buffer)/sizeof(WCHAR));
  if (size)
  {
    lua_pushlstring(L, buffer, size*sizeof(WCHAR));

    LUASTACK_CLEAN(L, 1);
    return 1;
  }

  LUASTACK_CLEAN(L, 0);
  return 0;
}
Exemplo n.º 15
0
int UserImp::getClassNameW(HWND hWnd, LPTSTR lpClassName, int nMaxCount)
{
	if (!bUserLoaded && !loadExports(bAllowLoadLibrary))
	{
		_ASSERTEX(hUser32!=NULL);
		return 0;
	}
	
	int lRc = GetClassNameW(hWnd, lpClassName, nMaxCount);
	/*
	if (getClassNameW_f)
	{
		lRc = getClassNameW_f(hWnd, lpClassName, nMaxCount);
	}
	else
	{
		_ASSERTEX(getClassNameW_f!=NULL);
	}
	*/
	return lRc;
}
Exemplo n.º 16
0
BOOL CALLBACK enumWindowsProc(HWND hWnd, LPARAM lParam)
{
	WCHAR buffer[1024] = { L"\0" };
	INT32 len = GetWindowTextW(hWnd, buffer, ARRAYSIZE(buffer));
	if (!len || 
		(std::wstring(buffer) == _Nena_Ignore_DefaultImeW) ||
		(std::wstring(buffer) == _Nena_Ignore_MsctfimeW))
		return TRUE;

	std::string bufferconv;
	std::wstring bufferwconv = buffer;
	Nena::Converter::String16To8(bufferconv, bufferwconv);
	g_windows[hWnd] = bufferconv;

	GetClassNameW(hWnd, buffer, ARRAYSIZE(buffer));
	bufferwconv = buffer;
	Nena::Converter::String16To8(bufferconv, bufferwconv);
	g_classes[hWnd] = bufferconv;

	DWORD processId;
	GetWindowThreadProcessId(hWnd, &processId);

	HANDLE processHandle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ, FALSE, processId);

	if (processHandle)
	{
		BOOL ok;
		DWORD size;

		size = GetModuleFileNameExW(processHandle, NULL, buffer, ARRAYSIZE(buffer));
		bufferwconv = buffer;
		Nena::Converter::String16To8(bufferconv, bufferwconv);
		g_images[hWnd] = bufferconv;
	}

	CloseHandle(processHandle);
	return TRUE;
}
Exemplo n.º 17
0
Arquivo: updown.c Projeto: devyn/wine
/***********************************************************************
 *           UPDOWN_SetBuddy
 *
 * Sets bud as a new Buddy.
 * Then, it should subclass the buddy
 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
 * process the UP/DOWN arrow keys.
 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
 * the size/pos of the buddy and the control are adjusted accordingly.
 */
static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
{
    static const WCHAR editW[] = { 'E', 'd', 'i', 't', 0 };
    static const WCHAR listboxW[] = { 'L', 'i', 's', 't', 'b', 'o', 'x', 0 };
    RECT  budRect;  /* new coord for the buddy */
    int   x, width;  /* new x position and width for the up-down */
    WNDPROC baseWndProc;
    WCHAR buddyClass[40];
    HWND ret;

    TRACE("(hwnd=%p, bud=%p)\n", infoPtr->Self, bud);

    ret = infoPtr->Buddy;

    /* there is already a body assigned */
    if (infoPtr->Buddy)  RemovePropW(infoPtr->Buddy, BUDDY_UPDOWN_HWND);

    if(!IsWindow(bud))
        bud = 0;

    /* Store buddy window handle */
    infoPtr->Buddy = bud;

    if(bud) {

        /* keep upDown ctrl hwnd in a buddy property */
        SetPropW( bud, BUDDY_UPDOWN_HWND, infoPtr->Self);

        /* Store buddy window class type */
        infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN;
        if (GetClassNameW(bud, buddyClass, COUNT_OF(buddyClass))) {
            if (lstrcmpiW(buddyClass, editW) == 0)
                infoPtr->BuddyType = BUDDY_TYPE_EDIT;
            else if (lstrcmpiW(buddyClass, listboxW) == 0)
                infoPtr->BuddyType = BUDDY_TYPE_LISTBOX;
        }

        if(infoPtr->dwStyle & UDS_ARROWKEYS){
            /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
               when we reset the upDown ctrl buddy to another buddy because it is not
               good to break the window proc chain. */
            if (!GetPropW(bud, BUDDY_SUPERCLASS_WNDPROC)) {
                baseWndProc = (WNDPROC)SetWindowLongPtrW(bud, GWLP_WNDPROC, (LPARAM)UPDOWN_Buddy_SubclassProc);
                SetPropW(bud, BUDDY_SUPERCLASS_WNDPROC, (HANDLE)baseWndProc);
            }
        }

        /* Get the rect of the buddy relative to its parent */
        GetWindowRect(infoPtr->Buddy, &budRect);
        MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy), (POINT *)(&budRect.left), 2);

        /* now do the positioning */
        if  (infoPtr->dwStyle & UDS_ALIGNLEFT) {
            x  = budRect.left;
            budRect.left += DEFAULT_WIDTH + DEFAULT_XSEP;
        } else if (infoPtr->dwStyle & UDS_ALIGNRIGHT) {
            budRect.right -= DEFAULT_WIDTH + DEFAULT_XSEP;
            x  = budRect.right+DEFAULT_XSEP;
        } else {
            /* nothing to do */
            return ret;
        }

        /* first adjust the buddy to accommodate the up/down */
        SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
                     budRect.right  - budRect.left, budRect.bottom - budRect.top,
                     SWP_NOACTIVATE|SWP_NOZORDER);

        /* now position the up/down */
        /* Since the UDS_ALIGN* flags were used, */
        /* we will pick the position and size of the window. */
        width = DEFAULT_WIDTH;

        /*
         * If the updown has a buddy border, it has to overlap with the buddy
         * to look as if it is integrated with the buddy control.
         * We nudge the control or change its size to overlap.
         */
        if (UPDOWN_HasBuddyBorder(infoPtr)) {
            if(infoPtr->dwStyle & UDS_ALIGNLEFT)
                width += DEFAULT_BUDDYBORDER;
            else
                x -= DEFAULT_BUDDYBORDER;
        }

        SetWindowPos(infoPtr->Self, 0, x,
                     budRect.top - DEFAULT_ADDTOP, width,
                     budRect.bottom - budRect.top + DEFAULT_ADDTOP + DEFAULT_ADDBOT,
                     SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
    } else {
        RECT rect;
        GetWindowRect(infoPtr->Self, &rect);
        MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Self), (POINT *)&rect, 2);
        SetWindowPos(infoPtr->Self, 0, rect.left, rect.top, DEFAULT_WIDTH, rect.bottom - rect.top,
                     SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
    }
    return ret;
}
Exemplo n.º 18
0
QString windowClass(HWND window)
{
    WCHAR buf[32];
    GetClassNameW(window, buf, 32);
    return QString::fromUtf16(reinterpret_cast<ushort *>(buf));
}
Exemplo n.º 19
0
/***********************************************************************
 *           UPDOWN_SetBuddy
 *
 * Sets bud as a new Buddy.
 * Then, it should subclass the buddy
 * If window has the UDS_ARROWKEYS, it subclasses the buddy window to
 * process the UP/DOWN arrow keys.
 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
 * the size/pos of the buddy and the control are adjusted accordingly.
 */
static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
{
    RECT  budRect;  /* new coord for the buddy */
    int   x, width;  /* new x position and width for the up-down */
    WCHAR buddyClass[40];
    HWND ret;

    TRACE("(hwnd=%p, bud=%p)\n", infoPtr->Self, bud);

    ret = infoPtr->Buddy;

    /* there is already a buddy assigned */
    if (infoPtr->Buddy) RemoveWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc,
                BUDDY_SUBCLASSID);
    if (!IsWindow(bud)) bud = NULL;

    /* Store buddy window handle */
    infoPtr->Buddy = bud;

    if(bud) {
        /* Store buddy window class type */
        infoPtr->BuddyType = BUDDY_TYPE_UNKNOWN;
        if (GetClassNameW(bud, buddyClass, COUNT_OF(buddyClass))) {
            if (lstrcmpiW(buddyClass, WC_EDITW) == 0)
                infoPtr->BuddyType = BUDDY_TYPE_EDIT;
            else if (lstrcmpiW(buddyClass, WC_LISTBOXW) == 0)
                infoPtr->BuddyType = BUDDY_TYPE_LISTBOX;
        }

        if (infoPtr->dwStyle & UDS_ARROWKEYS)
            SetWindowSubclass(bud, UPDOWN_Buddy_SubclassProc, BUDDY_SUBCLASSID,
                              (DWORD_PTR)infoPtr->Self);

        /* Get the rect of the buddy relative to its parent */
        GetWindowRect(infoPtr->Buddy, &budRect);
        MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy), (POINT *)(&budRect.left), 2);

        /* now do the positioning */
        if  (infoPtr->dwStyle & UDS_ALIGNLEFT) {
            x  = budRect.left;
            budRect.left += DEFAULT_WIDTH + DEFAULT_XSEP;
        } else if (infoPtr->dwStyle & UDS_ALIGNRIGHT) {
            budRect.right -= DEFAULT_WIDTH + DEFAULT_XSEP;
            x  = budRect.right+DEFAULT_XSEP;
        } else {
            /* nothing to do */
            return ret;
        }

        /* first adjust the buddy to accommodate the up/down */
        SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
                     budRect.right  - budRect.left, budRect.bottom - budRect.top,
                     SWP_NOACTIVATE|SWP_NOZORDER);

        /* now position the up/down */
        /* Since the UDS_ALIGN* flags were used, */
        /* we will pick the position and size of the window. */
        width = DEFAULT_WIDTH;

        /*
         * If the updown has a buddy border, it has to overlap with the buddy
         * to look as if it is integrated with the buddy control.
         * We nudge the control or change its size to overlap.
         */
        if (UPDOWN_HasBuddyBorder(infoPtr)) {
            if(infoPtr->dwStyle & UDS_ALIGNLEFT)
                width += DEFAULT_BUDDYBORDER;
            else
                x -= DEFAULT_BUDDYBORDER;
        }

        SetWindowPos(infoPtr->Self, 0, x,
                     budRect.top - DEFAULT_ADDTOP, width,
                     budRect.bottom - budRect.top + DEFAULT_ADDTOP + DEFAULT_ADDBOT,
                     SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
    } else {
        RECT rect;
        GetWindowRect(infoPtr->Self, &rect);
        MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Self), (POINT *)&rect, 2);
        SetWindowPos(infoPtr->Self, 0, rect.left, rect.top, DEFAULT_WIDTH, rect.bottom - rect.top,
                     SWP_NOACTIVATE|SWP_FRAMECHANGED|SWP_NOZORDER);
    }
    return ret;
}
Exemplo n.º 20
0
/******************************************************************
 *		WDML_ClientProc
 *
 * Window Proc created on client side for each conversation
 */
static LRESULT CALLBACK WDML_ClientProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    UINT	uiLo, uiHi;
    WDML_CONV*	pConv = NULL;
    HSZ		hszSrv, hszTpc;

    TRACE("%p %04x %08lx %08lx\n", hwnd, iMsg, wParam , lParam);

    if (iMsg == WM_DDE_ACK &&
	/* in the initial WM_INITIATE sendmessage */
	((pConv = WDML_GetConvFromWnd(hwnd)) == NULL || pConv->wStatus == XST_INIT1))
    {
	/* In response to WM_DDE_INITIATE, save server window  */
	char		buf[256];
	WDML_INSTANCE*	pInstance;

        /* note: sent messages do not need packing */
	uiLo = LOWORD(lParam);
        uiHi = HIWORD(lParam);

	/* FIXME: convlist should be handled here */
	if (pConv)
	{
	    /* we already have started the conv with a server, drop other replies */
	    GlobalDeleteAtom(uiLo);
	    GlobalDeleteAtom(uiHi);
            PostMessageW((HWND)wParam, WM_DDE_TERMINATE, (WPARAM)hwnd, 0);
	    return 0;
	}

	pInstance = WDML_GetInstanceFromWnd(hwnd);

	hszSrv = WDML_MakeHszFromAtom(pInstance, uiLo);
	hszTpc = WDML_MakeHszFromAtom(pInstance, uiHi);

	pConv = WDML_AddConv(pInstance, WDML_CLIENT_SIDE, hszSrv, hszTpc, hwnd, (HWND)wParam);

	SetWindowLongPtrW(hwnd, GWL_WDML_CONVERSATION, (ULONG_PTR)pConv);
	pConv->wStatus |= ST_CONNECTED;
	pConv->wConvst = XST_INIT1;

	/* check if server is handled by DDEML */
	if ((GetClassNameA((HWND)wParam, buf, sizeof(buf)) &&
	     lstrcmpiA(buf, WDML_szServerConvClassA) == 0) ||
	    (GetClassNameW((HWND)wParam, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
	     lstrcmpiW((LPWSTR)buf, WDML_szServerConvClassW) == 0))
	{
	    pConv->wStatus |= ST_ISLOCAL;
	}

	GlobalDeleteAtom(uiLo);
	GlobalDeleteAtom(uiHi);

	/* accept conversation */
	return 1;
    }

    if (iMsg >= WM_DDE_FIRST && iMsg <= WM_DDE_LAST)
    {
	pConv = WDML_GetConvFromWnd(hwnd);

	if (pConv)
	{
	    MSG		msg;
	    HDDEDATA	hdd;

	    msg.hwnd = hwnd;
	    msg.message = iMsg;
	    msg.wParam = wParam;
	    msg.lParam = lParam;

	    WDML_HandleReply(pConv, &msg, &hdd, NULL);
	}

	return 0;
    }

    return IsWindowUnicode(hwnd) ? DefWindowProcW(hwnd, iMsg, wParam, lParam) :
                                   DefWindowProcA(hwnd, iMsg, wParam, lParam);
}
Exemplo n.º 21
0
bool IsWindowClassW(HWND hwnd, const wchar_t *cn) {
	wchar_t cnw[256];
	if (!GetClassNameW(hwnd, cnw, sizeof(cnw))) return false;
	return (!wcscmp(cnw, cn));
}
Exemplo n.º 22
0
void CExtentMonitorTextService::_DumpExtent(TfEditCookie ec, ITfContext *pContext, UINT nEventId)
{
    if (!_pMemStream)
        return;

    ClearStream(_pMemStream);

    switch (nEventId)
    {
        case DE_EVENTID_ACTIVATE:        
            AddStringToStream(_pMemStream, L"Event: Activate\r\n"); 
            break;
        case DE_EVENTID_ONSETFOCUS:
            AddStringToStream(_pMemStream, L"Event: OnSetFocus\r\n"); 
            break;
        case DE_EVENTID_ONENDEDIT:
            AddStringToStream(_pMemStream, L"Event: OnEndEdit\r\n"); 
            break;
        case DE_EVENTID_ONLAYOUTCHANGE:
            AddStringToStream(_pMemStream, L"Event: OnLayoutChange\r\n"); 
            break;
        case DE_EVENTID_FROMLANGUAGEBAR:
            AddStringToStream(_pMemStream, L"Event: From LanguageBar\r\n"); 
            break;
        default:
            AddStringToStream(_pMemStream, L"Event: Unknoen\r\n"); 
            break;
    }

    WCHAR sz[512];
    ITfContextView *pView = NULL;
    TF_SELECTION sel;

    memset(&_rcStartPos , 0, sizeof(RECT));
    memset(&_rcEndPos , 0, sizeof(RECT));
    memset(&_rcSelection , 0, sizeof(RECT));
    memset(&_rcView , 0, sizeof(RECT));

    if (SUCCEEDED(pContext->GetActiveView(&pView)))
    {
         ITfRange *pRange;
         RECT rc;
         BOOL fClipped;
         HWND hwnd;

         AddStringToStream(_pMemStream, L"Wnd Handle - ");
         if (SUCCEEDED(pView->GetWnd(&hwnd)))
         {
             WCHAR szWndClass[32];
             if (IsWindow(hwnd)) 
             {
                 GetClassNameW(hwnd, szWndClass, ARRAYSIZE(szWndClass));
                 StringCchPrintf(sz, ARRAYSIZE(sz), L"%08x %s\r\n", (DWORD)(ULONG_PTR)hwnd, szWndClass);
                 AddStringToStream(_pMemStream, sz);
             }
             else
             {
                 AddStringToStream(_pMemStream, L"null window handle\r\n");
             }
         }

         AddStringToStream(_pMemStream, L"Screen Ext\r\n");
         if (SUCCEEDED(pView->GetScreenExt(&rc)))
         {
             StringCchPrintf(sz, ARRAYSIZE(sz), L"    (%d, %d, %d, %d) - (%d, %d)\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top);
             AddStringToStream(_pMemStream, sz);
             _rcView = rc;
         }

         AddStringToStream(_pMemStream, L"Start Pos\r\n");
         if (SUCCEEDED(pContext->GetStart(ec, &pRange)))
         {
             if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped)))
             {
                 StringCchPrintf(sz, ARRAYSIZE(sz), L"    (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L"");

                 AddStringToStream(_pMemStream, sz);
                 _rcStartPos = rc;
             }

             pRange->Release();
         }

         AddStringToStream(_pMemStream, L"End Pos\r\n");
         if (SUCCEEDED(pContext->GetEnd(ec, &pRange)))
         {
             if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped)))
             {
                 StringCchPrintf(sz, ARRAYSIZE(sz), L"    (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L"");

                 AddStringToStream(_pMemStream, sz);
                 _rcEndPos = rc;
             }

             pRange->Release();
         }

         AddStringToStream(_pMemStream, L"Selection Pos\r\n");
         ULONG cFetched;
         if (SUCCEEDED(pContext->GetSelection(ec, 0, 1, &sel, &cFetched)))
         {
             if (sel.range)
             {
                 if (SUCCEEDED(pView->GetTextExt(ec, sel.range, &rc, &fClipped)))
                 {
                     StringCchPrintf(sz, ARRAYSIZE(sz), L"    (%d, %d, %d, %d) - (%d, %d) %s\r\n", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L"");

                     AddStringToStream(_pMemStream, sz);
                     _rcSelection = rc;
                 }
                 AddStringToStream(_pMemStream, L"    ");
                 _DumpRange(ec, sel.range);
                 AddStringToStream(_pMemStream, L"\r\n");
                 sel.range->Release();
             }
         }

         AddStringToStream(_pMemStream, L"Char Pos\r\n");
         if (SUCCEEDED(pContext->GetStart(ec, &pRange)))
         {
             LONG cch;
             memset(&_rcRanges[0] , 0, sizeof(RECT) * ARRAYSIZE(_rcRanges));
             if (SUCCEEDED(pRange->ShiftEnd(ec, 1, &cch, NULL)) && cch)
             {
                 for (int i = 0; i < ARRAYSIZE(_rcRanges); i++)
                 {
                     if (SUCCEEDED(pView->GetTextExt(ec, pRange, &rc, &fClipped)))
                     {
                         StringCchPrintf(sz, ARRAYSIZE(sz), L"    (%d, %d, %d, %d) - (%d, %d) %s", rc.left, rc.top, rc.right, rc.bottom, rc.right - rc.left, rc.bottom - rc.top, fClipped ? L"Clipped" : L"");
                         AddStringToStream(_pMemStream, sz);

                         AddStringToStream(_pMemStream, L" ");
                         ITfRange *pRangeTmp;
                         if (SUCCEEDED(pRange->Clone(&pRangeTmp)))
                         {
                             _DumpRange(ec, pRangeTmp);
                             pRangeTmp->Release();
                         }
                         AddStringToStream(_pMemStream, L"\r\n");

                         OffsetRect(&rc, 0 - _rcView.left, 0 - _rcView.top);
                         _rcRanges[i] = rc;
                     }

                     if (FAILED(pRange->ShiftEnd(ec, 1, &cch, NULL)) || !cch)
                         break;

                     if (FAILED(pRange->ShiftStart(ec, 1, &cch, NULL)) || !cch)
                         break;
                 }

             }
             pRange->Release();
         }

         pView->Release();
    }

    _EnsurePopupWindow();

    if (IsShownExtentVisualWindows())
        _UpdateExtentVisualWindows();

    if (IsShownRangeExtentViewer())
        _UpdateRangeExtentViewer();

    return;
}
Exemplo n.º 23
0
/******************************************************************
 *		WDML_ServerNameProc
 *
 *
 */
static LRESULT CALLBACK WDML_ServerNameProc(HWND hwndServer, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    HWND		hwndClient;
    HSZ			hszApp, hszTop;
    HDDEDATA		hDdeData = 0;
    WDML_INSTANCE*	pInstance;
    UINT		uiLo, uiHi;

    switch (iMsg)
    {
    case WM_DDE_INITIATE:

	/* wParam         -- sending window handle
	   LOWORD(lParam) -- application atom
	   HIWORD(lParam) -- topic atom */

	TRACE("WM_DDE_INITIATE message received!\n");
	hwndClient = (HWND)wParam;

	pInstance = WDML_GetInstanceFromWnd(hwndServer);
	TRACE("idInst=%ld, threadID=0x%lx\n", pInstance->instanceID, GetCurrentThreadId());
	if (!pInstance) return 0;

	/* don't free DDEParams, since this is a broadcast */
	UnpackDDElParam(WM_DDE_INITIATE, lParam, &uiLo, &uiHi);

	hszApp = WDML_MakeHszFromAtom(pInstance, uiLo);
	hszTop = WDML_MakeHszFromAtom(pInstance, uiHi);

	if (!(pInstance->CBFflags & CBF_FAIL_CONNECTIONS))
	{
	    BOOL 		self = FALSE;
	    CONVCONTEXT		cc;
	    CONVCONTEXT*	pcc = NULL;
	    WDML_CONV*		pConv;
	    char		buf[256];

	    if (GetWindowThreadProcessId(hwndClient, NULL) == GetWindowThreadProcessId(hwndServer, NULL) &&
		WDML_GetInstanceFromWnd(hwndClient) == WDML_GetInstanceFromWnd(hwndServer))
	    {
		self = TRUE;
	    }
	    /* FIXME: so far, we don't grab distant convcontext, so only check if remote is
	     * handled under DDEML, and if so build a default context
	     */
	    if ((GetClassNameA(hwndClient, buf, sizeof(buf)) &&
		 strcmp(buf, WDML_szClientConvClassA) == 0) ||
		(GetClassNameW(hwndClient, (LPWSTR)buf, sizeof(buf)/sizeof(WCHAR)) &&
		 lstrcmpW((LPWSTR)buf, WDML_szClientConvClassW) == 0))
	    {
		pcc = &cc;
		memset(pcc, 0, sizeof(*pcc));
		pcc->cb = sizeof(*pcc);
		pcc->iCodePage = IsWindowUnicode(hwndClient) ? CP_WINUNICODE : CP_WINANSI;
	    }
	    if ((pInstance->CBFflags & CBF_FAIL_SELFCONNECTIONS) && self)
	    {
		TRACE("Don't do self connection as requested\n");
	    }
	    else if (hszApp && hszTop)
	    {
		WDML_SERVER*	pServer = (WDML_SERVER*)GetWindowLongA(hwndServer, GWL_WDML_SERVER);

		/* check filters for name service */
		if (!pServer->filterOn || DdeCmpStringHandles(pServer->hszService, hszApp) == 0)
		{
		    /* pass on to the callback  */
		    hDdeData = WDML_InvokeCallback(pInstance, XTYP_CONNECT,
						   0, 0, hszTop, hszApp, 0, (DWORD)pcc, self);
		    if ((UINT)hDdeData)
		    {
			pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer,
						      hszApp, hszTop);
			if (pConv && pcc) pConv->wStatus |= ST_ISLOCAL;
		    }
		}
	    }
	    else if (pInstance->servers)
	    {
		/* pass on to the callback  */
		hDdeData = WDML_InvokeCallback(pInstance, XTYP_WILDCONNECT,
					       0, 0, hszTop, hszApp, 0, (DWORD)pcc, self);

		if (hDdeData == (HDDEDATA)CBR_BLOCK)
		{
		    /* MS doc is not consistent here */
		    FIXME("CBR_BLOCK returned for WILDCONNECT\n");
		}
		else if ((UINT)hDdeData != 0)
		{
		    HSZPAIR*	hszp;

		    hszp = (HSZPAIR*)DdeAccessData(hDdeData, NULL);
		    if (hszp)
		    {
			int	i;
			for (i = 0; hszp[i].hszSvc && hszp[i].hszTopic; i++)
			{
			    pConv = WDML_CreateServerConv(pInstance, hwndClient, hwndServer,
							  hszp[i].hszSvc, hszp[i].hszTopic);
			    if (pConv && pcc) pConv->wStatus |= ST_ISLOCAL;
			}
			DdeUnaccessData(hDdeData);
		    }
                    if (!WDML_IsAppOwned(hDdeData)) DdeFreeDataHandle(hDdeData);
		}
	    }
	}

	return 0;


    case WM_DDE_REQUEST:
	FIXME("WM_DDE_REQUEST message received!\n");
	return 0;
    case WM_DDE_ADVISE:
	FIXME("WM_DDE_ADVISE message received!\n");
	return 0;
    case WM_DDE_UNADVISE:
	FIXME("WM_DDE_UNADVISE message received!\n");
	return 0;
    case WM_DDE_EXECUTE:
	FIXME("WM_DDE_EXECUTE message received!\n");
	return 0;
    case WM_DDE_POKE:
	FIXME("WM_DDE_POKE message received!\n");
	return 0;
    case WM_DDE_TERMINATE:
	FIXME("WM_DDE_TERMINATE message received!\n");
	return 0;

    }

    return DefWindowProcA(hwndServer, iMsg, wParam, lParam);
}
Exemplo n.º 24
0
int _tmain(int argc, _TCHAR* argv[])
{
	printf("*GetWindowInfo*\n");
	printf("You can monitoring the window inforamtion and its process inforamtion that pointed by your mouse cursor\n");
	printf("If you press any key, start monitoring.\n");
	WCHAR wchtemp;
	scanf_s("%c", &wchtemp);

	HMODULE hmodule = GetModuleHandle(L"ntdll.dll");
	if (NULL == hmodule) hmodule = LoadLibraryW(L"ntdll.dll");
	if (NULL == hmodule)
	{
		printf("ntdll load failed with %d", ::GetLastError());
		return -1;
	}

	NtQueryInformationProcess = (PFNtQueryInformationProcess)::GetProcAddress(hmodule, "NtQueryInformationProcess");
	POINT p = { 0, };
	HWND prevhwnd = NULL;
	HWND curhwnd = NULL;
	while (GetCursorPos(&p))
	{
		if ((curhwnd = WindowFromPoint(p)) != prevhwnd)
		{
			WCHAR wchClass[MAX_NAME_LENGTH];
			memset(wchClass, 0, MAX_NAME_LENGTH*sizeof(WCHAR));
			GetClassNameW(curhwnd, wchClass, MAX_NAME_LENGTH);

			WCHAR wchWindow[MAX_NAME_LENGTH];
			memset(wchWindow, 0, MAX_NAME_LENGTH*sizeof(WCHAR));
			GetWindowTextW(curhwnd, wchWindow, MAX_NAME_LENGTH);

			DWORD dwPid = 0;
			DWORD dwTid = 0;
			dwTid = GetWindowThreadProcessId(curhwnd, &dwPid);

			printf("===============================================================================\n");
			printf("GetCursorPos : p.x-%d, p.y-%d\n", p.x, p.y);
			printf("-------------------------------------------------------------------------------\n");
			printf("Window Information\n");
			printf("-------------------------------------------------------------------------------\n");
			printf("Current Hwnd : 0x%x\n", (DWORD)curhwnd);
			printf("ClssName : %ws\n", wchClass);
			printf("WindowTitle : %ws\n", wchWindow);
			printf("-------------------------------------------------------------------------------\n");
			printf("Process Information\n");
			printf("-------------------------------------------------------------------------------\n");
			printf("Pid : %d\n", dwPid);
			printf("Tid : %d\n", dwTid);

			WCHAR wchstr[MAX_COMMANDLINE_LENGTH];
			memset(wchstr, 0, MAX_COMMANDLINE_LENGTH* sizeof(WCHAR));
			if (GetCommandLine(dwPid, wchstr))
			{
				printf("CommandLine : %ws\n", wchstr);
			}
			prevhwnd = curhwnd;
			printf("===============================================================================\n");
			printf("\n\n");
		}
	}

	return 0;
}