|
Hi,
For some reason, the path of the .ini file is asked not be specified. The .ini file is located in the same place with .exe file. I tried the functions fopen(strIniFileName,"r") and GetPrivateProfileString( ..,..,..,..,..,strIniFileName), where strIniFileName = ".\\myINI.ini". Both functions worked well in debug process, but failed in execution. I am confused.
I am using VC++ 6, and working on Windows XP.
Could someone please give me an assistance. Many thanks in advance.
hli
|
|
|
|
|
Call GetCurrentDirectory to see where your app runs from and go from there.
Things like this happen when you start your app from a shortcut (with the Start In param missconfigured)
|
|
|
|
|
Good idea. I will try. Thank you very much.
hli
|
|
|
|
|
Actually one wants to use GetModuleFileName() if the ini file is in the same folder as the exe.
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|
|
You are right GetCurrentDirectory works from .exe file itself, but fails from shortcut. My application must be used remotely from shortcut. ???
hli
|
|
|
|
|
Run app from shortcut, getCurrentDirectory returns C:\Documents and Settings. I guess that GetModuleFileName is the same. I will try.
hli
|
|
|
|
|
I resolved this problem by adding work directory in "Start In" box in shortcut property. Many thanks.
hli
|
|
|
|
|
Hi all,
I have a tab control in a dialog. There are 5 tabs in total, with each tab associated with a child dialog. I wanna exchange information between these tabs. I store and update all information in a global structure. When I switch between these tabs, I want to update data in these tabs. How can I do that? Currently I am using:
<br />
CMyTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)<br />
{<br />
int nSel = GetCurSel();<br />
if(m_Dialog[nSel]->m_hWnd)<br />
m_Dialog[nSel]->ShowWindow(SW_HIDE);
............<br />
for(int nCount=0; nCount < m_nPageCount; nCount++){<br />
m_Dialog[nCount]->SetWindowPos(&wndTop, l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_HIDEWINDOW);<br />
}<br />
m_Dialog[nSel]->SetWindowPos(&wndTop,l_rectClient.left,l_rectClient.top,l_rectClient.Width(),l_rectClient.Height(),SWP_SHOWWINDOW);<br />
m_Dialog[nSel]->ShowWindow(SW_SHOW);
m_Dialog[nSel]->OnInitDialog();
}<br />
I placed all updating code in each child dialog's OnInitDialog() function. The problem is this function will be called twice so some controls like ListView have double items. How to fix this problem? Do I need to use SendMessage(), PostMessage()?
thanks,
Gavin
|
|
|
|
|
Don't call OnInitDialog to init your data(i guess you used Create to create the dialogs...right?). Write some other methods for handling the OnDisplay Event.
|
|
|
|
|
thanks eusto,
Yes. I know I shouldn't use OnInitDialog(). I am just wondering which message or function of CDialog Class should I use.
I couldn't find the OnDisplay event in Class Wizard. which one of the following should I use?
<br />
WM_PAINT<br />
WM_DRAWITEM<br />
WM_COPYDATA<br />
WM_CAPTURECHANGE<br />
thanks,
Gavin
|
|
|
|
|
OnDisplay was just a name i came up with. Implement a method called LoadData for example and do everything that needs to be done there.
For example for the first CEmbeddedDialog do something like this.
Call CEmbededDialog.Create(...)
then Call CEmbededDialog.LoadData();
In your LoadData method you should put the code that loads your comboboxes and so forth.
You don't need to handle the actual selection of the dialog afterwards...all tabs from the CMyTabCtrl have been initialised when displaying the actual CMyTabCtrl. What your selection should do is hide all other CDialogs except for the one placed in the current selected tab.
Think of your dialogs as actual C++ Objects (wich they are...).
Sorry if this is a bit unclear... i'm not an english speaker
|
|
|
|
|
Can you explain why you use OnInitDialog for update,please.Do you have specific statements in this function
whitesky
|
|
|
|
|
Thanks WhiteSky,
No special reason. I just want to use an overrided function of CDialog class because I don't know which child dialog class is run at run time.
|
|
|
|
|
if you need to update you can write your function and use from it
whitesky
|
|
|
|
|
Hi!
I'm trying to make an MFC app that has two dialogs.
The first dialog is the main one, has some editboxes to imput some values, and a ok button. Pressing the ok button the second window comes up and there is another edit box showing the values previously insertd.
I used this code to open the second Dialog:
void CFirstDlg::OnBnClickedOk()<br />
{<br />
CSecondDlg dlg;<br />
dlg.DoModal();<br />
}
Once opened I don't know how to use the variable of the first I have tryed with firstDlg.m_VAR, adding #include "FirstDlg.h" and CFirstDlg firstDlg; but I'm making something wrong cause it doesn't work. I also tryed to search something on the web but got no results...
Does anyone has some ideas? Advices or some demo?
modified 11-Mar-21 21:01pm.
|
|
|
|
|
blpdone wrote: Does anyone has some ideas? Advices or some demo?
From a design perspective UI components (views) should NOT be tightly coupled (see MVC design pattern).
That issue aside, Dialogs are C++ classes so passing variables between them is the same as passing variables between any two classes. Do you know how to do that?
blpdone wrote: I have tryed with firstDlg.m_VAR
How? we can't read your mind.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
If you want to pass m_VAR from the 1st to 2nd dialog, you can add a SetVar() method to the 2nd dialog class. Then, the code becomes:
void CFirstDlg::OnBnClickedOk()
{
CSecondDlg dlg;
dlg.SetVar(m_VAR);
dlg.DoModal();
}
Best,
Jun
|
|
|
|
|
void CFirstDlg::OnBnClickedOk()
{
CSecondDlg dlg;
dlg.DoModal();
}
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thankyou So much everybody!!!
I understood!!! it works!!!
I didn't know I could do that!
modified 11-Mar-21 21:01pm.
|
|
|
|
|
Hi fellows,
I have a CStatic-derived class. When I get the WM_LBUTTONDOWN message, I change the current bitmap into another one, and restore them in the WM_LBUTTONUP message. It woks fine. Then I include it in my CDialog-derived class using DDX. However, when I add the ON_STN_CLICKED to the message map of my dialog, it does not receive any message. I assume that is because the control already managed te WM_LBUTTONDOWN message. What can I do about it? Prehaps I need to do some subclassing? Any thoughts will be really appreciated.
Regards,
FG.
A polar bear is a bear whose coordinates has been changed in terms of sine and cosine.
|
|
|
|
|
Are you wanting the WM_LBUTTONDOWN message to be handled in both the control class and in the dialog class? Have you seen this?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
one possible approach send dialog messages inside control derived class
Kuphryn
|
|
|
|
|
Fernando A. Gómez F. wrote: I assume that is because the control already managed te WM_LBUTTONDOWN message. What can I do about it?
Maybe. Read some MSDN articles on MFC message routing.
Fernando A. Gómez F. wrote: What can I do about it?
Lots of things. Since you have a custom control "CStatic-derived class" you can define a message that you post that the parent dialog can handle. Or you can do more of a Observer/Observable Design Pattern.
"Just about every question you've asked over the last 3-4 days has been "urgent". Perhaps a little planning would be helpful?" Colin Angus Mackay in the C# forum
led mike
|
|
|
|
|
I think I'll try your approach. Thanks a lot.
Regards,
FG.
A polar bear is a bear whose coordinates has been changed in terms of sine and cosine.
|
|
|
|
|
In your CStatic derived class' WM_LBUTTONUP and WM_LBUTTONDOWN handlers try placing a call to Default() .
You may be right I may be crazy -- Billy Joel --
Within you lies the power for good, use it!!!
|
|
|
|