case MOZ_NewBrowser: OpenWebPage(gFirstURL); break;  case MOZ_Save: SaveWebPage(webBrowser); break;  case MOZ_Print: {     if (webBrowserPrint) { nsCOMPtr<nsIPrintSettings> printSettings; webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings)); NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!"); if (printSettings) { printSettings->SetPrintSilent(PR_TRUE); webBrowserPrint->Print(printSettings, (nsIWebProgressListener*)nsnull); } } } break;
BOOL CALLBACK BrowserDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam){    // Get the browser and other pointers since they are used a lot below    HWND hwndBrowser = GetDlgItem(hwndDlg, IDC_BROWSER);    nsIWebBrowserChrome *chrome = nsnull ;    if (hwndBrowser)    {        chrome = (nsIWebBrowserChrome *) GetWindowLong(hwndBrowser, GWL_USERDATA);    }    nsCOMPtr<nsIWebBrowser> webBrowser;    nsCOMPtr<nsIWebNavigation> webNavigation;    nsCOMPtr<nsIWebBrowserPrint> webBrowserPrint;    if (chrome)    {        chrome->GetWebBrowser(getter_AddRefs(webBrowser));        webNavigation = do_QueryInterface(webBrowser);        webBrowserPrint = do_GetInterface(webBrowser);    }    // Test the message    switch (uMsg)    {    case WM_INITDIALOG:        SetupShellStuff(hwndDlg);        return TRUE;    case WM_SYSCOMMAND:        if (wParam == SC_CLOSE)        {            WebBrowserChromeUI::Destroy(chrome);            return TRUE;        }        break;    case WM_DESTROY:        PostQuitMessage(0);        sRunCondition = FALSE;        return TRUE;    case WM_COMMAND:        if (!webBrowser)        {            return TRUE;        }        // Test which command was selected        switch (LOWORD(wParam))        {        case IDC_ADDRESS:            if (HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam) == CBN_SELCHANGE)            {                // User has changed the address field so enable the Go button                EnableWindow(GetDlgItem(hwndDlg, IDC_GO), TRUE);            }            break;        case IDC_GO:            {                TCHAR szURL[2048];                memset(szURL, 0, sizeof(szURL));                GetDlgItemText(hwndDlg, IDC_ADDRESS, szURL, sizeof(szURL) / sizeof(szURL[0]) - 1);                webNavigation->LoadURI(NS_ConvertASCIItoUCS2(szURL).get(),                                       nsIWebNavigation::LOAD_FLAGS_NONE,                                       nsnull,                                       nsnull,                                       nsnull);            }            break;        case IDC_STOP:            webNavigation->Stop(nsIWebNavigation::STOP_ALL);            UpdateUI(chrome);            break;        case IDC_RELOAD:            webNavigation->Reload(nsIWebNavigation::LOAD_FLAGS_NONE);            break;        case IDM_EXIT:            PostMessage(hwndDlg, WM_SYSCOMMAND, SC_CLOSE, 0);            break;        // File menu commands        case MOZ_NewBrowser:            OpenWebPage(gFirstURL);            break;        case MOZ_Save:            SaveWebPage(webBrowser);            break;        case MOZ_Print:            {                // NOTE: Embedding code shouldn't need to get the docshell or                //       contentviewer AT ALL. This code below will break one                //       day but will have to do until the embedding API has                //       a cleaner way to do the same thing.              if (webBrowserPrint)              {                  nsCOMPtr<nsIPrintSettings> printSettings;                  webBrowserPrint->GetGlobalPrintSettings(getter_AddRefs(printSettings));                  NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!");                  if (printSettings)                   {                      printSettings->SetPrintSilent(PR_TRUE);                      webBrowserPrint->Print(printSettings, (nsIWebProgressListener*)nsnull);                  }              }            }            break;        // Edit menu commands        case MOZ_Cut:            {                nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser);                clipCmds->CutSelection();            }            break;        case MOZ_Copy:            {                nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser);                clipCmds->CopySelection();            }            break;        case MOZ_Paste:            {                nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser);                clipCmds->Paste();            }            break;        case MOZ_SelectAll:            {                nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser);                clipCmds->SelectAll();            }            break;        case MOZ_SelectNone:            {                nsCOMPtr<nsIClipboardCommands> clipCmds = do_GetInterface(webBrowser);                clipCmds->SelectNone();            }            break;        // Go menu commands        case IDC_BACK:        case MOZ_GoBack:            webNavigation->GoBack();            UpdateUI(chrome);            break;        case IDC_FORWARD:        case MOZ_GoForward:            webNavigation->GoForward();            UpdateUI(chrome);            break;        // Help menu commands        case MOZ_About:            {                TCHAR szAboutTitle[MAX_LOADSTRING];                TCHAR szAbout[MAX_LOADSTRING];                LoadString(ghInstanceApp, IDS_ABOUT_TITLE, szAboutTitle, MAX_LOADSTRING);                LoadString(ghInstanceApp, IDS_ABOUT, szAbout, MAX_LOADSTRING);                MessageBox(NULL, szAbout, szAboutTitle, MB_OK);            }            break;        }        return TRUE;    case WM_ACTIVATE:        {            SHFullScreen( hwndDlg, SHFS_SHOWTASKBAR | SHFS_SHOWSIPBUTTON );            nsCOMPtr<nsIWebBrowserFocus> focus(do_GetInterface(webBrowser));            if(focus)            {                switch (wParam)                {                case WA_ACTIVE:                    focus->Activate();                    break;                case WA_INACTIVE:                    focus->Deactivate();                    break;                default:                    break;                }            }        }        break;    case WM_SIZE:        {            UINT newDlgWidth = LOWORD(lParam);            UINT newDlgHeight = HIWORD(lParam);            // TODO Reposition the control bar - for the moment it's fixed size            // Reposition the status area. Status bar            // gets any space that the fixed size progress bar doesn't use.            int progressWidth;            int statusWidth;            int statusHeight;            HWND hwndStatus = GetDlgItem(hwndDlg, IDC_STATUS);            if (hwndStatus) {              RECT rcStatus;              GetWindowRect(hwndStatus, &rcStatus);              statusHeight = rcStatus.bottom - rcStatus.top;            } else              statusHeight = 0;            HWND hwndProgress = GetDlgItem(hwndDlg, IDC_PROGRESS);            if (hwndProgress) {              RECT rcProgress;              GetWindowRect(hwndProgress, &rcProgress);              progressWidth = rcProgress.right - rcProgress.left;            } else              progressWidth = 0;            statusWidth = newDlgWidth - progressWidth;            if (hwndStatus)              SetWindowPos(hwndStatus,                           HWND_TOP,                           0, newDlgHeight - statusHeight,                           statusWidth,                           statusHeight,                           SWP_NOZORDER);            if (hwndProgress)              SetWindowPos(hwndProgress,                           HWND_TOP,                           statusWidth, newDlgHeight - statusHeight,                           0, 0,                           SWP_NOSIZE | SWP_NOZORDER);            // Resize the browser area (assuming the browse is            // sandwiched between the control bar and status area)            RECT rcBrowser;            POINT ptBrowser;            GetWindowRect(hwndBrowser, &rcBrowser);            ptBrowser.x = rcBrowser.left;            ptBrowser.y = rcBrowser.top;            ScreenToClient(hwndDlg, &ptBrowser);            int browserHeight = newDlgHeight - ptBrowser.y - statusHeight;            if (browserHeight < 1)            {                browserHeight = 1;            }            SetWindowPos(hwndBrowser,                         HWND_TOP,                         0, 0,                         newDlgWidth,                         newDlgHeight - ptBrowser.y - statusHeight,                         SWP_NOMOVE | SWP_NOZORDER);        }        return TRUE;    }    return FALSE;}