kernel: Better support for detached processes.
[wine/gsoc_dplay.git] / dlls / commdlg / filetitle.c
blob95ce5390ac4a0572b2b3a410a664332d4f9edc5e
1 /*
2 * COMMDLG - File Dialogs
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "winternl.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "commdlg.h"
33 #include "cdlg.h"
34 #include "cdlg16.h"
35 #include "wine/unicode.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
40 /***********************************************************************
41 * GetFileTitleA (COMDLG32.@)
43 * See GetFileTitleW.
45 short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, WORD cbBuf)
47 int ret;
48 UNICODE_STRING strWFile;
49 LPWSTR lpWTitle;
51 RtlCreateUnicodeStringFromAsciiz(&strWFile, lpFile);
52 lpWTitle = RtlAllocateHeap( GetProcessHeap(), 0, cbBuf*sizeof(WCHAR));
53 ret = GetFileTitleW(strWFile.Buffer, lpWTitle, cbBuf);
54 if (!ret) WideCharToMultiByte( CP_ACP, 0, lpWTitle, -1, lpTitle, cbBuf, NULL, NULL );
55 RtlFreeUnicodeString( &strWFile );
56 RtlFreeHeap( GetProcessHeap(), 0, lpWTitle );
57 return ret;
61 /***********************************************************************
62 * GetFileTitleW (COMDLG32.@)
64 * Get the name of a file.
66 * PARAMS
67 * lpFile [I] name and location of file
68 * lpTitle [O] returned file name
69 * cbBuf [I] buffer size of lpTitle
71 * RETURNS
72 * Success: zero
73 * Failure: negative number.
75 short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, WORD cbBuf)
77 int i, len;
78 static const WCHAR brkpoint[] = {'*','[',']',0};
79 TRACE("(%p %p %d);\n", lpFile, lpTitle, cbBuf);
81 if(lpFile == NULL || lpTitle == NULL)
82 return -1;
84 len = strlenW(lpFile);
86 if (len == 0)
87 return -1;
89 if(strpbrkW(lpFile, brkpoint))
90 return -1;
92 len--;
94 if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':')
95 return -1;
97 for(i = len; i >= 0; i--)
99 if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':')
101 i++;
102 break;
106 if(i == -1)
107 i++;
109 TRACE("---> '%s'\n", debugstr_w(&lpFile[i]));
111 len = strlenW(lpFile+i)+1;
112 if(cbBuf < len)
113 return len;
115 strcpyW(lpTitle, &lpFile[i]);
116 return 0;
120 /***********************************************************************
121 * GetFileTitle (COMMDLG.27)
123 short WINAPI GetFileTitle16(LPCSTR lpFile, LPSTR lpTitle, UINT16 cbBuf)
125 return GetFileTitleA(lpFile, lpTitle, cbBuf);