1 |
/* wptW32API.cpp - Common W32 API functions |
/* wptW32API.cpp - Common W32 API functions |
2 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
42 |
extern "C" void _SHFree (void *p); |
extern "C" void _SHFree (void *p); |
43 |
|
|
44 |
|
|
|
|
|
45 |
/* Insert a new item into the menu @hm at position @pos. */ |
/* Insert a new item into the menu @hm at position @pos. */ |
46 |
void |
void |
47 |
insert_menu_item (HMENU hm, int pos, UINT m_id, const char *text) |
insert_menu_item (HMENU hm, int pos, UINT m_id, const char *text) |
129 |
get_filename_dlg (HWND hwnd, int id, const char *title, |
get_filename_dlg (HWND hwnd, int id, const char *title, |
130 |
const char *filter, const char *name) |
const char *filter, const char *name) |
131 |
{ |
{ |
132 |
static char file[512] = ""; |
static char file[2*MAX_PATH+1] = ""; |
133 |
|
char workdir[MAX_PATH+1]; |
134 |
|
char *sel_file = NULL; |
135 |
OPENFILENAME open; |
OPENFILENAME open; |
136 |
|
|
137 |
if (name && strlen (name) < (sizeof (file)-1)) |
if (name && strlen (name) < (DIM (file)-1)) |
138 |
strcpy (file, name); |
strcpy (file, name); |
139 |
else |
else |
140 |
memset (file, 0, sizeof (file)); |
memset (file, 0, sizeof (file)); |
141 |
if (!filter) |
if (!filter) |
142 |
filter = "All Files (*.*)\0*.*\0\0"; |
filter = "All Files (*.*)\0*.*\0\0"; |
143 |
/* XXX: problem with gettext because of the 'artificial' |
|
144 |
double string termination!. */ |
GetCurrentDirectory (MAX_PATH, workdir); |
145 |
memset (&open, 0, sizeof (open)); |
memset (&open, 0, sizeof (open)); |
146 |
open.lStructSize = sizeof (OPENFILENAME); |
open.lStructSize = sizeof (OPENFILENAME); |
147 |
open.hInstance = glob_hinst; |
open.hInstance = glob_hinst; |
149 |
open.lpstrFilter = filter; |
open.lpstrFilter = filter; |
150 |
open.hwndOwner = hwnd; |
open.hwndOwner = hwnd; |
151 |
open.lpstrFile = file; |
open.lpstrFile = file; |
152 |
open.nMaxFile = sizeof (file) - 1; |
open.nMaxFile = DIM (file) - 1; |
153 |
if (id == CDLG_FILE_OPEN) |
if (id == CDLG_FILE_OPEN) |
154 |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST; |
155 |
else |
else |
156 |
open.Flags = OFN_OVERWRITEPROMPT; |
open.Flags = OFN_OVERWRITEPROMPT; |
157 |
|
|
158 |
if (id == CDLG_FILE_OPEN && GetOpenFileName (&open)) |
if (id == CDLG_FILE_OPEN && GetOpenFileName (&open)) |
159 |
return open.lpstrFile; |
sel_file = open.lpstrFile; |
160 |
else if (id == CDLG_FILE_SAVE && GetSaveFileName (&open)) |
else if (id == CDLG_FILE_SAVE && GetSaveFileName (&open)) |
161 |
return open.lpstrFile; |
sel_file = open.lpstrFile; |
162 |
|
SetCurrentDirectory (workdir); |
163 |
|
|
164 |
return NULL; |
return sel_file; |
165 |
} |
} |
166 |
|
|
167 |
const char* |
const char* |
197 |
else |
else |
198 |
memset (folder, 0, sizeof (folder)); |
memset (folder, 0, sizeof (folder)); |
199 |
il = SHBrowseForFolder (&bi); |
il = SHBrowseForFolder (&bi); |
200 |
if (il) { |
if (il != NULL) { |
201 |
SHGetPathFromIDList (il, folder); |
SHGetPathFromIDList (il, folder); |
202 |
_SHFree (il); |
_SHFree (il); |
203 |
return folder; |
return folder; |
280 |
int |
int |
281 |
set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer) |
set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer) |
282 |
{ |
{ |
283 |
|
const char *fmt; |
284 |
char *p, *new_text; |
char *p, *new_text; |
285 |
|
|
286 |
p = get_clip_text (hwnd); |
p = get_clip_text (hwnd); |
287 |
if (!p) |
if (!p) |
288 |
return WPTERR_CLIP_GET; |
return WPTERR_CLIP_GET; |
289 |
new_text = new char [strlen (p)+strlen (text)+8]; |
if (as_footer == 0) |
290 |
|
fmt = "%s\r\n%s\r\n\r\n"; |
291 |
|
else |
292 |
|
fmt = "%s\n%s\n\n"; |
293 |
|
new_text = new char [strlen (p)+strlen (text)+strlen (fmt)+2]; |
294 |
if (!new_text) |
if (!new_text) |
295 |
BUG (0); |
BUG (0); |
296 |
if (as_footer == 0) |
if (as_footer == 0) |
297 |
sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p); |
sprintf (new_text, fmt, text, p); |
298 |
else |
else |
299 |
sprintf (new_text, "%s\n%s\n\n", p, text); |
sprintf (new_text, fmt, p, text); |
300 |
set_clip_text (hwnd, new_text, strlen (new_text)+1); |
set_clip_text (hwnd, new_text, strlen (new_text)+1); |
301 |
free_if_alloc (p); |
free_if_alloc (p); |
302 |
free_if_alloc (new_text); |
free_if_alloc (new_text); |
317 |
size += strlen (path); |
size += strlen (path); |
318 |
if (file && *file) |
if (file && *file) |
319 |
size += strlen (file); |
size += strlen (file); |
320 |
if( ext && *ext ) |
if (ext && *ext) |
321 |
size += strlen( ext ); |
size += strlen (ext); |
322 |
p = new char[size + 4]; |
p = new char[size + 4]; |
323 |
if (!p) |
if (!p) |
324 |
BUG (0); |
BUG (0); |
325 |
memset( p, 0, size ); |
memset (p, 0, size); |
326 |
if( path ) { |
if (path) { |
327 |
strcat( p, path ); |
strcat (p, path); |
328 |
if( path[strlen( path ) -1] != '\\' ) |
if (path[strlen (path) -1] != '\\') |
329 |
strcat( p, "\\" ); |
strcat (p, "\\"); |
330 |
} |
} |
331 |
if( file ) |
if (file != NULL) |
332 |
strcat( p, file ); |
strcat (p, file); |
333 |
if( ext ) { |
if (ext != NULL) { |
334 |
strcat( p, "." ); |
strcat (p, "."); |
335 |
strcat( p, ext ); |
strcat (p, ext); |
336 |
} |
} |
337 |
return p; |
return p; |
338 |
} |
} |
442 |
} |
} |
443 |
|
|
444 |
|
|
|
/* Safe strdup version (C++ version). */ |
|
|
char* |
|
|
m_strdup (const char *str) |
|
|
{ |
|
|
char *p = new char[strlen (str) + 1]; |
|
|
if (!p) |
|
|
BUG (NULL); |
|
|
strcpy (p, str); |
|
|
return p; |
|
|
} |
|
|
|
|
|
|
|
445 |
/* Center the hwndChild relative to parent. |
/* Center the hwndChild relative to parent. |
446 |
The style param allows to specificy additional styles (like topmost). */ |
The style param allows to specificy additional styles (like topmost). */ |
447 |
void |
void |
487 |
|
|
488 |
/* Center the given hwndChild window with no special style. */ |
/* Center the given hwndChild window with no special style. */ |
489 |
void |
void |
490 |
center_window (HWND hwndChild, HWND hwndParent) |
center_window (HWND child, HWND parent) |
491 |
{ |
{ |
492 |
center_window2 (hwndChild, hwndParent, NULL); |
center_window2 (child, parent, NULL); |
493 |
} |
} |
494 |
|
|
495 |
|
|
497 |
Format: MAJOR.MINOR.PATCH1.PATCH2 |
Format: MAJOR.MINOR.PATCH1.PATCH2 |
498 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
499 |
int |
int |
500 |
get_file_version (const char *fname, WORD *major, WORD *minor, |
get_file_version (const char *fname, |
501 |
WORD *patch1, WORD *patch2) |
WORD *major, WORD *minor, WORD *patch1, WORD *patch2) |
502 |
{ |
{ |
503 |
VS_FIXEDFILEINFO *inf; |
VS_FIXEDFILEINFO *inf; |
504 |
char file[MAX_PATH+1] = {0}; |
char file[MAX_PATH+1] = {0}; |
567 |
{ |
{ |
568 |
char tmp[32]; |
char tmp[32]; |
569 |
|
|
570 |
|
|
571 |
if (!name) { |
if (!name) { |
572 |
sprintf (tmp, "%08lX", GetTickCount ()); |
_snprintf (tmp, DIM (tmp)-1, "%08lX", GetTickCount ()); |
573 |
name = tmp; |
name = tmp; |
574 |
} |
} |
575 |
|
|
576 |
/* in the mobile mode we use a local temp folder |
/* In the mobile mode we need to use the current directory |
577 |
with the fixed name 'temp'. */ |
as the temp path because no files should be stored outside |
578 |
if (mobile_mode_active) { |
the USB disk drive. */ |
579 |
_snprintf (buf, buflen-1, "temp\\%s", name); |
#ifdef WINPT_MOBILE |
580 |
return 0; |
memset (buf, 0, buflen); |
581 |
} |
strncpy (buf, name, buflen-1); |
582 |
|
return 0; |
583 |
|
#endif |
584 |
|
|
585 |
if (!GetTempPath (buflen - strlen (name) -2, buf)) { |
if (!GetTempPath (buflen - strlen (name) -2, buf)) { |
586 |
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ()); |
log_debug ("GetTempPath() failed ec=%d\n", (int)GetLastError ()); |
587 |
return -1; |
return -1; |
588 |
} |
} |
589 |
|
|
590 |
strcat (buf, name); |
strcat (buf, name); |
591 |
return 0; |
return 0; |
592 |
} |
} |