Ebs2002

I'm working on a SmartPhone application that has an HTML Control window created with htmlview.dll:

Code Snippet

m_HtmlViewInstance = ::LoadLibrary(L"htmlview.dll");
VERIFY(InitHTMLControl(AfxGetInstanceHandle()));

::SetWindowLong(m_hwndHtml, GWL_ID, IDC_HTMLVIEW);

m_hwndHtml = ::CreateWindow(DISPLAYCLASS, NULL, dwStyle, rect.left, rect.top, rect.right, rect.bottom, m_hWnd, 0, m_HtmlViewInstance, NULL);





All of this is working well, but now we are attempting to process the input, and we want to handle input differently if there is a horizontal scroll bar in the HTML window.

I tried using GetScrollInfo(m_hwndHtml, SB_HORZ, &si) with &si zeroed out except for cbSize and fMask = SIF_RANGE (and have attempted other masks), but it's GetScrollInfo always returns null.

Is there another way to detect the scrollbar using htmlview If not, is there a way to detect the viewable width of a window (which I could then compare to the coordinates of the window to determine if there is a scroll bar or not)



Re: Smart Devices Native C++ Development HTMLView.dll -- Horizontal Scrolling?

Ebs2002

Don't you love it when people answer their own questions

After an hour or so of searching, I finally came across the DTM_LAYOUTWIDTH message.

However, the next problem is that sending the VK_LEFT / VK_RIGHT message to the html window hwind doesn't cause the window to scroll left/right (but VK_UP and VK_DOWN will allow it to scroll up/down).

How can I tell the HTML control to scroll left and right without clicking/dragging the scroll bar (ie, with a smartphone)






Re: Smart Devices Native C++ Development HTMLView.dll -- Horizontal Scrolling?

Ebs2002

Well, for anyone else who is wondering in the future, I have found the solution.

When you create an HTML window of class DISPLAYCLASS (from htmlview.dll/htmlctrl.h), that window is a wrapper window for a child window that does all the work. To detect the presence of a scrollbar and handle the VK_LEFT/VK_RIGHT properly, do the following:


Code Snippet
myDialogClass::PreTranslateMessage(MSG * pMsg)
{
if (pMsg->message == WM_KEYDOWN || pMsg->message==WM_SYSKEYDOWN)

{
if (pMsg->wParam == VK_RIGHT)
{
RECT rect;
int width = ::SendMessage(m_hwndHtml, DTM_LAYOUTWIDTH, 0, 0);
::GetClientRect(m_hwndHtml, &rect);
// if there is a horizontal scroll bar...
if (width > rect.right)
{
// HtmlCtrl windows have a child window to accept scroll messages
HWND childWindow = ::GetWindow(m_hwndHtml, GW_CHILD);
if (childWindow != NULL)
::SendMessage(childWindow, WM_HSCROLL, SB_LINERIGHT, NULL);
else
::SendMessage(m_hwndHtml, WM_HSCROLL, SB_LINERIGHT, NULL);
}
else
{
// Do alternative handling for the left/right keys if you want
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}






Re: Smart Devices Native C++ Development HTMLView.dll -- Horizontal Scrolling?

Zero Dai - MSFT

Thanks a lot for sharing your idea.

Zero Dai - MSFT