Code enhancement: remove duplicated code

This commit is contained in:
Don HO 2019-08-22 01:19:22 +02:00
parent 0d87d37d35
commit ab46fe0806
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
2 changed files with 13 additions and 40 deletions

View File

@ -148,7 +148,7 @@ INT_PTR CALLBACK HashFromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
return FALSE;
}
LRESULT HashFromFilesDlg::run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
LRESULT run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
@ -374,31 +374,6 @@ INT_PTR CALLBACK HashFromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
return FALSE;
}
LRESULT HashFromTextDlg::run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_GETDLGCODE:
{
return DLGC_WANTALLKEYS | ::CallWindowProc(oldEditProc, hwnd, message, wParam, lParam);
}
case WM_CHAR:
{
if (wParam == 1) // Ctrl+A
{
::SendMessage(hwnd, EM_SETSEL, 0, -1);
return TRUE;
}
break;
}
default:
break;
}
return ::CallWindowProc(oldEditProc, hwnd, message, wParam, lParam);
}
void HashFromTextDlg::setHashType(hashType hashType2set)
{
_ht = hashType2set;

View File

@ -21,6 +21,8 @@
enum hashType {hash_md5, hash_sha256};
LRESULT run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
class HashFromFilesDlg : public StaticDialog
{
public :
@ -34,16 +36,14 @@ protected :
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
hashType _ht = hash_md5;
LRESULT run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK HashPathEditStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LRESULT CALLBACK HashPathEditStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
const auto dlg = (HashFromFilesDlg *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
return (dlg->run_textEditProc(dlg->_oldHashPathEditProc, hwnd, message, wParam, lParam));
return (run_textEditProc(dlg->_oldHashPathEditProc, hwnd, message, wParam, lParam));
};
static LRESULT CALLBACK HashResultStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LRESULT CALLBACK HashResultStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
const auto dlg = (HashFromFilesDlg *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
return (dlg->run_textEditProc(dlg->_oldHashResultProc, hwnd, message, wParam, lParam));
return (run_textEditProc(dlg->_oldHashResultProc, hwnd, message, wParam, lParam));
};
private :
@ -66,16 +66,14 @@ protected :
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
hashType _ht = hash_md5;
LRESULT run_textEditProc(WNDPROC oldEditProc, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK HashTextEditStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LRESULT CALLBACK HashTextEditStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
const auto dlg = (HashFromTextDlg *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
return (dlg->run_textEditProc(dlg->_oldHashTextEditProc, hwnd, message, wParam, lParam));
return (run_textEditProc(dlg->_oldHashTextEditProc, hwnd, message, wParam, lParam));
};
static LRESULT CALLBACK HashResultStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static LRESULT CALLBACK HashResultStaticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
const auto dlg = (HashFromTextDlg *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
return (dlg->run_textEditProc(dlg->_oldHashResultProc, hwnd, message, wParam, lParam));
return (run_textEditProc(dlg->_oldHashResultProc, hwnd, message, wParam, lParam));
};
private :