1 |
/* wptW32API.cpp - Common W32 API functions |
/* wptW32API.cpp - Common W32 API functions |
2 |
* Copyright (C) 2001, 2002, 2003 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
20 |
|
|
21 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
22 |
#include <config.h> |
#include <config.h> |
23 |
#endif |
#endif |
76 |
{ |
{ |
77 |
MENUITEMINFO mii; |
MENUITEMINFO mii; |
78 |
|
|
79 |
memset( &mii, 0, sizeof (mii) ); |
memset (&mii, 0, sizeof (mii)); |
80 |
mii.cbSize = sizeof (mii); |
mii.cbSize = sizeof (mii); |
81 |
mii.fMask = MIIM_STATE; |
mii.fMask = MIIM_STATE; |
82 |
mii.fState = state; |
mii.fState = state; |
135 |
return get_filename_dlg (hwnd, CDLG_FILE_SAVE, title, filter, name); |
return get_filename_dlg (hwnd, CDLG_FILE_SAVE, title, filter, name); |
136 |
} |
} |
137 |
|
|
138 |
const char * |
const char* |
139 |
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
get_fileopen_dlg (HWND hwnd, const char *title, const char *filter, |
140 |
const char *name) |
const char *name) |
141 |
{ |
{ |
146 |
/* Use the common dialog to allow the user to select a folder. |
/* Use the common dialog to allow the user to select a folder. |
147 |
The return value is either the folder path or NULL if cancel was chosen. */ |
The return value is either the folder path or NULL if cancel was chosen. */ |
148 |
const char* |
const char* |
149 |
get_folder_dlg (HWND hwnd, const char * title, const char * name) |
get_folder_dlg (HWND hwnd, const char *title, const char *name) |
150 |
{ |
{ |
151 |
static char folder[MAX_PATH+1] = ""; |
static char folder[MAX_PATH+1] = ""; |
152 |
BROWSEINFO bi; |
BROWSEINFO bi; |
153 |
ITEMIDLIST * il; |
ITEMIDLIST *il; |
154 |
|
|
155 |
memset (&bi, 0, sizeof (bi)); |
memset (&bi, 0, sizeof (bi)); |
156 |
bi.hwndOwner = hwnd; |
bi.hwndOwner = hwnd; |
262 |
} |
} |
263 |
|
|
264 |
|
|
265 |
/* Make a file name out of the path, the file and an extension. */ |
/* Make a file name out of the path @path, the file @file and |
266 |
|
an extension. @ext. |
267 |
|
Return value: the full file name on success. */ |
268 |
char* |
char* |
269 |
make_filename (const char *path, const char *file, const char *ext) |
make_filename (const char *path, const char *file, const char *ext) |
270 |
{ |
{ |
291 |
strcat( p, ext ); |
strcat( p, ext ); |
292 |
} |
} |
293 |
return p; |
return p; |
294 |
} /* make_filename */ |
} |
295 |
|
|
296 |
|
|
297 |
/* return 0 if it exists, otherwise >0. */ |
/* return 0 if the file @fname exists, otherwise >0. */ |
298 |
int |
int |
299 |
file_exist_check (const char * fname) |
file_exist_check (const char *fname) |
300 |
{ |
{ |
301 |
struct stat st; |
struct stat st; |
302 |
if (stat (fname, &st) == -1) |
if (stat (fname, &st) == -1) |
394 |
} |
} |
395 |
|
|
396 |
|
|
397 |
void |
/* Safe strdup version (C++ version). */ |
|
set_active_window( HWND dlg) |
|
|
{ |
|
|
activ_hwnd = dlg; |
|
|
} /* set_active_window */ |
|
|
|
|
|
void |
|
|
reset_active_window( void ) |
|
|
{ |
|
|
activ_hwnd = NULL; |
|
|
} /* reset_active_window */ |
|
|
|
|
|
|
|
|
static DWORD CALLBACK |
|
|
reminder_thread (void *ctx) |
|
|
{ |
|
|
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
|
|
|
|
|
Sleep( c->msecs ); |
|
|
SetForegroundWindow( activ_hwnd ); |
|
|
|
|
|
return 0; |
|
|
} /* reminder_thread */ |
|
|
|
|
|
|
|
|
HANDLE |
|
|
window_reminder( struct reminder_ctx_s *ctx ) |
|
|
{ |
|
|
DWORD tid = 0; |
|
|
|
|
|
return CreateThread( NULL, 0, reminder_thread, ctx, 0, &tid ); |
|
|
} /* window_reminder */ |
|
|
|
|
|
|
|
398 |
char* |
char* |
399 |
m_strdup (const char *str) |
m_strdup (const char *str) |
400 |
{ |
{ |
401 |
char * p = new char[strlen (str) + 1]; |
char *p = new char[strlen (str) + 1]; |
402 |
if (p) |
if (!p) |
403 |
strcpy (p, str); |
BUG (NULL); |
404 |
|
strcpy (p, str); |
405 |
return p; |
return p; |
406 |
} /* m_strdup */ |
} |
407 |
|
|
408 |
|
|
409 |
/* Center the hwndChild relative to parent. |
/* Center the hwndChild relative to parent. |
455 |
{ |
{ |
456 |
center_window2 (hwndChild, hwndParent, NULL); |
center_window2 (hwndChild, hwndParent, NULL); |
457 |
} |
} |
458 |
|
|
459 |
|
|
460 |
|
/* Retrieve the product verion of the given file @fname. |
461 |
|
Format: MAJOR.MINOR.PATCH1.PATCH2 |
462 |
|
Return value: 0 on success. */ |
463 |
|
int |
464 |
|
get_file_version (const char *fname, WORD *major, WORD *minor, |
465 |
|
WORD *patch1, WORD *patch2) |
466 |
|
{ |
467 |
|
VS_FIXEDFILEINFO *inf = {0}; |
468 |
|
char file[MAX_PATH+1] = {0}; |
469 |
|
LPVOID buf, data; |
470 |
|
DWORD arg; |
471 |
|
DWORD size; |
472 |
|
UINT qlen; |
473 |
|
|
474 |
|
strncpy (file, fname, MAX_PATH); |
475 |
|
size = GetFileVersionInfoSize (file, &arg); |
476 |
|
if (!size) |
477 |
|
return -1; |
478 |
|
buf = (LPVOID)new CHAR[size]; |
479 |
|
if (!buf) |
480 |
|
BUG (NULL); |
481 |
|
GetFileVersionInfo (file, 0, size, buf); |
482 |
|
|
483 |
|
qlen=0; |
484 |
|
VerQueryValue (buf, "\\", &data, &qlen); |
485 |
|
if (!qlen) { |
486 |
|
delete [] (char*)buf; |
487 |
|
return -1; |
488 |
|
} |
489 |
|
inf = (VS_FIXEDFILEINFO*)data; |
490 |
|
|
491 |
|
if (major) |
492 |
|
*major = HIWORD (inf->dwProductVersionMS); |
493 |
|
if (minor) |
494 |
|
*minor = LOWORD (inf->dwProductVersionMS); |
495 |
|
if (patch1) |
496 |
|
*patch1 = HIWORD (inf->dwProductVersionLS); |
497 |
|
if (patch2) |
498 |
|
*patch2 = LOWORD (inf->dwProductVersionLS); |
499 |
|
|
500 |
|
delete [] (char*)buf; |
501 |
|
return 0; |
502 |
|
} |
503 |
|
|
504 |
|
|
505 |
|
void |
506 |
|
set_active_window( HWND dlg) |
507 |
|
{ |
508 |
|
activ_hwnd = dlg; |
509 |
|
} /* set_active_window */ |
510 |
|
|
511 |
|
void |
512 |
|
reset_active_window( void ) |
513 |
|
{ |
514 |
|
activ_hwnd = NULL; |
515 |
|
} /* reset_active_window */ |
516 |
|
|
517 |
|
|
518 |
|
static DWORD CALLBACK |
519 |
|
reminder_thread (void *ctx) |
520 |
|
{ |
521 |
|
reminder_ctx_s *c = (reminder_ctx_s *)ctx; |
522 |
|
|
523 |
|
Sleep( c->msecs ); |
524 |
|
SetForegroundWindow( activ_hwnd ); |
525 |
|
|
526 |
|
return 0; |
527 |
|
} /* reminder_thread */ |
528 |
|
|
529 |
|
|
530 |
|
HANDLE |
531 |
|
window_reminder( struct reminder_ctx_s *ctx ) |
532 |
|
{ |
533 |
|
DWORD tid = 0; |
534 |
|
|
535 |
|
return CreateThread( NULL, 0, reminder_thread, ctx, 0, &tid ); |
536 |
|
} /* window_reminder */ |