游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1576|回复: 1

the Los Object Set C++ library(lowest version)

[复制链接]

20

主题

136

帖子

172

积分

注册会员

Rank: 2

积分
172
发表于 2008-4-4 14:40:00 | 显示全部楼层 |阅读模式
[Summary]
project: los-lib since: Jan. 15, 2008

The Los Object Set C++ library support a set of object-oriented classes for windows development.

The library is distributed under GNU LGPL LICENSE Ver.3.

The library has a advanced message-mapping, command-mapping, message reflect, multithreading model and so on.Its programme interface is quite clean and anyone can use it to develop advanced Windows applications immediately.

[Preview]
project: los-lib
since: Jan. 15, 2008
code.google.com/p/los-lib
mail: loserwang at gmail.com


*The version format is suspensive.

1)Handle hierarchy

Object
    => Handle
        => DeviceContext
        => GDIObject
        => [resources] Accel | Cursor | Icon | Menu | Res
        => [controls] Window | Dialog | Button | Static | Edit | ListBox | Timer
        => KernelObject
            => Thread
                => ThreadManager
                    => Application
            => SyncObject
                => Event
                => Mutex
                => Semaphore
                => WaitableTimer

2)Logic cell
# Los

los.h
basic.h
declare.h
extendsyntax.h
winversion.h

    # controls
    
    controls.h
    dialog.h
    edit.h
    listbox.h
    static.h
    timer.h
    window.h
    
    # resources
    
    resources.h
    accel.h
    cursor.h
    icon.h
    menu.h
    resclass.h
    resname.h
    
    # graphics
    
    graphics.h
    graphicstypes.h
    devicecontext.h
    gdiobject.h
    
    # utilities
    
    errortypes.h
    mathtools.h
    stringtypes.h
    
    # types
    
    basictypes.h
    propertytmpl.h
    
    # messages
    
    messages.h
    messageadaptors.h
    messageclasses.h
    messageidentifiers.h
    messageinvokes.h
    messagetypes.h
    
    # multithreading
    
    multithreading.h
    kernelobject.h
    thread.h
    threadmanager.h
    tlsobject.h
    
        # synchronization
        
        criticalsection.h
        event.h
        interlocked.h
        mutex.h
        semaphore.h
        syncobject.h
        waitabletimer.h
        
    # framework
    
    framework.h
    globalservices.h
    
    #systeminformation
    
    systeminformation.h
    datetime.h
    
#runtime
    
    # golbalservices.cpp
    # messageidentifiers.cpp
    # threadmanager.cpp
    # window.cpp

20

主题

136

帖子

172

积分

注册会员

Rank: 2

积分
172
 楼主| 发表于 2008-4-4 14:41:00 | 显示全部楼层

Re: the Los Object Set C++ library(lowest version)

[Threading sample]

/********************************************************************
    created:    2008/03/31
    created:    31:3:2008   13:34
    filename:     {SOLUTION_DIRECTORY}\WaitableTimer\WaitableTimer.cpp
    file path:    {SOLUTION_DIRECTORY}\WaitableTimer
    file base:    WaitableTimer
    file ext:    cpp
    author:        Loserwang

    purpose:    

    This is a part of the Los Object Set C++ library.
    The library is distributed under GNU LGPL LICENSE Ver.3.
    For further information, read the file "GNU LGPL V3.0.txt"
    in the solution's root directory.

    Add {Solution directory}\Los in %INCLUDE% evironment parameter,
    and {Solution directory}\Lib in %LIB%, runtime files are not necessary.
*********************************************************************/

#include <los.h>
#include "resource.h"

using namespace los::types;
using namespace los::stringtypes;
using namespace los::framework;
using namespace los::controls;
using namespace los::mathtools;
using namespace los::multithreading;
using namespace los::systeminformation;

class MyWaitableTimer : public WaitableTimer
{
public:
    InheritClass(MyWaitableTimer);

    virtual void OnAPC(void* param_ptr_, ulong low_, ulong high_)
    {
        stringstream ss;
        ss << t("TimerAPCRoutine, ThreadId = ") << GetCurrentThreadId() << std::endl;
        ss << t("pArg = ") << param_ptr_ << std::endl;
        ss << t("ulLowPart = ") << low_ << std::endl;
        ss << t("ulHighPart = ") << high_ << std::endl << std::endl;
        OutputDebugString(ss.str().c_str());
    }
};

class WaitThread : public Thread<Window>
{
public:
    InheritClass(WaitThread);

    virtual ulong Run(pointer pWnd)
    {
        exit.Exchange(false);
        while (!exit.Get())
        {
            wtmr.WaitForSingleObject();
            DateTime dt;

            if (!s_cs.Try())
                continue;
            pWnd->GetChildWindow(IDC_EDIT7)->text = dt.ToString();
            s_cs.Leave();
        }
        return 0;
    }

    Interlocked exit;
    MyWaitableTimer wtmr;
    static CriticalSection s_cs;
};

CriticalSection WaitThread::s_cs;

class WTDialog : public Dialog
{
public:
    InheritClass(WTDialog);

    WTDialog()
        : Dialog(IDD_DIALOG1)
        , edt1(IDC_EDIT1)
        , edt2(IDC_EDIT2)
        , edt3(IDC_EDIT3)
        , edt4(IDC_EDIT4)
        , edt5(IDC_EDIT5)
        , edt6(IDC_EDIT6)
        , edt7(IDC_EDIT7)
        , btnTrans(IDC_BUTTON1)
        , btnOk(IDOK)
    {}

    virtual bool RealTime()
    {
        SleepEx(0, TRUE);
        return true;
    }

protected:
    virtual void MessageMap()
    {
        Base::MessageMap();
        Invoke(wm_initdialog, OnInitDialog);
        Invoke(btn1.clicked(), OnBtnTrans);
        Invoke(btnOk.clicked(), OnOk);
        Invoke(wm_close, OnClose);
    }

private:
    LRESULT OnInitDialog(Window& def_focus, void* data_ptr)
    {
        CenterWindow();

        los::controls::Color clr;

        InitControls(this, &edt1, &edt2, &edt3, &edt4, &edt5, &edt6, &edt6, &edt7, &btnTrans, &btnOk, 0);
        edt5.text = t("Y-M-D h:m:s");
        edt6.text = t("M/D/Y h:m:s");

        DateTime dt(DateTime::dtUTC);
        thrd.wtmr.CreateWaitableTimer(t("C951C46C-8527-48ee-A08E-B583E66375E8"));
        thrd.wtmr.SetWaitableTimerAPC(dt.ToInt64(), 1000, this);

        stringstream ss;
        ss << t("SetWaitableTimer, ThreadId = ") << GetCurrentThreadId() << std::endl;
        ss << t("pArg = ") << this << std::endl;
        ss << t("ulLowPart = ") << dt.ToLargeInteger().LowPart << std::endl;
        ss << t("ulHighPart = ") << dt.ToLargeInteger().HighPart << std::endl << std::endl;
        OutputDebugString(ss.str().c_str());

        thrd.CreateThread(this);

        return Base:roc();
    }

    LRESULT OnBtnTrans()
    {
        if (edt1.text == t(""))
        {
            MessageBox(t(&quotlease input date/time string"));
            return 0;
        }
    
        DateTime dt(edt1.text, DateTime::dtLocal, edt5.text);
        edt2.text = dt.ToString(edt6.text);

        stringstream ss;
        ss << dt.ToInt64();
        edt3.text = ss.str();
        ss.str(t(""));

        dt.ConvertToUTC();

        edt4.text = dt.ToString(edt6.text);

        return 0;
    }

    LRESULT OnOk()
    {
        Close(idOk);
        return 0;
    }

    LRESULT OnClose()
    {
        thrd.exit.Exchange(true);
        thrd.s_cs.Enter();
        while (thrd.WaitForSingleObject(0) == thrd.waitTimeOut)
            SwitchToThread();
        thrd.s_cs.Leave();
        return Base::Proc();
    }

private:
    Edit edt1, edt2, edt3, edt4, edt5, edt6, edt7;
    Button btnTrans, btnOk;
    WaitThread thrd;
};

INT WINAPI _tWinMain(HINSTANCE, HINSTANCE, LPTSTR, INT)
{
    WTDialog* pDlg = new WTDialog;
    pDlg->Create(0);
    pDlg->ShowWindow();
    pDlg->UpdateWindow();
    app->Initialize(pDlg);
    return app->Run(0);
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 15:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表