|
Joan Murt wrote: the dialog was not modal, but in fact, I'm trying to use the PostNCDestroy override function and it seems to work well.
Which means you have a modeless dialog. Do you have something like:
CMyDialog::CMyDialog(CWnd* pParent ) : CDialog(CMyDialog::IDD, pParent)
{
Create(IDD);
}
void CMyDialog::PostNcDestroy()
{
delete this;
CDialog::PostNcDestroy();
}
...
CMyDialog *pDlg;
pDlg = new CMyDialog;
pDlg->ShowWindow(SW_SHOW);
...
pDlg->DestroyWindow();
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Well, it is a little bit more complicated (but not a lot more ) in fact there are several property sheets that have several property pages that are being created dynamically at runtime.
Then when the main dialog is getting destroyed implicitly the other dialogs that are not modal are being destroyed... As I said it seems to be working... with PostNCDestroy.
|
|
|
|
|
Joan Murt wrote: ...I've seen that somehow the destructor of some of the dialogs is not called.
How are you verifying this?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I do it by placing a breakpoint there... (Moreover I'm changing all my destructors for PostNCDestroy overriden functions and it seems that the memory allocated becomes free).
|
|
|
|
|
I'm not sure if this helps, but a common approach with modeless dialogs is for them to delete themselves in their PostNcDestroy() handler, something like this:
CMyModelessDlg *dlg = new CMyModelessDlg;
dlg->Create(...);
dlg->ShowWindow(SW_SHOW);
CMyModelessDlg::PostNcDestroy()
{
CDialog::PostNcDestroy();
delete this;
} The WM_NCDESTROY message is guaranteed to be the last Windows message sent to the dialog. The PostNcDestroy handler, which is called after the window itself has been destroyed, is the last time a member of the MFC object will be called.
Using this technique, you don't need to keep track of when the user closes the modeless dialog. If you read my sig, you'll notice I've been here before .
Software Zen: delete this;
|
|
|
|
|
Nice thing to know, and yes, it seems a software zen
The thing here is that al the dialogs are not really dialogs, they are property pages...
But again, nice to know that.
Thank you.
|
|
|
|
|
Should I free everything before CDialog::PostNcDestroy(); or there is no difference if I do it before or after?
I'm not sure, but could it be interesting to delete/free all the members of that dialog before CDialog::PostNcDestroy(); and delete this; just after?
Thank you in advance.
|
|
|
|
|
Generally speaking, I do my cleanup before the CDialog::PostNcDestroy() call. This sort of makes sense, since the calling the base class PostNcDestroy() function passes the operation 'up' the hierarchy, and any derived version of that operation should be completed first.
I use PostNcDestroy() for things like calling DeleteObject on loaded resources (bitmaps, icons, fonts, etc.). I try to make it a practice to restore the MFC object to its initialized state, in the case user of the object is going to recreate the Window that the object manages.
Software Zen: delete this;
|
|
|
|
|
|
any easy way to scan a string that a user inputs in an editbox control,
for characters and remove them from the string?
charachters like: \ / ? * : " < > |
say i have this function...
void CMyDlg::OnCheck()
{
GetDlgItemText(IDC_EDIT1, str);
//do a scan of the string to see if it contains the characters \ / ? * : " < > |
//remove them from the string
//return the string without the characters
MessageBox("Your string: "+str,"");
}
or any other way to only let the user input only a-z and A-Z characters in the editbox?
thanks.
|
|
|
|
|
you can take advantage of CString.
There is a member function that wil automatically remove the chars or substrings that you pass to it.
I think it's called .Remove("");
You should call:
UpdateData();
editboxstring.Remove("/");
From the MSDN:
CString::Remove
int CString::Remove( TCHAR ch );
Return Value
The count of characters removed from the string. Zero if the string isn't changed.
Parameters
ch
The character to be removed from a string.
Remarks
Call this member function to remove instances of ch from the string. Comparisons for the character are case-sensitive.
Example
//remove the lower-case letter 't' from a sentence:
CString str("This is a test.");
int n = str.Remove('t');
ASSERT(n == 2);
ASSERT(str == "This is a es.");
|
|
|
|
|
thanks, this really helped a lot, it worked like a charm.
|
|
|
|
|
have a look at CString::Remove .
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.
|
|
|
|
|
CString::Remove() will do that, although you'll need to call it once for each character.
|
|
|
|
|
hobbyprogrammer wrote: //do a scan of the string to see if it contains the characters \ / ? * : " < > |
//remove them from the string
//return the string without the characters
Why not just disalloow them to begin with?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hobbyprogrammer wrote: or any other way to only let the user input only a-z and A-Z characters in the editbox?
You can have look at http://www.codeproject.com/editctrl/enhfocusedit.asp[^] for some ideas on how to filter the input.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
could anyone please guide me how can i get rid of the warning messges-
warning: format '%s' expects type 'char *', but argument 3 has type 'unsigned char (*)[3]'
warning: pointer targets in passing argument 1 of 'strlen' differ in signedness
---------------------------
struct test
{
unsigned char cont_type[3];
}
hits = sscanf(argv[i], "%s",&(test.cont_type));
printf("\nSending test packets with %s.\n", test.cont_type);
if(strlen(test.cont_type)>3)
------------------
thx
|
|
|
|
|
it seems that you want to store some kind of string inside cont_type .
Holding that hypothesis, I cannot understand why are you passing &(test.cont_type) , instead of (char *)test.cont_type . Note the cast that is needed also in the following statements in order to suppress the warning.
Hope that helps.
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.. I change the data type of cont_type from unsigned char to char...and it works..
|
|
|
|
|
ikbahrian wrote: hits = sscanf(argv[i], "%s",&(test.cont_type));
test.cont_type is already an address, so there is no need to preface it with the address-of operator.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
thx..ya man you are right.
|
|
|
|
|
Thank for most who helped me to find out random fun before..
I am new to programming .. I just writing simple twenty one game..
Now my random out is like that ... k 5 6 q j .. mix char and int together randomly.. it might be suck..! now i want to add evth together to get some value (number) for twenty one game..BUT what i want is to set char with numerial value... like 'k'is 10. for example.. k +5 , the result be 17 etc.. how can set char with numberial value..here is some of my simple code..:lol:
int compcard=3,urcard;//urtotal=0,comptotal=0;
int num;
string randomChar = "kqja";
srand( (unsigned int)time( 0 ) );
cout<<"u want ?"<<endl;
cin="">>urcard;
for ( int i = 0; i < urcard; i++ ) {
if ( rand() < RAND_MAX / 2 )
//in real, ur total .. have to put.. urtotal+=.....
cout << rand() % 10 + 1 << '\n';
else
cout << randomChar[rand() % randomChar.length()] <
|
|
|
|
|
This is not the exact answer that you ask, but...
Why don't you create a vector with the values that have been appearing. this vector should be dinamically modified.
then you could show the values making an easy function that would compare some values and substitute those values for the right letters.
In this way you could work always with numbers and you would separate the data from the visualization.
Hope this helps.
|
|
|
|
|
While not a C++ solution, how about something like:
struct
{
char face;
unsigned int value;
} card[13] = {
{'2', 2},{'3', 3},{'4', 4},
{'5', 5},{'6', 6},{'7', 7},
{'8', 8},{'9', 9},{'t', 10},
{'j', 10},{'q', 10},{'k', 10},
{'a', 11}
};
void main( void )
{
srand(time(NULL));
int x = rand() % 13;
printf("Card %c is worth %u points.\n", card[x].face, card[x].value);
x = rand() % 13;
printf("Card %c is worth %u points.\n", card[x].face, card[x].value);
} You'll need to figure out how to handle the Ace, however.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Thank a lot .. .. It really work .. but when I make adding process .. it not print out the right number .. I dont know why..here is my code ..
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <string>
using namespace std;
struct
{
char face;
unsigned int value;
} card[13] = {
{'2', 2},{'3', 3},{'4', 4},
{'5', 5},{'6', 6},{'7', 7},
{'8', 8},{'9', 9},{'10', 10},
{'j', 10},{'q', 10},{'k', 10},
{'a', 11}
};
int main( void )
{
//int num
urtotal=0;
//srand(time(NULL));
srand( (unsigned int)time( 0 ) );
for (int i=0;i<4;i++)
{
int x = rand() % 13;
printf("Card %c is worth %u points.\n", card[x].face, card[x].value);
card[x].value+=card[x].value;
urtotal=card[x].value;
}
cout<<urtotal;
cin="">>num;
return 0;
}
|
|
|
|
|