SOL9 2.0 Sample: MediaControl

SOL9 2.0 Samples

1 Screenshot


2 Source code

/*
 * MediaControl.cpp 
 * Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */



// SOL++2000
// 2008/09/15 Modified a parameter of open method of MediaControlView.
//    controller.open(name, MCIWNDOPENF_NEW);
//     ->    controller.open(name, MCIWNDF_SHOWALL|MCIWNDF_NOTIFYALL);
// 2008/09/15 Modified to use SOL::FileDialog to open WMV files.

// 2008/09/16 Modified to be able to select *.wmv and *.wma in FileDialog
//        ar.set(XmNfilter, "Windows Media(*.wmv *.wma)\0 *.wmv;*.wma\0");
// 2008/09/16 Modified to use restoreFileFolder/saveFileFolder in open method.

#include <sol\ApplicationView.h>
#include <sol\DesktopWindow.h>
#include <sol\Profile.h>
#include <sol\Stdio.h>
#include <sol\MediaControlView.h>
#include <sol\FileDialog.h>
#include "resource.h"

namespace SOL {

class MediaControl :public ApplicationView {
private:
    MediaControlView controller;

    FileDialog fileDialog;

public:
    /**
     * Constructor
     */
    MediaControl(Application& applet, const TCHAR* name, Args& args)
        :ApplicationView(applet, name, args)
    {
        Args ar;

        ar.reset();
        ar.set(XmNstyle, WS_BORDER|MCIWNDF_SHOWALL |
                                    MCIWNDF_NOTIFYSIZE|
                                    MCIWNDF_NOTIFYPOS);
        controller.create(this, NULL, ar);

        ar.reset();
        ar.set(XmNfilter, _T("Windows Media(*.wmv *.wma)\0 *.wmv;*.wma\0"));
        fileDialog.create(this, _T("FileSelection"), ar);

        addCallback(XmNmenuCallback, IDM_OPEN, this,
            (Callback)&MediaControl::open, NULL);

        addCallback(XmNmenuCallback, IDM_EXIT, this,
            (Callback)&MediaControl::exit, NULL);

        addCallback(XmNmenuCallback, IDM_VERSION, this,
            (Callback)&MediaControl::version, NULL);

        addEventHandler(WM_CLOSE, this, 
            (Handler)&MediaControl::close, NULL);

        addEventHandler(WM_WINDOWPOSCHANGED , this, 
            (Handler)&MediaControl::posChanged, NULL);

        addEventHandler(MCIWNDM_NOTIFYPOS,this,
            (Handler)&MediaControl::mciNotify, NULL);

        addEventHandler(MCIWNDM_NOTIFYSIZE,this,
            (Handler)&MediaControl::mciNotify, NULL);

        restorePlacement();
    }

private:
    void version(Action& action)
    {
        showMessageDialog(_T("Version"),
            _T("MediaControl Version 1.0.0.2\r\nCopyright(C) 2008-2009 Antillia.com"),
            MB_OK|MB_ICONINFORMATION);
    }

private:

    long mciNotify(Event& ev)
    {
        RECT r;
        controller.getWindowRect(&r);
         
        HWND hwnd = getWindow();
        AdjustWindowRectEx(&r, GetWindowLong(hwnd, GWL_STYLE),
                       TRUE, GetWindowLong(hwnd, GWL_EXSTYLE));
        move(r.left, r.top, 
            r.right - r.left, r.bottom - r.top, TRUE);
    
        controller.update();
        return 0L;
    }

private:

    long posChanged(Event& ev)
    {
        RECT r;
        getClientRect(&r);
        int w = r.right- r.left;
        int h = r.bottom - r.top;
        controller.move(0, 0, w, h);
        controller.invalidate((RECT*)NULL);
        update();
        controller.update();
        
        return 0L;
    }


private:
    /**
     * Callback for [Open] menu.
     */
    void    open(Action& action) {
        Args ar;
        
        TCHAR dir[MAX_PATH];
        memset(dir, (TCHAR)0, SizeOf(dir));

        //Restore previously select folder from a registry(profile of 
        //this application) for fileDialog
        if (restoreFileFolder(dir, SizeOf(dir))) {
            ar.set(XmNdirectory, dir);
            fileDialog.setValues(ar);
        }
    
        if(fileDialog.open()){
            TCHAR title[MAX_PATH];
            TCHAR* filename = fileDialog.getFileName();
            TCHAR* ftitle = fileDialog.getFileTitle();
        
            saveFileFolder(filename);

            controller.open(filename, 0);
           
            controller.play();

            _stprintf_s(title, SizeOf(title), _T("%s - MediaViewer"), filename);

            setText(title);
        }
    }

private:
    long close(Event& event)
    {
        savePlacement();
        return defaultProc(event);
    }

};

}

//////////////////////////////////
// MediaControl Main
void    Main(int argc, TCHAR** argv)
{
    const String appClass = "MediaControl";
    try {
        Application applet(appClass, argc, argv);
        
        Args args;

        MediaControl controller(applet, appClass, args);
        controller.realize();
        applet.run();

    } catch (...) {

    }
}


Last modified: 11 Nov 2009

Copyright (c) 2009 Antillia.com ALL RIGHTS RESERVED.