Click here to Skip to main content
15,884,176 members
Articles / Mobile Apps / Windows Mobile

Windows Mobile: Redirect Function Keys into Internet Explorer Mobile Browser

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
1 Oct 2012CPOL2 min read 8.7K   1  
This small tool enables you to use Function keys within Internet Explorer Mobile (IEM) web sites.
// iHookIE6.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "iHookIE6.h"

#include "hooks.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE			g_hInst;			// current instance
HWND				g_hWndMenuBar;		// menu bar handle

	TCHAR szAppName[] = L"iHookIE6v3.1.1";
	bool bForwardKey=false;
	NOTIFYICONDATA nid;

// Forward declarations of functions included in this code module:
ATOM			MyRegisterClass(HINSTANCE, LPTSTR);
BOOL			InitInstance(HINSTANCE, int);
LRESULT CALLBACK	WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK	About(HWND, UINT, WPARAM, LPARAM);

HICON g_hIcon[3];
void RemoveIcon(HWND hWnd);
void ChangeIcon(int idIcon);
HWND getIEMWindow(int* iResult);
HWND getIEMBrowserWindow();

// Global variables can still be your...friend.
// CIHookDlg* g_This			= NULL;			// Needed for this kludgy test app, allows callback to update the UI
HINSTANCE	g_hHookApiDLL	= NULL;			// Handle to loaded library (system DLL where the API is located)

HWND		g_hWndIEM6		= NULL;			// handle to browser component window
DWORD		g_dwTimer		= 1001;			//our timer id
UINT		g_uTimerId		= 0;			//timer id

DWORD g_lparamCodeDown[] = {	
							0x050001,	//f1
							0x060001,
							0x040001,
							0x0C0001,
							0x030001,
							0x0B0001,
							0x830001,
							0x0A0001,
							0x010001,
							0x090001,
							0x780001,
							0x070001,	//f12
							0x008000,	//f13
							0x010000,
							0x018000,
							0x020000,
							0x028000,
							0x030000,
							0x038000,
							0x040000,
							0x048000,
							0x050000,
							0x057000,
							0x05F000,	//f24
						};
DWORD g_lparamCodeUp[] = { 
							0xc0050001,	//f1
							0xc0060001,
							0xc0040001,
							0xc00C0001,
							0xc0030001,
							0xc00B0001,
							0xc0830001,
							0xc00A0001,
							0xc0010001,
							0xc0090001,
							0xc0780001,
							0xc0070001,	//f12
							0xc0008000,	//f13
							0xc0010000,
							0xc0018000,
							0xc0020000,
							0xc0028000,
							0xc0030000,
							0xc0038000,
							0xc0040000,
							0xc0048000,
							0xc0050000,
							0xc0057000,
							0xc005F000,	//f24
};

// Global functions: The original Open Source
BOOL g_HookDeactivate();
BOOL g_HookActivate(HINSTANCE hInstance);

//
#pragma data_seg(".HOOKDATA")									//	Shared data (memory) among all instances.
	HHOOK g_hInstalledLLKBDhook = NULL;						// Handle to low-level keyboard hook
	//HWND hWnd	= NULL;											// If in a DLL, handle to app window receiving WM_USER+n message
#pragma data_seg()

#pragma comment(linker, "/SECTION:.HOOKDATA,RWS")		//linker directive

// The command below tells the OS that this EXE has an export function so we can use the global hook without a DLL
__declspec(dllexport) LRESULT CALLBACK g_LLKeyboardHookCallback(
   int nCode,      // The hook code
   WPARAM wParam,  // The window message (WM_KEYUP, WM_KEYDOWN, etc.)
   LPARAM lParam   // A pointer to a struct with information about the pressed key
) 
{
	/*	typedef struct {
	    DWORD vkCode;
	    DWORD scanCode;
	    DWORD flags;
	    DWORD time;
	    ULONG_PTR dwExtraInfo;
	} KBDLLHOOKSTRUCT, *PKBDLLHOOKSTRUCT;*/
	
	// Get out of hooks ASAP; no modal dialogs or CPU-intensive processes!
	// UI code really should be elsewhere, but this is just a test/prototype app
	// In my limited testing, HC_ACTION is the only value nCode is ever set to in CE
	static int iActOn = HC_ACTION;
	bool processed_key=false;
	int iResult=0;
	if (nCode == iActOn) 
	{ 
		HWND hwndBrowserComponent=getIEMBrowserWindow();	//get the browser window
		if(getIEMWindow(&iResult)==NULL || hwndBrowserComponent==NULL)	// if IE is not loaded or not in foreground or browser window not found
			return CallNextHookEx(g_hInstalledLLKBDhook, nCode, wParam, lParam);

		PKBDLLHOOKSTRUCT pkbhData = (PKBDLLHOOKSTRUCT)lParam;
		//we are only interested in FKey press/release
		if(pkbhData->vkCode >= VK_F1 && pkbhData->vkCode <=VK_F24){
			DEBUGMSG(1,(L"found function key 0x%08x ...\n", pkbhData->vkCode));
			if(processed_key==false){
				if (wParam == WM_KEYUP)
				{
					//synthesize a WM_KEYUP
					DEBUGMSG(1,(L"posting WM_KEYUP 0x%08x to 0x%08x, lParam=0x%08x...\n", pkbhData->vkCode, hwndBrowserComponent, g_lparamCodeUp[pkbhData->vkCode - 0x70]));
					PostMessage(hwndBrowserComponent, WM_KEYUP, pkbhData->vkCode, g_lparamCodeUp[pkbhData->vkCode - 0x70]);
					processed_key=true;
				}
				else if (wParam == WM_KEYDOWN)
				{
					//synthesize a WM_KEYDOWN
					DEBUGMSG(1,(L"posting WM_KEYDOWN 0x%08x to 0x%08x, lParam=0x%08x...\n", pkbhData->vkCode, hwndBrowserComponent, g_lparamCodeDown[pkbhData->vkCode - 0x70]));
					PostMessage(hwndBrowserComponent, WM_KEYDOWN, pkbhData->vkCode, g_lparamCodeDown[pkbhData->vkCode - 0x70]);
					processed_key=true;
				}
			}
		}
	}
	else
		DEBUGMSG(1, (L"Got unknwon action code: 0x%08x\n", nCode));

	//shall we forward processed keys?
	if (processed_key)
	{
		processed_key=false; //reset flag
		if (bForwardKey){
			return CallNextHookEx(g_hInstalledLLKBDhook, nCode, wParam, lParam);
		}
		else
			return true;
	}
	else
		return CallNextHookEx(g_hInstalledLLKBDhook, nCode, wParam, lParam);

}

BOOL g_HookActivate(HINSTANCE hInstance)
{
	// We manually load these standard Win32 API calls (Microsoft says "unsupported in CE")
	SetWindowsHookEx		= NULL;
	CallNextHookEx			= NULL;
	UnhookWindowsHookEx	= NULL;

	// Load the core library. If it's not found, you've got CErious issues :-O
	//TRACE(_T("LoadLibrary(coredll.dll)..."));
	g_hHookApiDLL = LoadLibrary(_T("coredll.dll"));
	if(g_hHookApiDLL == NULL) return false;
	else {
		// Load the SetWindowsHookEx API call (wide-char)
		//TRACE(_T("OK\nGetProcAddress(SetWindowsHookExW)..."));
		SetWindowsHookEx = (_SetWindowsHookExW)GetProcAddress(g_hHookApiDLL, _T("SetWindowsHookExW"));
		if(SetWindowsHookEx == NULL) return false;
		else
		{
			// Load the hook.  Save the handle to the hook for later destruction.
			//TRACE(_T("OK\nCalling SetWindowsHookEx..."));
			g_hInstalledLLKBDhook = SetWindowsHookEx(WH_KEYBOARD_LL, g_LLKeyboardHookCallback, hInstance, 0);
			if(g_hInstalledLLKBDhook == NULL) return false;
		}

		// Get pointer to CallNextHookEx()
		//TRACE(_T("OK\nGetProcAddress(CallNextHookEx)..."));
		CallNextHookEx = (_CallNextHookEx)GetProcAddress(g_hHookApiDLL, _T("CallNextHookEx"));
		if(CallNextHookEx == NULL) return false;

		// Get pointer to UnhookWindowsHookEx()
		//TRACE(_T("OK\nGetProcAddress(UnhookWindowsHookEx)..."));
		UnhookWindowsHookEx = (_UnhookWindowsHookEx)GetProcAddress(g_hHookApiDLL, _T("UnhookWindowsHookEx"));
		if(UnhookWindowsHookEx == NULL) return false;
	}
	//TRACE(_T("OK\nEverything loaded OK\n"));
	return true;
}


BOOL g_HookDeactivate()
{
	//TRACE(_T("Uninstalling hook..."));
	if(g_hInstalledLLKBDhook != NULL)
	{
		UnhookWindowsHookEx(g_hInstalledLLKBDhook);		// Note: May not unload immediately because other apps may have me loaded
		g_hInstalledLLKBDhook = NULL;
	}

	//TRACE(_T("OK\nUnloading coredll.dll..."));
	if(g_hHookApiDLL != NULL)
	{
		FreeLibrary(g_hHookApiDLL);
		g_hHookApiDLL = NULL;
	}
	//TRACE(_T("OK\nEverything unloaded OK\n"));
	return true;
}


int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPTSTR    lpCmdLine,
                   int       nCmdShow)
{
	MSG msg;

	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	HACCEL hAccelTable;
	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_IHOOKIE6));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//
//  PURPOSE: Registers the window class.
//
//  COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_IHOOKIE6));
	wc.hCursor       = 0;
	wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = szWindowClass;

	return RegisterClass(&wc);
}

//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
    HWND hWnd;
    TCHAR szTitle[MAX_LOADSTRING];		// title bar text
    TCHAR szWindowClass[MAX_LOADSTRING];	// main window class name

    g_hInst = hInstance; // Store instance handle in our global variable

    // SHInitExtraControls should be called once during your application's initialization to initialize any
    // of the device specific controls such as CAPEDIT and SIPPREF.
    SHInitExtraControls();

    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); 
    LoadString(hInstance, IDC_IHOOKIE6, szWindowClass, MAX_LOADSTRING);

    //If it is already running, then focus on the window, and exit
    hWnd = FindWindow(szWindowClass, szTitle);	
    if (hWnd) 
    {
        // set focus to foremost child window
        // The "| 0x00000001" is used to bring any owned windows to the foreground and
        // activate them.
        SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
        return 0;
    } 

    if (!MyRegisterClass(hInstance, szWindowClass))
    {
    	return FALSE;
    }

    hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
        return FALSE;
    }

    // When the main window is created using CW_USEDEFAULT the height of the menubar (if one
    // is created is not taken into account). So we resize the window after creating it
    // if a menubar is present
    if (g_hWndMenuBar)
    {
        RECT rc;
        RECT rcMenuBar;

        GetWindowRect(hWnd, &rc);
        GetWindowRect(g_hWndMenuBar, &rcMenuBar);
        rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
		
        MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
    }

    ShowWindow   (hWnd , SW_HIDE); // nCmdShow);
    UpdateWindow(hWnd);

	//Create a Notification icon
	HICON hIcon;
	hIcon=(HICON) LoadImage (g_hInst, MAKEINTRESOURCE (IHOOK_STARTED), IMAGE_ICON, 16,16,0);
	nid.cbSize = sizeof (NOTIFYICONDATA);
	nid.hWnd = hWnd;
	nid.uID = 1;
	nid.uFlags = NIF_ICON | NIF_MESSAGE;
	// NIF_TIP not supported    
	nid.uCallbackMessage = MYMSG_TASKBARNOTIFY;
	nid.hIcon = hIcon;
	nid.szTip[0] = '\0';
	BOOL res = Shell_NotifyIcon (NIM_ADD, &nid);
	if(!res){
		DEBUGMSG(1 ,(L"Could not add taskbar icon. LastError=%i\r\n", GetLastError() ));
	}

	//load icon set
	g_hIcon[0] =(HICON) LoadImage (g_hInst, MAKEINTRESOURCE (IDI_ICON_BAD), IMAGE_ICON, 16,16,0);
	g_hIcon[1] =(HICON) LoadImage (g_hInst, MAKEINTRESOURCE (IDI_ICON_WARN), IMAGE_ICON, 16,16,0);
	g_hIcon[2] =(HICON) LoadImage (g_hInst, MAKEINTRESOURCE (IDI_ICON_OK), IMAGE_ICON, 16,16,0);

#ifdef DEBUG
	if (!res)
		DEBUGMSG(1, (L"InitInstance: %i\n", GetLastError()));
#endif
	
    return TRUE;
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    //PAINTSTRUCT ps;
    //HDC hdc;

    static SHACTIVATEINFO s_sai;
	
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
                case IDM_HELP_ABOUT:
                    DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
                    break;
                case IDM_OK:
                    SendMessage (hWnd, WM_CLOSE, 0, 0);				
                    break;
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
		case WM_TIMER:	//used to update notification icon
			if(wParam==g_dwTimer){
				int iResult = 0;
				getIEMWindow(&iResult);
				DEBUGMSG(1,(L"Timer: getIEMWindow(), iResult=%i\n", iResult));
				ChangeIcon(iResult);
			}
			return 0;
			break;
        case WM_CREATE:
			if (g_HookActivate(g_hInst))
			{
				MessageBeep(MB_OK);
				//system bar icon
				//ShowIcon(hWnd, g_hInst);
				DEBUGMSG(1, (L"Hook loaded OK"));
			}
			else
			{
				MessageBeep(MB_ICONEXCLAMATION);
				MessageBox(hWnd, L"Could not hook. Already running a copy of iHook3? Will exit now.", L"iHook3", MB_OK | MB_ICONEXCLAMATION);
				PostQuitMessage(-1);
			}
			g_uTimerId = SetTimer(hWnd, g_dwTimer, 5000, NULL);
			//TRACE(_T("Hook did not success"));
			return 0;

			SHMENUBARINFO mbi;

            memset(&mbi, 0, sizeof(SHMENUBARINFO));
            mbi.cbSize     = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hWnd;
            mbi.nToolBarId = IDR_MENU;
            mbi.hInstRes   = g_hInst;

            if (!SHCreateMenuBar(&mbi)) 
            {
                g_hWndMenuBar = NULL;
            }
            else
            {
                g_hWndMenuBar = mbi.hwndMB;
            }

            // Initialize the shell activate info structure
            memset(&s_sai, 0, sizeof (s_sai));
            s_sai.cbSize = sizeof (s_sai);
			if(true){
				int iResult = 0;
				getIEMWindow(&iResult);
				DEBUGMSG(1,(L"Timer: getIEMWindow(), iResult=%i\n", iResult));
				ChangeIcon(iResult);
			}
			break;
        case WM_PAINT:
			PAINTSTRUCT ps;    
			RECT rect;    
			HDC hdc;     // Adjust the size of the client rectangle to take into account    
			// the command bar height.    
			GetClientRect (hWnd, &rect);    
			hdc = BeginPaint (hWnd, &ps);     
			DrawText (hdc, TEXT ("iHookIE6 loaded"), -1, &rect,
				DT_CENTER | DT_VCENTER | DT_SINGLELINE);    
			EndPaint (hWnd, &ps);     
			return 0;
            break;
        case WM_DESTROY:
            CommandBar_Destroy(g_hWndMenuBar);
			//taskbar system icon
			RemoveIcon(hWnd);
			MessageBeep(MB_OK);
			g_HookDeactivate();
			//Shell_NotifyIcon(NIM_DELETE, &nid);
            PostQuitMessage(0);
            break;

        case WM_ACTIVATE:
            // Notify shell of our activate message
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
            break;
        case WM_SETTINGCHANGE:
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;
		case MYMSG_TASKBARNOTIFY:
				switch (lParam) {
					case WM_LBUTTONUP:
						//ShowWindow(hWnd, SW_SHOWNORMAL);
						SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE | SWP_NOREPOSITION | SWP_SHOWWINDOW);
						if (MessageBox(hWnd, L"Hook is loaded. End hooking?", szAppName, 
							MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL | MB_SETFOREGROUND | MB_TOPMOST)==IDYES)
						{
							g_HookDeactivate();
							Shell_NotifyIcon(NIM_DELETE, &nid);
							PostQuitMessage (0) ; 
						}
						ShowWindow(hWnd, SW_HIDE);
					}
			return 0;
			break;

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG:
            {
                // Create a Done button and size it.  
                SHINITDLGINFO shidi;
                shidi.dwMask = SHIDIM_FLAGS;
                shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
                shidi.hDlg = hDlg;
                SHInitDialog(&shidi);
            }
            return (INT_PTR)TRUE;

        case WM_COMMAND:
            if (LOWORD(wParam) == IDOK)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return TRUE;
            }
            break;

        case WM_CLOSE:
            EndDialog(hDlg, message);
            return TRUE;

    }
    return (INT_PTR)FALSE;
}

void ChangeIcon(int idIcon)
{
//    NOTIFYICONDATA nid;
    int nIconID=1;
    nid.cbSize = sizeof (NOTIFYICONDATA);
    //nid.hWnd = hWnd;
    //nid.uID = idIcon;//	nIconID;
    //nid.uFlags = NIF_ICON | NIF_MESSAGE;   // NIF_TIP not supported
    //nid.uCallbackMessage = MYMSG_TASKBARNOTIFY;
    nid.hIcon = g_hIcon[idIcon];	// (HICON)LoadImage (g_hInst, MAKEINTRESOURCE (ID_ICON), IMAGE_ICON, 16,16,0);
    //nid.szTip[0] = '\0';

    BOOL r = Shell_NotifyIcon (NIM_MODIFY, &nid);
	if(!r){
		DEBUGMSG(1 ,(L"Could not change taskbar icon. LastError=%i\r\n", GetLastError() ));
	}
}

void RemoveIcon(HWND hWnd)
{
	NOTIFYICONDATA nid;

    memset (&nid, 0, sizeof nid);
    nid.cbSize = sizeof (NOTIFYICONDATA);
    nid.hWnd = hWnd;
    nid.uID = 1;

    Shell_NotifyIcon (NIM_DELETE, &nid);

}

//search for a child window with class name
static BOOL bStopScan=FALSE;
BOOL scanWindow(HWND hWndStart, TCHAR* szClass){
	HWND hWnd = NULL;
	HWND hWnd1 = NULL;	

	hWnd = hWndStart;

	TCHAR cszWindowString [MAX_PATH]; // = new TCHAR(MAX_PATH);
	TCHAR cszClassString [MAX_PATH]; //= new TCHAR(MAX_PATH);
	TCHAR cszTemp [MAX_PATH]; //= new TCHAR(MAX_PATH);
	
	BOOL bRet=FALSE;

	while (hWnd!=NULL && !bStopScan){
		//do some formatting

		GetClassName(hWnd, cszClassString, MAX_PATH);
		GetWindowText(hWnd, cszWindowString, MAX_PATH);

		wsprintf(cszTemp, L"\"%s\"  \"%s\"\t0x%08x\n", cszClassString, cszWindowString, hWnd);//buf);
		//DEBUGMSG(1, (cszTemp));

		if(wcsicmp(cszClassString, szClass)==0){
			DEBUGMSG(1 , (L"\n################### found target window, hwnd=0x%08x\n\n", hWnd));
			//set global hwnd
			g_hWndIEM6=hWnd;	//store in global var
			hWnd=NULL;
			hWndStart=NULL;
			bRet=TRUE;
			bStopScan=TRUE;
			return TRUE;	//exit loop
		}
		// Find next child Window
		hWnd1 = GetWindow(hWnd, GW_CHILD);
		if( hWnd1 != NULL ){ 
			scanWindow(hWnd1, szClass);
		}
		//Find next neighbor window
		hWnd=GetWindow(hWnd,GW_HWNDNEXT);		// Get Next Window
	}
	return bRet;
}

/// look for IE window and test if in foreground
/// if found and in foreground, return window handle
/// else return NULL
///	result will be 0 or 1 or 2
HWND getIEMWindow(int* iResult){
	HWND hwnd_ret = NULL;
	HWND hwnd_iem = FindWindow(L"IEMobile", NULL);	// try MSHTML window
	static int iRes=0;	//0=no window, 1=window found, 2=window in foreground

	if(hwnd_iem==NULL){
		DEBUGMSG(1, (L"could not find IEMobile window. Trying IExplore window...\n"));
		hwnd_iem = FindWindow(L"IExplore", NULL);	// try with PIE window
		if(hwnd_iem==NULL){
			DEBUGMSG(1, (L"could not find IExplore window. No window, no Fun!\n"));
			iRes=0;
			hwnd_ret = NULL;	//unable to find either window
		}
	}
	else{
		DEBUGMSG(1, (L"Found IEMobile window\n"));
		iRes=1;
	}

	if(hwnd_iem!=NULL){
		HWND hwnd_foreground = GetForegroundWindow();

		if(hwnd_iem != hwnd_foreground){
			DEBUGMSG(1, (L"IEMobile or IExplore is not foreground window!\n"));
			iRes=1;
			hwnd_ret = NULL;	//although IE window is found, it is not in foreground
		}
		else{
			DEBUGMSG(1, (L"IEMobile or IExplore window is foreground window.\n"));
			iRes=2;
			hwnd_ret = hwnd_iem;
		}
	}
	*iResult=iRes;
	return hwnd_iem;
}

enum IETYPE{
	None = 0,
	IEMobile,
	IExplore
} myIETYPE;

HWND getIEMBrowserWindow(){
	//DEBUGMSG(1, (L"using hardcoded IEMobile window\n"));
	//g_hWndIEM6 = (HWND)0x7c0d28A0;
	//return;

	enum IETYPE ieType = None;
	//EnumWindows(GetDesktopWindow(), 
	HWND hwnd_iem = FindWindow(L"IEMobile", NULL);
	if(hwnd_iem==NULL){
		//now try the PIE window?, although PIE does NOT support keyboard events!
		hwnd_iem = FindWindow(L"IExplore", NULL);
		if(hwnd_iem==NULL){
			g_hWndIEM6=NULL;
			DEBUGMSG(1, (L"could not find IEMobile or IExpore window\n"));
			return g_hWndIEM6;	//return global var
		}
		else
			ieType=IExplore;
	}
	else
		ieType=IEMobile;

	bStopScan=FALSE;
	g_hWndIEM6=NULL;
	if(ieType==IEMobile)
		scanWindow(hwnd_iem, L"Internet Explorer_Server");
	else if(ieType==IExplore)
		scanWindow(hwnd_iem, L"PIEHTML");	//PIE does NOT support key events, but you may try yourself

	DEBUGMSG(1, (L"g_hWndIEM6 = 0x%08x\n", g_hWndIEM6));

	return g_hWndIEM6;	//return global var

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions