📄 volumedlg.cpp
字号:
// VolumeDlg.cpp : implementation file
//
#include "stdafx.h"
#include "GPS.h"
#include "VolumeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const TCHAR szregRootScreenKey[]=TEXT("ControlPanel\\Volume");
const TCHAR szregScreen[]=TEXT("Screen");
/////////////////////////////////////////////////////////////////////////////
// CVolumeDlg dialog
CVolumeDlg::CVolumeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVolumeDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVolumeDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CVolumeDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVolumeDlg)
DDX_Control(pDX, IDB_VOLUME9, m_staVol9);
DDX_Control(pDX, IDB_VOLUME8, m_staVol8);
DDX_Control(pDX, IDB_VOLUME7, m_staVol7);
DDX_Control(pDX, IDB_VOLUME6, m_staVol6);
DDX_Control(pDX, IDB_VOLUME5, m_staVol5);
DDX_Control(pDX, IDB_VOLUME4, m_staVol4);
DDX_Control(pDX, IDB_VOLUME3, m_staVol3);
DDX_Control(pDX, IDB_VOLUME2, m_staVol2);
DDX_Control(pDX, IDB_VOLUME1, m_staVol1);
DDX_Control(pDX, IDB_VOLUME0, m_staVol0);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CVolumeDlg, CDialog)
//{{AFX_MSG_MAP(CVolumeDlg)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_WM_KEYDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVolumeDlg message handlers
BOOL CVolumeDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_Left=0;
m_Top=0;
m_Width=320;
m_Height=240;
::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,m_Left, m_Top,
m_Width, m_Height,SWP_SHOWWINDOW);
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
m_BackScreenBitmap.LoadBitmap(IDB_VOLUME_BKG);
SetToolRectangle();
m_prePick=-1;
m_currentPick=0;
m_bIsExecute=FALSE ;
DWORD dwVolume;
DWORD sVolume;
waveOutGetVolume(0, &dwVolume);
sVolume=dwVolume>>16;
if(sVolume==0)
out=0;
else if(sVolume<((DWORD)0xffff/9*1))
out=1;
else if(sVolume<((DWORD)0xffff/9*2))
out=2;
else if(sVolume<((DWORD)0xffff/9*3))
out=3;
else if(sVolume<((DWORD)0xffff/9*4))
out=4;
else if(sVolume<((DWORD)0xffff/9*5))
out=5;
else if(sVolume<((DWORD)0xffff/9*6))
out=6;
else if(sVolume<((DWORD)0xffff/9*7))
out=7;
else if(sVolume<((DWORD)0xffff/9*8))
out=8;
else
out=9;
ShowVolume(out);
////////////////////////
HKEY hKey1;
LONG lResult1;
DWORD dwType1;
DWORD dwScreen;
DWORD dwLen1;
lResult1 = RegOpenKeyEx(HKEY_CURRENT_USER,szregRootScreenKey, 0, KEY_ALL_ACCESS, &hKey1);
if(ERROR_SUCCESS == lResult1)
{
dwType1 = REG_DWORD;
dwLen1 = sizeof(DWORD);
lResult1 = RegQueryValueEx(hKey1, szregScreen, NULL, &dwType1,(LPBYTE)&dwScreen, &dwLen1);
}
if (dwScreen == 65536)
{
m_Screen = false;//点击屏静音
}
if (dwScreen == 65538)
{
m_Screen = true;
}
RegCloseKey(hKey1);
/////////////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CVolumeDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_prePick = m_currentPick ;
for ( int i = 0 ; i < 4 ; i ++ )
{
if ( m_rect[i].PtInRect (point) )
{
{
CDC* pDC = GetDC () ;
CDC memDC ;
memDC.CreateCompatibleDC ( pDC ) ;
CBitmap bmp ;
switch ( m_prePick )
{
case 0:
{//白
bmp.LoadBitmap ( IDB_VOLUME_SUB_W ) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(),
m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 1:
{
bmp.LoadBitmap ( IDB_VOLUME_ADD_W ) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(),
m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 2:
{
// bmp.LoadBitmap ( IDB_VOLUME_YES_W ) ;
// CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
// pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(),
// m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
// memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 3:
{
bmp.LoadBitmap ( IDB_VOLUME_OK_W ) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(),
m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
}
CBitmap bmp1 ;
switch ( i )
{
case 0:
{
//load the bitmap
//黑
bmp1.LoadBitmap ( IDB_VOLUME_SUB_B ) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(),
m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 1:
{
//load the bitmap
bmp1.LoadBitmap ( IDB_VOLUME_ADD_B) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(),
m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 2:
{
//load the bitmap
// bmp1.LoadBitmap ( IDB_VOLUME_YES_B ) ;
// CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
// pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(),
// m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
// memDC.SelectObject ( pOldBitmap ) ;
break ;
}
case 3:
{
//load the bitmap
bmp1.LoadBitmap ( IDB_VOLUME_OK_B ) ;
CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(),
m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
break ;
}
}
memDC.DeleteDC () ;
ReleaseDC ( pDC ) ;
m_currentPick = i ;
}
}
}
}
void CVolumeDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CopyBMP(IDB_VOLUME_SUB_W,0);
CopyBMP(IDB_VOLUME_ADD_W,1);
// CopyBMP(IDB_VOLUME_YES_W,2);
CopyBMP(IDB_VOLUME_OK_W,3);
m_bIsExecute = FALSE ;
for ( int i = 0 ; i < 4 ; i ++ )
{
if ( m_rect[i].PtInRect (point) )
{
if ( m_currentPick == i)
{
m_bIsExecute =TRUE ;
switch (i)
{
case 0:
OnBtnVolumeAdd();
break ;
case 1:
OnBtnVolumeSub();
break ;
case 2:
// OnBtnScreenClick();
ScreenClick();
InvalidateRect(CRect(138,149,183,184));
break ;
case 3:
CDialog::OnOK();
break ;
default:
break ;
}
}
}
}
}
void CVolumeDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
DrawInterface(dc);
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CVolumeDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
BITMAP bmpInfo;
m_BackScreenBitmap.GetBitmap(&bmpInfo);
// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&m_BackScreenBitmap);
// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);
dcMemory.SelectObject(pOldBitmap);
return TRUE;
}
void CVolumeDlg::CopyBMP(int m_map, int i)
{
CDC* pDC = GetDC () ;
CDC memDC ;
memDC.CreateCompatibleDC ( pDC ) ;
CBitmap bmp,bmp1 ;
CBitmap* pOldBitmap ;
bmp1.LoadBitmap ( m_map) ;
pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(),
m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
memDC.SelectObject ( pOldBitmap ) ;
memDC.DeleteDC () ;
ReleaseDC ( pDC ) ;
}
void CVolumeDlg::DrawInterface(CDC &dc)
{
CDC memDC ;
memDC.CreateCompatibleDC ( &dc ) ;
CBitmap* pBitmap ; //load all bitmap
CBitmap* pOldBitmap ; //save old bitmap temp
//.............................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if (m_NavRefresh || m_currentPick == 0)
{
//黑
pBitmap ->LoadBitmap ( IDB_VOLUME_SUB_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
else
{ //白
pBitmap ->LoadBitmap ( IDB_VOLUME_SUB_W) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
//将图片COPY到指定的像素位置
dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
}
memDC.SelectObject ( pOldBitmap ) ;
//释放bitmap对象内存
delete pBitmap ;
//.............................................................
//分配bitmap对象内存
pBitmap = new CBitmap ;
if ( m_currentPick == 1 )
{
pBitmap ->LoadBitmap ( IDB_VOLUME_ADD_B ) ;
pOldBitmap = memDC.SelectObject ( pBitmap ) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -