Click here to Skip to main content
Click here to Skip to main content

Dialog with HTML skin using CDHtmlDialog and SetWindowRgn

, 27 Oct 2004
Rate this:
Please Sign up or sign in to vote.
Describes how to use an external HTML page as a non-rectangular skin of a dialog.

Figure. 1 The demo dialog with HTML skin

Introduction

This program demonstrates how to use CDHtmlDialog and SetWindowRgn functions to give a dialog non-rectangular HTML skins. If you are familiar with HTML, it will be faster than other ways to deal with beautiful skins. The idea comes from the article, "Gimme Some Skin... VideoSkins", but I use CDHtmlDialog instead. There was an article, "Create Skins from Ordinary Web Pages", on CodeProject from the same author, but I can not reach it now.

Hope it is useful to you. I have tested my sample under Win98/Win2000/Win2003, with IE6 SP1.

Using the code

You need to change the following items to make the dialog into your own:

  1. Content of the external HTML file _Html_Skin.htm.
  2. The GIF mask images.
  3. The handlers for HTML events in the file HtmlSkinDlg.cpp.

Features

  1. Non-rectangular skinned dialog.
  2. Three skins in one external HTML page.
  3. Some unwanted behaviors of the browser control are banned.
    • Context menu is available only in edit control.
    • Text selection is available only in edit control.
    • Dropping file is not available. But you can drag and drop text between edit controls.
    • All the function keys F1-F12 and Escape key do not work.
    • Ctrl-P for printing is banned.
    • User can not press Ctrl-N to open a new browser window for the current URL.
  4. You will be dragging the whole window if you drag anywhere in the UI, except the scroll bar and inside edit controls.
  5. In Win2000, rectangular dragging outline always fits the current size of the whole window.
  6. In Win2000/XP/2003, with 16 bits or higher colors, window can be set transparent.
  7. Layout almost does not change when the system's theme is changed.

Compare between Figures 2a and 2b, Figures 3a and 3b, you can notice that the width of the scroll bar is the only minor difference of the same skin under two different themes.

Figure. 2a Luna skin, Windows classic theme.

Figure. 2b Luna skin, theme with super big font.

Figure. 3a WebFX skin, Windows classic theme.

Figure. 3b WebFX skin, theme with super big font.

Defects

  1. The very HTML page I use in my sample needs IE5.5+.
  2. The "WinClassic" skin only fits the Windows Classic theme of the system.
  3. This sample supports external page only. If you want to put the HTML page and images into resource, please refer to my other article: CDHtmlDialog with CSS, JavaScript and images.
  4. Loading a HTML page with beautiful images and layout may take a long time, so maybe you can add a splash screen before your skin page is loaded. Refer to this article: CSplashScreenEx.

Points of Interest

  1. Dropping target can mess up the page.

    In the dialog's OnInitDialog() member, I have banned the dropping file action like this:

    //refuse dragging file into this dialog
    m_pBrowserApp->put_RegisterAsDropTarget(VARIANT_FALSE);

    But when I attempt to drop a file into the dialog, the content is messed up when mouse pointer is passing across the border. I notice that the key is the margin of the HTML body. In the HTML page, the following must be added to avoid the mess:

    <STYLE type=text/css>
    ...
    BODY {
      ...
      MARGIN-BOTTOM: 0px;
      MARGIN-RIGHT: 0px;
      ...
    }
    ...
    </STYLE>
  2. First entrance of OnDocumentComplete is not for your external HTML page.

    The first one is for the internal HTML page in the program resource, so you may check this as follows:

    void CHtmlSkinDlg::OnDocumentComplete(LPDISPATCH , LPCTSTR szUrl)
    {
      CString sUrl=szUrl;
      sUrl.MakeLower();
      if( sUrl != _sDestUrl )
      {
        //OnDocumentComplete for built-in resource or other URLs,
        //not for your external page
        //...
      }
      else
      {
        //OnDocumentComplete for your external page
        //...
      }
    }

History

25 Oct 2004

Version 1.0.0.2

  • [Article] Images, text and zip files are all updated.
  • [Source code] Added a macro DHTML_EVENT_TAG_ALL.
  • [Source code] Killed some defects on banning accelerators. Behavior inside edit control is normal now.
  • [Source code] Used class CLayeredWindowHelperST to make window transparent.
  • [Source code] Used GIFs instead of BMPs for small size of files.

20 Oct 2004

Version 1.0.0.1, initial release.

By the way

Smile | :) This is my second article on CodeProject. Welcome to my page iTreeSoft.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

iTreeSoft
Web Developer
China China
No Biography provided

Comments and Discussions

 
GeneralSuperb! PinmemberPaul Roberts27-Nov-08 5:15 
GeneralGreat code! Pinmembersodar8-Jul-08 16:31 
QuestionCDHtmlDialog compatibility with Vista PinmemberJohn Tan Jin Kiat28-Nov-07 20:53 
GeneralLink on welcome page not working PinmemberAmit220317-Jul-07 21:40 
Generalem... seems all iTreeSoft stuff is out of date... PinmemberiTreeSoft26-Mar-08 3:44 
AnswerSolved. PinmemberiTreeSoft29-Mar-08 3:26 
QuestionHitting return key closes the application Pinmembernutz0610-Jun-07 22:48 
GeneralRe: Hitting return key closes the application PinmemberMember 30770909-Jan-08 8:16 
QuestionHow To Make Internet Explorer GUI "Draggable" PinmemberAmit22031-Feb-07 22:09 
AnswerRe: How To Make Internet Explorer GUI "Draggable" PinmemberAmit22032-Feb-07 4:43 
GeneralNeed Help on Http Header to add my own User-Agent Pinmemberrex_chen13-May-06 7:09 
I use CDHTMLDialog to program a simple web browser, and I had a trobule on Http Header modify.
I want add my own "User-Agent" when client use my application to browse web.
 
//------------------------------------------------------------------------------------------------
#define WM_NVTO          (WM_USER+1000)
 
class NvToParam
{
public:
     CString URL;
     DWORD Flags;
     CString TargetFrameName;
     CByteArray PostedData;
     CString Headers;
     DWORD dwPostDataLen;
};
//------------------------------------------------------------------------------------------------
LRESULT Ccdhtml_t1Dlg::OnNvTo(WPARAM wParam, LPARAM lParam)
{
     NvToParam* pNvTo = (NvToParam*)wParam;
    
     CDHtmlDialog::Navigate((LPCTSTR)pNvTo->URL, pNvTo->Flags, (LPCTSTR)pNvTo->TargetFrameName, (LPCTSTR)pNvTo->Headers, pNvTo->PostedData.GetData());
     delete pNvTo;
     return 1;
}
 
//------------------------------------------------------------------------------------------------
void Ccdhtml_t1Dlg::OnBeforeNavigate2(LPDISPATCH pDisp, VARIANT FAR* URL, VARIANT FAR* Flags, VARIANT FAR* TargetFrameName, VARIANT FAR* PostData, VARIANT FAR* Headers, BOOL FAR* Cancel)
{
          CString strHeaders(V_BSTR(Headers));
          if(strHeaders.Find("User-Agent:LHPBrowser 1.0") < 0)// Check User-Agent
          {
               *Cancel = TRUE; // Cancel this request
 
               if(!strHeaders.IsEmpty())
                    strHeaders += "\r\n";
               strHeaders += "User-Agent:LHPBrowser 1.0";// Add Customize Http Header
 
               NvToParam* pNvTo = new NvToParam;
               ASSERT(V_VT(URL) == VT_BSTR);
               ASSERT(V_VT(TargetFrameName) == VT_BSTR);
               ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
               ASSERT(V_VT(Headers) == VT_BSTR);
               ASSERT(Cancel != NULL);
 
               USES_CONVERSION;
 
               VARIANT* vtPostedData = V_VARIANTREF(PostData);
               CByteArray array;
               if (V_VT(vtPostedData) & VT_ARRAY)
               {
                    // must be a vector of bytes
                    ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
 
                    vtPostedData->vt |= VT_UI1;
                    COleSafeArray safe(vtPostedData);
 
                    DWORD dwSize = safe.GetOneDimSize();
 
                    LPVOID pVoid;
                    safe.AccessData(&pVoid);
 
                    array.SetSize(dwSize);
                    LPBYTE lpByte = array.GetData();
 
                    memcpy(lpByte, pVoid, dwSize);
 
                    safe.UnaccessData();
               }
               // make real parameters out of the notification
 
               CString strTargetFrameName(V_BSTR(TargetFrameName));
               CString strURL(V_BSTR(URL));
               DWORD nFlags = V_I4(Flags);
 
               //=====================================================
               pNvTo->URL = strURL;
               pNvTo->Flags = nFlags;
               pNvTo->TargetFrameName = strTargetFrameName;
               pNvTo->PostedData.Copy(array);
               pNvTo->Headers = strHeaders;
               //=====================================================
              
               // Post msg
               PostMessage(WM_NVTO,(WPARAM)pNvTo);
 
               return;
          }
     CDHtmlDialog::_OnBeforeNavigate2( pDisp, URL, Flags, TargetFrameName, PostData, Headers, Cancel );                   
}
 
----------------------------------------------------------
After the testing, I found it will work fine on "http reqest", "http form get" and "http form post".
But if my http form is "multipart/form-data" (upload file form), some of the post datas will lost.
 
How should I fix it? Does any one can help me? Or any better method to add http header when navigate a url?
GeneralOther disabled functions PinmemberScott Owen9-May-06 11:26 
GeneralCOOL! PinmemberiTreeSoft26-Mar-08 3:35 
QuestionCan CDHtmlDialog be used in CView? PinmemberEternity357717-Jan-05 10:04 
AnswerMaybe ATL or find in articles... PinmemberiTreeSoft18-Jan-05 16:10 
AnswerRe: Can CDHtmlDialog be used in CView? Pinmembergillnrb21-May-06 0:21 
GeneralOnHtmlDragStart PinmemberEffiniti9-Jan-05 23:58 
GeneralMake it the div background image... PinmemberiTreeSoft10-Jan-05 13:47 
GeneralRe: Make it the div background image... PinmemberEffiniti10-Jan-05 19:58 
GeneralCDHtmlDialog and IE version Pinmembertestgames@gmail.com5-Jan-05 3:33 
GeneralIt should. PinmemberiTreeSoft5-Jan-05 22:57 
GeneralRe: It should. Pinmembertestgames@gmail.com6-Jan-05 0:38 
GeneralSo test it first. PinmemberiTreeSoft6-Jan-05 2:16 
GeneralRe: So test it first. Pinmembertestgames@gmail.com8-Jan-05 23:44 
QuestionHow to do about frameset Pinmembernewman208816-Nov-04 5:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 27 Oct 2004
Article Copyright 2004 by iTreeSoft
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid