|
OK, thank you for help.
danginkgo
|
|
|
|
|
I use ::GetOpenFileName instead CFileDialog to show the OpenFile Dialog.
accidently I found it(the dialog) a modeless dialog, user can click the button to show as many OpenFile Dialogs as she/he wants, this is not the thing I want.
Is it possible to make ::GetOpenFileName openfile Dialog modal?
|
|
|
|
|
You could try something like this perhaps: Code removed
Sandip's answer is the best way to go about it.
modified on Thursday, July 10, 2008 2:45 AM
|
|
|
|
|
Specify valid window handle in parameter hwndOwner
if you specify NULL it would create modless dialog.
i hope it helps.
Regards,
Sandip.
|
|
|
|
|
I always specify the hwndOwner, it doesn't work.
|
|
|
|
|
i tried this and it works fine for me.
void CTrialMFCDlg::OnOK()
{
OPENFILENAME ofn;
char szFile[260];
HWND hwnd;
HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = this->GetSafeHwnd();
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
MessageBox("Open");
else
MessageBox("Cancel");
}
Regards,
Sandip.
|
|
|
|
|
And I found a misunderstanding problem, when I first show the openfile Dialog,
it just shows on the topmost corner in the screen(it means the openfile dialog shows in the (0,0) according the screen coordination).
But when show the openfile dialog after, it shows in the center relative to the main dialog.
Who can tell me why?
|
|
|
|
|
fantasy1215 wrote: the openfile dialog shows in the (0,0) according the screen coordination).
But when show the openfile dialog after, it shows in the center relative to the main dialog.
I see this behavior, only when the owner of the dialog opened is not specified. Specify the handle of your application's window as the owner of the dialog that you open.
|
|
|
|
|
Thanks all of you. I specify the wrong hwndOwner handle, I reCreate a simple project, it works fine.
BTW, is it possible to SetIcon for the ::GetOpenFileDialog dialog?
It always use the IDR_MAINFRAME icon.
|
|
|
|
|
Hi,
I have 2 threads in my app.
one is main application thread which has UI.
second is the worker thread.
second thread will get some status from a database and send the information to the main thread using SendMessageAPI. One of the parameters in the SendMessage API is a global variable across the threads.
After the recieving the message from second thread, first thread will display the error to the user and return the control so that the second thread can monitor the status continuously.
But at some point, my app hangs.
I suspect that the hang happens in this loop.
As the return depends on the response from the main thread (thru user input via messagebox), i could not use SendMessageTimeout API in this case.
1. Is it because of the global variable usage in SendMessage function?
Can you please let me know how can i come out of this problem.
Any help is appreciated.
Selva
|
|
|
|
|
Please post some code: from your worker thread when you send the message and from the main thread where you handle this message.
By 'hangs' you mean that your UI freeze completely and you can't do anything anymore with your app ?
|
|
|
|
|
Hi,
Thanks for the reply.
Code will look like below.
int g_nInt;
Main thread
LRESULT CMyDlg::OnProcessMsg(WPARAM wparam, LPARAM lparam)
{
Display Message box ....... Get result from user.
return 0;
}
Worker thread
{
get status from DB.
GetMainWnd()->SendMessage(PROC_MSG, wp, g_nInt);
.....
GetMainWnd()->SendMessage(PROC_MSG2, wp, lp);
.........
}
Yes. My main app window looks like freezed (continuous even after an hour).
Thanks in advance.
Selva
|
|
|
|
|
SendMessage is a blocking function: it will only return once the message has been processed by the other window. In your case, it will return only after the user has closed the MessageBox. You didn't provide enough code for me to verify this but you probably have a deadlock: your worker thread is waiting for the UI thread (because of the SendMessage function) which is in turn waiting for the worker thread.
If your design allows it, try with PostMessage instead of SendMessage: PostMessage puts the message in the message queue of the window and returns immediately.
|
|
|
|
|
Hi,
Thanks for the reply.
Main thread won't be waiting for the worker thread..
only if the second request from the worker thread comes, it will be processing.
But i too suspect that its because of the deadlock.
But my doubt is,
whether passing the global variable (which will be accessed by both the threads) causes this hang. any way storing the value in global variable will happen with proper locks from both the threads.
But whether passing this as the parameter to the SendMessage causes any problem?
Thanks in advance.
Selva
|
|
|
|
|
Sorry but your question is not really clear. Please post some more relevant code instead of explaining what your code does. Anyway, why do you pass the value in the message ? It is globally available so, there's no need to pass it in the message. But accessing this variable from two threads won't make your UI hang (unless you are using critical section to access it, then the problem might come from that).
SelvaKr wrote: any way storing the value in global variable will happen with proper locks from both the threads.
I'm not sure what that means but if you are using critical section, then this is probably the problem.
Did you try with PostMessage as I told you ? What happened ?
|
|
|
|
|
Hi,
Thanks for the reply.
I will try postmessage instead of SendMessage and
reply in case of any problems.
Thanks a lot.
Selva
|
|
|
|
|
Perhaps your problem is using the MainWnd object across threads (you didn't say if this is MFC or not, but I suspect it is).
It would be safer to either pass the hWnd of your main window in the thread parameters when you start the thread, or to use GetSafeHwnd() when you send your message.
For example:
Worker thread
{
get status from DB.
::SendMessage(GetMainWnd()->GetSafeHwnd(),PROC_MSG, wp, g_nInt)
.....
::SendMessage(GetMainWnd()->GetSafeHwnd(),PROC_MSG, wp, g_nInt)
.........
}
Also, you say the code will "look like" below. Post your actual code, including how you start the thread.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Hi all,
How can use enter key on ListCtrl.
I m using NM_RETURN but its not working, i m also check NM_KEYDOWN.
But problem is not shortout.
I want on which row of list cotrol the user pressed the enter key then the purticular relevant Column or row information get from listctrol.
How can i do this please help me for this.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
I think you should first derive a class called CMyListCtrl from CListCtrl.
from the menu [Insert]->[Class], Create your CMyListCtrl.
then open the MyListCtrl.cpp file, press CTRL+W to show the ClassWizard.
In the [Message Maps] tab, you choose the NM_RETURN, to add a function to deal with the message that the user press the ENTER key in the ListCtrl.
then in your Dlg class substitute CListCtrl with CMyListCtrl.
Hope I express my mind. And Hope it works.
|
|
|
|
|
Please tell me with example.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
NMLVKEYDOWN* nmkd = (NMLVKEYDOWN*)pNMHDR;
switch(nmkd->wVKey)
{
case VK_SPACE:
int nIndex= GetNextItem(-1, LVNI_SELECTED);
CString strItem = GetItemText(nIndex, 0);
AfxMessageBox(strItem );
}
*pResult = 0;
i m using thisfor keydown ,i m using key space if i m using VK_RETURN in place of VK_SPACE than its not working.(Means the message box not show)
and in case of VK_SPACE its working but after this Unhandeled exeception occur the message of exeception is "Unhandled exception at 0x5d0f0892 in Test.exe: 0xC0000094: Integer division by zero."
Please help me for this.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Do be sorry for my first reply, I've tried my first code, it doesn't work at all, sorry.
I can't see which message do you handle, But you do can ovrride the PreTranslateMessage method to achive your goal.
BOOL CListCtrlEnterKeyDlg::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message) {
case WM_KEYDOWN:
if (VK_RETURN == (INT)pMsg->wParam && ::GetFocus() == m_ctlList.GetSafeHwnd())
{
int iSelMask = -1;
iSelMask = m_ctlList.GetSelectionMark();
if (iSelMask != -1)
{
LVITEM lvi = {0};
lvi.iItem = iSelMask;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
TCHAR szBuf[50] = {0};
lvi.pszText = szBuf;
lvi.cchTextMax = 50;
VERIFY( m_ctlList.GetItem(&lvi) );
::AfxMessageBox(szBuf);
}
}
return TRUE;
default:
break;
}
BOOL bRet = CDialog::PreTranslateMessage(pMsg);
return bRet;
}
I hope this time everything will go fine.^_^
|
|
|
|
|
Thanks it really helps me.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
I have two property pages incorporated in a property sheet.
Property page 1 has a edit control and property page 2 has
a simple push button.
I have overridden the OnApply virtual function for both
the property pages.
When the property sheet is shown, I enable the 'Apply'
button by handling EN_cHANGE notification of the edit
control for Property page 1. On clicking the 'Apply'
button, I show a message defined in overridden OnApply ()
of Property Page 1 and disable the 'Apply' button by
SetModified(FALSE).
Then, I go to Property Page 2 tab and click on the button
on it to enable the 'Apply' button.Now, I click on the 'Apply'
button expecting a message defined in the overridden OnApply()
of Property page 2.
But, I get the message defined in Property Page 1 first and then
get the message in Property page 2.
To summarize, On clicking the 'Apply' button while the
Property page 2 is active, my control is going into the
OnApply() of Property page 1 and then comes into the OnApply()
of Property page 2.
Why is this happening ? Is this the expected behavior ?
Thanks in advance.
|
|
|
|
|
SherTeks wrote: Why is this happening ? Is this the expected behavior ?
This is perfectly fine. The Apply button is on the property sheet, not any individual page.
To borrow a phrase, "what would happen if it only did Apply to the current page?". It's very easy to imagine how things would break down.
If you *really* only wanted it to apply to an individual setting on a page, put a button next to that setting, rather than rely on OnApply. Or you could modify all your OnApply's to check if they're the current page. That's less hard that in sounds - you could have each page inherit from a class inheriting from CPropertyPage called
CMyPropertyPageThatBreaksUserExpectations.
(OK, my opinion is subtly encoded in the name).
I hope this helped,
Iain.
|
|
|
|