【VC开源代码栏目提醒】:网学会员在VC开源代码频道为大家收集整理了AudioCompress.cpp提供大家参考,希望对大家有所帮助!
// AudioCompress.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "AudioCompress.h"
#include "AudioCompressDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAudioCompressApp
BEGIN_MESSAGE_MAP(CAudioCompressApp, CWinApp)
//{{AFX_MSG_MAP(CAudioCompressApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAudioCompressApp construction
CAudioCompressApp::CAudioCompressApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CAudioCompressApp object
CAudioCompressApp theApp;
HHOOK hWndHook ;
int CDrawButton::m_Style = 2;
LRESULT __stdcall DefWindowProc1(HWND hWnd,UINT Msg,WPARAM wParam,
LPARAM lParam )
{
CPoint pt;
CDrawButton *pButton=(CDrawButton*)GetWindowLong(hWnd,GWL_USERDATA);
switch (Msg)
{
case WM_LBUTTONDBLCLK: //屏蔽双击事件
{
return TRUE;
break;
}
case WM_PAINT:
{
if (pButton->m_Style>0)
return pButton->OnPaint( hWnd);
else
return CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
break;
}
case WM_LBUTTONDOWN:
{
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
if (pButton->m_Style>0)
return pButton->OnLButtonDown( hWnd, 0, pt );
else
return CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
break;
}
case WM_LBUTTONUP:
{
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
if (pButton->m_Style>0)
return pButton->OnLButtonUp( hWnd, 0,pt );
else
return CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
break;
}
case WM_MOUSEMOVE:
{
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
if (pButton->m_Style>0)
return pButton->OnMouseMove(hWnd,0, pt);
else
return CallWindowProc(pButton->m_OldProc, hWnd,Msg,wParam,lParam);
break;
}
case WM_DESTROY:
{
WNDPROC procOld=pButton->m_OldProc;
SetWindowLong(hWnd,GWL_WNDPROC,(long)procOld); //恢复原来的窗口函数
pButton->m_Flag = 1;
LRESULT ret = ::CallWindowProc(procOld,hWnd,Msg,wParam,lParam);
return ret;
}
default :
{
break;
}
}
return CallWindowProc(pButton->m_OldProc, hWnd, Msg, wParam, lParam );
}
//定义钩子函数
LRESULT CALLBACK HOOKProc( int nCode, WPARAM wParam, LPARAM lParam )
{
PCWPSTRUCT wc = (PCWPSTRUCT) lParam;
HWND hWnd = wc->hwnd;
if( hWnd )
{
char ClassName[MAX_PATH] = "";
GetClassName( hWnd, ClassName, MAX_PATH );
if( strcmp( ClassName, "Button" ) == 0 )
{
CWnd *pWnd = CWnd::FromHandle( hWnd );
BOOL IsDefaultButton = pWnd->GetStyle()&BS_DEFPUSHBUTTON;
BOOL IsGroupButton = pWnd->GetStyle()&BS_GROUPBOX;
int CommonButton = ((CButton*)pWnd)->GetButtonStyle();
if (IsDefaultButton )
if (CommonButton!=7)
pWnd->ModifyStyle(BS_DEFPUSHBUTTON,0,0);
WNDPROC WndProc;
WndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
CDrawButton *pButton = NULL;
pButton =(CDrawButton*)GetWindowLong(hWnd,GWL_USERDATA);
if (pButton != NULL&& pButton->m_Flag==1 )
{
SetWindowLong(hWnd,GWL_USERDATA,0);
SetWindowLong( hWnd, GWL_WNDPROC, (LONG)pButton->m_OldProc );
pButton->m_OldProc = NULL;
delete pButton;
}
else if (pButton == NULL )
{
if( WndProc !=DefWindowProc1 )
{
if (!IsGroupButton)
{
pButton = new CDrawButton;
pButton->m_OldProc = WndProc;
SetWindowLong(hWnd,GWL_USERDATA,(long)pButton);
WndProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) DefWindowProc1);
}
}
}
}
}
return CallNextHookEx( hWndHook, nCode, wParam, lParam );
}
//安装钩子
BOOL RunHook( HMODULE hModule, DWORD dwThreadID)
{
hWndHook = SetWindowsHookEx(
WH_CALLWNDPROC, (HOOKPROC) HOOKProc, hModule, dwThreadID );
return TRUE;
}
//卸载钩子
BOOL StopHook()
{
UnhookWindowsHookEx(hWndHook);
return TRUE;
}
int CAudioCompressApp::ExitInstance()
{
CoUninitialize();
StopHook();
return CWinApp::ExitInstance();
}
/////////////////////////////////////////////////////////////////////////////
// CAudioCompressApp initialization
BOOL CAudioCompressApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
HINSTANCE hModule = GetModuleHandle( NULL );
RunHook ( hModule, GetCurrentThreadId() );
CAudioCompressDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
上一篇:
AudioCode.cpp
下一篇:
应用数学学报编辑部联系方式