Common Dialog Problem 
Author Message
 Common Dialog Problem

When I using the OpenFile Common Dialog to get a file name,
and use wsprintf to store the file name to the buffer, the string is
cut and the first few characetors are disappeared. The program as
the follow:

OPENFILENAME fn;
char wintextbuf [1024];

memset(&fn, 0, sizeof(OPENFILENAME));
fn.nMaxFile = 512;
fn.nFileOffset = 512;
fn.nFileExtension = 512;
fn.lStructSize = sizeof(OPENFILENAME);
fn.hwndOwner = hWnd;
fn.hInstance = hInst;
fn.lpstrFilter = "All Files\0*.*\0EXE Files\0*.exe\0\COM
Files\0\*.com\0\0";
fn.lpstrFile = "\0\0";
fn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY;
if (GetOpenFileName(&fn))
{
        //open file
        wsprintf(wintextbuf, "Edit File - %s". fn.lpstrFile);

Quote:
}

If the fn.lpstrFile is "C:\\DOS\\EDIT.COM", after calling wsprintf
function, wintextbuf becomes "\DOS\EDIT.COM", the previous part of the
string was disappeared. It seems that there is insufficient buffer or
wrong calling of the common dialog. If someone knows there is some
mistake or how to reinitilialize the length of the string in the



Fri, 23 Nov 2001 03:00:00 GMT  
 Common Dialog Problem
I don't think this is the right group for this question, but here's a quick
answer. Pass a pointer to a string instead of using the lpstrFile member.

char szFileName[MAX_PATH + 64];

fn.lpstrFile = &szFileName[0];

When the function returns, the szFileName var should contain the selected
file name.

Quote:

> When I using the OpenFile Common Dialog to get a file name,
> and use wsprintf to store the file name to the buffer, the string is
> cut and the first few characetors are disappeared. The program as
> the follow:

> OPENFILENAME fn;
> char wintextbuf [1024];

> memset(&fn, 0, sizeof(OPENFILENAME));
> fn.nMaxFile = 512;
> fn.nFileOffset = 512;
> fn.nFileExtension = 512;
> fn.lStructSize = sizeof(OPENFILENAME);
> fn.hwndOwner = hWnd;
> fn.hInstance = hInst;
> fn.lpstrFilter = "All Files\0*.*\0EXE Files\0*.exe\0\COM
> Files\0\*.com\0\0";
> fn.lpstrFile = "\0\0";
> fn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY;
> if (GetOpenFileName(&fn))
> {
> file://open file
> wsprintf(wintextbuf, "Edit File - %s". fn.lpstrFile);
> }

> If the fn.lpstrFile is "C:\\DOS\\EDIT.COM", after calling wsprintf
> function, wintextbuf becomes "\DOS\EDIT.COM", the previous part of the
> string was disappeared. It seems that there is insufficient buffer or
> wrong calling of the common dialog. If someone knows there is some
> mistake or how to reinitilialize the length of the string in the




Fri, 23 Nov 2001 03:00:00 GMT  
 Common Dialog Problem

Quote:

>When I using the OpenFile Common Dialog to get a file name,
>and use wsprintf to store the file name to the buffer, the string is
>cut and the first few characetors are disappeared. The program as
>the follow:

You're asking about Windows system functions, they have nothing to do with
standard C (i.e. the topic of this newsgroup). Try asking in a newsgroup
such as comp.os.ms-windows.programmer.win32.

--
-----------------------------------------


-----------------------------------------



Fri, 23 Nov 2001 03:00:00 GMT  
 Common Dialog Problem
<< When I using the OpenFile Common Dialog to get a file name, >>

No, I am sorry, C has no "OpenFile Common Dialog." Please post this message
to a newsgroup specific to your compiler.

--

Paul Lutus
www.arachnoid.com

Quote:

>When I using the OpenFile Common Dialog to get a file name,
>and use wsprintf to store the file name to the buffer, the string is
>cut and the first few characetors are disappeared. The program as
>the follow:

>OPENFILENAME fn;
>char wintextbuf [1024];

>memset(&fn, 0, sizeof(OPENFILENAME));
>fn.nMaxFile = 512;
>fn.nFileOffset = 512;
>fn.nFileExtension = 512;
>fn.lStructSize = sizeof(OPENFILENAME);
>fn.hwndOwner = hWnd;
>fn.hInstance = hInst;
>fn.lpstrFilter = "All Files\0*.*\0EXE Files\0*.exe\0\COM
>Files\0\*.com\0\0";
>fn.lpstrFile = "\0\0";
>fn.Flags = OFN_EXPLORER|OFN_HIDEREADONLY;
>if (GetOpenFileName(&fn))
>{
> //open file
> wsprintf(wintextbuf, "Edit File - %s". fn.lpstrFile);
>}

>If the fn.lpstrFile is "C:\\DOS\\EDIT.COM", after calling wsprintf
>function, wintextbuf becomes "\DOS\EDIT.COM", the previous part of the
>string was disappeared. It seems that there is insufficient buffer or
>wrong calling of the common dialog. If someone knows there is some
>mistake or how to reinitilialize the length of the string in the




Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Common Dialog problems in NT but not Win95

2. Common Dialog sample problem

3. Common Font Dialog problem

4. Common Font Dialog: problems returning the selected font

5. Color selection Common Dialog Customization problem

6. Common dialog customization problem

7. Problem with Common Dialogs and embedded Perl

8. Customizing the Common Print Dialog Box - Problem with Collate Icon

9. Customizing Common Page Setup Dialog Box problem

10. Problem with print setup common dialog

11. Cannot display the dialog derived from common file dialog

12. Nesting Common File Dialog within my Dialog

 

 
Powered by phpBB® Forum Software