顯示具有 Programming 標籤的文章。 顯示所有文章
顯示具有 Programming 標籤的文章。 顯示所有文章

2011年6月24日 星期五

MAC OS X上的 Beyond compare-like 應用程式




在MAC 寫程式 或是要比對文件所需的compare tool

找了很久 找到了一套免費的

DiffMerge
http://www.sourcegear.com/diffmerge/index.html

可以取代Win/Linux 上的 Beyond compare...(<--為啥你不出MAC版的)

推薦給您

2009年7月1日 星期三

GNU tools 以及 C/C++教學網頁

前幾天發現底下這些好用的link 紀錄在我的blog上 以免哪天瀏覽器當掉 都不見了

(1) 黃郁熙,用Open Source工具開發軟體 http://www.study-area.org/cyril/opentools/opentools/book1.html

(2) NTHU的c語言教學 http://larc.ee.nthu.edu.tw/~jrhuang/2310/index.htm

(3) 語言技術:C Gossip http://caterpillar.onlyfun.net/Gossip/CGossip/CGossip.html

(4) 語言技術:C++ Gossip http://caterpillar.onlyfun.net/Gossip/CppGossip/CppGossip.html

2009年5月18日 星期一

XOR 這個神奇的東西

XOR 這個運算是一種互斥運算, 簡單來講 兩個bit一樣輸出為1, 不一樣則為0

真值表:

X--A--B
1--0--0
0--1--0
0--0--1
1--1--1

兩個數你把他排成binary, ex: A=0010, B=0100, 則X=A XOR B=A^B
X = 1001 很好玩吧

剛剛逛網頁時候 發現這篇 利用XOR來作變數交換的例子 (來源網頁 http://codingnote.blogspot.com/2008/04/xor.html)

當我們要implement SWAP function
只要先把 B=A^B --> A=A^B --> B=A^B

For example (in C language)

void Swap(int *a, int *b)
{
*b = *b^*a;
*a = *a^*b;
*b = *b^*a;
}

以後加到我的utils裡頭

2008年12月17日 星期三

[BCB] 資料庫備份/還原程式

最近這套應用程式 加上其資料庫備份及還原的功能

備份還蠻容易做的, 直接將目前的 mdb檔案 複製到某個目錄下即可, 這部分我做成當使用者把form關掉的時候 自動備份

還原我遇到了一些問題, ADOConnection 這個元件, 我執行了 Close()這個函式之後, 資料庫依然被lock住, 最後搞了一個很賤的方法, 寫了另外一隻批次檔 當使用者選好他要還原的資料庫檔案
我會呼叫 這隻批次檔, 批次檔的內容是:
1. 將原本的應用程式關掉(這樣子就沒有資料庫被lock的問題)
2. 自動備份目前的資料庫到某個備份目錄下
3. 將使用者選的資料庫檔案替換掉目前使用的資料庫檔案
4. 重開應用程式

這裡遇到一個問題 怎麼關掉原本呼叫批次檔的這隻應用程式呢?
我找到一個shell指令, tasklist 以及 taskkill
tasklist 是顯示目前電腦中正在執行的程式
taskkill 則是讓他關掉, taskkill /f /im "應用程式名稱"

這樣子就完成了~這其實是無奈的解法(因為資料庫檔案一直被Lock住)

2008年12月15日 星期一

[BCB] 取得目前執行檔所在路徑

在BCB中取得目前執行檔所在路徑很簡單
只要一行 ExtractFilePath(Application->ExeName);

如果要在之後加一個資料夾 只要

AnsiString szExecPath;
AnsiString szBackupFolderPath;

szBackupFolderPath= szExecPath + "BackUpFolder\\";
CreaterDir(szBackupFolderPath.c_str());
這樣子就會在執行檔目錄下建立一個 "BackUpFolder" 的目錄囉

[BCB][WIN32] 檔案處理

這次終於把朋友請我客製化的軟體修改好

其中搞定了連接來電顯示裝置並得到來電號碼且跳至訂購單建立的功能以及自動建立一筆未存在資料庫的新客戶資料, 自動備份功能

而關於自動備份功能 就是當程式開啟以及關閉的時候, 將資料庫檔案拷貝到另外的資料夾而已

以下紀錄一下 我用的Win32API
資料夾建立API: CreateDir(填目錄名稱, ex: "\BKDB");
檔案拷貝API: CopyFile("來源檔名", "目的檔名", (FALSE: 強制覆蓋同檔名檔案, TRUE則否));

還有 在BCB去得到windows msg方法

1. 先於 header file 加入要聽取的號碼
#define WM_USBLINEMSG (WM_USER + 180)

2. 在 class definition的地方加入
void __fastcall RecvDeviceMsg(TMessage& Message);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_USBLINEMSG, TMessage, RecvDeviceMsg)
END_MESSAGE_MAP(TForm)
3. 將code implement到 cpp檔裡頭
void __fastcall TfmMain::RecvDeviceMsg(TMessage& Message)
{
int nMsg = LOWORD(Message.WParam);
int dwChannel = HIWORD(Message.WParam);
int intSearchRes=0;

pcMain->ActivePage = tsAddRecord;

switch(nMsg)
{
....
}
TForm::Dispatch(&Message);
}

這樣子就完成啦~

至於載入dll的方式 跟在vc上一樣 都是用 Win32 API, 就 LoadLibrary and FreeLibrary
在此紀錄一下

2008年10月27日 星期一

WIN32 API 高階的Copy檔案以及 Delete檔案

這兩個API蠻適合拿來做軟體的備份還有回復的功能
就把資料庫檔案或是設定檔 用COPY的方式備份到另外的地方或改檔名

Delete

BOOL DeleteFile(LPCTSTR lpFileName);

Example:
DeleteFile("c:\\Test.txt");

Copy
BOOL CopyFile(
LPCTSTR lpExistingFileName, // pointer to name of an existing file
LPCTSTR lpNewFileName, // pointer to filename to copy to
BOOL bFailIfExists // flag for operation if file exists
);

Example:
CopyFile("c:\\Test.txt", "d:\\Test.txt", false);

2008年9月10日 星期三

用Win32 API 得到 電腦名稱和登入使用者名稱

今天老闆請我找這個API

直覺就是在MSDN上鍵入 GetComputerName, 結果 竟然有這個API (會不會運氣太好了)
就研究一下 (MSDN 介紹在此)

這個 API 剛好就是我要的

Syntax

BOOL WINAPI GetComputerName(
__out LPTSTR lpBuffer,
__inout LPDWORD lpnSize
);

Parameters

lpBuffer [out]

A pointer to a buffer that receives the computer name or the cluster virtual server name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1 characters.

lpnSize [in, out]

On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs copied to the destination buffer, not including the terminating null character.

If the buffer is too small, the function fails and GetLastError returns ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer required, not including the terminating null character.

Return Value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

就這樣 滿足了老闆的要求

2008年9月9日 星期二

用WIN32 API 得到檔案最後修改時間

之前照著MSDN範例所寫的讀取檔案最後修改時間的function
被老闆發現時間怎麼會差四小時 後來仔細去看新版的MSDN 竟然多了一行

SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

要先把UTC的時間轉換成本地的Local Time

我把function 內容貼在下方

SYSTEMTIME stUTC, stLocal;
FILETIME tmModifyTime;

GetFileTime(hFile, NULL, NULL, &tmModifyTime);
FileTimeToSystemTime(&tmModifyTime, &stUTC);

SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

之後拿 stLocal 這個變數來用即可

紀錄一下 以免之後忘掉