|
I really hope some spam-bot picks up your E-Mail address.
I get all the news I need from the weather report - Paul Simon (from "The Only Living Boy in New York")
|
|
|
|
|
Sure. Do you want the free bowl of soup with that? Oh, and we'll bring you your slippers and the newspaper every morning as an added bonus!
We'll get right on that...
|
|
|
|
|
Did you search on the internet?
|
|
|
|
|
I need to pass a variable (via CWnd parameter) to CDialog from CWnd derived class.
I did this
CCC_Dialog_EditFile *pDlg = new CCC_Dialog_EditFile(this );
pDlg->DoModal();
In CDialog I now have CWnd pointer *pParent.
Obviously this pointer is to the base class, is it?
Silly - but I cannot figure out how to get to my calling class variables and process them in the dialog. (I tried handle etc without success.)
This is pretty basic but I am lost.
I am after displaying text data in rich text control.
I can do this in modeless dialog just fine, but I need modal dialog.
I even tried to build another constructor but the compiler did not like it.
Neither do I because the dialog would work only for specific class anyway.
CCC_Dialog_EditFile((CCC_Form_Edit*) pParent = NULL);
Just FYI here is the VC 6.0 error
error C2629: unexpected 'class CCC_Dialog_EditFile ('
error C2238: unexpected token(s) preceding ';'
Any help would be greatly appreciated.
Thanks
Vaclav
|
|
|
|
|
try:
CCC_Dialog_EditFile(CCC_Form_Edit* pParent = NULL);
|
|
|
|
|
That is the format the compiler complains about.
|
|
|
|
|
but it's not the format you posted in your original comment.
|
|
|
|
|
Sorry I missed some details here.
I tried both casts - with and without parenthesis - makes no difference
.
Get same errors.
|
|
|
|
|
Vaclav_Sal wrote: error C2629: unexpected 'class CCC_Dialog_EditFile ('
The compiler encountered a reference to CCC_Dialog_EditFile unexpectedly. What statement(s) come before it?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I tried to build a different constructor then I get this error.
class CCC_Dialog_EditFile : public CDialog
{
// Construction
public:
CCC_Dialog_EditFile(CCC_Form_Edit* pParent = NULL);
CCC_Dialog_EditFile(CWnd* pParent = NULL); // standard constructor
Anyway,
I think I found the solution. I "pull" the calling class window from the pParent handle like this
CCC_Form_Edit * pWnd = (CCC_Form_Edit*)FromHandle(pParent->m_hWnd);
Does it makes sense? It still ties the dialog to one class but it will work for now.
I am still interested in proper solution, this is a hack!
Thanks for all your input.
Cheers
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: CCC_Dialog_EditFile(CCC_Form_Edit* pParent = NULL);
CCC_Dialog_EditFile(CWnd* pParent = NULL); // standard constructor
How's the compiler going to differentiate between the two?
Vaclav_Sal wrote: Does it makes sense?
No, I'm still unclear as to what you are doing?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Vaclav_Sal wrote:
CCC_Dialog_EditFile *pDlg = new CCC_Dialog_EditFile(this );
pDlg->DoModal(); Obviously this pointer is to the base class, is it?
No. The 'this' pointer is to the parent window.
If you're wanting to have the dialog manipulate values in the parent, there are a couple of ways to do that. You can either pass pointers to the variables in the dialog's constructor, or you can pass the variable values in, and then have a way of retrieving them. I prefer the second method, since it's easier to handle the case where the use clicks the Cancel button to close the dialog.
The dialog class looks like this:
class CMyDialog : public CDialog {
public:
CMyDialog(Type1 initial_value_1,
Type2 initial_value_2,
CWnd *pParent = NULL);
void GetValues(Type1 *value_1,
Type2 *value_2,
};
CMyDialog::CMyDialog(Type1 initial_value_1,
Type2 initial_value_2,
CWnd *pParent)
: CDialog(pParent),
Value1(initial_value_1),
Value2(initial_value_2),
{
}
void CMyDialog::GetValues(Type1 *value_1,
Type2 *value_2,
{
*value_1 = Value1;
*value_2 = Value2;
} and you use it like this:
Type1 my_value_1;
Type2 my_value_2;
CMyDialog my_dialog(my_value_1,
my_value_2,
this);
if (my_dialog.DoModal() == IDOK) {
my_dialog.GetValues(&my_value_1,
&my_value_2,
);
}
Software Zen: delete this;
|
|
|
|
|
Thanks Gary,
it looks like I am getting closer to what I want to accomplish.
I cobbled this "solution"
The parrent calls the dialog with (this) pointer.
The dialog retrieves handle from passed pointer and than I build another
CWnd to get to the caller variables. ( Can't show you now because my mashine is overloaded with restoring the RAID arrays and I don't want to get any " cannnot access because it is in use ").
I have not gotten to actual work on the variables - still working on the dialog "results" actions.
I like your approch and will try it.
But...I am still curious why the "standard" constructor get the CWnd pParent and how to use this pParent pointer "properly".
Cheers
Vaclav
PS Sorry no spell check - my MS Word is in gone for couple of hours.
|
|
|
|
|
Vaclav_Sal wrote: I am still curious why the "standard" constructor get the CWnd pParent and how to use this pParent pointer "properly".
Passing the parent window to the dialog constructor lets the dialog disable the parent window if the dialog is used modally. You've seen examples of this before. For example, when you run Notepad and select File, Print, the Print dialog is modal and you're not allowed to interact with the Notepad window again until you dismiss the Print dialog.
Most of the time, passing this parent window pointer to the standard constructor is sufficient. If you need the parent window later on in the dialog for some reason, it's better to call the GetParent() function rather than use a saved copy of the parent window pointer.
Software Zen: delete this;
|
|
|
|
|
J want to add an icon i one of the column i my CGridCtrl.
Firts i add a class:
class MGrid : public CGridCtrl
{
...
public:
CImageList m_ImageList;
}
In my function Init_grid:
m_ImageList.Create(MAKEINTRESOURCE(IDB_IMAGES), 16, 1, RGB(255,255,255));
SetImageList(&m_ImageList);
(IDB_IMAGES is a smallicon.bmp file)
Now I want to add an icon in 2 column of my grid:
void MGrid::Draw_icon(int ARow)
{
int ACol = 0;
int ilosc_col = GetColumnCount();
CString str = "";
GV_ITEM Item;
for(ACol = 1; ACol <= ilosc_col; ACol++)
{
Item.row = ARow;
Item.col = ACol;
if(ACol == 2)
{
Item.mask = GVIF_TEXT;
str.Format(_T("Column %d"), ACol);
Item.strText = str;
Item.iImage = 1;
Item.mask |= (GVIF_IMAGE);
SetItem(&Item);
}
}
What I see is a string "Column 1" (..n) but there is no image in the column.
Can you help me?
Regards
mwgomez
Poland
|
|
|
|
|
hi
i have been searching an *easy* way to place pictures on a dialog box. indeed i can use the static control from the toolbox but then i'll have to use CWnd::SendMessage to change the picture at runtime. isn't there anything like the VB6 picture control or image control? i saw someone mentioning CImage somewhere but it's nowhere on the MSDN. does that mean it's a user-defined class? if anyone has ever used it please tell me. or shall i just go for the static control? thanks.
imran.
|
|
|
|
|
mr_m_imran wrote: i saw someone mentioning CImage somewhere but it's nowhere on the MSDN.
You must've been looking on that *other* MSDN:
http://msdn2.microsoft.com/en-us/library/bwea7by5(VS.80).aspx[^]
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
thanks, David. you're right. i was looking at the (NON-ATL) MFC...
|
|
|
|
|
If you want to use CImage its easy to use.
|
|
|
|
|
Is it just me, or is there no way to do a direct conversion from ANSI to UTF8 in one call? Currently, I'm converting from ANSI to UTF16, and then from UTF16 to UTF8 (MultiByteToWideChar et al). That's rather clumbsy...
|
|
|
|
|
What about the A2W() macro?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
That macro converts to UTF16 (through MultiByteToWideChar()). Basically, I'm doing WideCharToMultiByte(MultiByteToWideChar()). One call too much for my taste.
|
|
|
|
|
A2W() is an indirect wrapper around MultiByteToWideChar() . W2A() is an indirect wrapper around WideCharToMultiByte() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If by "ANSI" you mean ISO 8859-1, the nice thing is that it corresponds to Unicode code points, so you can simply "widen" them and convert to utf-8 directly (I recommend my utf8-cpp library for that )
If, on the other hand, by "ANSI" you mean Windows CP-1252 there is an area where it differs from Unicode, so you would need to map these characters first.
|
|
|
|
|
Now I'm unsure. I *think* my system settings is ISO 8859-1[5], but I'm not sure. It could also be CP-1252. Argh. I think I'll return to this problem on monday. My brain wants to go home...
|
|
|
|