用win32创建了一个HTML页面,想取得网页上的链接文字?怎么做?

 

//
LRESULT TestWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//
HRESULT CMyHtmlShow::RegisterTestClass(HINSTANCE hInstance)
{
    WNDCLASS wc = { 0 };
    HRESULT hrResult;
    if(!GetClassInfo(hInstance, WC_HTMLCONTAINER, &wc))
    {
        wc.style = CS_HREDRAW | CS_VREDRAW | CS_IME;//CS_IME
wc.lpfnWndProc = TestWndProc;
wc.hInstance = hInstance;
        wc.lpszClassName = WC_HTMLCONTAINER;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
        hrResult = (RegisterClass(&wc) ? S_OK : E_FAIL);
    }
    else
{
        hrResult = S_OK;
}
    return hrResult;
}
//
int CMyHtmlShow::CreateMyHtmlWindow(CString strHtml)
{
HWND hwndParent;
    HWND hwndHTML;
//
    VERIFY(SUCCEEDED(RegisterTestClass(hInstance)));
   
    //parent window
    hwndParent = CreateWindow(WC_HTMLCONTAINER,
   L"窗口标题",
   WS_VISIBLE,
   CW_USEDEFAULT,
   CW_USEDEFAULT,
   CW_USEDEFAULT,
   CW_USEDEFAULT,
   NULL,
   NULL,
   hInstance,
   0);
    RECT rc;
    GetWindowRect(hwndParent, &rc); 
SHFullScreen(hwndParent, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
//SHFullScreen(hwndParent, SHFS_SHOWSIPBUTTON | SHFS_SHOWSTARTICON);
//new position of parent window
MoveWindow( hwndParent, 
                rc.left, 
                rc.top - (MENU_HEIGHT + 5), 
                rc.right, 
                rc.bottom - MENU_HEIGHT + 5 + 10, 
                TRUE);
    VERIFY(InitHTMLControl(hInstance));
//HTML window
hwndHTML = CreateWindow(WC_HTML,
                            NULL,
                            //WS_CHILD | WS_BORDER | WS_VISIBLE,
WS_BORDER | WS_VISIBLE,
                            5,
                            35,
                            (rc.right - rc.left) - 10,
                            (rc.bottom - rc.top) - 33,
                            hwndParent,
                            NULL,
                            hInstance,
                            NULL);
//
//SetActiveWindow(hwndParent);
//
    if (hwndHTML != NULL)
    {
BSTR bstrURL = SysAllocString(strHtml);
        SendMessage(hwndHTML, DTM_NAVIGATE,0,(LPARAM)bstrURL);//0 turn to 1,DTM_INTEGRALPAGING DTM_NAVIGATE
        SysFreeString(bstrURL);        
        MSG msg;
        while (GetMessage(&msg,NULL,0,0)) //0,0
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }
    return 0;
}
/****************************************************************************
*                                                                          *
*  FUNCTION   : HandleCreate ( hwnd )                                      *
*                                                                          *
*  PURPOSE    : Creates a new (empty) menu and appends to it the "State"   *
*               menu items. It sets up the user-defined checkmarks for the *
*               menu. It then inserts this menu into the main menu bar.    *
*                                                                          *
****************************************************************************/
VOID APIENTRY HandleCreate(
    HWND hwnd
    )
{
#if _WIN32_WCE > 211 //Pocket PC devices
    //Create a MenuBar for WCE devices
    SHMENUBARINFO info;
info.cbSize = sizeof(info);
info.hwndParent = hwnd;
info.dwFlags = SHCMBF_HMENU;
info.nToolBarId = IDR_MENU_HTML;
info.hInstRes = ::AfxGetInstanceHandle();
info.nBmpId = 0;
info.cBmpImages = 0;
SHCreateMenuBar(&info);
    
    if (FALSE == SHCreateMenuBar(&info))
    {
        MessageBox(hwnd, L"Create MenuBar Failed", L"Error", MB_OK);
    }
    g_hWndCB = info.hwndMB;
    
#else
    g_hWndCB = CommandBar_Create(g_hInst, hwnd, 1);
    CommandBar_InsertMenubar(g_hWndCB, g_hInst, IDM_MAIN_MENU, 0);
    CommandBar_AddAdornments(g_hWndCB, 0, 0);    
#endif    
    return;
}
//
HRESULT ProcessMainMenu(HWND hDlg, WORD wLo)
{
    HRESULT hr = S_OK;
    WCHAR pszSubject[MAX_LOADSTRING];
    IItem * pItem = NULL;
    long lOID = 0;
    switch(wLo)
{
case ID_MYOK:
{
            DestroyWindow(hDlg);
            PostQuitMessage(0);
            break;
}
    }
    return hr;
}
//
LRESULT TestWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
LRESULT lResult = 0;
    switch (uMsg)
    {
//MENU
case WM_CREATE:
{
// Create the menu 
HandleCreate(hwnd);//
break;
}
case WM_COMMAND:
{
            ProcessMainMenu(hwnd, LOWORD(wParam));
            break;
}
case WM_CANCELMODE:
{
            DestroyWindow(hwnd);
            PostQuitMessage(0);
            break;
}
/*case WM_TIMER:
{
DestroyWindow(hwnd);
            PostQuitMessage(0);
            break;
}*/
default:
        {
            lResult = DefWindowProc(hwnd, uMsg, wParam, lParam);
            break;
        }
    }
    return lResult;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值