|
// MainDlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "resource.h"
#include "MainDlg.h"
#include <boost/bind.hpp>
LRESULT CMainDlg::OnInitDialog( UINT /*uMsg*/,
WPARAM /*wParam*/,
LPARAM /*lParam*/,
BOOL& /*bHandled*/ )
{
// center the dialog on the screen
CenterWindow();
DoDataExchange();
// set icons
HICON hIcon = ( HICON )::LoadImage( _Module.GetResourceInstance(),
MAKEINTRESOURCE( IDR_MAINFRAME ),
IMAGE_ICON,
::GetSystemMetrics( SM_CXICON ),
::GetSystemMetrics( SM_CYICON ),
LR_DEFAULTCOLOR );
SetIcon( hIcon, TRUE );
HICON hIconSmall = ( HICON )::LoadImage( _Module.GetResourceInstance(),
MAKEINTRESOURCE( IDR_MAINFRAME ),
IMAGE_ICON,
::GetSystemMetrics( SM_CXSMICON ),
::GetSystemMetrics( SM_CYSMICON ),
LR_DEFAULTCOLOR );
SetIcon( hIconSmall, FALSE );
// update the dialog controls to reflect the current state of the WiFi radio
UpdateControlState( ndis_power_.IsRadioEnabled() );
// start listening for changes in the WiFi radio state
ndis_monitor_.Start( boost::bind( &CMainDlg::OnRadioStateChanged, this, _1 ) );
return TRUE;
}
LRESULT CMainDlg::OnEnable( WORD /*wNotifyCode*/,
WORD /*wID*/,
HWND /*hWndCtl*/,
BOOL& /*bHandled*/ )
{
if( ndis_power_.IsRadioEnabled() )
ndis_power_.Disable();
else
ndis_power_.Enable();
return 0;
}
LRESULT CMainDlg::OnCancel( WORD /*wNotifyCode*/,
WORD wID,
HWND /*hWndCtl*/,
BOOL& /*bHandled*/ )
{
EndDialog( wID );
return 0;
}
LRESULT CMainDlg::OnDestroy( UINT /*uMsg*/,
WPARAM /*wParam*/,
LPARAM /*lParam*/,
BOOL& /*bHandled*/ )
{
ndis_monitor_.Stop();
return 0;
}
LRESULT CMainDlg::OnRadioStateChanged( UINT /*uMsg*/,
WPARAM wParam,
LPARAM /*lParam*/,
BOOL& /*bHandled*/ )
{
bool enabled = static_cast< bool >( wParam );
UpdateControlState( enabled );
return 0;
}
void CMainDlg::OnRadioStateChanged( bool enabled )
{
/// we must return to the UI thread to change the state of the UI.
PostMessage( UWM_RADIO_STATE_CHANGED, enabled );
}
void CMainDlg::UpdateControlState( bool enabled )
{
status_.SetWindowText( enabled ? L"WiFi is enabled." : L"WiFi is disabled." );
enable_.SetWindowText( enabled ? L"Disable" : L"Enable" );
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.