• 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>;
    


    头文件 

    1. #include < Mmsystem.h>      


    播放音乐

    1. PlaySound(L"1.wav", NULL, SND_ASYNC | SND_FILENAME );  

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

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


    循环播放

    1. PlaySound(currentDirectory, NULL, SND_ASYNC | SND_FILENAME |SND_LOOP);  

    停止播放

    1. PlaySound(NULL, NULL, SND_ASYNC | SND_FILENAME );  


    2 对话框初始化后立即进行的操作

       

        假设把诸多操作都放在初始化中,那么,对话框须要非常长时间才完毕初始化。 因此。对话框会延迟出现。不能及时蹦出。

        方法一 : 设置定时器 

    1. SetTimer(1,50,NULL);  

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

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

    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  在屏幕上画图


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

    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  设置选中状态。并将其默认 不能再选择

    1. CButton CheckButton;   //关联一变量  

    1. m_CheckButton.SetCheck(1);               //选中  
    2. m_CheckButton.EnableWindow(FALSE);       //不能再选  


    6 CFileDialog显示两种扩展名

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


    7  去掉标题栏的语句

    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组合键


    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

  • 相关阅读:
    FLV视频转换的利器 ffmpeg.exe
    ffmpeg参数设定解说
    SQL里加减日期
    SQL Server 获得影响行数
    CheckBoxList RadioButtonList 不生成table 表示
    SQL语句 从一个表读取数据,写入到另一个表的相同字段中
    ffmpeg和Mencoder使用实例小全
    执行存储过程出现:"不是有效的标识符。"
    SQL 格式化超长的字段
    js遍历选中的dom元素
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/7105809.html
Copyright © 2020-2023  润新知