#pragma once

#include "stringmap.h"
#include "ATLComTime.h"

// Obtain the class id for a given image encoder
// valid encoders are:
// image/bmp 
// image/jpeg 
// image/gif 
// image/tiff 
// image/png 
int GetEncoderClsid(WCHAR* encoder, CLSID* pClsid);

// Draws the image with the transparency defined in the environment
int DrawTransparentImage(Graphics* graphics, Image* image, int x, int y);
int DrawTransparentImage(Graphics* graphics, Image* image, int x, int y, int width, int height);


// prints to console the last windows error, prefixing with the given identifier
void PrintLastError(const char * identifier);

// image resource management
Image * LoadImageResource(const TCHAR * filename);

// convert ASCII to UNICODE
TCHAR * ConvertToWideString(const char * str);

// waits on the event, printing to console on every one second timeout
void SafeWait(HANDLE event, const TCHAR * identifier);

// returns the required height (in pixels) for the given text and font
int MeasureTextHeight(const TCHAR * fontname, int fontsize, const TCHAR * string, int width);

// Handle all the pending messages in this thread's message Q and return
void DoEvents();

// This will do events until one of the objects in the array has been signaled
// returns the index of the signaled object
int DoEventsUntil ( 
    HANDLE* lphObjects,  // handles that need to be waited on 
    int     cObjects     // number of handles to wait on 
  );

// This safely sends messages to queues in any thread
DWORD SafeSendMessage(HWND h, UINT msg, WPARAM wparam, LPARAM lparam );


// various network routines
BOOL IsInternetConnection();
int  IsNetworkWireless();
void GetMacAddress(Vector<unsigned char>& addr);
const char * GetNetworkAdapterName();
// looks up the local host name
TCHAR * GetLocalHostName();
TCHAR * GetLocalIPAddress();

// converts the given time span to a short inexact string representation
TCHAR * ConvertTimeSpanToCompactString(COleDateTimeSpan & span);