GitHub網址:
https://github.com/kwedr/kchartgame
使用 Python3.8, Pyside2, Pandas
實現功能:閃電下單介面
觸價功能
支持歷史回測 (讀取台灣期交所RPT檔案)
隨機開檔功能
DDE即時模擬盤
歷史盤行情加速
歷史盤回到指定時間
下單標點位
輸出點位圖檔
我寫程式,所以我存在
GitHub網址:
https://github.com/kwedr/kchartgame
使用 Python3.8, Pyside2, Pandas
實現功能:svn co svn://gcc.gnu.org/svn/gcc/tags/gcc_5_3_0_releasestd::__cxx11::string 或是 std::__cxx11::list 的錯誤<Resource type="ResourceDynOLTrueTypeFont" name="OLMSJHFont.17">(2)在MyGUI_FontManager.cpp註冊ResourceDynOLTrueTypeFont
<Property key="Source" value="msjh.ttf"/>
<Property key="Size" value="36"/>
<Property key="Antialias" value="false"/>
<Property key="SpaceWidth" value="4"/>
<Property key="TabWidth" value="8"/>
<Property key="CursorWidth" value="2"/>
<Property key="Distance" value="6"/>
<Property key="OffsetHeight" value="0"/>
<Property key="OutlineColor" value="#000000"/> <!-- 外框文字 -->
<Property key="FontColor" value="#FFFFFF"/> <!-- 文字顏色 –->
<Property key="OutlineWidth" value="2"/> <!-- 描邊的寬度 -->
</Resource>
最近更新了顯示程式方式,也好久沒有更新了。
這是我在KWallPaper 中使用的目錄監控Class。
由於在寫這程式時,曾參考上網路上的許多範例,因此在此分享與回饋~
在取得檔案變動時,我是將其變動放入一個queue中,如果直接寫入資料庫,延遲的時間,會造成後面的檔案沒有監控到。
此程式碼還有許多不足之處,歡迎批評指教,謝謝
#include "StdAfx.h"
#include ".\directorymonitor.h"
#include "ImgManager.h"
unsigned __stdcall DirectoryMonitorThreadCallback(LPVOID lpParm)
{
CDirectoryMonitor* pObj = (CDirectoryMonitor*) lpParm;
if( !pObj )
{
_endthreadex( 0 );
return 0;
}
pObj->RunThread();
_endthreadex( 0 );
return 0;
}
CDirectoryMonitor::CDirectoryMonitor( CImgManager* pOwnter ):
m_pOwner(pOwnter),
m_hCompletionPort(NULL),
m_ulCompletionKey(0),
m_hDir(NULL),
m_pBuffer(NULL),
m_nBufferSize(0)
{
memset( &m_Overlapped, 0, sizeof(m_Overlapped) );
}
CDirectoryMonitor::~CDirectoryMonitor(void)
{
if( m_hCompletionPort )
{
//The thread will catch this and exit the thread
PostQueuedCompletionStatus(m_hCompletionPort, 0, 0, NULL);
Sleep(1000);
for( unsigned int i = 0; i < m_nThreadCount; ++i )
{
HANDLE nThread = m_vecThread[i];
//wait for it to exit
WaitForSingleObject(nThread, INFINITE);
SAFE_CLOSEHANDLE(nThread);
}
m_hCompletionPort = NULL;
m_vecThread.clear();
}
SAFE_CLOSEHANDLE(m_hDir);
SAFE_DELETE_ARRAY(m_pBuffer);
m_nBufferSize = 0;
}
bool CDirectoryMonitor::Initialize( const TCHAR* szPath )
{
m_strMoniDir = szPath;
m_hDir = CreateFile( m_strMoniDir.c_str(), // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ|FILE_SHARE_DELETE|FILE_SHARE_WRITE, // share mode
NULL, // security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED, // file attributes
NULL // file with attributes to copy
);
if ( INVALID_HANDLE_VALUE == m_hDir )
return false;
SYSTEM_INFO SystemInfo;
GetSystemInfo(&SystemInfo);
m_nThreadCount = 1; //SystemInfo.dwNumberOfProcessors;
m_hCompletionPort = CreateIoCompletionPort(
m_hDir, // Handle to a file opened for overlapped I/O completion.
NULL, // existed Handle to the I/O completion port.
(ULONG_PTR)&m_ulCompletionKey, // CompletionKey
m_nThreadCount // NumberOfConcurrentThreads
);
if( NULL == m_hCompletionPort )
return false;
m_nBufferSize = 4096;//2*(sizeof(FILE_NOTIFY_INFORMATION)+MAX_PATH);
m_pBuffer = new char[m_nBufferSize];
if( !_callReadDirectoryChanges() )
return false;
for( unsigned int i = 0; i < m_nThreadCount; ++i)
{
HANDLE nThread = (HANDLE)_beginthreadex( NULL, 0, &::DirectoryMonitorThreadCallback, (LPVOID)this, 0, NULL );
if( NULL != nThread )
{
m_vecThread.push_back( nThread );
}
}
KLOG( LOG_DEBUG, _T("DirectoryMonitor : %s"), m_strMoniDir.c_str() );
return true;
}
void CDirectoryMonitor::RunThread()
{
BOOL bSucceed = FALSE;
DWORD dwBytesReturned = 0;
TCHAR szFileName[MAX_PATH] = {0};
TCHAR szNotiryFileName[MAX_PATH] = {0};
DWORD dwAction = 0;
while(TRUE)
{
::Sleep(1);
LPOVERLAPPED lpOverlapped = &m_Overlapped;
bSucceed = GetQueuedCompletionStatus( m_hCompletionPort, // [in]Handle to the completion port of interest.
&dwBytesReturned, // lpNumberOfBytes
&m_ulCompletionKey, // lpCompletionKey
&lpOverlapped, // lpOverlapped
INFINITE // dwMilliseconds
);
if( NULL == lpOverlapped )
break;
if(!bSucceed || 0 == m_ulCompletionKey )
continue;
FILE_NOTIFY_INFORMATION * pNotify = (FILE_NOTIFY_INFORMATION*)m_pBuffer;
DWORD dwNextEntryOffset = 0;
do
{
pNotify = (FILE_NOTIFY_INFORMATION*)&m_pBuffer[dwNextEntryOffset];
dwNextEntryOffset += pNotify->NextEntryOffset;
dwAction = pNotify->Action;
memset( szNotiryFileName, 0, sizeof(szNotiryFileName));
_tcsncpy( szNotiryFileName, pNotify->FileName, pNotify->FileNameLength);
szNotiryFileName[pNotify->FileNameLength / sizeof(TCHAR) ] = '\0';
_stprintf( szFileName, _T("%s\\%s"), m_strMoniDir.c_str(), szNotiryFileName );
if( m_pOwner )
m_pOwner->NotifyFileChange( dwAction, szFileName );
}while ( 0 != pNotify->NextEntryOffset );
_callReadDirectoryChanges();
}
}
bool CDirectoryMonitor::Release()
{
return true;
}
bool CDirectoryMonitor::_callReadDirectoryChanges()
{
if( m_pBuffer )
{
memset( m_pBuffer, 0, m_nBufferSize );
}
BOOL BRet = ReadDirectoryChangesW( m_hDir, // hDirectory. Handle to the directory to be monitored
m_pBuffer, // [in, out] Pointer to the formatted buffer in which the read results are to be returned.
m_nBufferSize, // [in] Length of the buffer pointed to by the lpBuffer parameter, in bytes.
true, // bWatchSubtree
FILE_NOTIFY_CHANGE_FILE_NAME| // [in] Filter criteria the function checks to determine if the wait operation has completed.
FILE_NOTIFY_CHANGE_DIR_NAME|
FILE_NOTIFY_CHANGE_CREATION,
NULL, // lpBytesReturned. For asynchronous calls, this parameter is undefined.
&m_Overlapped, // [in] Pointer to an OVERLAPPED structure that supplies data to be used during asynchronous operation.
NULL ); // lpCompletionRoutine
return BRet == TRUE ? true : false;
}
以上,歡迎參考~
最近在寫自已的程式,聽說 STLport 不錯用,就拿來編譯了一下,沒想到沒有支持vs2008,
於是就參考網路上的文章,如何順利編譯成功,
(1) 首先執行 C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat
我在執行這個bat的時候,還是不能編譯,於是發揮我努力的精神發現,是執行C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat,於是我就COPY到 \STLport-5.1.5\build\lib\ 目錄下,再執行
(2)然後在 \STLport-5.1.5\build\lib\ 進入 cmd 視窗,輸入 configure -c msvc8
(3)如果要編譯成lib 輸入 nmake /fmsvc.mak install
(4)以上如果沒有意外的話 應該會順便成功編譯,不過當然沒有這麼順利,編譯後會出現一堆 dll 的錯誤
此時,就要到 \STLport-5.1.5\stlport\st\config\user_config.h增加一行
#define _STLP_STATIC_CONST_INIT_BUG 1
(5)最後再重複上面的指令,應該就可以編譯成功了
以上,感謝 估狗大神,和網路上分享大大的經驗
參考以下網站:
http://kimiya25.spaces.live.com/blog/cns!27A083D4FD9435E9!920.entry
http://blog.narahome.com/archive/200806
最近把之前工作的 DirectX 程式拿來重做了一下,把一些元件分離,設定一下 CallBack Function ,讓每個程式可以設定不同的Device設定,不需要每當做新的程式時,就更改原本的設定。
另外加入了 OIS 這個OpenSource,可以控管 鍵盤/滑鼠/搖桿 ,OGRE 也有使用,編譯也很簡單。使用上看範例也很容易。
另外還想加入 OPENAL (聲音的OpenSource) 、CEGUI(介面的OpenSource)。
不過OPENAL 好像沒有mp3的支援(不太確定,
CEGUI編譯不太容易,雖然比起OGRE簡單多了,可是目前OGRE還沒有建起來過。
原本的程式已經可以繪製2D了 ,只是鏡頭跟世界沒辦法旋轉,所以製作了這個 Sample 01 ,有看過DirectX9的Tutorials的一定很面熟,我就是拿了Matrices的程式來套用。
另外,右邊的東西是什麼呢?其實就是 Console Log, 也就是記載 log 訊息的視窗,與主視窗 共生。可以及時顯示訊息,蠻方便的使用。
繼續來研究 DirectX9 的 Tutorials ,建製自已的3d引擎 ^_^
在面試的時候,遇見一個主管 問說 會不會 "Design Pattern" ,當場就被問倒了!!
那主管說,如果要繼續走程式的路,可能就要學習 "Design Pattern"。
因此相關的資料都會在此留存 讓以後參考用!!
http://www.codeguru.com/forum/showthread.php?t=327982
http://www.javaworld.com.tw/confluence/display/designpattern/Home
就是會在同一個目錄內檔案增加幾行的文字,程式碼如下:
' 日期:20080308
' 作者:Kwedr
' 作用:在檔案後增加資料'
' 開啟瀏覽資料夾畫面,選擇資料夾
dim oShell
dim oFolder
dim oFolderItem
set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0, "選擇你要更改檔名的資料夾", 0)
set oFolderItem = oFolder.Items.Item
dim fileItem
dim name
Const ForAppend = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each fileItem in oFolder.Items
name = oFolderItem.Path & "\" & fileItem.name
Set opFile = objFSO.OpenTextFile( name , ForAppend)
opFile.WriteLine("")
opFile.Close
Next
Wscript.echo "完成"
最近都在用PDA看小說,可是下載下來的檔案都很大,如果一次開啟,就會造成一整個LAG。
然後就在網路上找切割程式,但是好像沒有找到文字檔的切割,就隨便找一個切割軟體來使用。
但是,如果檔名為"xxx.txt",切割後就會變成"xxx.txt.001",於是我就寫了一個程式,把後面的001 跟 txt 互換的程式。
原始碼如下:
' 日期:20080308
' 作者:Kwedr
' 作用:更改檔名
'
'開啟瀏覽資料夾畫面,選擇資料夾
dim oShell
dim oFolder
dim oFolderItem
set oShell = CreateObject("Shell.Application")
set oFolder = oShell.BrowseForFolder(0, "選擇你要更改檔名的資料夾", 0)
set oFolderItem = oFolder.Items.Item
dim fileItem
dim tmp,pos,name,ext,no,strlen
dim oldname,newname
Set objFSO = CreateObject("Scripting.FileSystemObject")
For each fileItem in oFolder.Items
strlen=Len(fileItem.name)
oldname = oFolderItem.Path & "\" & fileItem.name
'Wscript.echo "oldname:"&oldname
if pos <= 0 then
Wscript.echo "oldname:"&oldname
end if
pos = InStr(fileItem.name,".")
name = Left(fileItem.name,pos-1)
'Wscript.echo "name:"&name
tmp = Right(fileItem.name,strlen-pos)
pos = InStr(tmp,".")
'Wscript.echo "tmp:"&tmp
strlen=Len(tmp)
ext = Left(tmp,pos-1)
'Wscript.echo "ext:"&ext
tmp = Right(tmp,strlen-pos)
no = String(3-Len(tmp),"0")+tmp
'Wscript.echo "no:"&no
newname = oFolderItem.Path & "\" & name&"_"+no&"."&ext
'Wscript.echo "newname:"&newname
objFSO.MoveFile oldname, newname
Next
Wscript.echo "完成"
最近在寫WAnts 的更新,使用 ie 透過 ActiveX,用wxWidgets 實在是不方便,有許多的錯誤,例如在IE7下抓取iFrame不知道為什麼一直錯誤,所以就想來裝裝看另一款有名的「WTL」。
在WTL安裝之前,請先安裝 PlamtForm SDK。我安裝的版本是「Microsoft Platform SDK for Windows Server 2003 SP1」
#pragma pack(pop)
/*
PVOID __stdcall __AllocStdCallThunk(VOID);
VOID __stdcall __FreeStdCallThunk(PVOID);#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)#pragma comment(lib, "atlthunk.lib")
*/
#define AllocStdCallThunk() HeapAlloc(GetProcessHeap(),0,sizeof(_stdcallthunk))
#define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)#elif defined (_M_AMD64)
#pragma pack(push,2)以上,也可以增加專案中的stdafx.h 修改如下:(由TabBrowser中 支援 2005 Express 參考)
//#ifdef _VC80X
// Support for VS2005 Express & SDK ATL
#define _CRT_SECURE_NO_DEPRECATE
#pragma conform(forScope, off)
#pragma comment(linker, "/NODEFAULTLIB:atlthunk.lib")
#pragma warning(disable: 4565) // redefinition; the symbol was previously declared with __declspec(noalias)
#pragma warning(disable: 4068) // unknown pragma
//#endif // _VC80X#include <atlbase.h>
//#ifdef _VC80X
// Support for VS2005 Express & SDK ATL
namespace ATL
{
inline void * __stdcall __AllocStdCallThunk()
{
return ::HeapAlloc(::GetProcessHeap(), 0, sizeof(_stdcallthunk));
}inline void __stdcall __FreeStdCallThunk(void *p)
{
::HeapFree(::GetProcessHeap(), 0, p);
}
};
//#endif // _VC80X
for(int i = 0; i < m_aChainEntry.GetSize(); i++)
[!if WTL_COM_SERVER]
1 TYPELIB "[!output PROJECT_NAME].tlb"
[!endif]
[!if WTL_USE_MANIFEST]
//CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "res\\[!output PROJECT_NAME].exe.manifest"
[!endif]
CVTRES : fatal error CVT1100: duplicate resource. type:MANIFEST, name:1, language:0x0409
LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt.
就尋找專案中的 ".rc" 檔案,並注解掉
//CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST
以上,就是編譯WTL Sample 中遇到的問題,解決的方式。
由於"我的最愛"在公司跟家裡的電腦一直想要合併成一個,於是前一陣子買了一個隨身碟,來當作個人資料的儲存與備份。
如果要讓AutoRun隨插即啟動,首先就要灌APO Usb Autorun,這軟體網路上的文章不少,有需要請自行尋找估狗大神。不過之前隨身碟病毒不少,要小心服用。
然後在隨身碟根目錄建一個Autorun.inf內容如下,如果有喜歡的小icon也可以在這裡設定:
[autorun]
shellexecute=autorun.vbs
然後再建立一個autorun.vbs的檔案,如下:
Dim PIM
Set PIM = CreateObject("WScript.Shell")
PIM.Run "Tools\Essentialpimport2\EssentialPIM.exe" ,7
Dim BackUp
Set BackUp = CreateObject("WScript.Shell")
BackUp.Run "Tools\FileBackupPro\FileBackup.exe" ,7
WScript.Quit
本來是用BAT檔,不過一執行就會跳出Dos視窗,而我也找不到如何不顯現。VBS我也不熟,從網路上參考而來的,非常簡單,Run "路徑檔案",7代表的是一執行就最小化。
我的隨身碟中,一開始就啟用的有個人行事曆(EssentialPIM)和備份系統(FileBackup),之前曾經發生插入電腦之後就發生資料不見,所以就一插入電腦就讓他自動備份。
PSD的讀取參考了幾個地方 發現 有讀取 8BIM 跟 8BPS 的 不太一樣
8BIM是讀取資源內容
8BPS是檔頭判斷
以下是程式碼,請參考
bool GetPsdWidthHeight(const wxChar* buf,int size,int&Width,int& Height,bool& ReadWidthHeight)
{
char Head[5];
memcpy(&Head,&buf[0],sizeof(wxChar)*4);
if(strncmp( Head, "8BPS", 4 ))
{
ReadWidthHeight=true;
return false;
}
int check=(BYTE)buf[4]<<8 | (BYTE)buf[5];
if (check != 1)
{
ReadWidthHeight=true;
return false;
}
//Read32; 6 7 8 9
//Read16; 10 11
unsigned channel_count = (BYTE)buf[12]<<8 | (BYTE)buf[13];
if( channel_count >= 0 && channel_count <= 16)
{
Height = (BYTE)buf[14]<<24 | (BYTE)buf[15]<<16 | (BYTE)buf[16]<<8 | (BYTE)buf[17];
Width = (BYTE)buf[18]<<24 | (BYTE)buf[19]<<16 | (BYTE)buf[20]<<8 | (BYTE)buf[21];
ReadWidthHeight=true;
return true;
}
return false;
}
以上 , 不負責讀取所有格式,另有問題概不負責.
歡迎轉載並請標明出處.謝謝
標籤: 程式, Visual C++ 2005, WxWidgets
BMP的讀取32Bit 的值 找了許久..
以下是程式碼,請參考
bool GetBmpWidthHeight(const wxChar* buf,int size,int&Width,int& Height,bool& ReadWidthHeight)
{
if(size < 26)
{
ReadWidthHeight = false;
return false;
}
width =(BYTE)buf[21] << 24;
height =(BYTE)buf[25] << 16;
readwidthheight=true;
}
以上 , 不負責讀取所有格式,另有問題概不負責.
歡迎轉載並請標明出處.謝謝
參考:
http://www.google.com/codesearch?hl=en&q=+lang:c%2B%2B+read+bmp+width+-img+show:MSwKpY23o4k:RjXxUM8aNXA:UKPc_fAe5nA&sa=N&cd=2&ct=rc&cs_p=ftp://ftp.idsoftware.com/idstuff/source/GtkRadiant-GPL.zip&cs_f=GPL/GtkRadiant/plugins/image/bmp.cpp#a0
http://www.google.com/codesearch?hl=zh-TW&q=+lang:c%2B%2B+read+bmp+width+%3C%3C+-img+show:aqffVhSjOiA:HMWZi5kbbPk:khnt1EYmZBw&sa=N&cd=6&ct=rc&cs_p=http://gentoo.osuosl.org/distfiles/BillardGL-1.75.tar.gz&cs_f=BillardGL-1.75/src/bmp.cpp#a0
標籤: 程式, Visual C++ 2005, WxWidgets
沒想到GIF的長寬 這麼簡單取得,比較特別的是長寬的取得是前後交換
以下是程式碼,請參考
bool GetGifWidthHeight(const wxChar* buf,int size,int&Width,int& Height,bool& ReadWidthHeight)
{
if(size<10)
{
ReadWidthHeight=false;
return false;
}
char Head[7];
memcpy(&Head,&buf[0],sizeof(wxChar)*6);
ReadWidthHeight=false;
if(strncmp( Head, "GIF89a", 6 )==0)
{
ReadWidthHeight=true;
}
else if(strncmp( Head, "GIF87a", 6 )==0)
{
ReadWidthHeight=true;
}
else
{
ReadWidthHeight=true;
return false;
}
Width=(BYTE)buf[7]<<8 | (BYTE)buf[6];
Height=(BYTE)buf[9]<<8 | (BYTE)buf[8];
return true;
}
以上 , 不負責讀取所有格式,另有問題概不負責.
歡迎轉載並請標明出處.謝謝
標籤: 程式, Visual C++ 2005, wxDev-C++