线程函数里if(File_dlg.DoModal()==IDOK)

djh512 2010-09-10 01:40:18
请问一下在线程函数里面

CFileDialog File_dlg(FALSE, _T(""), strname, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.*"));
if(File_dlg.DoModal()==IDOK)

这一句DoModal没有执行,没有弹出窗口
而改成下面的代码,去掉if就可以弹出窗口

CFileDialog File_dlg(FALSE, _T(""), strname, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,_T("*.*"));
File_dlg.DoModal();

求解问什么?
...全文
213 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
anyingliesou 2010-09-13
  • 打赏
  • 举报
回复
你可以 看看File_dlg.DoModal(); 现在返回什么值,然后再参考问题.
  • 打赏
  • 举报
回复
不应该的事
xiguapigeinichi 2010-09-11
  • 打赏
  • 举报
回复
不应该啊~~~
孤客天涯 2010-09-10
  • 打赏
  • 举报
回复
比较诡异,哈哈,应该是其他原因引起的吧
Eleven 2010-09-10
  • 打赏
  • 举报
回复
应该不会吧
xgPaul 2010-09-10
  • 打赏
  • 举报
回复
可能你的对话框被关闭了。。。
arong1234 2010-09-10
  • 打赏
  • 举报
回复
任何一个线程都可以创建,他这里肯定有其他问题:如一个对话框刚关了,又试图弹出这个窗口,就会有问题[Quote=引用 3 楼 lifecode 的回复:]
可能问题在“在线程函数里面”这句话里,应该由主线程创建窗口。
[/Quote]
dinjay 2010-09-10
  • 打赏
  • 举报
回复
既然去掉IF可以就应该不是主线程问题,很诡异啊。
LZ可以试试在主线程中去弹文件框,尽量不要在子线程中做涉及到UI的工作。
wolffan3150 2010-09-10
  • 打赏
  • 举报
回复
顶楼上的,在线程函数里面有问题
lifecode 2010-09-10
  • 打赏
  • 举报
回复
可能问题在“在线程函数里面”这句话里,应该由主线程创建窗口。
dickbarry 2010-09-10
  • 打赏
  • 举报
回复
就是不该吧?
有这等事?
dengzikun 2010-09-10
  • 打赏
  • 举报
回复
不应该吧,

if(File_dlg.DoModal()==IDOK)
{
return ;
}
基于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_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CtestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CtestDlg, CDialog) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() //}}AFX_MSG_MAP ON_BN_CLICKED(IDC_BUTTON_OPEN, &CtestDlg::OnBnClickedButtonOpen) ON_BN_CLICKED(IDC_BUTTON_PLAY, &CtestDlg::OnBnClickedButtonPlay) ON_WM_DESTROY() ON_BN_CLICKED(IDC_BUTTON_STOP, &CtestDlg::OnBnClickedButtonStop) END_MESSAGE_MAP() //ON_BN_CLICKED(IDC_Sound_Play, OnSound2) //ON_BN_CLICKED(IDC_Sound_stop, OnSound1) //ON_BN_CLICKED(IDC_sound_pause, OnBothSounds) //ON_WM_DESTROY() //ON_BN_CLICKED(IDC_BUTTON_Slow, OnBUTTONSlow) //ON_BN_CLICKED(IDC_BUTTON_Fast, OnBUTTONFast) //ON_BN_CLICKED(IDC_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 = GetSystemMenu(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 framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, 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(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // 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 framework. void CtestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR CtestDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } //--------------------------------------------------------------------------------- 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)_beginthreadex(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(); }
自己写的数据库大作业,用MFC ODBC +access 写的 内含完整工程,解压后就能用 // MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "ODBCdemo.h" #include "MainFrm.h" #include "BrwMessagedlg.h" #include "ReaderAdmindlg.h" #include "BookUpdatedlg.h" #include "LogIndlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(ID_BCG, OnBcg) ON_COMMAND(IDD_ReaderUpdate, OnReaderUpdate) ON_COMMAND(IDBK_UPDATE, OnBookUpdate) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { // TODO: add member initialization code here m_bAutoMenuEnable=FALSE; } CMainFrame::~CMainFrame() { } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } if (!m_wndDlgBar.Create(this, IDD_DIALOGBAR, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC, IDD_DIALOGBAR)) { TRACE0("Failed to create dialogbar\n"); return -1; // fail to create } m_wndDlgBar.EnableDocking(CBRS_ORIENT_HORZ); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndDlgBar); CLogIndlg cdlg; if( cdlg.DoModal()==IDOK) { if(cdlg.role=="读者") { for(int i=0;iGetSubMenu(i)->EnableMenuItem(1,MF_BYPOSITION|MF_GRAYED); } } else Destroy

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧