|
This problem cropped up after I converted the dialog from modal to non-modal, so that might have something to do with it. The question: why should I have to call GetDlgItem to get a pointer to a dialog box control in every function instead of just once in OnInitDialog?
I've got these pointers in my modeless dialog box header file:
CListBox* ExpressionsListBoxPtr;
CListBox* FiltersListBoxPtr;
CListBox* TargetsListBoxPtr;
All were initialized to null by the constructor. In OnInitDialog() I put this (I checked to make shure OnInitDialog got called, and that the pointers were not null afterwords):
ExpressionsListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_EXPRESSIONLISTBOX));
FiltersListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_FILTERLISTBOX));
TargetsListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_TARGETLISTBOX));
The issue is that when I execute this fuction I get a debug assertation error and I've determined that the class level pointers are the source of the problem. I have worked around it by calling GetDlgItem in the function itself instead of just in OnInitDialog:
afx_msg void CRatiosNewSearchDialog::OnAddFilter()
{
CListBox* TempListBoxPtr = (CListBox*)(GetDlgItem(IDC_DLGS_EXPRESSIONLISTBOX));
int CurrentSelection = TempListBoxPtr->GetCurSel();
int Pos = 0;
CString Expression = "";
if(CurrentSelection == LB_ERR)
MessageBox("You must select an expression before you can add a filter. LB_ERR.", "User Error", MB_ICONHAND);
else
{
ExpressionsListBoxPtr->GetText(CurrentSelection, Expression);
Pos = Expression.Find(" - ", 0);
Expression.Delete(0, Pos + 3);
Pos = FiltersListBoxPtr->AddString(Expression);
ResetListboxScrollbar(FiltersListBoxPtr);
FiltersListBoxPtr->SetCurSel(Pos);
}
}
Can anyone tell me why it is not letting me just call GetDlgItem once when the dialog pops up instead of making me call it every time I want to use a control?
|
|
|
|
|
from MSDN
CWnd::GetDlgItem
Return Value
A pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL.
The returned pointer may be temporary and should not be stored for later use.
Why don't you simply associate control variables with your controls - i.e. associate a CListBox with IDC_DLGS_EXPRESSIONLISTBOX etc.
see: http://www.flounder.com/getdlgitem.htm[^]
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Thanks for the help. I got it working now...I just have to get rid of all of those GetDlgItem calls now. Guess I'll be using find and replace a lot too.
|
|
|
|
|
I should have explained the cause of the problem: Creating a listbox in the dialog creates a windows listbox (identified by a handle) but not any CWnd object. MFC overloads the GetDlgItem() to return a CWnd* so that you can use all the MFC CWnd:: functions, but as there is no CWnd object, it creates a temporary one which is cleaned up later in some idle processing time. I guess that your experience shows that this cleanup doesn't usually happen during DoModal(), but does if the dialog is run modeless.
What you could get and save is the HWND of each of your controls, this would stay valid for the lifetime of the dialog window. This is what you are essentially doing when you add a CListBox data member to your class and associate it with the particular windows control in the DoDataExchange() function. The HWND of the control is set in the DDX_Control() function from the ID you provide.
Adding these data members is automated (in VC6 use the class wizard, in VS2005 simply right click on the control in the dialog editor and select "Add Variable"). Then you have a CListBox that you can use in any member function once the dialog has been created.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
|
You can write Windows Services with the Standard Edition. However, there is no wizard available for native C++ or C++/CLI. The comments about not being able to write Window Services is directed toward C++/CLI in the standard version of VS.NET since there is a Windows Service wizard in the Professional version.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Ah, thanks for clarifying. So it won't help you create one from scratch, but if you have the code you can build it. Cool.
Thanks again,
DB
|
|
|
|
|
int j;
j=4; //100
printf("\n\nj value:%d",(~j));//100-->(NOT)-->011-->So shouldn't this be 2??
It prints -5??? Why?
----------------------------
286? WOWW!
|
|
|
|
|
(4) is hex 0x00000004
~(4) is hex 0xfffffffb which is a signed integer which is (-5)
Jeron
|
|
|
|
|
_8086 wrote: 011-->So shouldn't this be 2
Actually that's 3
The ~ operator effects ALL the bits of the integer
int j;
j=4;
j=~j;
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Mark Salsbery wrote: Actually that's 3
Thanks
----------------------------
286? WOWW!
|
|
|
|
|
|
Hi
I want to compile source code of a program written under linux.
I want to compile the source under windows xp.
Is there any tool to do the port.? please suggest me any...
regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Hi
How about cygwin?
anyone familiar with it?
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
Zainu wrote: How about cygwin?
it's been a while since i've used it, but i think that if you want to run the program on XP, cygwin is the way to go. but, if you want to compile the program on XP to run on a Linux machine, the process is very complicated - IIRC, you have to rebuild all the tools (gc, the linker, the libraries, maybe even the kernel) first.
a few years ago, i needed to build an EXE that could run on a specific Linux distribution, and i went down they cygwin path for a few days, trying to get it to work; but it quickly became far too much hassle. i ended up spending a couple hundred $ to buy a cheap PC, installed the Linux distribution on it and built the EXE there. then i moved the EXE to the target computer, and got on with my life.
|
|
|
|
|
What kind of program is it ? Was it planned to be cross-platform ? If no, then as far as I know you can't do that. But it all depends of the program itself. If it is a simple console application that doesn't use any linux API, then it is cross-platfrom. If it is a program that display a GUI for instance using the Linux API, then it won't work.
|
|
|
|
|
Zainu wrote: Is there any tool to do the port.?
Yes[^]
led mike
|
|
|
|
|
AHHH I just HAD to click on the link. When it popped up I spewed root beer on my
monitor.
Thanks man.
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
cygwin is great.
I was using to compile a 3d game. For the past two days i was sitting on this.
The only problem is initial setting up of the libraries and headers and then too download the cygwin packages you require.
Regards
The Best Religion is Science.
Once you understand it, you will know God.
|
|
|
|
|
hi iam doing a project with my friends, and its about find the posbile path of the linklist
and one of the function is wrong
i got the struct
struct node
{
int v1;
int v2;
int w;
}first;
struct node[] *findposibility(int index) // is this wrong the way i call the node
{
struct node *curr;
struct node *a[5];
curr = first;
int i = 0;
while(curr->next != NULL)
{
if(index = curr->v1)
{
a[i] = cur;
i++;
}
curr == curr->next;
}
return a;
}
thanks
|
|
|
|
|
Where's the "next" member of node?
There's several problems involving uninitialized variables and your function definition.
What are you trying to do?
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
hi sory i forgot to put the next
and one of the function is wrong
i got the struct
struct node
{
int v1;
int v2;
int w;
struct node *next
}first;
struct node[] *findposibility(int index) // is this wrong the way i call the node
{
struct node *curr;
struct node *a[5];
curr = first;
int i = 0;
while(curr->next != NULL)
{
if(index = curr->v1)
{
a[i] = cur;
i++;
}
curr == curr->next;
}
return a;
}
thanks
|
|
|
|
|
One way to get your code to compile is like this (changes in red):
struct node
{
int v1;
int v2;
int w;
struct node *next;
} first;
struct <code>node **</code>findposibility(int index)
{
struct node *curr = <code>&</code>first;
<code>static</code> struct node *a[5];
int i = 0;
while(curr->next != NULL)
{
if(index <code>==</code> curr->v1)
{
a[i] = curr;
i++;
}
curr <code>=</code> curr->next;
}
return a;
}
There's still a couple problems:
1) first is not initialized
2) Is 5 the max number of hits you will ever encounter?
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
THANKS ITS HELP ME alot actually first i declare in another function but i want to ask u why i have to put static instead of struct node *a[5]?
|
|
|
|
|
arifliminto86 wrote: i want to ask u why i have to put static instead of struct node *a[5]?
That's the only way to "return a;" safely. If "a" is not static then it is a temporary variable
that only exists (its scope) in this case for the life of the function. If you return it, and
it doesn't exist after returning, then that's quite a problem.
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|