MFC 小知识总结四

1 PlaySound  播放WAV格式的音乐

This function plays a sound specified by a file name, resource, or system event.

<strong>BOOL WINAPI PlaySound( 
  LPCSTR</strong> <em><a target=_blank class="synParam" href="http://write.blog.csdn.net/postedit" style="color: rgb(255, 153, 0); text-decoration: none;">pszSound</a></em><strong>, 
  HMODULE</strong> <em><a target=_blank class="synParam" href="http://write.blog.csdn.net/postedit" style="color: rgb(255, 153, 0); text-decoration: none;">hmod</a></em><strong>, 
  DWORD</strong> <em><a target=_blank class="synParam" href="http://write.blog.csdn.net/postedit" style="color: rgb(255, 153, 0); text-decoration: none;">fdwSound</a> </em>
<strong>)</strong>;


头文件 

[cpp]  view plain copy
  1. #include < Mmsystem.h>      


播放音乐

[cpp]  view plain copy
  1. PlaySound(L"1.wav", NULL, SND_ASYNC | SND_FILENAME );  

// SND_ASYNC  异步播放     即: 执行完这一句,直接执行下一条语句  ,播放交由播放器播放着

// SND_SYNC    同步播放     即:  执行这一语句后,先不执行下一条语句,而是等播放器播放完这段音乐后,再执行下一条语句


循环播放

[cpp]  view plain copy
  1. PlaySound(currentDirectory, NULL, SND_ASYNC | SND_FILENAME |SND_LOOP);  

停止播放

[cpp]  view plain copy
  1. PlaySound(NULL, NULL, SND_ASYNC | SND_FILENAME );  


2 对话框初始化后马上进行的操作

   

    如果把诸多操作都放在初始化中,那么,对话框需要很长时间才完成初始化。 因此,对话框会延迟出现,不能及时蹦出。

    方法一 : 设置定时器 

[cpp]  view plain copy
  1. SetTimer(1,50,NULL);  

   方法二:PostMessage() 发送消息 通知初始化完成

 3  更新对话框上 某几个控件的值

[cpp]  view plain copy
  1. void UPDATE(){  
  2.   
  3.     UpdateData(FALSE);  
  4.   
  5.     GetDlgItem(IDC_COMBO2)->RedrawWindow();  
  6.     GetDlgItem(IDC_EDIT2)->RedrawWindow();  
  7.     GetDlgItem(IDC_EDIT3)->RedrawWindow();  
  8.     GetDlgItem(IDC_EDIT4)->RedrawWindow();  
  9. };  

4  在屏幕上绘图


[cpp]  view plain copy
  1. Bitmap bmp(400,100);    
  2. Graphics grp(&bmp);  // 先绘制在位图中  
  3.   
  4. CWindowDC dc(CWnd::GetDesktopWindow());  
  5. Graphics gDeskTop(dc.GetSafeHdc());       //将位图绘制在屏幕中  

[cpp]  view plain copy
  1. grp.FillRectangle(&backBrush,0,0,400,100);  
  2.   
  3. grp.DrawString(     
  4.     string.GetBuffer(),     
  5.     string.GetLength(),     
  6.     &myFont,    
  7.     rect,     
  8.     &format,     
  9.     &brush );    
  10.   
  11.   
  12.   
  13. gDeskTop.FillRectangle(&backBrush,0,0,400,100);  
  14.   
  15. gDeskTop.DrawImage(&bmp,0,0,400,100);  


5 check box control  设置选中状态,并将其默认 不能再选择

[cpp]  view plain copy
  1. CButton CheckButton;   //关联一变量  

[cpp]  view plain copy
  1. m_CheckButton.SetCheck(1);               //选中  
  2. m_CheckButton.EnableWindow(FALSE);       //不能再选  


6 CFileDialog显示两种扩展名

[cpp]  view plain copy
  1. CFileDialog dlg(TRUE,NULL,NULL,0,"图片文件(*.jpg;*.bmp)|*.jpg;*.bmp||",this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框  


7  去掉标题栏的语句

[cpp]  view plain copy
  1. //去除标题和边框  
  2.   SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE)&(~(WS_CAPTION | WS_BORDER)));  
  3. // 置对话框为最顶端并扩充到整个屏幕  
  4.   ::SetWindowPos(m_hWnd, HWND_TOPMOST, -(GetSystemMetrics(SM_CXBORDER)+1),  
  5.     -(GetSystemMetrics(SM_CYBORDER)+1), cx+1,cy+1, SWP_NOZORDER);  
  6.   
  7. 还原标题栏和边框  
  8.   SetWindowLong(this-> GetSafeHwnd(), GWL_STYLE, GetWindowLong(m_hWnd,GWL_STYLE) + (WS_CAPTION|WS_BORDER) );  
  9.   ::SetWindowPos(m_hWnd, HWND_TOPMOST, 500, 300, 600,500, SWP_SHOWWINDOW);  

8 判断按下CTL+V组合键


[cpp]  view plain copy
  1. BOOL CRichEditDlg::PreTranslateMessage(MSG* pMsg)  
  2. {  
  3.       
  4.   
  5.     if (pMsg->message==WM_KEYDOWN)  
  6.     {  
  7.         if (pMsg->wParam=='V'&&(GetKeyState(VK_CONTROL)<0))//按下CTRL+V  
  8.         {  
  9.             OnPaste();  
  10.             return TRUE;//直接返回 要不然会响应系统的粘贴消息  从而导致粘贴2遍  
  11.         }  
  12.     }  
  13. //  
  14. }  

转自:http://blog.csdn.net/shuilan0066/article/details/8727113

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值