foobar2000 SDK  2015-01-14
Data Structures | Typedefs | Functions
win32_misc.h File Reference

Go to the source code of this file.

Data Structures

class  CDLL
 
class  CloseHandleScope
 
class  CModelessDialogEntry
 
class  CMutex
 
class  CMutexScope
 
class  CoInitializeScope
 
class  EnableWindowScope
 
class  mutexScope
 
class  OleInitializeScope
 
class  registerclass_scope_delayed
 
class  SetTextColorScope
 
class  TypeFind
 
class  winLocalFileScope
 

Typedefs

typedef CGlobalLockScope CGlobalLock
 

Functions

template<typename t_array >
static bool GetClipboardDataBlock (UINT p_format, t_array &p_array)
 
static WORD GetOSVersion ()
 
void GetOSVersionString (pfc::string_base &out)
 
void GetOSVersionStringAppend (pfc::string_base &out)
 
bool IsMenuNonEmpty (HMENU menu)
 
unsigned QueryScreenDPI ()
 
SIZE QueryScreenDPIEx ()
 
bool SetClipboardDataBlock (UINT p_format, const void *p_block, t_size p_block_size)
 
template<typename t_array >
static bool SetClipboardDataBlock (UINT p_format, const t_array &p_array)
 
void SetDefaultMenuItem (HMENU p_menu, unsigned p_id)
 
void WIN32_OP_D_FAIL (const wchar_t *_Message, const wchar_t *_File, unsigned _Line)
 
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL ()
 
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL (const char *what)
 
static DWORD WS_EX_COMPOSITED_Safe ()
 

Typedef Documentation

Definition at line 55 of file win32_misc.h.

Function Documentation

template<typename t_array >
static bool GetClipboardDataBlock ( UINT  p_format,
t_array &  p_array 
)
static

Definition at line 66 of file win32_misc.h.

66  {
67  PFC_STATIC_ASSERT( sizeof(p_array[0]) == 1 );
68  if (OpenClipboard(NULL)) {
69  HANDLE handle = GetClipboardData(p_format);
70  if (handle == NULL) {
71  CloseClipboard();
72  return false;
73  }
74  {
75  CGlobalLock lock(handle);
76  const t_size size = lock.GetSize();
77  try {
78  p_array.set_size(size);
79  } catch(...) {
80  CloseClipboard();
81  throw;
82  }
83  memcpy(p_array.get_ptr(),lock.GetPtr(),size);
84  }
85  CloseClipboard();
86  return true;
87  } else {
88  return false;
89  }
90 }
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
size_t t_size
Definition: int_types.h:48
static WORD GetOSVersion ( )
static

Definition at line 125 of file win32_misc.h.

125  {
126  const DWORD ver = GetVersion();
127  return (WORD)HIBYTE(LOWORD(ver)) | ((WORD)LOBYTE(LOWORD(ver)) << 8);
128 }
void GetOSVersionString ( pfc::string_base out)

Definition at line 81 of file win32_misc.cpp.

81  {
82  out.reset(); GetOSVersionStringAppend(out);
83 }
void GetOSVersionStringAppend(pfc::string_base &out)
Definition: win32_misc.cpp:111
void GetOSVersionStringAppend ( pfc::string_base out)

Definition at line 111 of file win32_misc.cpp.

111  {
112 
113  if (FetchWineInfoAppend(out)) return;
114 
115  OSVERSIONINFO ver = {}; ver.dwOSVersionInfoSize = sizeof(ver);
116  WIN32_OP( GetVersionEx(&ver) );
117  SYSTEM_INFO info = {};
118  GetNativeSystemInfo(&info);
119 
120  out << "Windows " << (int)ver.dwMajorVersion << "." << (int)ver.dwMinorVersion << "." << (int)ver.dwBuildNumber;
121  if (ver.szCSDVersion[0] != 0) out << " " << pfc::stringcvt::string_utf8_from_os(ver.szCSDVersion, PFC_TABSIZE(ver.szCSDVersion));
122 
123  switch(info.wProcessorArchitecture) {
124  case PROCESSOR_ARCHITECTURE_AMD64:
125  out << " x64"; break;
126  case PROCESSOR_ARCHITECTURE_IA64:
127  out << " IA64"; break;
128  case PROCESSOR_ARCHITECTURE_INTEL:
129  out << " x86"; break;
130  }
131 }
void info(const char *p_message)
Definition: console.cpp:4
string_utf8_from_wide string_utf8_from_os
Definition: string_conv.h:517
static bool FetchWineInfoAppend(pfc::string_base &out)
Definition: win32_misc.cpp:90
bool IsMenuNonEmpty ( HMENU  menu)

Definition at line 43 of file win32_misc.cpp.

43  {
44  unsigned n,m=GetMenuItemCount(menu);
45  for(n=0;n<m;n++) {
46  if (GetSubMenu(menu,n)) return true;
47  if (!(GetMenuState(menu,n,MF_BYPOSITION)&MF_SEPARATOR)) return true;
48  }
49  return false;
50 }
unsigned QueryScreenDPI ( )

Definition at line 27 of file win32_misc.cpp.

27  {
28  HDC dc = GetDC(0);
29  unsigned ret = GetDeviceCaps(dc,LOGPIXELSY);
30  ReleaseDC(0,dc);
31  return ret;
32 }
SIZE QueryScreenDPIEx ( )

Definition at line 35 of file win32_misc.cpp.

35  {
36  HDC dc = GetDC(0);
37  SIZE ret = { GetDeviceCaps(dc,LOGPIXELSY), GetDeviceCaps(dc,LOGPIXELSY) };
38  ReleaseDC(0,dc);
39  return ret;
40 }
bool SetClipboardDataBlock ( UINT  p_format,
const void *  p_block,
t_size  p_block_size 
)

Definition at line 143 of file win32_misc.cpp.

143  {
144  bool success = false;
145  if (OpenClipboard(NULL)) {
146  EmptyClipboard();
147  HANDLE handle = GlobalAlloc(GMEM_MOVEABLE,p_block_size);
148  if (handle == NULL) {
149  CloseClipboard();
150  throw std::bad_alloc();
151  }
152  {CGlobalLock lock(handle);memcpy(lock.GetPtr(),p_block,p_block_size);}
153  if (SetClipboardData(p_format,handle) == NULL) {
154  GlobalFree(handle);//todo?
155  } else {
156  success = true;
157  }
158  CloseClipboard();
159  }
160  return success;
161 }
typedef HANDLE(WINAPI *pPowerCreateRequest_t)(__in void *Context)
template<typename t_array >
static bool SetClipboardDataBlock ( UINT  p_format,
const t_array &  p_array 
)
static

Definition at line 60 of file win32_misc.h.

60  {
61  PFC_STATIC_ASSERT( sizeof(p_array[0]) == 1 );
62  return SetClipboardDataBlock(p_format,p_array.get_ptr(),p_array.get_size());
63 }
bool SetClipboardDataBlock(UINT p_format, const void *p_block, t_size p_block_size)
Definition: win32_misc.cpp:143
void SetDefaultMenuItem ( HMENU  p_menu,
unsigned  p_id 
)

Definition at line 134 of file win32_misc.cpp.

134  {
135  MENUITEMINFO info = {sizeof(info)};
136  info.fMask = MIIM_STATE;
137  GetMenuItemInfo(p_menu,p_id,FALSE,&info);
138  info.fState |= MFS_DEFAULT;
139  SetMenuItemInfo(p_menu,p_id,FALSE,&info);
140 }
void info(const char *p_message)
Definition: console.cpp:4
void WIN32_OP_D_FAIL ( const wchar_t *  _Message,
const wchar_t *  _File,
unsigned  _Line 
)

Definition at line 66 of file win32_misc.cpp.

66  {
67  const DWORD code = GetLastError();
68  pfc::array_t<wchar_t> msgFormatted; msgFormatted.set_size(pfc::strlen_t(_Message) + 64);
69  wsprintfW(msgFormatted.get_ptr(), L"%s (code: %u)", _Message, code);
70  if (IsDebuggerPresent()) {
71  OutputDebugString(TEXT("WIN32_OP_D() failure:\n"));
72  OutputDebugString(msgFormatted.get_ptr());
73  OutputDebugString(TEXT("\n"));
74  pfc::crash();
75  }
76  _wassert(msgFormatted.get_ptr(),_File,_Line);
77 }
const t_item * get_ptr() const
Definition: array.h:213
t_size strlen_t(const t_char *p_string, t_size p_length=~0)
Definition: primitives.h:771
void crash()
Definition: other.cpp:105
void set_size(t_size p_size)
Definition: array.h:104
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL ( )

Definition at line 52 of file win32_misc.cpp.

52  {
53  const DWORD code = GetLastError();
54  PFC_ASSERT( code != NO_ERROR );
55  throw exception_win32(code);
56 }
PFC_NORETURN PFC_NOINLINE void WIN32_OP_FAIL_CRITICAL ( const char *  what)

Definition at line 58 of file win32_misc.cpp.

58  {
59  const DWORD code = GetLastError();
60  PFC_ASSERT( code != NO_ERROR );
61  pfc::string_formatter msg; msg << what << " failure #" << (uint32_t)code;
62  TRACK_CODE(msg.get_ptr(), uBugCheck());
63 }
string8_fastalloc string_formatter
Definition: string_base.h:614
PFC_NORETURN void SHARED_EXPORT uBugCheck()
static DWORD WS_EX_COMPOSITED_Safe ( )
static

Definition at line 133 of file win32_misc.h.

133  {
134  return (GetOSVersion() < 0x501) ? 0 : 0x02000000L;
135 }
static WORD GetOSVersion()
Definition: win32_misc.h:125