2015年12月9日 星期三

Create Customer DependencyProperty in WPF

使用Dependency property流程:
1. 建立Dependency object, 熱鍵(propdp), 最後一個參數可選擇要對應的屬性,

也可以選擇用function pointer
 這樣在呼叫的地方就可以使用此屬性


Reference: http://www.codeproject.com/Articles/135913/WPF-Dependency-Property-Compatible-with-XAML-Bindi


Create thread for functions which are class members


You need to create a static method to use as the actual thread start function, and pass a pointer to the instance as the lpParameter argument to CreateThread. That will get passed to the static method, which can cast it to an object pointer and call through to the member function.



class MyClass
{
    static DWORD WINAPI StaticThreadStart(void* Param)
    {
        MyClass* This = (MyClass*) Param;
        return This->ThreadStart();
    }

    DWORD ThreadStart(void)
    {
        // Do stuff
    }

    void startMyThread()
    {
       DWORD ThreadID;
       CreateThread(NULL, 0, StaticThreadStart, (void*) this, 0, &ThreadID);
    }
};
reference: 
http://stackoverflow.com/questions/1372967/how-do-you-use-createthread-for-functions-which-are-class-members