OPENFILENAME ofn;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
I really don't know what the code above means...
I read through the tutorial but I still don't understand.
Please help...
OPENFILENAME ofn;
ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
I really don't know what the code above means...
I read through the tutorial but I still don't understand.
Please help...
>>OPENFILENAME ofn;
This is a structure defined in the headers of the Windows SDK. You create an instance of this structure and then initialise some of its members before using it with GetOpenFileName() or GetSaveFileName()..
>>ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
You are assigning a pointer to a literal string to the lpstrFilter member of the structure.....
This string tells the dialog box what files to list....for instance....use office or inernet explorer and try open a file....on the bottom you will have a drop down box for say HTML files......text files...word files...whatever.
This string defines how that box works.....
First you have text to describe the first type of files you want the dialog to try open (or save)........then this is ended with a NULL (remember '\0' in a string is a NULL char!!)....then you put a search criteria like "*.txt" - select all text files....then another NULL....repeat this process for all selections and end with 2 NULLs (on the example above there is only 1....but dont forget that the literal string itself is NULL terminated.....so that makes up the extra)
So the above allows you to choose Text files (files with a .txt extention)...or all files (any extention)
Fordy, wouldn't it be superfluous to put that second NULL char at the end? Wouldn't it compile to be another? Or maybe since he explicitly put one there the compiler assumes that that's the NULL one, but yet he needs another?
1978 Silver Anniversary Corvette
Very detailed explanation!!!Originally posted by Fordy
>>OPENFILENAME ofn;
This is a structure defined in the headers of the Windows SDK. You create an instance of this structure and then initialise some of its members before using it with GetOpenFileName() or GetSaveFileName()..
>>ofn.lpstrFilter = "Text Files (*.txt)\0*.txt\0All Files (*.*)\0*.*\0";
You are assigning a pointer to a literal string to the lpstrFilter member of the structure.....
This string tells the dialog box what files to list....for instance....use office or inernet explorer and try open a file....on the bottom you will have a drop down box for say HTML files......text files...word files...whatever.
This string defines how that box works.....
First you have text to describe the first type of files you want the dialog to try open (or save)........then this is ended with a NULL (remember '\0' in a string is a NULL char!!)....then you put a search criteria like "*.txt" - select all text files....then another NULL....repeat this process for all selections and end with 2 NULLs (on the example above there is only 1....but dont forget that the literal string itself is NULL terminated.....so that makes up the extra)
So the above allows you to choose Text files (files with a .txt extention)...or all files (any extention)
Really thanks your help!!
The line only has 1 NULL char as text at the end (1 * '\0')Originally posted by Garfield
Fordy, wouldn't it be superfluous to put that second NULL char at the end? Wouldn't it compile to be another?
The compiler doesnt second guess you........I havent checked, but I assume that when you put lieral text into your code, the compiler adds a line like the Define Byte instruction in MASM ...it then defines space for the amount of chars as well as a terminating NULL byte.....then it fills the memory with the chars and puts the NULL on the end......then if you add the line as above with the '\0' on the end it just so happens that the region in memory ends with 2 NULLs....which is perfect for GetOpenFileName()Originally posted by Garfield
Or maybe since he explicitly put one there the compiler assumes that that's the NULL one, but yet he needs another?
So is this:
char string[] = "This is a string";
Is this NULL terminated?
1978 Silver Anniversary Corvette
Yeah...the compiler does it for you....put this in a program and the feed it into your debugger...........When you hit the line above you will notice that string[16] = 0x00...........the NULL charOriginally posted by Garfield
So is this:
char string[] = "This is a string";
Is this NULL terminated?