/[winpt]/trunk/Src/wptW32API.cpp
ViewVC logotype

Diff of /trunk/Src/wptW32API.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 32 by twoaday, Mon Oct 24 08:03:48 2005 UTC revision 36 by werner, Thu Oct 27 15:25:13 2005 UTC
# Line 1  Line 1 
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 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
6   * WinPT is free software; you can redistribute it and/or modify   * WinPT is free software; you can redistribute it and/or modify
7   * it under the terms of the GNU General Public License as published by   * it under the terms of the GNU General Public License as published by
8   * the Free Software Foundation; either version 2 of the License, or   * the Free Software Foundation; either version 2 of the License, or
9   * (at your option) any later version.   * (at your option) any later version.
10   *   *
11   * WinPT is distributed in the hope that it will be useful,   * WinPT is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.   * GNU General Public License for more details.
15   *   *
16   * You should have received a copy of the GNU General Public License   * You should have received a copy of the GNU General Public License
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  #include <windows.h>  #ifdef HAVE_CONFIG_H
22  #include <stdio.h>  #include <config.h>
23  #include <sys/types.h>  #endif
24  #include <sys/stat.h>  
25  #include <shellapi.h>  #include <windows.h>
26  #include <shlobj.h>  #include <windows.h>
27  #include <commctrl.h>  #include <stdio.h>
28    #include <sys/types.h>
29  #include "wptNLS.h"  #include <sys/stat.h>
30  #include "wptW32API.h"  #include <shellapi.h>
31  #include "wptErrors.h"  #include <shlobj.h>
32  #include "wptVersion.h"  #include <commctrl.h>
33  #include "wptTypes.h"  
34    #include "wptNLS.h"
35    #include "wptW32API.h"
36  extern "C" void _SHFree (void *p);  #include "wptErrors.h"
37    #include "wptVersion.h"
38    #include "wptTypes.h"
39  static void  
40  set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text)  
41  {  extern "C" void _SHFree (void *p);
42      MENUITEMINFO mii;  
43        
44      memset (&mii, 0, sizeof mii);  static void
45      mii.cbSize = sizeof mii;  set_menu_text_ext (HMENU menu, int by_pos, int m_uid, const char *text)
46      mii.fMask = MIIM_TYPE;  {
47      mii.fType = MFT_STRING;      MENUITEMINFO mii;
48      mii.dwTypeData = (char *) text;      
49      SetMenuItemInfo (menu, m_uid, by_pos? TRUE : FALSE, &mii);      memset (&mii, 0, sizeof mii);
50  }      mii.cbSize = sizeof mii;
51        mii.fMask = MIIM_TYPE;
52        mii.fType = MFT_STRING;
53  /* Set the text of a menu item @m_uid to @text. */      mii.dwTypeData = (char *) text;
54  void      SetMenuItemInfo (menu, m_uid, by_pos? TRUE : FALSE, &mii);
55  set_menu_text (HMENU menu, int m_uid, const char *text)  }
56  {  
57      set_menu_text_ext (menu, 0, m_uid, text);  
58  }  /* Set the text of a menu item @m_uid to @text. */
59    void
60    set_menu_text (HMENU menu, int m_uid, const char *text)
61  /* Set the text of a menu item with the position @pos to @text. */  {
62  void      set_menu_text_ext (menu, 0, m_uid, text);
63  set_menu_text_bypos (HMENU menu, int pos, const char *text)  }
64  {  
65      set_menu_text_ext (menu, 1, pos, text);  
66  }  /* Set the text of a menu item with the position @pos to @text. */
67    void
68    set_menu_text_bypos (HMENU menu, int pos, const char *text)
69  /* Set the state of a menu item @m_uid to @state. */  {
70  void      set_menu_text_ext (menu, 1, pos, text);
71  set_menu_state (HMENU menu, int m_uid, int state)  }
72  {        
73      MENUITEMINFO mii;  
74    /* Set the state of a menu item @m_uid to @state. */
75      memset( &mii, 0, sizeof (mii) );  void
76      mii.cbSize = sizeof (mii);  set_menu_state (HMENU menu, int m_uid, int state)
77      mii.fMask = MIIM_STATE;  {      
78      mii.fState = state;      MENUITEMINFO mii;
79      SetMenuItemInfo (menu, m_uid, FALSE, &mii);  
80  }      memset( &mii, 0, sizeof (mii) );
81        mii.cbSize = sizeof (mii);
82        mii.fMask = MIIM_STATE;
83        mii.fState = state;
84  /* Use the common dialog to request a file from the user.      SetMenuItemInfo (menu, m_uid, FALSE, &mii);
85     id can be either FILE_OPEN or FILE_SAVE.  }
86     The return value is the file name or NULL if cancel was chosen. */  
87  const char *  
88  get_filename_dlg (HWND hwnd, int id, const char * title,  
89                    const char * filter, const char * name)  /* Use the common dialog to request a file from the user.
90  {     id can be either FILE_OPEN or FILE_SAVE.
91      static char file[512] = "";     The return value is the file name or NULL if cancel was chosen. */
92      OPENFILENAME open;  const char *
93        get_filename_dlg (HWND hwnd, int id, const char * title,
94      if (name && strlen (name) < (sizeof (file)-1))                    const char * filter, const char * name)
95          strcpy (file, name);  {
96      else      static char file[512] = "";
97          memset (file, 0, sizeof (file));      OPENFILENAME open;
98      if (!filter)      
99          filter = _("All Files (*.*)\0*.*\0\0");      if (name && strlen (name) < (sizeof (file)-1))
100      /* XXX: problem with gettext because of the 'artificial'          strcpy (file, name);
101              double string termination!. */      else
102      memset (&open, 0, sizeof (open));          memset (file, 0, sizeof (file));
103      open.lStructSize = sizeof (OPENFILENAME);      if (!filter)
104      open.hInstance = glob_hinst;          filter = _("All Files (*.*)\0*.*\0\0");
105      open.lpstrTitle = title;      /* XXX: problem with gettext because of the 'artificial'
106      open.lpstrFilter = filter;              double string termination!. */
107      open.hwndOwner = hwnd;      memset (&open, 0, sizeof (open));
108      open.lpstrFile = file;      open.lStructSize = sizeof (OPENFILENAME);
109      open.nMaxFile = sizeof (file) - 1;      open.hInstance = glob_hinst;
110      if (id == FILE_OPEN)      open.lpstrTitle = title;
111          open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;      open.lpstrFilter = filter;
112      else      open.hwndOwner = hwnd;
113          open.Flags = OFN_OVERWRITEPROMPT;      open.lpstrFile = file;
114        open.nMaxFile = sizeof (file) - 1;
115      if (id == FILE_OPEN && GetOpenFileName (&open))      if (id == FILE_OPEN)
116          return open.lpstrFile;          open.Flags = OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST;
117      else if (id == FILE_SAVE && GetSaveFileName (&open))      else
118          return open.lpstrFile;          open.Flags = OFN_OVERWRITEPROMPT;
119        
120      return NULL;      if (id == FILE_OPEN && GetOpenFileName (&open))
121  }          return open.lpstrFile;
122        else if (id == FILE_SAVE && GetSaveFileName (&open))
123  const char*          return open.lpstrFile;
124  get_filesave_dlg (HWND hwnd, const char *title,      
125                    const char *filter, const char *name)      return NULL;
126  {  }
127      return get_filename_dlg (hwnd, FILE_SAVE, title, filter, name);  
128  }  const char*
129    get_filesave_dlg (HWND hwnd, const char *title,
130  const char *                    const char *filter, const char *name)
131  get_fileopen_dlg (HWND hwnd, const char *title, const char *filter,  {
132                    const char *name)      return get_filename_dlg (hwnd, FILE_SAVE, title, filter, name);
133  {  }
134      return get_filename_dlg (hwnd, FILE_OPEN, title, filter, name);  
135  }  const char *
136    get_fileopen_dlg (HWND hwnd, const char *title, const char *filter,
137                      const char *name)
138  /* Use the common dialog to allow the user to select a folder.  {
139     The return value is either the folder path or NULL if cancel was chosen. */      return get_filename_dlg (hwnd, FILE_OPEN, title, filter, name);
140  const char*  }
141  get_folder_dlg (HWND hwnd, const char * title, const char * name)  
142  {  
143      static char folder[MAX_PATH+1] = "";  /* Use the common dialog to allow the user to select a folder.
144      BROWSEINFO bi;     The return value is either the folder path or NULL if cancel was chosen. */
145      ITEMIDLIST * il;  const char*
146    get_folder_dlg (HWND hwnd, const char * title, const char * name)
147      memset (&bi, 0, sizeof (bi));  {
148      bi.hwndOwner = hwnd;      static char folder[MAX_PATH+1] = "";
149      if (title)      BROWSEINFO bi;
150          bi.lpszTitle = title;      ITEMIDLIST * il;
151      if (name && strlen (name) < MAX_PATH-1)  
152          strcpy (folder, name);      memset (&bi, 0, sizeof (bi));
153      else      bi.hwndOwner = hwnd;
154          memset (folder, 0, sizeof (folder));      if (title)
155      il = SHBrowseForFolder (&bi);          bi.lpszTitle = title;
156      if (il) {      if (name && strlen (name) < MAX_PATH-1)
157          SHGetPathFromIDList (il, folder);          strcpy (folder, name);
158          _SHFree (il);      else
159          return folder;          memset (folder, 0, sizeof (folder));
160      }      il = SHBrowseForFolder (&bi);
161      return NULL;      if (il) {
162  }          SHGetPathFromIDList (il, folder);
163            _SHFree (il);
164            return folder;
165  /* Return the clipboard contents as a string or NULL      }
166     if the clipboard does not contain text. */      return NULL;
167  char*  }
168  get_clip_text (HWND hwnd)  
169  {  
170      HANDLE clipmem;  /* Return the clipboard contents as a string or NULL
171      char *cliptxt, *p;       if the clipboard does not contain text. */
172      int len;  char*
173        get_clip_text (HWND hwnd)
174      if (OpenClipboard (hwnd) == FALSE)  {
175          return NULL;      HANDLE clipmem;
176      clipmem = GetClipboardData (CF_TEXT);      char *cliptxt, *p;  
177      if (clipmem == NULL) {      int len;
178          p = NULL;      
179          goto leave;      if (OpenClipboard (hwnd) == FALSE)
180      }          return NULL;
181      cliptxt = (char *) GlobalLock (clipmem);      clipmem = GetClipboardData (CF_TEXT);
182      if (cliptxt == NULL) {      if (clipmem == NULL) {
183          p = NULL;          p = NULL;
184          goto leave;          goto leave;
185      }      }
186            cliptxt = (char *) GlobalLock (clipmem);
187      len =  strlen (cliptxt);      if (cliptxt == NULL) {
188      p = new char[len + 1];          p = NULL;
189      if (!p)          goto leave;
190          BUG (NULL);      }
191      memcpy (p, cliptxt, len);      
192      p[len] = '\0';      len =  strlen (cliptxt);
193      GlobalUnlock (clipmem);      p = new char[len + 1];
194            if (!p)
195  leave:          BUG (NULL);
196      CloseClipboard ();      memcpy (p, cliptxt, len);
197      return p;      p[len] = '\0';
198  }      GlobalUnlock (clipmem);
199        
200    leave:
201  /* Set @text as the new clipboard content. */      CloseClipboard ();
202  int      return p;
203  set_clip_text (HWND hwnd, const char *text, int nbytes)  }
204  {      
205      HANDLE clipmem;  
206      int rc = 0;  /* Set @text as the new clipboard content. */
207      char *p;  int
208        set_clip_text (HWND hwnd, const char *text, int nbytes)
209      if (OpenClipboard (hwnd) == FALSE)    {    
210          return WPTERR_CLIP_OPEN;      HANDLE clipmem;
211      EmptyClipboard ();      int rc = 0;
212        char *p;
213      clipmem = GlobalAlloc (GHND, nbytes + 1);      
214      if (clipmem == NULL)      if (OpenClipboard (hwnd) == FALSE)  
215          BUG (NULL);          return WPTERR_CLIP_OPEN;
216      p = (char *) GlobalLock (clipmem);      EmptyClipboard ();
217      if (p == NULL) {  
218          rc = WPTERR_GENERAL;;      clipmem = GlobalAlloc (GHND, nbytes + 1);
219          goto leave;          if (clipmem == NULL)
220      }          BUG (NULL);
221      memcpy (p, text, nbytes);      p = (char *) GlobalLock (clipmem);
222      p[nbytes] = '\0';      if (p == NULL) {
223                rc = WPTERR_GENERAL;;
224      GlobalUnlock (clipmem);          goto leave;    
225      SetClipboardData (CF_TEXT, clipmem);      }
226            memcpy (p, text, nbytes);
227  leave:      p[nbytes] = '\0';
228      CloseClipboard ();      
229      return rc;      GlobalUnlock (clipmem);
230  } /* set_clip_text */      SetClipboardData (CF_TEXT, clipmem);
231        
232    leave:
233  /* Append or prepend some text to the clipboard contents.      CloseClipboard ();
234     If as_footer = 1, append the text otherwise prepend. */      return rc;
235  int  } /* set_clip_text */
236  set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer)  
237  {  
238      char *p, *new_text;  /* Append or prepend some text to the clipboard contents.
239       If as_footer = 1, append the text otherwise prepend. */
240      p = get_clip_text (hwnd);  int
241      if (!p)  set_clip_text2 (HWND hwnd, const char *text, int nbytes, int as_footer)
242          return WPTERR_CLIP_GET;  {
243      new_text = new char [strlen (p)+strlen (text)+8];      char *p, *new_text;
244      if (!new_text)  
245          BUG (0);      p = get_clip_text (hwnd);
246      if (as_footer == 0)      if (!p)
247          sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p);          return WPTERR_CLIP_GET;
248      else      new_text = new char [strlen (p)+strlen (text)+8];
249          sprintf (new_text, "%s\n%s\n\n", p, text);      if (!new_text)
250      set_clip_text (hwnd, new_text, strlen (new_text)+1);          BUG (0);
251      free_if_alloc (p);      if (as_footer == 0)
252      free_if_alloc (new_text);          sprintf (new_text, "%s\r\n%s\r\n\r\n", text, p);
253      return 0;      else
254  }          sprintf (new_text, "%s\n%s\n\n", p, text);
255        set_clip_text (hwnd, new_text, strlen (new_text)+1);
256        free_if_alloc (p);
257  /* Make a file name out of the path, the file and an extension. */      free_if_alloc (new_text);
258  char*      return 0;
259  make_filename (const char *path, const char *file, const char *ext)  }
260  {  
261      char *p;  
262      size_t size = 0;  /* Make a file name out of the path, the file and an extension. */
263    char*
264      if( path && *path )  make_filename (const char *path, const char *file, const char *ext)
265          size += strlen( path );  {
266      if( file && *file )      char *p;
267          size += strlen( file );      size_t size = 0;
268      if( ext && *ext )  
269          size += strlen( ext );      if( path && *path )
270      p = new char[size + 4];          size += strlen( path );
271      memset( p, 0, size );      if( file && *file )
272      if( path ) {          size += strlen( file );
273          strcat( p, path );      if( ext && *ext )
274          if( path[strlen( path ) -1] != '\\' )          size += strlen( ext );
275              strcat( p, "\\" );      p = new char[size + 4];
276      }      memset( p, 0, size );
277      if( file )      if( path ) {
278          strcat( p, file );          strcat( p, path );
279      if( ext ) {          if( path[strlen( path ) -1] != '\\' )
280          strcat( p, "." );              strcat( p, "\\" );
281          strcat( p, ext );      }
282      }      if( file )
283      return p;          strcat( p, file );
284  } /* make_filename */      if( ext ) {
285            strcat( p, "." );
286            strcat( p, ext );
287  /* return 0 if it exists, otherwise >0. */      }
288  int      return p;
289  file_exist_check (const char * fname)  } /* make_filename */
290  {  
291      struct stat st;  
292      if (stat (fname, &st) == -1)  /* return 0 if it exists, otherwise >0. */
293          return WPTERR_FILE_EXIST;  int
294      return 0;  file_exist_check (const char * fname)
295  }  {
296        struct stat st;
297        if (stat (fname, &st) == -1)
298  /* Check if the current folder exists.          return WPTERR_FILE_EXIST;
299     Return 0 for success. */      return 0;
300  int  }
301  dir_exist_check (const char *dir)  
302  {  
303      struct stat statbuf;      /* Check if the current folder exists.
304           Return 0 for success. */
305      if( stat( dir, &statbuf ) == -1 )  int
306          return WPTERR_GENERAL;  dir_exist_check (const char *dir)
307      if( statbuf.st_mode & _S_IFDIR )  {
308          return 0;      struct stat statbuf;    
309      return WPTERR_GENERAL;      
310  }      if( stat( dir, &statbuf ) == -1 )
311            return WPTERR_GENERAL;
312        if( statbuf.st_mode & _S_IFDIR )
313  /* Return the file size of the given file. */          return 0;
314  size_t      return WPTERR_GENERAL;
315  get_file_size (const char *fname)  }
316  {  
317      size_t fsize;  
318      HANDLE fh;  /* Return the file size of the given file. */
319    size_t
320      fh = CreateFile( fname, GENERIC_READ, FILE_SHARE_READ,  get_file_size (const char *fname)
321                      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );  {
322      if( fh == INVALID_HANDLE_VALUE )      size_t fsize;
323          return 0;      HANDLE fh;
324      fsize = GetFileSize( fh, NULL );  
325      if( fsize == 0xFFFFFFFF )      fh = CreateFile( fname, GENERIC_READ, FILE_SHARE_READ,
326          fsize = 0;                      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
327      CloseHandle( fh );      if( fh == INVALID_HANDLE_VALUE )
328      return fsize;          return 0;
329  } /* get_file_size */      fsize = GetFileSize( fh, NULL );
330        if( fsize == 0xFFFFFFFF )
331            fsize = 0;
332  int      CloseHandle( fh );
333  init_file_lock( LOCK *ctx, const char *file )      return fsize;
334  {  } /* get_file_size */
335        
336      ctx->size = get_file_size( file );  
337      ctx->file = m_strdup( file );  int
338      ctx->fh = CreateFile( file, GENERIC_READ, FILE_SHARE_READ, NULL,  init_file_lock( LOCK *ctx, const char *file )
339                           OPEN_ALWAYS, 0, NULL );  {
340      if( ctx->fh == INVALID_HANDLE_VALUE )      
341          return WPTERR_GENERAL;      ctx->size = get_file_size( file );
342      if( LockFile( ctx->fh, 0, 0, ctx->size, 0 ) == FALSE ) {      ctx->file = m_strdup( file );
343          CloseHandle( ctx->fh );      ctx->fh = CreateFile( file, GENERIC_READ, FILE_SHARE_READ, NULL,
344          ctx->fh = INVALID_HANDLE_VALUE;                           OPEN_ALWAYS, 0, NULL );
345          ctx->size = 0;      if( ctx->fh == INVALID_HANDLE_VALUE )
346          free( ctx->file );          return WPTERR_GENERAL;
347          return WPTERR_GENERAL;      if( LockFile( ctx->fh, 0, 0, ctx->size, 0 ) == FALSE ) {
348      }          CloseHandle( ctx->fh );
349      return 0;          ctx->fh = INVALID_HANDLE_VALUE;
350  } /* init_file_lock */          ctx->size = 0;
351            free( ctx->file );
352            return WPTERR_GENERAL;
353  void      }
354  release_file_lock( LOCK *ctx )      return 0;
355  {  } /* init_file_lock */
356      free_if_alloc( ctx->file );  
357      ctx->file = NULL;  
358      ctx->size = 0;  void
359      CloseHandle( ctx->fh );  release_file_lock( LOCK *ctx )
360  } /* release_file_lock */  {
361        free_if_alloc( ctx->file );
362        ctx->file = NULL;
363  /* Start a dialog with the exception that before it is checked that the      ctx->size = 0;
364     dialog is not already openened. */      CloseHandle( ctx->fh );
365  int  } /* release_file_lock */
366  dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc,  
367                                    LPARAM param, LPCTSTR title, int title_id )  
368  {  /* Start a dialog with the exception that before it is checked that the
369      #ifndef LANG_DE     dialog is not already openened. */
370      if( FindWindowEx( GetDesktopWindow(), NULL, NULL, title ) )  int
371          return -1;        dialog_box_param( HINSTANCE hinst, LPCTSTR name, HWND parent, DLGPROC fnc,
372      #else                                    LPARAM param, LPCTSTR title, int title_id )
373      char strdesc[256];  {
374      LoadString( glob_hinst, title_id, strdesc, sizeof (strdesc) -1 );      #ifndef LANG_DE
375      if( FindWindowEx( GetDesktopWindow(), NULL, NULL, strdesc ) )      if( FindWindowEx( GetDesktopWindow(), NULL, NULL, title ) )
376          return -1;          return -1;      
377      #endif      #else
378            char strdesc[256];
379      return DialogBoxParam( hinst, name, parent, fnc, param );      LoadString( glob_hinst, title_id, strdesc, sizeof (strdesc) -1 );
380  } /* dialog_box_param */      if( FindWindowEx( GetDesktopWindow(), NULL, NULL, strdesc ) )
381            return -1;
382        #endif
383  /* Wrapper for message box which forces the message box into the      
384     foreground and it is displayed always on top. */      return DialogBoxParam( hinst, name, parent, fnc, param );
385  int  } /* dialog_box_param */
386  msg_box (HWND hwnd, const char *text, const char *title, int mode)  
387  {  
388      mode |= MB_SETFOREGROUND;  /* Wrapper for message box which forces the message box into the
389      mode |= MB_TASKMODAL;     foreground and it is displayed always on top. */
390      mode |= MB_TOPMOST;  int
391      return MessageBox(hwnd, text, title, mode);  msg_box (HWND hwnd, const char *text, const char *title, int mode)
392  }  {
393        mode |= MB_SETFOREGROUND;
394        mode |= MB_TASKMODAL;
395  void      mode |= MB_TOPMOST;
396  set_active_window( HWND dlg)      return MessageBox(hwnd, text, title, mode);
397  {        }
398      activ_hwnd = dlg;  
399  } /* set_active_window */  
400    void
401  void  set_active_window( HWND dlg)
402  reset_active_window( void )  {      
403  {            activ_hwnd = dlg;
404      activ_hwnd = NULL;  } /* set_active_window */
405  } /* reset_active_window */  
406    void
407    reset_active_window( void )
408  static DWORD CALLBACK  {      
409  reminder_thread (void *ctx)      activ_hwnd = NULL;
410  {  } /* reset_active_window */
411      reminder_ctx_s *c = (reminder_ctx_s *)ctx;  
412    
413      Sleep( c->msecs );  static DWORD CALLBACK
414      SetForegroundWindow( activ_hwnd );  reminder_thread (void *ctx)
415    {
416      return 0;      reminder_ctx_s *c = (reminder_ctx_s *)ctx;
417  } /* reminder_thread */  
418        Sleep( c->msecs );
419        SetForegroundWindow( activ_hwnd );
420  HANDLE  
421  window_reminder( struct reminder_ctx_s *ctx )      return 0;
422  {  } /* reminder_thread */
423      DWORD tid = 0;  
424        
425      return CreateThread( NULL, 0, reminder_thread, ctx, 0, &tid );  HANDLE
426  } /* window_reminder */  window_reminder( struct reminder_ctx_s *ctx )
427    {
428        DWORD tid = 0;
429  char*      
430  m_strdup (const char *str)      return CreateThread( NULL, 0, reminder_thread, ctx, 0, &tid );
431  {  } /* window_reminder */
432      char * p = new char[strlen (str) + 1];  
433      if (p)  
434          strcpy (p, str);  char*
435      return p;  m_strdup (const char *str)
436  } /* m_strdup */  {
437        char * p = new char[strlen (str) + 1];
438        if (p)
439  /* Center the hwndChild relative to parent.          strcpy (p, str);
440     The style param allows to specificy additional styles (like topmost). */      return p;
441  void  } /* m_strdup */
442  center_window2 (HWND hwndChild, HWND parent, HWND style)  
443  {      
444      HWND hwndParent;  /* Center the hwndChild relative to parent.
445      RECT rChild, rParent;         The style param allows to specificy additional styles (like topmost). */
446      HDC hdc;  void
447      int wChild, hChild, wParent, hParent;      center_window2 (HWND hwndChild, HWND parent, HWND style)
448      int wScreen, hScreen, xNew, yNew;  {    
449      int flags = SWP_NOSIZE | SWP_NOZORDER;      HWND hwndParent;
450        RECT rChild, rParent;    
451      hwndParent = parent;      HDC hdc;
452      if (hwndParent == NULL)      int wChild, hChild, wParent, hParent;    
453          hwndParent = GetDesktopWindow ();      int wScreen, hScreen, xNew, yNew;
454      GetWindowRect (hwndChild, &rChild);          int flags = SWP_NOSIZE | SWP_NOZORDER;
455      wChild = rChild.right - rChild.left;      
456      hChild = rChild.bottom - rChild.top;      hwndParent = parent;
457        if (hwndParent == NULL)
458      GetWindowRect (hwndParent, &rParent);              hwndParent = GetDesktopWindow ();
459      wParent = rParent.right - rParent.left;          GetWindowRect (hwndChild, &rChild);    
460      hParent = rParent.bottom - rParent.top;            wChild = rChild.right - rChild.left;    
461            hChild = rChild.bottom - rChild.top;
462      hdc = GetDC (hwndChild);      
463      wScreen = GetDeviceCaps (hdc, HORZRES);          GetWindowRect (hwndParent, &rParent);    
464      hScreen = GetDeviceCaps (hdc, VERTRES);          wParent = rParent.right - rParent.left;    
465      ReleaseDC (hwndChild, hdc);            hParent = rParent.bottom - rParent.top;      
466      xNew = rParent.left + ((wParent - wChild) /2);          
467      if (xNew < 0)      hdc = GetDC (hwndChild);    
468          xNew = 0;      wScreen = GetDeviceCaps (hdc, HORZRES);    
469      else if ((xNew+wChild) > wScreen)      hScreen = GetDeviceCaps (hdc, VERTRES);    
470          xNew = wScreen - wChild;      ReleaseDC (hwndChild, hdc);      
471      yNew = rParent.top  + ((hParent - hChild) /2);      xNew = rParent.left + ((wParent - wChild) /2);    
472      if (yNew < 0)      if (xNew < 0)
473          yNew = 0;          xNew = 0;
474      else if ((yNew+hChild) > hScreen)      else if ((xNew+wChild) > wScreen)
475          yNew = hScreen - hChild;          xNew = wScreen - wChild;
476      if (style == HWND_TOPMOST || style == HWND_NOTOPMOST)      yNew = rParent.top  + ((hParent - hChild) /2);
477          flags = SWP_NOMOVE | SWP_NOSIZE;      if (yNew < 0)
478      SetWindowPos (hwndChild, style? style : NULL, xNew, yNew, 0, 0, flags);          yNew = 0;
479  }      else if ((yNew+hChild) > hScreen)
480            yNew = hScreen - hChild;
481        if (style == HWND_TOPMOST || style == HWND_NOTOPMOST)
482  /* Center the given hwndChild window with no special style. */          flags = SWP_NOMOVE | SWP_NOSIZE;
483  void      SetWindowPos (hwndChild, style? style : NULL, xNew, yNew, 0, 0, flags);
484  center_window (HWND hwndChild, HWND hwndParent)  }
485  {  
486      center_window2 (hwndChild, hwndParent, NULL);  
487  }  /* Center the given hwndChild window with no special style. */
488    void
489    center_window (HWND hwndChild, HWND hwndParent)
490    {
491        center_window2 (hwndChild, hwndParent, NULL);
492    }

Legend:
Removed from v.32  
changed lines
  Added in v.36

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26