想讀書?
最近這個念頭一直在興起...
看著新進的同仁, 每個都頂著國立大學的碩士學歷,
看著104裡面每個股價高過100元的公司, 要的都是碩士...
以前想說沒錢不要唸那麼高, 唸到大學應該就足夠了,
但是現在的情況不同了...
大學生掩腳目...
不, 碩士生掩腳目...
這樣的形容真貼切...:P
雖然自己告訴自己, 學歷比不過經歷,
但人家會說老經驗的比較會拿翹??? 是這樣的嗎?
總歸是拼不過學歷高的...
看來進修一途是注定的,
不然, 等到失去了競爭力才後悔的時候,
就來不及了~~~
努力吧~~~2008 唸書去...
離現在還有點早吧?
不, 不早了, 現在就要開始準備了,
不然等到到時候再準備, 可又是...
年復一年又一年呀~~~
:P
Andrew 隨筆
2007年1月5日 星期五
Nice MFC control - CEditCtrl
Today I want to share all of you one basic control of MFC which is inherit from CEdit ctrl,
this control can help you to take care of data type verification, for example, once you define the data type to be "int" (the naming inside control is "EN_DATATYPE_INTEGER"), no matter you have input any character in, it will just recognize the allowed char by data type, the others will be reject, if over range, it's will warning you automatically.
Is it useful?
let's take a look about this control. :)
Definition:
enum enDataType {
EN_DATATYPE_ALPHABET = 0, // Standard C++ naming rule
EN_DATATYPE_INTEGER = 1, // int
EN_DATATYPE_UNSIGNED_INTEGER = 2, // unsigned int
EN_DATATYPE_DOUBLE = 3, // double
EN_DATATYPE_UNSIGNED_DOUBLE = 4, // unsigned double
EN_DATATYPE_NONE = 5 // original CEdit behavior
};
From now, You just need to call SetEditDataType(EN_DATATYPE_INTEGER), then the data type of CEditCtrl will become "int" and no longer support the other data types anymore.
Till now, I believe as smart as you should understand why I can said this control can support many data types.
One place you have to read it more detail is OnChar(),
This function block is defined and qualified the input rule of CEditCtrl class, so you should be read it very carefully to understand the know how of it.
How to use it?
Here I support 2 way for you,
1. Using DDX_Control to manage it
2. Use SubclassDlgItem()
below is the source code:
EditCtrl.h
=======================================================
#pragma once
// CEditCtrl
namespace nsAuxLib {
class CEditCtrl : public CEdit
{
DECLARE_DYNAMIC(CEditCtrl)
// This is define how many data types can be judge by this control
enum enDataType {
EN_DATATYPE_ALPHABET = 0,
EN_DATATYPE_INTEGER = 1,
EN_DATATYPE_UNSIGNED_INTEGER = 2,
EN_DATATYPE_DOUBLE = 3,
EN_DATATYPE_UNSIGNED_DOUBLE = 4,
EN_DATATYPE_NONE = 5
};
public:
// Constructor and Destructor
CEditCtrl();
virtual ~CEditCtrl();
private:
enDataType edatatype_;
CString maxvalue_;
CString minvalue_;
CString defaultvalue_;
public:
// Define the current data type for the current object
inline void SetEditDataType(enDataType eType)
{ edatatype_ = eType; }
// Define the initial values of default value,
// minimun value and maximun value
inline void SetMinMaxValue(CString strDefault,
CString strMin,
CString strMax)
{
defaultvalue_ = strDefault;
maxvalue_ = strMax;
minvalue_ = strMin;
}
// Check Range function can return the result status back
bool CheckRange(CString strMin, CString strMax);
bool CheckRange();
double GetValDouble(bool bool_unsighed = true);
int GetValInt(bool bool_unsighed = true);
void SetValDouble(double dblvalue, bool bool_unsighed = true);
void SetValInt(int intvalue, bool bool_unsighed = true);
CString GetValText();
enDataType GetEditDatatype()
{ return edatatype_; }
protected:
DECLARE_MESSAGE_MAP()
public:
// Event handlers table
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnEnChange();
afx_msg void OnEnKillfocus();
};
}
=======================================================
If you are interesting about this control, you can email to me,
I will send it to you a.s.a.p.
Cheers,
Andrew
this control can help you to take care of data type verification, for example, once you define the data type to be "int" (the naming inside control is "EN_DATATYPE_INTEGER"), no matter you have input any character in, it will just recognize the allowed char by data type, the others will be reject, if over range, it's will warning you automatically.
Is it useful?
let's take a look about this control. :)
Definition:
enum enDataType {
EN_DATATYPE_ALPHABET = 0, // Standard C++ naming rule
EN_DATATYPE_INTEGER = 1, // int
EN_DATATYPE_UNSIGNED_INTEGER = 2, // unsigned int
EN_DATATYPE_DOUBLE = 3, // double
EN_DATATYPE_UNSIGNED_DOUBLE = 4, // unsigned double
EN_DATATYPE_NONE = 5 // original CEdit behavior
};
From now, You just need to call SetEditDataType(EN_DATATYPE_INTEGER), then the data type of CEditCtrl will become "int" and no longer support the other data types anymore.
Till now, I believe as smart as you should understand why I can said this control can support many data types.
One place you have to read it more detail is OnChar(),
This function block is defined and qualified the input rule of CEditCtrl class, so you should be read it very carefully to understand the know how of it.
How to use it?
Here I support 2 way for you,
1. Using DDX_Control to manage it
2. Use SubclassDlgItem()
below is the source code:
EditCtrl.h
=======================================================
#pragma once
// CEditCtrl
namespace nsAuxLib {
class CEditCtrl : public CEdit
{
DECLARE_DYNAMIC(CEditCtrl)
// This is define how many data types can be judge by this control
enum enDataType {
EN_DATATYPE_ALPHABET = 0,
EN_DATATYPE_INTEGER = 1,
EN_DATATYPE_UNSIGNED_INTEGER = 2,
EN_DATATYPE_DOUBLE = 3,
EN_DATATYPE_UNSIGNED_DOUBLE = 4,
EN_DATATYPE_NONE = 5
};
public:
// Constructor and Destructor
CEditCtrl();
virtual ~CEditCtrl();
private:
enDataType edatatype_;
CString maxvalue_;
CString minvalue_;
CString defaultvalue_;
public:
// Define the current data type for the current object
inline void SetEditDataType(enDataType eType)
{ edatatype_ = eType; }
// Define the initial values of default value,
// minimun value and maximun value
inline void SetMinMaxValue(CString strDefault,
CString strMin,
CString strMax)
{
defaultvalue_ = strDefault;
maxvalue_ = strMax;
minvalue_ = strMin;
}
// Check Range function can return the result status back
bool CheckRange(CString strMin, CString strMax);
bool CheckRange();
double GetValDouble(bool bool_unsighed = true);
int GetValInt(bool bool_unsighed = true);
void SetValDouble(double dblvalue, bool bool_unsighed = true);
void SetValInt(int intvalue, bool bool_unsighed = true);
CString GetValText();
enDataType GetEditDatatype()
{ return edatatype_; }
protected:
DECLARE_MESSAGE_MAP()
public:
// Event handlers table
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnEnChange();
afx_msg void OnEnKillfocus();
};
}
=======================================================
If you are interesting about this control, you can email to me,
I will send it to you a.s.a.p.
Cheers,
Andrew
好文共賞 - 你吃『晚餐』了嗎?
你吃『晚餐』了嗎?
如果可以, 我希望我能再吃一次『晚餐』。
我記得去年的時候, 想要待在家裡吃飯。
那或許只是我懶得出去而已吧。
我走下樓梯,走進廚房, 看見老媽依舊在站在那煮飯。
這麼多年來,都是如此 …
我坐在客廳那看著電視,等著老媽煮好飯。
老媽煮好以後,叫我去吃飯。
我添好飯坐在飯桌前。
想叫老媽一起吃飯,
老媽說:「你先吃就好,我等你爸回來再吃。」
我依舊的回答說:「喔,那我先吃了。」
為什麼說依舊呢?
因為就當我偶而幾次待在家裡吃飯的時候,
每當我問老媽,她都是這樣的回答我。
這麼多年了,從未變過。
而我… 卻也一直不知道為什麼。
有一次,我問老媽:「為什麼你不先吃呀?」
老媽回答我說:「你老爸他每天在外面辛苦工作,回來又一個人在那吃飯,
我會不忍心啊。」
我這時候不知道說什麼了…
我那時候,好像是默默的把飯吃完吧。
過不久,有天晚上,老媽的舊病又復發了,
在晚上11 點多的時候,送往急診室。
我也是隔天回到家裡才知道的。
那天,我總覺得少了什麼。
我那天的晚餐就隨隨便便的吃了,吃完後,我騎著車到醫院去,我走進病房內,
老媽就問我:「你晚餐吃了沒阿?」
我回答說:「我剛剛有吃了。」
說完以後,老媽似乎才露出安心的表情。
這時候,老爸把我叫到病房外,用著很嚴肅、很悲傷的語氣跟我說:
「你媽的病,大概是不會好了。」
那時候,是我第一次看到,老爸的眼睛紅紅的。
回到家裡,我發現,原來我還記得怎麼哭泣。我忘了我哭了多久 …
過不久,老媽死了…
老媽在醫院的時候,最後跟我一句話:「以後晚餐要記得吃喔,別再隨便
在外面吃了,試試自己煮煮看。」
「不要讓你爸一個人孤獨的在那吃飯。」
說完以後,老媽死了…
我又再一次哭了,眼淚 …沾滿了病床上的床單,
似乎也沾滿了老爸跟一旁的醫護人 員。
如果可以 … .我多麼希望老媽可以再煮晚餐給我吃。
這篇故事,只是我感慨現在人的不懂事罷了。
父母對我們的關心,絕對是真的!
以前的人常說:「考試一百分,不如孝順多一分。」這句台語的俗話,
或許你也曾聽過吧。但你做到了嗎?
※ 『晚餐』是要跟家人一起吃,才能叫做『晚餐』。※
我常找藉口說自己好忙好忙好忙,
其實吃一餐飯又用你多少時間呢?
好好珍惜父母親及關心你的人
如果可以, 我希望我能再吃一次『晚餐』。
我記得去年的時候, 想要待在家裡吃飯。
那或許只是我懶得出去而已吧。
我走下樓梯,走進廚房, 看見老媽依舊在站在那煮飯。
這麼多年來,都是如此 …
我坐在客廳那看著電視,等著老媽煮好飯。
老媽煮好以後,叫我去吃飯。
我添好飯坐在飯桌前。
想叫老媽一起吃飯,
老媽說:「你先吃就好,我等你爸回來再吃。」
我依舊的回答說:「喔,那我先吃了。」
為什麼說依舊呢?
因為就當我偶而幾次待在家裡吃飯的時候,
每當我問老媽,她都是這樣的回答我。
這麼多年了,從未變過。
而我… 卻也一直不知道為什麼。
有一次,我問老媽:「為什麼你不先吃呀?」
老媽回答我說:「你老爸他每天在外面辛苦工作,回來又一個人在那吃飯,
我會不忍心啊。」
我這時候不知道說什麼了…
我那時候,好像是默默的把飯吃完吧。
過不久,有天晚上,老媽的舊病又復發了,
在晚上11 點多的時候,送往急診室。
我也是隔天回到家裡才知道的。
那天,我總覺得少了什麼。
我那天的晚餐就隨隨便便的吃了,吃完後,我騎著車到醫院去,我走進病房內,
老媽就問我:「你晚餐吃了沒阿?」
我回答說:「我剛剛有吃了。」
說完以後,老媽似乎才露出安心的表情。
這時候,老爸把我叫到病房外,用著很嚴肅、很悲傷的語氣跟我說:
「你媽的病,大概是不會好了。」
那時候,是我第一次看到,老爸的眼睛紅紅的。
回到家裡,我發現,原來我還記得怎麼哭泣。我忘了我哭了多久 …
過不久,老媽死了…
老媽在醫院的時候,最後跟我一句話:「以後晚餐要記得吃喔,別再隨便
在外面吃了,試試自己煮煮看。」
「不要讓你爸一個人孤獨的在那吃飯。」
說完以後,老媽死了…
我又再一次哭了,眼淚 …沾滿了病床上的床單,
似乎也沾滿了老爸跟一旁的醫護人 員。
如果可以 … .我多麼希望老媽可以再煮晚餐給我吃。
這篇故事,只是我感慨現在人的不懂事罷了。
父母對我們的關心,絕對是真的!
以前的人常說:「考試一百分,不如孝順多一分。」這句台語的俗話,
或許你也曾聽過吧。但你做到了嗎?
※ 『晚餐』是要跟家人一起吃,才能叫做『晚餐』。※
我常找藉口說自己好忙好忙好忙,
其實吃一餐飯又用你多少時間呢?
好好珍惜父母親及關心你的人
2007年1月4日 星期四
How to know your child appcication is running?
The subject what we want to discuss now is how to verify your child application is running or disappeared, for this case what we will do?
Follow below steps:
1. we can use the function called EnumProcesses() to get a list of all PIDs running status.
2. calling OpenProcess() to get a handle to the passed-in process ID
3. calling EnumProcessModules() and GetModuleBaseName() to get procedss name
after you finished above 3 steps, you can know your all child process running status.
below code is the sample function:
bool IsProcessRunning(LPCTSTR process_name)
{
DWORD aProcesses[1024]; // Array of process IDs
DWORD cbNeeded; // Byte count returned...
DWORD cProcesses; // The number of 'em obtained
DWORD dwExitCode = STILL_ACTIVE;
unsigned int i;
// Get a list of all current PIDs running
if(!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded))
return false;
// Get the count of PIDs in the array
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process
for(i = 0; i < cProcesses; i++)
{
char szProcessName[MAX_PATH] = "unknown";
// Get a handle to the passed-in process ID
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
|PROCESS_ALL_ACCESS,
FALSE,
aProcesses[i] );
// Get the process name
if(hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if(::EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
::GetModuleBaseName(hProcess,
hMod,
szProcessName,
sizeof(szProcessName));
}
if( stricmp(szProcessName, process_name) == 0)
return true;
}
}
return false;
}
you can also copy this paragraph code into your project, to enrich the power of your application.
Follow below steps:
1. we can use the function called EnumProcesses() to get a list of all PIDs running status.
2. calling OpenProcess() to get a handle to the passed-in process ID
3. calling EnumProcessModules() and GetModuleBaseName() to get procedss name
after you finished above 3 steps, you can know your all child process running status.
below code is the sample function:
bool IsProcessRunning(LPCTSTR process_name)
{
DWORD aProcesses[1024]; // Array of process IDs
DWORD cbNeeded; // Byte count returned...
DWORD cProcesses; // The number of 'em obtained
DWORD dwExitCode = STILL_ACTIVE;
unsigned int i;
// Get a list of all current PIDs running
if(!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded))
return false;
// Get the count of PIDs in the array
cProcesses = cbNeeded / sizeof(DWORD);
// Print the name and process identifier for each process
for(i = 0; i < cProcesses; i++)
{
char szProcessName[MAX_PATH] = "unknown";
// Get a handle to the passed-in process ID
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION
|PROCESS_ALL_ACCESS,
FALSE,
aProcesses[i] );
// Get the process name
if(hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if(::EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
::GetModuleBaseName(hProcess,
hMod,
szProcessName,
sizeof(szProcessName));
}
if( stricmp(szProcessName, process_name) == 0)
return true;
}
}
return false;
}
you can also copy this paragraph code into your project, to enrich the power of your application.
2007年1月3日 星期三
How to get the language id in MFC
If we want to know which language id is we are using now,
Some of you may asked this question. Especially, your program have to support
multi-language.
Below code is the sample code:
WORD GetSystemLanguageID()
{
return LANGIDFROMLCID(::GetSystemDefaultLCID());
}
After calling this function, it's will return one WORD datatype information,
For example English : 0x0409, Traditional Chinese : 0x0404
From now, I believe that you should understand how to use the result.
Cheers.
Some of you may asked this question. Especially, your program have to support
multi-language.
Below code is the sample code:
WORD GetSystemLanguageID()
{
return LANGIDFROMLCID(::GetSystemDefaultLCID());
}
After calling this function, it's will return one WORD datatype information,
For example English : 0x0409, Traditional Chinese : 0x0404
From now, I believe that you should understand how to use the result.
Cheers.
How to display the System Message by error code From GetlastError() in MFC
今天討論的主題是, 如何在MFC的程式裡, 顯示 System Error code 的真正含意.
通常我們會使用 GetlastError(), 來取得系統錯誤碼, 但取回的錯誤碼, 又該如何顯示其中的含意呢?
在此我們引用了一個 FormatMessage() 的MFC函式.
以下是範例:
std::string FormattingMessage(DWORD error_code)
{
LPVOID lpMsgBuf;
std::string ret_string;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_code,
0x0409, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
// Display the string.
ret_string = "[WINDOWS SYSTEM WARNING] - ";
ret_string += (LPCTSTR)lpMsgBuf;
// Free the buffer.
LocalFree( lpMsgBuf );
return ret_string;
}
其中 Default language的部分, 填入 NULL 則會根據你的語系來決定,
如此若ErrorCode = 32; 則會顯示
[WINDOWS SYSTEM WARNING] - The process cannot access the file because it is being used by another process.
通常我們會使用 GetlastError(), 來取得系統錯誤碼, 但取回的錯誤碼, 又該如何顯示其中的含意呢?
在此我們引用了一個 FormatMessage() 的MFC函式.
以下是範例:
std::string FormattingMessage(DWORD error_code)
{
LPVOID lpMsgBuf;
std::string ret_string;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
FORMAT_MESSAGE_FROM_SYSTEM
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error_code,
0x0409, // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL);
// Display the string.
ret_string = "[WINDOWS SYSTEM WARNING] - ";
ret_string += (LPCTSTR)lpMsgBuf;
// Free the buffer.
LocalFree( lpMsgBuf );
return ret_string;
}
其中 Default language的部分, 填入 NULL 則會根據你的語系來決定,
如此若ErrorCode = 32; 則會顯示
[WINDOWS SYSTEM WARNING] - The process cannot access the file because it is being used by another process.
訂閱:
文章 (Atom)