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
plaincopy
- #include < Mmsystem.h>
播放音乐
[cpp] view
plaincopy
- PlaySound(L"1.wav", NULL, SND_ASYNC | SND_FILENAME );
// SND_ASYNC 异步播放 即: 运行完这一句。直接运行下一条语句 ,播放交由播放器播放着
// SND_SYNC 同步播放 即: 运行这一语句后。先不运行下一条语句。而是等播放器播放完这段音乐后。再运行下一条语句
循环播放
[cpp] view
plaincopy
- PlaySound(currentDirectory, NULL, SND_ASYNC | SND_FILENAME |SND_LOOP);
停止播放
[cpp] view
plaincopy
- PlaySound(NULL, NULL, SND_ASYNC | SND_FILENAME );
2 对话框初始化后立即进行的操作
假设把诸多操作都放在初始化中,那么,对话框须要非常长时间才完毕初始化。 因此。对话框会延迟出现。不能及时蹦出。
方法一 : 设置定时器
[cpp] view
plaincopy
- SetTimer(1,50,NULL);
方法二:PostMessage() 发送消息 通知初始化完毕
3 更新对话框上 某几个控件的值
[cpp] view
plaincopy
- void UPDATE(){
- UpdateData(FALSE);
- GetDlgItem(IDC_COMBO2)->RedrawWindow();
- GetDlgItem(IDC_EDIT2)->RedrawWindow();
- GetDlgItem(IDC_EDIT3)->RedrawWindow();
- GetDlgItem(IDC_EDIT4)->RedrawWindow();
- };
4 在屏幕上画图
[cpp] view
plaincopy
- Bitmap bmp(400,100);
- Graphics grp(&bmp); // 先绘制在位图中
- CWindowDC dc(CWnd::GetDesktopWindow());
- Graphics gDeskTop(dc.GetSafeHdc()); //将位图绘制在屏幕中
[cpp] view
plaincopy
- grp.FillRectangle(&backBrush,0,0,400,100);
- grp.DrawString(
- string.GetBuffer(),
- string.GetLength(),
- &myFont,
- rect,
- &format,
- &brush );
- gDeskTop.FillRectangle(&backBrush,0,0,400,100);
- gDeskTop.DrawImage(&bmp,0,0,400,100);
5 check box control 设置选中状态。并将其默认 不能再选择
[cpp] view
plaincopy
- CButton CheckButton; //关联一变量
[cpp] view
plaincopy
- m_CheckButton.SetCheck(1); //选中
- m_CheckButton.EnableWindow(FALSE); //不能再选
6 CFileDialog显示两种扩展名
[cpp] view
plaincopy
- CFileDialog dlg(TRUE,NULL,NULL,0,"图片文件(*.jpg;*.bmp)|*.jpg;*.bmp||",this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
7 去掉标题栏的语句
[cpp] view
plaincopy
- //去除标题和边框
- SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE)&(~(WS_CAPTION | WS_BORDER)));
- // 置对话框为最顶端并扩充到整个屏幕
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, -(GetSystemMetrics(SM_CXBORDER)+1),
- -(GetSystemMetrics(SM_CYBORDER)+1), cx+1,cy+1, SWP_NOZORDER);
- 还原标题栏和边框
- SetWindowLong(this-> GetSafeHwnd(), GWL_STYLE, GetWindowLong(m_hWnd,GWL_STYLE) + (WS_CAPTION|WS_BORDER) );
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, 500, 300, 600,500, SWP_SHOWWINDOW);
8 推断按下CTL+V组合键
[cpp] view
plaincopy
- BOOL CRichEditDlg::PreTranslateMessage(MSG* pMsg)
- {
- if (pMsg->message==WM_KEYDOWN)
- {
- if (pMsg->wParam==‘V‘&&(GetKeyState(VK_CONTROL)<0))//按下CTRL+V
- {
- OnPaste();
- return TRUE;//直接返回 要不然会响应系统的粘贴消息 从而导致粘贴2遍
- }
- }
- //
- }
转自:http://blog.csdn.net/shuilan0066/article/details/8727113