锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
澶у閮藉仛榪囧熀浜嶮FC Dialog鐨勫簲鐢ㄧ▼搴?鎴戞洿鍠滄鐢–FrameWnd媧劇敓綾繪潵瀹炵幇搴旂敤紼嬪簭鐨勪富妗嗘灦,鎴戜笉澶枩嬈DI妯℃澘,鍙堟槸Document鍙堟槸View鐨?MFC鑳岀潃浣犲共浜?jiǎn)寰堝浜嬫?
濂戒簡(jiǎn)錛岃璇撮棶棰?澶у濡傛灉浣滆繃鍩轟簬CFrameWnd鐨勪富紿楀彛,鍙兘浼?xì)鍙戠庮C富紿楀彛浼?xì)鏈変竴涓?D鐨勮竟妗?涓寮濮嬫垜鐢∕odifyStyle鍙戠幇涓嶈,閭e氨鍦≒reCreateWindow閲岄潰鍚?鍛靛懙,涔熶笉綆$敤,璺熻繘MFC鐨勪唬鐮?鍙戠幇CFrameWnd::PreCreateWindow浼?xì)閲嵕|甦wExStyle,濂戒簡(jiǎn)鐪嬩唬鐮佸惂!
BOOL聽CMainFrame::PreCreateWindow(CREATESTRUCT
&
聽cs)聽
{
聽聽BOOL聽bRet
=
CFrameWnd::PreCreateWindow(cs);
聽聽
if
(bRet)
{
聽聽聽cs.dwExStyle
&=~
WS_EX_CLIENTEDGE;
聽聽聽
return
聽TRUE;
聽}
聽
return
聽FALSE;
}
HRESULT聽hr聽
=
聽S_FALSE;
聽聽聽聽I(yíng)NetFwMgr
*
聽fwMgr聽
=
聽NULL;
聽聽聽聽I(yíng)NetFwPolicy
*
聽fwPolicy聽
=
聽NULL;
聽聽聽聽FW_ERROR_CODE聽ret聽
=
聽FW_NOERROR;
聽聽聽聽
try
聽聽聽聽
{
聽聽聽聽聽聽聽聽
if
(聽m_pFireWallProfile聽)
聽聽聽聽聽聽聽聽聽聽聽聽
throw
聽FW_ERR_INITIALIZED;
聽聽聽聽聽聽聽聽
//
聽Create聽an聽instance聽of聽the聽firewall聽settings聽manager.
聽聽聽聽聽聽聽聽hr聽
=
聽CoCreateInstance(聽__uuidof(NetFwMgr),聽NULL,聽CLSCTX_INPROC_SERVER,聽__uuidof(聽I(yíng)NetFwMgr),聽(
void
**
)
&
fwMgr聽);
聽聽聽聽聽聽聽聽
if
(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽
throw
聽FW_ERR_CREATE_SETTING_MANAGER;
聽聽聽聽聽聽聽聽
//
聽Retrieve聽the聽local聽firewall聽policy.
聽聽聽聽聽聽聽聽hr聽
=
聽fwMgr
->
get_LocalPolicy(聽
&
fwPolicy聽);
聽聽聽聽聽聽聽聽
if
(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽
throw
聽FW_ERR_LOCAL_POLICY;
聽聽聽聽聽聽聽聽
//
聽Retrieve聽the聽firewall聽profile聽currently聽in聽effect
聽聽聽聽聽聽聽聽hr聽
=
聽fwPolicy
->
get_CurrentProfile(聽
&
m_pFireWallProfile聽);
聽聽聽聽聽聽聽聽
if
(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽
throw
聽FW_ERR_PROFILE;
聽聽聽聽}
聽聽聽聽
catch
(聽FW_ERROR_CODE聽nError)
聽聽聽聽
{
聽聽聽聽聽聽聽聽ret聽
=
聽nError;
聽聽聽聽}
聽聽聽聽
if
(聽fwPolicy聽)
聽聽聽聽聽聽聽聽fwPolicy
->
Release();
聽聽聽聽
if
(聽fwMgr聽)
聽聽聽聽聽聽聽聽fwMgr
->
Release();
聽聽聽聽
return
聽ret;
WinXPSP2FireWall::AddApplication(聽const聽wchar_t*聽lpszProcessImageFileName,聽const聽wchar_t*聽lpszRegisterName聽)

{
聽聽聽聽FW_ERROR_CODE聽ret聽=聽FW_NOERROR;
聽聽聽聽HRESULT聽hr;
聽聽聽聽BOOL聽bAppEnable;
聽聽聽聽BSTR聽bstrProcessImageFileName聽=聽NULL;
聽聽聽聽BSTR聽bstrRegisterName聽=聽NULL;
聽聽聽聽I(yíng)NetFwAuthorizedApplication*聽pFWApp聽=聽NULL;
聽聽聽聽I(yíng)NetFwAuthorizedApplications*聽pFWApps聽=聽NULL;
聽聽聽聽try
聽聽聽聽
{
聽聽聽聽聽聽聽聽if(聽m_pFireWallProfile聽==聽NULL聽)
聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_INITIALIZED;
聽聽聽聽聽聽聽聽if(聽lpszProcessImageFileName聽==聽NULL聽||聽lpszRegisterName聽聽==聽NULL聽)
聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_INVALID_ARG;
聽聽聽聽聽聽聽聽//聽First聽of聽all,聽check聽the聽application聽is聽already聽authorized;
聽聽聽聽聽聽聽聽FW_ERROR_CODE聽聽nError聽=聽this->IsAppEnabled(聽lpszProcessImageFileName,聽bAppEnable聽);
聽聽聽聽聽聽聽聽if(聽nError聽!=聽FW_NOERROR聽)
聽聽聽聽聽聽聽聽聽聽聽聽throw聽nError;
聽聽聽聽聽聽聽聽//聽Only聽add聽the聽application聽if聽it聽isn't聽authorized
聽聽聽聽聽聽聽聽if(聽bAppEnable聽==聽FALSE聽)
聽聽聽聽聽聽聽聽
{
聽聽聽聽聽聽聽聽聽聽聽聽//聽Retrieve聽the聽authorized聽application聽collection
聽聽聽聽聽聽聽聽聽聽聽聽hr聽=聽m_pFireWallProfile->get_AuthorizedApplications(聽&pFWApps聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_AUTH_APPLICATIONS;
聽聽聽聽聽聽聽聽聽聽聽聽//聽Create聽an聽instance聽of聽an聽authorized聽application
聽聽聽聽聽聽聽聽聽聽聽聽hr聽=聽CoCreateInstance(聽__uuidof(NetFwAuthorizedApplication),聽NULL,聽CLSCTX_INPROC_SERVER,聽__uuidof(INetFwAuthorizedApplication),聽(void**)&pFWApp);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_CREATE_APP_INSTANCE;
聽聽聽聽聽聽聽聽聽聽聽聽//聽Allocate聽a聽BSTR聽for聽the聽Process聽I(yíng)mage聽FileName
聽聽聽聽聽聽聽聽聽聽聽聽bstrProcessImageFileName聽=聽SysAllocString(聽lpszProcessImageFileName聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽SysStringLen(聽bstrProcessImageFileName聽)聽==聽0)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_SYS_ALLOC_STRING;
聽聽聽聽聽聽聽聽聽聽聽聽//聽Set聽the聽process聽image聽file聽name
聽聽聽聽聽聽聽聽聽聽聽聽hr聽=聽pFWApp->put_ProcessImageFileName(聽bstrProcessImageFileName聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽FAILED(聽hr聽)聽)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_PUT_PROCESS_IMAGE_NAME;
聽聽聽聽聽聽聽聽聽聽聽聽//聽Allocate聽a聽BSTR聽for聽register聽name
聽聽聽聽聽聽聽聽聽聽聽聽bstrRegisterName聽=聽SysAllocString(聽lpszRegisterName聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽SysStringLen(聽bstrRegisterName聽)聽==聽0)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_SYS_ALLOC_STRING;
聽聽聽聽聽聽聽聽聽聽聽聽//聽Set聽a聽registered聽name聽of聽the聽process
聽聽聽聽聽聽聽聽聽聽聽聽hr聽=聽pFWApp->put_Name(聽bstrRegisterName聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_PUT_REGISTER_NAME;
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽//聽Add聽the聽application聽to聽the聽collection
聽聽聽聽聽聽聽聽聽聽聽聽hr聽=聽pFWApps->Add(聽pFWApp聽);
聽聽聽聽聽聽聽聽聽聽聽聽if(聽FAILED(聽hr聽))
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽throw聽FW_ERR_ADD_TO_COLLECTION;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽catch(聽FW_ERROR_CODE聽nError聽)
聽聽聽聽
{
聽聽聽聽聽聽聽聽ret聽=聽nError;
聽聽聽聽}
聽聽聽聽SysFreeString(聽bstrProcessImageFileName聽);
聽聽聽聽SysFreeString(聽bstrRegisterName聽);
聽聽聽聽if(聽pFWApp聽)
聽聽聽聽聽聽聽聽pFWApp->Release();
聽聽聽聽if(聽pFWApps聽)
聽聽聽聽聽聽聽聽pFWApps->Release();
聽聽聽聽return聽ret;
}//http://www.handytech.cn
#include <dvoice.h>
#pragma聽 comment(lib,"dxguid.lib")
void CTestDlg::OnButton1()
{
聽// TODO: Add your control notification handler code here
聽I(yíng)DirectPlayVoiceTest* pTest;
聽HRESULT hr=CoCreateInstance(CLSID_DirectPlayVoiceTest,NULL,CLSCTX_INPROC_SERVER,IID_IDirectPlayVoiceTest,(void**)&pTest);
聽if(SUCCEEDED(hr))
聽{
聽聽pTest->CheckAudioSetup(&DSDEVID_DefaultVoicePlayback,&DSDEVID_DefaultCapture,NULL,DVFLAGS_ALLOWBACK);
聽聽pTest->Release();
聽}
聽 OK涓婇潰鐨勪唬鐮佸氨璋冪敤浜?jiǎn)DirectVoice涓殑瀹炵幇,澶у鐪嬬湅鏁堟灉!