|
That's possible, although every CWnd derived object supports SetWindowText, so my best guess is GetDlgItem is returning null.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
you right(of course in this thread it seems that my guess is ture)and i think he find problem. and i agree with GetDlgItem is returning null
whitesky
|
|
|
|
|
you said this code has problem
<br />
CEdit *pNameText;<br />
pNameText = (CEdit *) GetDlgItem(IDC_ENAME);<br />
pNameText->SetWindowText("test");<br />
Do you have IDC_ENAME in your program
and is this CEdit
whitesky
|
|
|
|
|
you know...i went back to check the ids and names of controls as you said to do...noticed that some how the names of controls in another window were being used in that window so i changed them to what they needed to be and well it works fine, now to see if i can get it to do what i need(which should be no problem at all.) thank you so much .
|
|
|
|
|
Hi
in my application I use the bellow statement.
<br />
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.begin() + 17, SortInX);<br />
its working fine.
But when I change 17 to 18 or more than 18 the application halts there.
like the bellow statements making problem.
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.begin() + 17, SortInX);<br />
std::sort(m_nOrgPtSortX.begin(), m_nOrgPtSortX.end(), SortInX);
m_nOrgPtSortX is a vector.
Please suggest any idea.
One more thing is that, when I use the vector I used push_back funtion.
So the size should increase accordingly. But the capacity() funtion shows 2048 element. and when I push more than that data it fails. I solved it by resize(5000) . But couldn't find the reason for the fail.
Regards
Anil
|
|
|
|
|
How many items are in there, more than 2000 ? Why would you want to sort the first 17, just for a test ? What about sorting 16 somewhere in the middle ? And what does your functor look like ( what's SortInX ) ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Christian Graus wrote: How many items are in there, more than 2000 ?
yes more than 2000 i.e 3050 data are there.
Christian Graus wrote: And what does your functor look like ( what's SortInX ) ?
BOOL SortInX(const Point& ptOne, const Point&ptTwo)<br />
{<br />
if( ptOne.X == ptTwo.X )<br />
return( ptOne.Y <= ptTwo.Y );<br />
<br />
return( ptOne.X < ptTwo.X);<br />
}
and the vector is like
struct Point<br />
{<br />
WORD X;<br />
WORD Y;<br />
WORD Val;<br />
};<br />
<br />
typedef std::vector < Point > CPointArray;<br />
CPointArray m_nOrgPtSortX;
Thank you very much for your reply.
Regards
Anil
-- modified at 23:00 Wednesday 7th June, 2006
std::sort(m_nOrgPtSortX.begin() + 10, m_nOrgPtSortX.begin() + 25, SortInX);
the above statement is also working
|
|
|
|
|
If I compile this in VC2005, I get an ASSERT, which seems to be saying that your function object does not return consistently, that is it doesn't return true for a < b and false for b < a. I changed it to this:
bool SortInX(const Point& ptOne, const Point&ptTwo)
{
if( ptOne.X == ptTwo.X )
return( ptOne.Y < ptTwo.Y );
return( ptOne.X < ptTwo.X);
}
and filled a list with 3000 random objects and sorted them, no problems. I reckon your list is being thrown into an endless sorting loop based on your 18th element.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Yes after changing the funtion as you told its working fine.
Thank you verry much for your supprot.
I am using STL for the first time, as used of using CArray
But I like STL after using it.
Thank you very much again.
Regards
Anil
|
|
|
|
|
Like a lot of c++ newbies, I spent a little time struggling with pointers, the address-of business, and references. I think I got a handle on it now, so I wrote this addition operator for a matrix class...
// Matrix addition (overloads the plus operator)
// Notice that the matrix is passed as a reference.
// This will be less taxing if the matrices are really big.
// However, this leaves the matrix referred to here as toAdd
// vulnerable to changes, so we add a const to the parameter.
// Returns a reference as well
matrix& operator + (const matrix &toAdd)
{
// Create a zero matrix of the same size to output.
// Allocate the memory from the heap so it won't get
// deleted after this method is called (use "new")
matrix* output = new matrix(toAdd.get_rows(), toAdd.get_cols(), 0);
matrix& outref = *output; // Create a reference to the output matrix
// Don't forget to dereference output with *
// A temporary variable to hold the sum of each element
double val;
// Go through every element and sum
for(int i = 0; i < nrows; i++)
{
for(int j = 0; j < ncols; j++)
{
// Don't forget... the indices are always one less
// than the row and column numbers
val = elements[i][j] + toAdd.get_el(i+1,j+1);
output->set_el(i+1, j+1, val); // output is a pointer so use ->
}
}
// Just return a reference, rather than a giant matrix...
return outref;
}
Can someone with more experience than me please take a look at that and make sure there's nothing funny going on? I get the right result, but I want to make sure it's actually doing everything with references. The idea is that if I need to deal with very large matrices, I only want to pass references in, and pass a reference out.
Also, I was curious why the compiler threw an error if I did
matrix output = new matrix
rather than
matrix* output
I think I'm on the right track here. If I can get confirmation that everything's ok, I should be on my way.
Thanks everyone
-Mark
|
|
|
|
|
MALDATA wrote: Also, I was curious why the compiler threw an error if I did
matrix output = new matrix
Because new only creates pointers. matrix output; is fine, as is matrix output(/*constructor parameters*/);
Operator plus has two objects to work with, why don't you work with 'this', rather than create a new one ? At least, that's how I thought it worked.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I just did that to preserve the matrices being summed. If I use "this" will that change one of the matrices involved in the sum? Seems to me that it would, but I could be wrong. Is there really a benefit to doing it that way? I figure if I'm passing by reference anyway, the only thing that'll help is by saving the memory.
Thanks for the suggestions,
-Mark
|
|
|
|
|
MALDATA wrote: If I use "this" will that change one of the matrices involved in the sum?
No, the regular aritmetic operators should not change the operands.
It's a convention that operator overloads where the first operand is of type T , are made members of class T . You don't have to write the operators that way, but making them members can make the code easier to maintain since it keeps the matrix-related code closer together.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi there,
I wanna read the boot sector of a floppy without using DeviceIoControl() function.So i just made a structure shown below;
struct boot_sector
{
char jump[3];
char name[8];
unsigned char secpercluster;
short int bytepersec;
short int reserved;
unsigned char fatcopy;
short int maxdirentry;
short int totalsec;
unsigned char mediadescriptor;
short int secperfat;
short int secoertrack;
short int noofsides;
long int hiddensectors;
long int hugesectors;
unsigned char biosdriveno;
unsigned char reservedsec;
unsigned char signature;
long int volumeid;
unsigned char volumelabel[11];
char filesystem[8];
}bt;
Now the size of the structure should be 62 bytes but vc++ compiler shows it to be 68 bytes .But i hav cross checked it using borland c++ compiler.In that also the sixe is 62 bytes. Can anybody help me out of this ,specially u nish. Suggest me something plzzzzz..
|
|
|
|
|
I'd say it has something to do with in memory padding. Why is it a problem ? Have you tried adding to parts of the struct using byte offsets to see where it's going wrong, if anywhere apart from the end ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I would agree with Mr. Graus.
Try
#pragma pack(1)
and it'll give you 62 in the Microsoft compiler
|
|
|
|
|
|
|
I am trying to develop MFC application with a CDialogBar control always active. I have added a CDialogBar object to the frame window. In the CDialog bar, I have few buttons and an image control. All works great, I can click on the button and some action takes place.
Now, I want to have an access to the button objects even if Modal dialog is showing or AfxMessageBox is showing. When a modal dialog box is called with DoModal(), internally, it gets the parent window and disables the window, which prevents the parent window from getting a message from the message pump. Since the CDialogBar is containd in the CFrameWnd object, it too gets disabled. But what I want is my CDialogBar to be enabled all the time, so it can recieved user actions, such as clicking on the button.
I tried to override the WM_ENABLE message of the frame window as well as the CDialogBar derived object, when WM_ENABLE message is posted, I ignore it if the parameter is FALSE, but that didn't do any thing.
So, how do I enable the CDialogBar object all the time?
-----------------------------------------------------------------------------------------
/* I can C */
// or !C
Yusuf
|
|
|
|
|
I have a dialog application with a handful of edit boxes. The
class CView1 is the class that handles the functions and variables
from this dialog. I have variables:
CEdit m_edit1;
and so forth.
I created some print functions in PrintForm.cpp/.h which prints
out some stuff. Id like to print out the variable m_edit1 in the
PrintForm.cpp functions, but Im just stumped. Rather than saving
the data and then retrieving it in PrintForm.cpp or making the
variables global, there has go to be a way to access m_edit1
directly. I keep getting:
ASSERT(::IsWindow(m_hWnd));
which tells me that the CView1 resource is not created. Is there
an easy way to resolve this?
Please, any response any one can give me will be greatly
appreciated.
Sincerely,
Danielle Brina (an overworked graduate student)
|
|
|
|
|
First off, the class CView1 will need to know about the dlg class so lets say the dlg class is called CMyDialog.
In your CView1 cpp file, you will need to include "mydialog.h"
/*
Note: When you do this with an SDI/MDI app, whenever you include the view, you will also need to include the doc, in that order because the view has some references to the doc that will generate errors if it can't figure out what the doc class is.
*/
Now in this class, you can call
void CView1::DoStuff()
{
CMyDialog* pWnd=(CMyDialog*)AfxGetMainWnd();
CString sEdit;
if (pWnd) {
pWnd->m_Edit1.GetWindowText(sEdit);
TRACE(sEdit);
}
}
/*
Remember that when you get asserts like that to make sure the window you are trying to get a pointer to exists. If you put this code in the constructor of CView1, for example, you will likely get asserts or errors of some kind.
*/
For other generic CWnd functions, you won't need the cast or the include.
Usually, any code that accesses the dialogs children is probably best placed in the dialog class to avoid dependent coupling like this. However, I hate it when people question "why" I'm doing this or that a certain way so as not to become a hypocrite, just consider that last statement a passing, friendly, reminder or helpful hint.;)
Take care
-- modified at 23:27 Wednesday 7th June, 2006
|
|
|
|
|
I'm writing a DLL that has to call a function after a certain event. However from all the articles I've read, you need to declare a function prototype inside the dll to be able to properly call the function.
Eg : typedef int (CALLBACK *someFunction)(const byte*, const byte*);
But what if I want to callback a function that has an arbitrary number of arguments, or return value?
Thanks.
|
|
|
|
|
I'm not sure to understand fully your question. You want to be able to call a callback without knowing in advance the number of parameters you need to send ? The only way of doing that is by using '...' in the argument list.
But this is really ugly. May I ask why you want to do that ? This looks like a bad design for me.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
The reason I need to do this, is because my dll needs to support an arbitrary callback function.
The user would "register" the callback function with the dll, by passing a function pointer. However, I need to have a prototype inside the dll anyways to callback any function.
I was thinking I could make the user pass in the parameters, and number of parameters when the function is registered, then I could push it on the stack with inline assembly before I call the function.
However, this is a little bit tardy way of doing it.
Any better suggestions?
Thanks
|
|
|
|
|
vasanth1004 wrote: The reason I need to do this, is because my dll needs to support an arbitrary callback function.
Clearly, this is something that I don't understand. Why do you want to do such a thing ? The purpose of the callback is to notify the 'registered' that something happened and in every case, the prototype of your function is the same.
vasanth1004 wrote: I was thinking I could make the user pass in the parameters, and number of parameters when the function is registered, then I could push it on the stack with inline assembly before I call the function.
However, this is a little bit tardy way of doing it.
Yes, this is quite tricky and not elegant at all
vasanth1004 wrote: Any better suggestions?
Yes, change your design so you don't have to use different prototypes .
Maybe, if you describe the situation why you need to have an arbitrary function, I can help you to find a better solution. But please, you have to describe the situation so that I can fully understand the problem (and maybe some RELEVANT code snippet can help, altough it's not necessary).
Cédric Moonen
Software developer
Charting control
|
|
|
|
|