Classes | Functions | Variables

explorer.cpp File Reference

#include <precomp.h>
#include "resource.h"
#include <locale.h>
#include <io.h>
#include <fcntl.h>
#include "dialogs/settings.h"
#include "services/shellservices.h"
Include dependency graph for explorer.cpp:

Go to the source code of this file.

Classes

struct  ExplorerAboutDlg
 "About Explorer" Dialog More...

Functions

int initialize_gdb_stub ()
void _log_ (LPCTSTR txt)
HBITMAP create_bitmap_from_icon (HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd)
 create a bitmap from an icon
HBITMAP create_small_bitmap_from_icon (HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd)
int ImageList_AddAlphaIcon (HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd)
 add icon with alpha channel to imagelist using the specified background color
void SetWindowIcon (HWND hwnd, UINT nid)
 set big and small icons out of the resources for a window
void explorer_show_frame (int cmdShow, LPTSTR lpCmdLine)
void explorer_about (HWND hwndParent)
int explorer_main (HINSTANCE hInstance, LPTSTR lpCmdLine, int cmdShow)
int WINAPI _tWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)

Variables

DynamicLoadLibFct< void(__stdcall
*)(BOOL)> 
g_SHDOCVW_ShellDDEInit (TEXT("SHDOCVW"), 118)
ExplorerGlobals g_Globals

Function Documentation

void _log_ ( LPCTSTR  txt )

Definition at line 143 of file explorer.cpp.

References ExplorerGlobals::_log, and TEXT.

{
    FmtString msg(TEXT("%s\n"), txt);

    if (g_Globals._log)
        _fputts(msg, g_Globals._log);

    OutputDebugString(msg);
}
int WINAPI _tWinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
LPTSTR  lpCmdLine,
int  nShowCmd 
)

Todo:
save previous shell application in config file
Todo:
save previous shell application in config file

TODO launching autostart programs can be moved into a background thread.

Definition at line 1029 of file explorer.cpp.

References ExplorerGlobals::_desktop_mode, ExplorerGlobals::_desktops, ExplorerGlobals::_hwndDesktop, ExplorerGlobals::_log, _tcsstr, CONTEXT, COUNTOF, DesktopWindow::Create(), explorer_main(), g_SHDOCVW_ShellDDEInit, HWND, Desktops::init(), ExplorerGlobals::init(), initialize_gdb_stub(), IsAnyDesktopRunning(), LOG, ExplorerGlobals::read_persistent(), Thread::Start(), Thread::Stop(), TEXT, and ExplorerGlobals::write_persistent().

{
    CONTEXT("WinMain()");

    BOOL any_desktop_running = IsAnyDesktopRunning();

    BOOL startup_desktop;

     // strip extended options from the front of the command line
    String ext_options;

    while(*lpCmdLine == '-') {
        while(*lpCmdLine && !_istspace((unsigned)*lpCmdLine))
            ext_options += *lpCmdLine++;

        while(_istspace((unsigned)*lpCmdLine))
            ++lpCmdLine;
    }

     // command line option "-install" to replace previous shell application with ROS Explorer
    if (_tcsstr(ext_options,TEXT("-install"))) {
         // install ROS Explorer into the registry
        TCHAR path[MAX_PATH];

        int l = GetModuleFileName(0, path, COUNTOF(path));
        if (l) {
            HKEY hkey;

            if (!RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey)) {

                ///@todo save previous shell application in config file

                RegSetValueEx(hkey, TEXT("Shell"), 0, REG_SZ, (LPBYTE)path, l*sizeof(TCHAR));
                RegCloseKey(hkey);
            }

            if (!RegOpenKey(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon"), &hkey)) {

                ///@todo save previous shell application in config file

                RegSetValueEx(hkey, TEXT("Shell"), 0, REG_SZ, (LPBYTE)TEXT(""), l*sizeof(TCHAR));
                RegCloseKey(hkey);
            }
        }

        HWND shellWindow = GetShellWindow();

        if (shellWindow) {
            DWORD pid;

             // terminate shell process for NT like systems
            GetWindowThreadProcessId(shellWindow, &pid);
            HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);

             // On Win 9x it's sufficient to destroy the shell window.
            DestroyWindow(shellWindow);

            if (TerminateProcess(hProcess, 0))
                WaitForSingleObject(hProcess, INFINITE);

            CloseHandle(hProcess);
        }

        startup_desktop = TRUE;
    } else {
         // create desktop window and task bar only, if there is no other shell and we are
         // the first explorer instance
         // MS Explorer looks additionally into the registry entry HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\shell,
         // to decide wether it is currently configured as shell application.
        startup_desktop = !any_desktop_running;
    }


    bool autostart = !any_desktop_running;

     // disable autostart if the SHIFT key is pressed
    if (GetAsyncKeyState(VK_SHIFT) < 0)
        autostart = false;

#ifdef _DEBUG   //MF: disabled for debugging
    autostart = false;
#endif

     // If there is given the command line option "-desktop", create desktop window anyways
    if (_tcsstr(ext_options,TEXT("-desktop")))
        startup_desktop = TRUE;
#ifndef ROSSHELL
    else if (_tcsstr(ext_options,TEXT("-nodesktop")))
        startup_desktop = FALSE;

     // Don't display cabinet window in desktop mode
    if (startup_desktop && !_tcsstr(ext_options,TEXT("-explorer")))
        nShowCmd = SW_HIDE;
#endif

    if (_tcsstr(ext_options,TEXT("-noautostart")))
        autostart = false;
    else if (_tcsstr(ext_options,TEXT("-autostart")))
        autostart = true;

#ifndef __WINE__
    if (_tcsstr(ext_options,TEXT("-console"))) {
        AllocConsole();

        _dup2(_open_osfhandle((long)GetStdHandle(STD_INPUT_HANDLE), _O_RDONLY), 0);
        _dup2(_open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), 0), 1);
        _dup2(_open_osfhandle((long)GetStdHandle(STD_ERROR_HANDLE), 0), 2);

        g_Globals._log = _fdopen(1, "w");
        setvbuf(g_Globals._log, 0, _IONBF, 0);

        LOG(TEXT("starting explorer debug log\n"));
    }
#endif


    if (startup_desktop) {
         // hide the XP login screen (Credit to Nicolas Escuder)
         // another undocumented event: "Global\\msgina: ReturnToWelcome"
        if (!SetShellReadyEvent(TEXT("msgina: ShellReadyEvent")))
            SetShellReadyEvent(TEXT("Global\\msgina: ShellReadyEvent"));
    }
#ifdef ROSSHELL
    else
        return 0;   // no shell to launch, so exit immediatelly
#endif


    if (!any_desktop_running) {
         // launch the shell DDE server
        if (g_SHDOCVW_ShellDDEInit)
            (*g_SHDOCVW_ShellDDEInit)(TRUE);
    }


    bool use_gdb_stub = false;  // !IsDebuggerPresent();

    if (_tcsstr(ext_options,TEXT("-debug")))
        use_gdb_stub = true;

    if (_tcsstr(ext_options,TEXT("-break"))) {
        LOG(TEXT("debugger breakpoint"));
#ifdef _MSC_VER
        __asm int 3
#else
        asm("int3");
#endif
    }

     // activate GDB remote debugging stub if no other debugger is running
    if (use_gdb_stub) {
        LOG(TEXT("waiting for debugger connection...\n"));

        initialize_gdb_stub();
    }

    g_Globals.init(hInstance);

     // initialize COM and OLE before creating the desktop window
    OleInit usingCOM;

     // init common controls library
    CommonControlInit usingCmnCtrl;

    g_Globals.read_persistent();

    if (startup_desktop) {
        WaitCursor wait;

        g_Globals._desktops.init();

        g_Globals._hwndDesktop = DesktopWindow::Create();
#ifdef _USE_HDESK
        g_Globals._desktops.get_current_Desktop()->_hwndDesktop = g_Globals._hwndDesktop;
#endif
    }

    if (_tcsstr(ext_options,TEXT("-?"))) {
        MessageBoxA(g_Globals._hwndDesktop,
            "/e     open cabinet window in explorer mode\r\n"
            "/root      open cabinet window in rooted mode\r\n"
            "/mdi       open cabinet window in MDI mode\r\n"
            "/sdi       open cabinet window in SDI mode\r\n"
            "\r\n"
            "-?     display command line options\r\n"
            "\r\n"
            "-desktop       start in desktop mode regardless of an already running shell\r\n"
            "-nodesktop disable desktop mode\r\n"
            "-explorer      display cabinet window regardless of enabled desktop mode\r\n"
            "\r\n"
            "-install       replace previous shell application with ROS Explorer\r\n"
            "\r\n"
            "-noautostart   disable autostarts\r\n"
            "-autostart enable autostarts regardless of debug build\r\n"
            "\r\n"
            "-console       open debug console\r\n"
            "\r\n"
            "-debug     activate GDB remote debugging stub\r\n"
            "-break     activate debugger breakpoint\r\n",
            "ROS Explorer - command line options", MB_OK);
    }

    Thread* pSSOThread = NULL;

    if (startup_desktop) {
         // launch SSO thread to allow message processing independent from the explorer main thread
        pSSOThread = new SSOThread;
        pSSOThread->Start();
    }

    /**TODO launching autostart programs can be moved into a background thread. */
    if (autostart) {
        const char* argv[] = {"", "s"}; // call startup routine in SESSION_START mode
        startup(2, argv);
    }

#ifndef ROSSHELL
    if (g_Globals._hwndDesktop)
        g_Globals._desktop_mode = true;
#endif


    int ret = explorer_main(hInstance, lpCmdLine, nShowCmd);


     // write configuration file
    g_Globals.write_persistent();

    if (pSSOThread) {
        pSSOThread->Stop();
        delete pSSOThread;
    }

    if (!any_desktop_running) {
         // shutdown the shell DDE server
        if (g_SHDOCVW_ShellDDEInit)
            (*g_SHDOCVW_ShellDDEInit)(FALSE);
    }

    return ret;
}

Here is the call graph for this function:

HBITMAP create_bitmap_from_icon ( HICON  hIcon,
HBRUSH  hbrush_bkgnd,
HDC  hdc_wnd 
)

create a bitmap from an icon

Definition at line 336 of file explorer.cpp.

References ICON_SIZE_SMALL.

Referenced by Icon::create_bitmap(), TaskBar::EnumWndProc(), and ImageList_AddAlphaIcon().

{
    int cx = ICON_SIZE_SMALL;
    int cy = ICON_SIZE_SMALL;
    HBITMAP hbmp = CreateCompatibleBitmap(hdc_wnd, cx, cy);

    MemCanvas canvas;
    BitmapSelection sel(canvas, hbmp);

    RECT rect = {0, 0, cx, cy};
    FillRect(canvas, &rect, hbrush_bkgnd);

    DrawIconEx(canvas, 0, 0, hIcon, cx, cy, 0, hbrush_bkgnd, DI_NORMAL);

    return hbmp;
}

Here is the caller graph for this function:

HBITMAP create_small_bitmap_from_icon ( HICON  hIcon,
HBRUSH  hbrush_bkgnd,
HDC  hdc_wnd 
)

Definition at line 353 of file explorer.cpp.

{
    int cx = GetSystemMetrics(SM_CXSMICON);
    int cy = GetSystemMetrics(SM_CYSMICON);
    HBITMAP hbmp = CreateCompatibleBitmap(hdc_wnd, cx, cy);

    MemCanvas canvas;
    BitmapSelection sel(canvas, hbmp);

    RECT rect = {0, 0, cx, cy};
    FillRect(canvas, &rect, hbrush_bkgnd);

    DrawIconEx(canvas, 0, 0, hIcon, cx, cy, 0, hbrush_bkgnd, DI_NORMAL);

    return hbmp;
}
void explorer_about ( HWND  hwndParent )

Definition at line 927 of file explorer.cpp.

References Dialog::DoModal(), IDD_ABOUT_EXPLORER, and WINDOW_CREATOR.

Referenced by MainFrameBase::Command(), DesktopBar::Command(), and DesktopShellView::DoDesktopContextMenu().

Here is the call graph for this function:

Here is the caller graph for this function:

int explorer_main ( HINSTANCE  hInstance,
LPTSTR  lpCmdLine,
int  cmdShow 
)

Definition at line 954 of file explorer.cpp.

References CONTEXT, explorer_show_frame(), HandleException(), and Window::MessageLoop().

Referenced by _tWinMain().

{
    CONTEXT("explorer_main");

     // initialize Common Controls library
    CommonControlInit usingCmnCtrl;

    try {
        InitInstance(hInstance);
    } catch(COMException& e) {
        HandleException(e, GetDesktopWindow());
        return -1;
    }

#ifndef ROSSHELL
    if (cmdShow != SW_HIDE) {
/*  // don't maximize if being called from the ROS desktop
        if (cmdShow == SW_SHOWNORMAL)
                ///@todo read window placement from registry
            cmdShow = SW_MAXIMIZE;
*/

        explorer_show_frame(cmdShow, lpCmdLine);
    }
#endif

    return Window::MessageLoop();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void explorer_show_frame ( int  cmdShow,
LPTSTR  lpCmdLine 
)

Definition at line 711 of file explorer.cpp.

References ExplorerCmd::_cmdShow, ExplorerGlobals::_hMainWnd, ExplorerGlobals::_hwndDesktop, ExplorerCmd::_mdi, ExplorerGlobals::_prescan_nodes, MainFrameBase::Create(), Dialog::DoModal(), ExplorerGlobals::get_cfg(), IDD_MDI_SDI, ExplorerCmd::ParseCmdLine(), and WINDOW_CREATOR.

Referenced by StartMenuHandler::Command(), DesktopBar::Command(), explorer_main(), DesktopBar::ProcessHotKey(), and DesktopWindow::WndProc().

{
    ExplorerCmd cmd;

    if (g_Globals._hMainWnd) {
        if (IsIconic(g_Globals._hMainWnd))
            ShowWindow(g_Globals._hMainWnd, SW_RESTORE);
        else
            SetForegroundWindow(g_Globals._hMainWnd);

        return;
    }

    g_Globals._prescan_nodes = false;

    XMLPos explorer_options = g_Globals.get_cfg("general/explorer");
    XS_String mdiStr = XMLString(explorer_options, "mdi");

     // If there isn't yet the "mdi" setting in the configuration, display the MDI/SDI dialog.
    if (mdiStr.empty())
        Dialog::DoModal(IDD_MDI_SDI, WINDOW_CREATOR(MdiSdiDlg), g_Globals._hwndDesktop);

     // Now read the MDI attribute again and interpret it as boolean value.
    cmd._mdi = XMLBool(explorer_options, "mdi", true);

    cmd._cmdShow = cmdShow;

     // parse command line options, which may overwrite the MDI flag
    if (lpCmdLine)
        cmd.ParseCmdLine(lpCmdLine);

     // create main window
    MainFrameBase::Create(cmd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int ImageList_AddAlphaIcon ( HIMAGELIST  himl,
HICON  hIcon,
HBRUSH  hbrush_bkgnd,
HDC  hdc_wnd 
)

add icon with alpha channel to imagelist using the specified background color

Definition at line 370 of file explorer.cpp.

References create_bitmap_from_icon().

Referenced by Icon::add_to_imagelist(), MainFrameBase::FillBookmarks(), TrayNotifyDlg::InsertItem(), and TrayNotifyDlg::TrayNotifyDlg().

{
    HBITMAP hbmp = create_bitmap_from_icon(hIcon, hbrush_bkgnd, hdc_wnd);

    int ret = ImageList_Add(himl, hbmp, 0);

    DeleteObject(hbmp);

    return ret;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int initialize_gdb_stub (  )

Referenced by _tWinMain().

Here is the caller graph for this function:

void SetWindowIcon ( HWND  hwnd,
UINT  nid 
)

set big and small icons out of the resources for a window

Definition at line 693 of file explorer.cpp.

References Window_SetIcon.

Referenced by DesktopBar::DesktopBar(), ExplorerAboutDlg::ExplorerAboutDlg(), FindProgramDlg::FindProgramDlg(), and TrayNotifyDlg::TrayNotifyDlg().

{
    HICON hIcon = ResIcon(nid);
    (void)Window_SetIcon(hwnd, ICON_BIG, hIcon);

    HICON hIconSmall = SmallIcon(nid);
    (void)Window_SetIcon(hwnd, ICON_SMALL, hIconSmall);
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 53 of file explorer.cpp.

Referenced by StartMenu::AddButton(), FavoritesMenu::AddEntries(), SearchMenu::AddEntries(), BrowseMenu::AddEntries(), SettingsMenu::AddEntries(), QuickLaunchBar::AddShortcuts(), StartMenuHandler::Command(), MdiSdiDlg::Command(), TaskbarSettingsDlg::Command(), DesktopSettingsDlg::Command(), MainFrameBase::Command(), DesktopBar::Command(), ChildWindow::create(), Window::Create(), SDIMainFrame::Create(), MDIMainFrame::Create(), MainFrameBase::Create(), FileChildWindow::create(), Pane::create_header(), DesktopSettingsDlg::DesktopSettingsDlg(), Dialog::DoModal(), Pane::draw_item(), Entry::extract_icon(), BookmarkList::fill_tree(), ShellDirectory::fill_w32fdata_shell(), MainFrameBase::FillBookmarks(), FindProgramDlg::FindProgramDlg(), ShellBrowser::get_image_idx(), StartMenuRoot::Init(), Pane::init(), DesktopBar::Init(), DesktopWindow::Init(), ShellBrowser::InsertSubitems(), ShellBrowser::invalidate_cache(), MainFrameBase::MainFrameBase(), MDIMainFrame::MDIMainFrame(), MdiSdiDlg::MdiSdiDlg(), TaskbarSettingsDlg::Notify(), DesktopSettingsDlg::Notify(), FindProgramDlg::Notify(), MainFrameBase::OpenShellFolders(), MainFrameBase::ProcessMessage(), PropertySheetDialog::PropertySheetDialog(), PropSheetPage::PropSheetPage(), Favorites::read(), NotifyArea::read_config(), WinDirectory::read_directory(), ShellDirectory::read_directory(), Entry::read_directory_base(), TrayNotifyDlg::RefreshProperties(), StartMenuRoot::StartMenuRoot(), Desktops::SwitchToDesktop(), TaskbarSettingsDlg::TaskbarSettingsDlg(), TrayNotifyDlg::TrayNotifyDlg(), MDIShellBrowserChild::update_shell_browser(), SDIMainFrame::update_shell_browser(), WindowClass::WindowClass(), DesktopWindow::WndProc(), BackgroundWindow::WndProc(), NotifyArea::write_config(), Entry::~Entry(), and MainFrameBase::~MainFrameBase().

DynamicLoadLibFct<void(__stdcall*)(BOOL)> g_SHDOCVW_ShellDDEInit(TEXT("SHDOCVW"), 118)

Definition at line 50 of file explorer.cpp.

Referenced by _tWinMain().


ROS Explorer Source Code Documentation
generated on 02.01.2013 by doxygen

ROS Explorer Homepage