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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26