/[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 193 by twoaday, Sat Apr 1 12:36:35 2006 UTC revision 248 by twoaday, Fri Jul 28 11:11:09 2006 UTC
# Line 35  Line 35 
35  #include "wptW32API.h"  #include "wptW32API.h"
36  #include "wptErrors.h"  #include "wptErrors.h"
37  #include "wptVersion.h"  #include "wptVersion.h"
38    #include "wptUTF8.h"
39  #include "wptTypes.h"  #include "wptTypes.h"
40    
41    
# Line 256  set_clip_text (HWND hwnd, const char *te Line 257  set_clip_text (HWND hwnd, const char *te
257          BUG (NULL);          BUG (NULL);
258      p = (char *) GlobalLock (clipmem);      p = (char *) GlobalLock (clipmem);
259      if (p == NULL) {      if (p == NULL) {
260          rc = WPTERR_GENERAL;;          CloseClipboard ();
261          goto leave;              GlobalFree (clipmem);
262            return WPTERR_GENERAL;
263      }      }
264      memcpy (p, text, nbytes);      memcpy (p, text, nbytes);
265      p[nbytes] = '\0';      p[nbytes] = '\0';
266            
     GlobalUnlock (clipmem);  
267      SetClipboardData (CF_TEXT, clipmem);      SetClipboardData (CF_TEXT, clipmem);
268        GlobalUnlock (clipmem);
269        CloseClipboard ();
270      GlobalFree (clipmem);      GlobalFree (clipmem);
271            
 leave:  
     CloseClipboard ();  
272      return rc;      return rc;
273  }  }
274    
# Line 502  int Line 503  int
503  get_file_version (const char *fname, WORD *major, WORD *minor,  get_file_version (const char *fname, WORD *major, WORD *minor,
504                    WORD *patch1, WORD *patch2)                    WORD *patch1, WORD *patch2)
505  {  {
506      VS_FIXEDFILEINFO *inf = {0};      VS_FIXEDFILEINFO *inf;
507      char file[MAX_PATH+1] = {0};      char file[MAX_PATH+1] = {0};
508      LPVOID buf, data;      LPVOID buf, data;
509      DWORD arg;      DWORD arg;
# Line 513  get_file_version (const char *fname, WOR Line 514  get_file_version (const char *fname, WOR
514      size = GetFileVersionInfoSize (file, &arg);      size = GetFileVersionInfoSize (file, &arg);
515      if (!size)      if (!size)
516          return -1;          return -1;
517      buf = (LPVOID)new CHAR[size];      buf = (LPVOID)new char[size];
518      if (!buf)      if (!buf)
519          BUG (NULL);          BUG (NULL);
520      GetFileVersionInfo (file, 0, size, buf);      GetFileVersionInfo (file, 0, size, buf);
# Line 521  get_file_version (const char *fname, WOR Line 522  get_file_version (const char *fname, WOR
522      qlen=0;      qlen=0;
523      VerQueryValue (buf, "\\", &data, &qlen);      VerQueryValue (buf, "\\", &data, &qlen);
524      if (!qlen) {      if (!qlen) {
525          delete [] (char*)buf;          delete [](char*)buf;
526          return -1;          return -1;
527      }      }
528      inf = (VS_FIXEDFILEINFO*)data;      inf = (VS_FIXEDFILEINFO*)data;
# Line 535  get_file_version (const char *fname, WOR Line 536  get_file_version (const char *fname, WOR
536      if (patch2)      if (patch2)
537          *patch2 = LOWORD (inf->dwProductVersionLS);          *patch2 = LOWORD (inf->dwProductVersionLS);
538    
539      delete [] (char*)buf;      delete [](char*)buf;
540      return 0;      return 0;
541  }  }
542    
# Line 590  get_temp_name (char *buf, DWORD buflen, Line 591  get_temp_name (char *buf, DWORD buflen,
591  }  }
592    
593    
594  struct reminder_hd_s {  void
595      int msecs;  ListBox_AddString_utf8 (HWND lb, const char *txt)
596      HWND dlg;  {
597      HANDLE hd;      char *utf8_txt;
 };  
598    
599        utf8_txt = utf8_to_native (txt);
600        SendMessage (lb, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)(utf8_txt));
601        safe_free (utf8_txt);
602    }
603    
604  static DWORD CALLBACK  
605  foreground_reminder_thread (void *c)  void
606    ComboBox_AddString_utf8 (HWND cb, const char *txt)
607  {  {
608      struct reminder_hd_s *ctx = (struct reminder_hd_s *)c;  
609      Sleep (ctx->msecs);      char *utf8_txt;
610      SetForegroundWindow (ctx->dlg);  
611      CloseHandle (ctx->hd);      utf8_txt = utf8_to_native (txt);
612      delete ctx;      SendMessage ((cb), CB_ADDSTRING, 0, (LPARAM)(LPCSTR)(utf8_txt));
613      ExitThread (0);      safe_free (utf8_txt);
     return 0;  
614  }  }
615    
616  /* Try to force the window @dlg to the foreground.  
617     On NT5 or later this will not work if the user  /* GetDlgItemText replacement with UTF8 support. */
618     is working in another window (console for example). */  int
619  void  GetDlgItemText_utf8 (HWND dlg, int id, char **r_txt)
620  force_foreground_window (HWND dlg, int msecs)  {
621        int len = GetWindowTextLength (GetDlgItem (dlg, id));
622        char *txt;
623    
624        *r_txt = NULL;
625        if (len < 1)
626            return 0;
627        txt = new char[len+2];
628        if (!txt)
629            BUG (NULL);
630        GetDlgItemText (dlg, id, txt, len+1);
631        *r_txt = native_to_utf8 (txt);
632        free_if_alloc (txt);
633        return len;
634    }
635    
636    
637    /* Return TRUE if the current user has admin privileges. */
638    BOOL
639    user_is_admin (void)
640  {  {
641      struct reminder_hd_s *hd;      SID_IDENTIFIER_AUTHORITY SystemSidAuthority = SECURITY_NT_AUTHORITY;
642      DWORD tid;      HANDLE hd;
643        TOKEN_GROUPS  *ptg = NULL;
644        DWORD ngtoken;
645        DWORD i;
646        BOOL admin = FALSE;
647        PSID psid = 0;
648    
649        if (GetVersion () & 0x80000000) /* Win9X */
650            return TRUE;
651    
652        if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, FALSE, &hd) &&
653            !OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &hd))
654            return FALSE;
655        
656        if (!GetTokenInformation (hd, TokenGroups, NULL, 0, &ngtoken) &&
657            GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
658            ptg = (TOKEN_GROUPS*)GlobalAlloc (GPTR, ngtoken);
659            if (!ptg)
660                return FALSE;
661    
662            if (!GetTokenInformation (hd, TokenGroups,
663                                      ptg, ngtoken, &ngtoken)) {
664                GlobalFree (ptg);
665                return FALSE;
666            }
667            AllocateAndInitializeSid (&SystemSidAuthority,
668                                      2, SECURITY_BUILTIN_DOMAIN_RID,
669                                      DOMAIN_ALIAS_RID_ADMINS,
670                                      0, 0, 0, 0, 0, 0,
671                                      &psid);
672            for (i = 0; i < ptg->GroupCount; i++) {
673                if (EqualSid (ptg->Groups[i].Sid, psid)) {
674                    admin = TRUE;
675                    break;
676                }
677            }
678            FreeSid (psid);
679            GlobalFree (ptg);
680        }
681    
682      hd = new reminder_hd_s;      CloseHandle (hd);
683      hd->dlg = dlg;      return admin;
     hd->msecs = msecs;  
     hd->hd = CreateThread (NULL, 0, foreground_reminder_thread,  
                            hd, NULL, &tid);  
684  }  }

Legend:
Removed from v.193  
changed lines
  Added in v.248

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26