|
Gofur Halmurat wrote: I want to know when IDOK is clicked On CMyAlert,
The CMyAlert dialog will have to notify the parent window that the OK button was clicked. either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked.
What is your intention ?
Do you want to have the dialog dismissed when the user clicks on Ok ?
|
|
|
|
|
Hello,
My parent window has a button, if i click the button the CMyAlert appears, and there is a button on CMyAlert, when i click the button on CMyAlert, Some changes will have to be done on parent window. How can i implement this?
either by passing a pointer to the parent to the dialog? or from the dialog, send a private message to the parent window saying the OK was clicked.
How can i implement this option? can u show me with examples?
thanks
|
|
|
|
|
are you wanting a modeless dialog by any chances ?
if not, then why don't you do the job when the modal dialog is closed ?
|
|
|
|
|
Hello,
yes, i want a modeless dialog by any changes
|
|
|
|
|
so you mustn't use DoModal() (which, as its name states, creates a Modal Dialog).
use Create() method to create it.
to have the possibility to modify the window which spamn it, you must give it a pointer to its parent (commonly, this ) as a constructor parameter
also read This[^] good article about modeless dialogs.
|
|
|
|
|
Thanks, that was what i was looking for. it helped me alot
|
|
|
|
|
And no, you can't use Create() and DoModal() - you use one or the other,
depending on whether you want a modal or a modeless dialog.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
No. By calling the Create function for your alert dialog, you've made it a modeless dialog. Calling DoModal() in this case will not work correctly.
There are two solutions here. One, use the alert dialog modally:
CMyAlert *alert = new CMyAlert;
if (alert->DoModal() == IDOK) {
message("IDOK is clicked");
}
delete alert; The second is to use your alert dialog as a modeless dialog, and have it send a user-defined message to the parent when the OK button is clicked, which is more complicated:
#define WM_MyAlertMessage (WM_USER + 1)
void CMyAlert::OnOK()
{
CWnd *parent = GetParent();
if (parent != NULL) {
parent->SendMessage(WM_MyAlertMessage,0,0);
}
}
BEGIN_MESSAGE_MAP(CMyParentWindow,CDialog)
ON_MESSAGE(WM_MyAlertMessage,OnMyAlertMessage)
END_MESSAGE_MAP()
LRESULT CMyParentWindow::OnMyAlertMessage(WPARAM ,LPARAM )
{
message("IDOK is clicked");
return (LRESULT)0;
}
Software Zen: delete this;
|
|
|
|
|
Hello everyone,
I am surprised to see that the value of sign ' is the same as \'. So, there is no need to add sign \ before sign '? In my past knowledge of sign ', we always need to add sign \ before sign '. Any comments?
Here is my simple program to test.
<br />
<br />
int main (int argc, char** argv)<br />
{<br />
char* p1 = "Hello \'World\'";<br />
char* p2 = "Hello 'World'";<br />
int result = 0;<br />
<br />
result = strcmp(p1, p2);<br />
<br />
return 0;<br />
}<br />
thanks in advance,
George
|
|
|
|
|
My friend, is quite obvious that ' is different from \' (just kidding).
Talking a bit seriously, you need such an escape sequence (that is symbol \' ) in circumstances like the following:
char c = '\'';
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi CPallini,
Actually I am also confused when I tried that,
"Hello 'World'" is the same as "Hello \'World\'". I have also tried your sample. Now I am more confused...
1. What is the rule when we should use \' or single ' ?
2. When there is no differences between \' and '? (like my Hello 'World' sample)
regards,
George
|
|
|
|
|
Hi.
You use single ' inside a string delimited by " characters
i.e.
char* p2 = "Hello 'World'";
You use the \' when iusing it as a single character that need to be quoted within ' characters
i.e.
char p1 = '\'';
Habetis bona deum
|
|
|
|
|
Good reply, thanks DoomedOne!
regards,
George
|
|
|
|
|
as C Pallini stated, you need to use \' only when the compiler can get confused.
technically, \' is the same ascii code as the character ' .
just same as \" is the same ascii code as the character " .
so, in brief, ben you use ' in a string (so, rounded with " s), you don't need to use the escapment char ( \ ).
when you use " as a single char, no need either to use \ .
some examples:
"Hello \'World\'" is the same as "Hello 'World'" .
"Hello "World"" is forbidden because the second " char is understood as the end of the string.
here, you MUST write: "Hello \"World\""
'"' is the ascii code of the " character.
''' is forbidden. here again, the second ' char is understood as the end of the character specification.
You MUST write: '\'' .
get it now ?
subsidiary question: please, for god' sake, in what school level are you, and how old are you ? i'm not judging you, i'm questionning myself.
|
|
|
|
|
Cool toxcct!
I must save your reply to somewhere.
regards,
George
|
|
|
|
|
hi,
I am using the function ConvertResourceStringIdToLptstr() to assign the value of the TV_INSERTSTRUCT's pszText for the creation/initialization of a TreeCtrl. (or) to convert the 'resource string' into a pointer to a character string.
<br />
LPTSTR COperDialog::ConvertResourceStringIdToLptstr(UINT nResString)<br />
{<br />
CString strLoad;<br />
strLoad.LoadString(nResString);<br />
LPTSTR lpsz = new TCHAR[strLoad.GetLength()+1];<br />
CHECK_FOR_NULL(lpsz)<br />
_tcscpy(lpsz,strLoad);<br />
return lpsz;<br />
}<br />
And the fuction is used in:
<br />
void COperDialog::AddProjectRootItem()<br />
{<br />
TV_INSERTSTRUCT curTreeItem;<br />
<br />
curTreeItem.hParent =TVI_ROOT ;<br />
curTreeItem.hInsertAfter = TVI_ROOT ;<br />
curTreeItem.item.iImage = 0;<br />
curTreeItem.item.iSelectedImage = 0;<br />
<br />
curTreeItem.item.pszText = ConvertResourceStringIdToLptstr(IDS_PROJECT);<br />
curTreeItem.item.cchTextMax=15;<br />
<br />
curTreeItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;<br />
<br />
htrProjectRoot = m_Edit->InsertItem(&curTreeItem); <br />
<br />
}<br />
In this situation i am getting memory leaks in ConvertResourceStringIdToLptstr().
So to avoid that where should i insert the delete[]? If i use it inside the function - ConvertResourceStringIdToLptstr() i am not able to get the string displayed!
Kindly give sugesstions!!
Priya Sundar
|
|
|
|
|
You can use the pointer as member or global variable, fill it, use it and when you dont need it anymore... use delete. That way you will have the control about the pointer along the whole class / project.
LPSTR pMyLpstr;
.
pMyLpstr = NULL;
.
LPTSTR COperDialog::ConvertResourceStringIdToLptstr(UINT nResString)
{
CString strLoad;
strLoad.LoadString(nResString);
pMyLpstr = new TCHAR[strLoad.GetLength()+1];
CHECK_FOR_NULL(pMyLpstr)
_tcscpy(pMyLpstr,strLoad);
return pMyLpstr;
}
.
void COperDialog::AddProjectRootItem()
{
TV_INSERTSTRUCT curTreeItem;
curTreeItem.hParent =TVI_ROOT ;
curTreeItem.hInsertAfter = TVI_ROOT ;
curTreeItem.item.iImage = 0;
curTreeItem.item.iSelectedImage = 0;
curTreeItem.item.pszText = ConvertResourceStringIdToLptstr(IDS_PROJECT);
delete [] pMyLpstr;
pMyLpstr = NULL;
curTreeItem.item.cchTextMax=15;
curTreeItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
htrProjectRoot = m_Edit->InsertItem(&curTreeItem);
}
.
delete [] pMyLpstr;
pMyLpstr = NULL;
Hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
That way you have to be very careful.
I think it is an hazardous design.
Probably it would be better if both memory allocation and deallocation are delegated to the caller (e.g. the standard behaviour of Windows API).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi,
CPallini wrote: Probably it would be better if both memory allocation and deallocation are delegated to the caller (e.g. the standard behaviour of Windows API).
I didnot understand what you are referring to??
Priya Sundar
|
|
|
|
|
Was a note on Nelek suggestion.
For instance GetWindowText WIN32 API work that way, the caller has to
(1) Allocate a buffer
const int SIZE = 256;
TCHAR * buffer = new TCHAR[SIZE];
(2) pass it (together as is size) as function argument
if ( buffer)
{
GetWindowText(hWnd, buffer, SIZE);
}
(3) release the buffer
if (buffer) delete buffer;
buffer = NULL;
BTW all the above stuff can be done (and the life will be easier...) using the stack instead of the heap.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Can you explain a bit what are you referring to? I don't understand you well and I want to learn more.
That this is not the best option... I agree (I know I am just a low/middle skilled programmer that needs to learn more), but... what do you mean with the standard behaviour of windows api? can you put an example?
Maybe something like this?
LPTSTR COperDialog::ConvertResourceStringIdToLptstr(UINT nResString, LPSTR pStr)
{
CString strLoad;
strLoad.LoadString(nResString);
pStr = new TCHAR[strLoad.GetLength()+1];
CHECK_FOR_NULL(pStr)
_tcscpy(pStr,strLoad);
return pStr;
}
void COperDialog::AddProjectRootItem()
{
TV_INSERTSTRUCT curTreeItem;
curTreeItem.hParent =TVI_ROOT;
curTreeItem.hInsertAfter = TVI_ROOT;
curTreeItem.item.iImage = 0;
curTreeItem.item.iSelectedImage = 0;
;
LPSTR pMyLpstr = NULL;
curTreeItem.item.pszText = ConvertResourceStringIdToLptstr(IDS_PROJECT, pMyLpstr);
;
delete [] pMyLpstr; pMyLpstr = NULL;
curTreeItem.item.cchTextMax=15;
curTreeItem.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
htrProjectRoot = m_Edit->InsertItem(&curTreeItem);
}
Is this option better than the other one?
-- modified at 8:11 Friday 23rd November, 2007
-- modified at 8:12 Friday 23rd November, 2007
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: Maybe something like this?
No.
Nelek wrote: LPTSTR COperDialog::ConvertResourceStringIdToLptstr(UINT nResString, LPSTR pStr) //parameter added
The parameter added is irrelevant.
I meant the standard behaviour of WIN32 API, for instance:
int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount );
The above function doesn't allocate the buffer, it relies on the one allocated by the caller.
Please note that your suggestion is a perfectly viable solution I only noted that it must be handled with care.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yes, it can be viable, but I prefer to know the best ways to do things.
CPallini wrote: int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount );
The above function doesn't allocate the buffer, it relies on the one allocated by the caller.
So before calling the function you have to create the LPTSTR lpString to give him as a parameter, and after the use delete it. And what is the difference with my second option? That the new is inside the function that is being called? For this schema... how can be dealed? To use the new, it must be known the length of the loadString that is calculated inside the called function. (I know, resctructurating and not using the function is a solution)
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: And what is the difference with my second option? That the new is inside the function that is being called?
Yes, the caller has total responsibility on buffer allocation/deletion. This, IMHO is a quite acceptable design choice.
On the other hand, I insist on saying that yours is a viable solution.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for answering,
CPallini wrote: On the other hand, I insist on saying that yours is a viable solution.
I know. But I want to learn, and be better. I like to programm against idiots (although I know is very complicated) and my programms usually are working in 99% of time and situations. But that doesn't mean that are "designly correct". I actually studied electronic engineering not informatic. But that doesn't mean that I may not be able to be a good programer, if I learn with the bests
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|