社区
其他技术讨论专区
帖子详情
SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);
weixin_38088281
2016-09-06 07:01:03
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
...全文
30
1
打赏
收藏
SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
1 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
VS2010 实现对话框程序设置背景图片
VS2010 实现对话框程序设置背景图片 void CMySendToDlg::OnPa
int
() { if (Is
Icon
ic()) { CPa
int
DC
dc
(this); // 用于绘制的设备上下文
SendMessage
(
WM
_
ICON
ERASE
BKGND
, re
int
erp
ret_
cas
t(
dc
.
GetS
afeH
dc
()), 0);
MFC中GDI与Direct2D交互_D2D1_例子
MFC中GDI与Direct2D交互_D2D1_例子
vc++可视化计算器
词法分析器
词法分析// TranslationDlg.cpp : 实现文件 // #include "stdafx.h" #include "Translation.h" #include "TranslationDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialog { public: CAboutDlg(); // 对话框数据 enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CTranslationDlg 对话框 CTranslationDlg::CTranslationDlg(CWnd* pParent /*=NULL*/) : CDialog(CTranslationDlg::IDD, pParent) { m_h
Icon
= AfxGetApp()->Load
Icon
(IDR_MAINF
RAM
E); } void CTranslationDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, I
DC
_EDIT2, content); DDX_Control(pDX, I
DC
_EDIT1, result); } BEGIN_MESSAGE_MAP(CTranslationDlg, CDialog) ON_
WM
_SYSCOMMAND() ON_
WM
_PA
INT
() ON_
WM
_QUERYDRAG
ICON
() //}}AFX_MSG_MAP ON_BN_CLICKED(I
DC
_BUTTON1, &CTranslationDlg::OnBnClickedButton1) END_MESSAGE_MAP() // CTranslationDlg 消息处理程序 BOOL CTranslationDlg::OnInitDialog() { CDialog::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu =
GetS
ystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 Set
Icon
(m_h
Icon
, TRUE); // 设置大图标 Set
Icon
(m_h
Icon
, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 CAboutDlg dlgAbout; dlgAbout.DoModal(); return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CTranslationDlg::OnSysCommand(U
INT
nID, LPA
RAM
lPa
ram
) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lPa
ram
); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CTranslationDlg::OnPa
int
() { if (Is
Icon
ic()) { CPa
int
DC
dc
(this); // 用于绘制的设备上下文
SendMessage
(
WM
_
ICON
ERASE
BKGND
, re
int
erp
ret_
cas
t<
WPA
RAM
>(
dc
.
GetS
afeH
dc
()), 0); // 使图标在工作区矩形中居中
int
cx
Icon
=
GetS
ystemMetrics(SM_CX
ICON
);
int
cy
Icon
=
GetS
ystemMetrics(SM_CY
ICON
); CRect rect; GetClientRect(&rect);
int
x = (rect.Width() - cx
Icon
+ 1) / 2;
int
y = (rect.Height() - cy
Icon
+ 1) / 2; // 绘制图标
dc
.Draw
Icon
(x, y, m_h
Icon
); } else { CDialog::OnPa
int
(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CTranslationDlg::OnQueryDrag
Icon
() { return static_
cas
t
(m_h
Icon
); } void CTranslationDlg::SplideFrontSpc (CString &str) {
int
i = 0; for(i;str[i]==' ';) {str.Delete (0);}//MessageBox (_T("ok")); } void CTranslationDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 CString code ,temp ,output; //CString word[8] = ; CString flag[3][10] = {{_T("if"),_T("
int
"),_T("for"),_T("while"),_T("do"),_T("return"),_T("break"),_T("continue")}, {_T("+"),_T("-"),_T("*"),_T("/"),_T("="),_T(">"),_T("<"),_T("<="),_T(">="),_T("!=")}, { _T(","),_T(";"),_T("{"),_T("}"),_T("("),_T(")")}}; content.GetWindowTextW (code); code.Replace (_T("\r\n"),_T("")); code.Append (_T(" ")); while(!code.IsEmpty ()) { temp.Empty ();
int
i,j;
int
isfind = 0;//是否找到,找到了代表其类型 SplideFrontSpc(code); //temp = code.Left (code.Find (_T(","))); //code.Delete (0,2);//temp = code[0]; //截取下一个单词 temp = code.Left (code.Find (_T(" "))); code.Delete (0,code.Find (_T(" "))); //对比单词类型 for(i=0;!isfind&&i<3;i++) for(j=0;j<10;j++) if(temp == flag[i][j]) { if(i==0) isfind = 1; else if(i==1) isfind = 4; else isfind = 5; break; } if(isfind==0) {
int
isnum = temp[0]-'0'; if(isnum>-1||isnum<10) isfind = 3; else isfind = 2; } CString cnum; cnum.Format (_T("%d"),isfind); if(!temp.IsEmpty ()) temp = _T("(") + cnum + _T(", \"") + temp + _T("\")"); else temp = _T("词法分析完毕!\r\n"); output = output + temp + _T("\r\n"); } //output = _T("asdjfk\r\naksdjfl\nasldkfj\n"); result.SetWindowTextW (output); } BOOL CTranslationDlg::PreTranslateMessage(MSG* pMsg) { // TODO: 在此添加专用代码和/或调用基类 return CDialog::PreTranslateMessage(pMsg); } void CTranslationDlg::OnOK() { // TODO: 在此添加专用代码和/或调用基类 CDialog::OnOK(); }
简易的播放器
基于DirectSound的简易播放器 #include "stdafx.h" #include "test.h" #include "testDlg.h" #include "process.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data enum { IDD = IDD_ABOUTBOX }; protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) END_MESSAGE_MAP() // CtestDlg dialog CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/) : CDialog(CtestDlg::IDD, pParent) { m_h
Icon
= AfxGetApp()->Load
Icon
(IDR_MAINF
RAM
E); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, CDialog) ON_
WM
_SYSCOMMAND() ON_
WM
_PA
INT
() ON_
WM
_QUERYDRAG
ICON
() //}}AFX_MSG_MAP ON_BN_CLICKED(I
DC
_BUTTON_OPEN, &CtestDlg::OnBnClickedButtonOpen) ON_BN_CLICKED(I
DC
_BUTTON_PLAY, &CtestDlg::OnBnClickedButtonPlay) ON_
WM
_DESTROY() ON_BN_CLICKED(I
DC
_BUTTON_STOP, &CtestDlg::OnBnClickedButtonStop) END_MESSAGE_MAP() //ON_BN_CLICKED(I
DC
_Sound_Play, OnSound2) //ON_BN_CLICKED(I
DC
_Sound_stop, OnSound1) //ON_BN_CLICKED(I
DC
_sound_pause, OnBothSounds) //ON_
WM
_DESTROY() //ON_BN_CLICKED(I
DC
_BUTTON_Slow, OnBUTTONSlow) //ON_BN_CLICKED(I
DC
_BUTTON_Fast, OnBUTTONFast) //ON_BN_CLICKED(I
DC
_BUTTON_Normal, OnBUTTONNormal) // CtestDlg message handlers BOOL CtestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu =
GetS
ystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the
icon
for this dialog. The f
ram
ework does this automatically // when the application's main window is not a dialog Set
Icon
(m_h
Icon
, TRUE); // Set big
icon
Set
Icon
(m_h
Icon
, FALSE); // Set small
icon
// TODO: Add extra initialization here m_sndSound1 = new CDirectSound(); if(!m_sndSound1) { exit(-1); } return TRUE; // return TRUE unless you set the focus to a control } void CtestDlg::OnSysCommand(U
INT
nID, LPA
RAM
lPa
ram
) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lPa
ram
); } } // If you add a minimize button to your dialog, you will need the code below // to draw the
icon
. For MFC applications using the document/view model, // this is automatically done for you by the f
ram
ework. void CtestDlg::OnPa
int
() { if (Is
Icon
ic()) { CPa
int
DC
dc
(this); // device context for pa
int
ing
SendMessage
(
WM
_
ICON
ERASE
BKGND
, re
int
erp
ret_
cas
t<
WPA
RAM
>(
dc
.
GetS
afeH
dc
()), 0); // Center
icon
in client rectangle
int
cx
Icon
=
GetS
ystemMetrics(SM_CX
ICON
);
int
cy
Icon
=
GetS
ystemMetrics(SM_CY
ICON
); CRect rect; GetClientRect(&rect);
int
x = (rect.Width() - cx
Icon
+ 1) / 2;
int
y = (rect.Height() - cy
Icon
+ 1) / 2; // Draw the
icon
dc
.Draw
Icon
(x, y, m_h
Icon
); } else { CDialog::OnPa
int
(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CtestDlg::OnQueryDrag
Icon
() { return static_
cas
t
(m_h
Icon
); } //--------------------------------------------------------------------------------- void CtestDlg::OnBnClickedButtonOpen() { // TODO: Add your control notification handler code here LPCTSTR lpszFilter =L"Wave File(*.wav)|*.wav|All Files|*.*||"; CFileDialog dlg(TRUE,NULL,NULL,/*OFN_HIDEREADONLY |*/ OFN_OVERWRITEPROMPT,lpszFilter); if(dlg.DoModal()==IDOK) { m_soundfile = dlg.GetPathName(); } } // unsigned
int
WINAPI FileReadProc(LPVOID pOwner) { CtestDlg* pThis = (CtestDlg*)pOwner; pThis->ReadFileProc(); return 1; } // typedef struct _WAVE_FORMAT { WORD AudioFormat; WORD NumChannels; DWORD SampleRate; DWORD ByteRate; WORD BlockAlign; WORD BitsPerSample; }WAVE_FORMAT,*PWAVE_FORMAT; void CtestDlg::OnBnClickedButtonPlay() { // TODO: Add your control notification handler code here if(m_soundfile.IsEmpty()) { MessageBox(L"请选中播放文件!"); return; } USES_CONVERSION; fp = fopen(W2A(m_soundfile.GetBuffer(m_soundfile.GetLength())),"rb"); if(NULL == fp) { MessageBox(L"打开所所定的播放文件失败,请确认文件是否存在!"); return; } fseek(fp,20,0); //Skip previous 20 bytes RIFF header WAVE_FORMAT waveFormat;
int
nLen =fread(&waveFormat,1,sizeof(WAVE_FORMAT),fp); AUDIO_CONFIG WaveHead; WaveHead.wFormatTag = 1; WaveHead.nChannels = 2; WaveHead.nSamplesPerSec = 44100; WaveHead.nAvgBytesPerSec = 176400; WaveHead.nBlockAlign = 4; WaveHead.wBitsPerSample = 16; WaveHead.nBlockAlign=waveFormat.BlockAlign; WaveHead.nChannels=waveFormat.NumChannels; WaveHead.nSamplesPerSec=waveFormat.SampleRate; WaveHead.wBitsPerSample=waveFormat.BitsPerSample; WaveHead.nAvgBytesPerSec=waveFormat.ByteRate; m_sndSound1->CreateDSound(&WaveHead,8000); fseek(fp,20+sizeof(WAVE_FORMAT),0); unsigned
int
dwReadID; m_hThread = (HANDLE)_beg
int
hreadex(0,0,FileReadProc,this,0,&dwReadID); Sleep(200); m_bStop = 0; m_bContine = 1; m_sndSound1->Play(); } void CtestDlg::ReadFileProc() { //BYTE buf[1025];
int
n = 0; while(1) { BYTE buf[1025];
int
nlen; if(m_bStop) break; nlen = fread(buf,1,1024,fp); if(!nlen) break; while(m_sndSound1->WriteDataToBuf(buf,nlen)==-1) { Sleep(100); } } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnDestroy() { CDialog::OnDestroy(); // TODO: Add your message handler code here m_bStop = 1; OnBnClickedButtonStop(); if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = 0; } if(m_sndSound1) { delete m_sndSound1; m_sndSound1 = NULL; } if(fp) { fclose(fp); fp = NULL; } } void CtestDlg::OnBnClickedButtonStop() { // TODO: Add your control notification handler code here m_bStop = 1; if(m_hThread) { WaitForSingleObject(m_hThread,2000); CloseHandle(m_hThread); m_hThread = NULL; } m_sndSound1->Stop(); }
其他技术讨论专区
476
社区成员
790,963
社区内容
发帖
与我相关
我的任务
其他技术讨论专区
其他技术讨论专区
复制链接
扫一扫
分享
社区描述
其他技术讨论专区
其他
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章