VC播放器心得一

有疑问的可以Q我,236823103,先写这些,其他的以后有时间再写

1.按钮图标的美化:

如果聚焦和非聚焦无区别显示的话,以下就行了。

HBITMAP hBitmap;//位图句柄 hBitmap
 HINSTANCE hInstance;//应用程序实例句柄 hInstance
 hInstance = ::AfxGetInstanceHandle();//获得当前的应用程序实例句柄
 hBitmap = ::LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BMP_Prev)); //加载位图
 m_btnPrev.SetBitmap(hBitmap);//CButton 类对象
如果需要有区别显示,要重写CButton类

BOOL  CButtonBeauty::SetBitmaps(HBITMAP hBitmapNormal, HBITMAP hBitmapMouseDown, HBITMAP hBitmapHigh, HBITMAP hBitmapDisable)
{
 int  nRetValue = 0;
 BITMAP csBitmapSize;

 // Free any loaded resource
 FreeResources();

 if (hBitmapNormal)
 {
  m_csBitmaps[0].hBitmap = hBitmapNormal;
  // Get bitmap size
  nRetValue = ::GetObject(hBitmapNormal, sizeof(csBitmapSize), &csBitmapSize);
  if (nRetValue == 0)
  {
   FreeResources();
   return FALSE;
  } // if
  m_csBitmaps[0].dwWidth = (DWORD)csBitmapSize.bmWidth;
  m_csBitmaps[0].dwHeight = (DWORD)csBitmapSize.bmHeight;

  if (hBitmapMouseDown)
  {
   m_csBitmaps[1].hBitmap = hBitmapMouseDown;
   // Get bitmap size
   nRetValue = ::GetObject(hBitmapMouseDown, sizeof(csBitmapSize), &csBitmapSize);
   if (nRetValue == 0)
   {
    FreeResources();
    return FALSE;
   } // if
   m_csBitmaps[1].dwWidth = (DWORD)csBitmapSize.bmWidth;
   m_csBitmaps[1].dwHeight = (DWORD)csBitmapSize.bmHeight;

  } // if

  if (hBitmapHigh)
  {
   m_csBitmaps[2].hBitmap = hBitmapHigh;
   // Get bitmap size
   nRetValue = ::GetObject(hBitmapHigh, sizeof(csBitmapSize), &csBitmapSize);
   if (nRetValue == 0)
   {
    FreeResources();
    return FALSE;
   } // if
   m_csBitmaps[2].dwWidth = (DWORD)csBitmapSize.bmWidth;
   m_csBitmaps[2].dwHeight = (DWORD)csBitmapSize.bmHeight;

  } // if

  if (hBitmapDisable)
  {
   m_csBitmaps[3].hBitmap = hBitmapDisable;
   // Get bitmap size
   nRetValue = ::GetObject(hBitmapDisable, sizeof(csBitmapSize), &csBitmapSize);
   if (nRetValue == 0)
   {
    FreeResources();
    return FALSE;
   } // if
   m_csBitmaps[3].dwWidth = (DWORD)csBitmapSize.bmWidth;
   m_csBitmaps[3].dwHeight = (DWORD)csBitmapSize.bmHeight;

  } // if
 } // if

 Invalidate();

 return TRUE;
} // End of SetBitmaps

当然用到了在头文件里许多申请的变量

2.热键的使用

在主对话框OnInitDialog()里添加

 RegisterHotKey(GetSafeHwnd(),1000,MOD_SHIFT, 'U'); 具体详解请查看MSDN

然后在主对话框的CPP文件下

LRESULT   CPlayerDlg::WindowProc(UINT   message,   WPARAM   wParam,   LPARAM   lParam)  
{
//   TODO:   Add   your   special  ized   code   here   and/or   call   the   base   class
 if   (message==WM_HOTKEY)
 {
  if   (wParam==1000)
  { 
     MessageBox("you press shift+u");
    } 
  }
 return   CDialog::WindowProc(message,   wParam,   lParam);
}

这样就注册了一个SHIFT+U的热键

3.初始化对话框的位置

MS提供了可视化操作,不需要编码实现,选中对话框属性,在位置里,设置你想要显示的X和Y的坐标

4.停靠实现

我们需要在拖动主对话框时,子对话框跟着一起被拖动。

1)在主对话框里加上WM_MOVE的消息

void CPlayerDlg::OnMove(int x, int y)
{
 CDialog::OnMove(x, y);
 
 // TODO: Add your message handler code here

 if(init){ 
 
        MovePlayListWindow();
 }
}

init在初始化之前为false,初始化之后置为true

2)

void CPlayerDlg::MovePlayListWindow()
{
 CRect rectParent;
 CRect rect;
 GetWindowRect(&rectParent);
 rect.top=rectParent.top+rectParent.Height();
 rect.left=rectParent.left;
 rect.bottom=rect.top+400;
 rect.right=rect.left+rectParent.Width();
 m_playlistdlg->MoveWindow(&rect,TRUE);
}

5.如果想在主对话框和子对话框里要实现消息的传递,该怎么实现呢?

我们需要使用类的前置声明

在主对话框头文件里不需要添加子对话框的头文件,

class 子类;

class 父类{

……

子类类名 对象;

};

子对话框的头文件应该加下主对话框CPP文件里

在子对话框里也是类似的。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值