Ejemplo n.º 1
0
// FIX message composer function
static
void message_to_string(FILE* const builder, const fix_message_data* const data)
{
	// message body
	unsigned body_size;
	char* const body = make_message_body(data, &body_size);

	// message header
	char hdr[100];
	int hdr_size = snprintf(hdr, sizeof(hdr), "8=FIX.4.4\x01" "9=%u\x01", body_size);

	ASSURE(hdr_size >= 0);

	// checksum
	unsigned char cs = 0;

	for(const char* s = hdr; s < hdr + hdr_size; ++s)
		cs += *s;

	for(const char* s = body; s < body + body_size; ++s)
		cs += *s;

	// write result
	ASSURE(fwrite(hdr, 1, hdr_size, builder) == (unsigned)hdr_size
		&& fwrite(body, 1, body_size, builder) == body_size
		&& fprintf(builder, "10=%.03u\x01", (unsigned)cs) >= 0);

	// clean-up
	free(body);
}
Ejemplo n.º 2
0
void Subclassed::Subclass(HWND parent_, UINT id_)
{
	ASSURE(parent_ != NULL)

	parent = parent_;
	id = id_;

	hwnd = ::GetDlgItem(parent, id);
	ASSURE(hwnd != NULL)

	Subclass();
}
Ejemplo n.º 3
0
//void CenterText(HDC hdc, int x, int w, int y, int h, const wchar_t* str, RECT* out)
void CenterText(HDC hdc, int x, int w, int y, int h, const char* str, RECT* out)
{
	ASSURE(str != NULL)

	size_t len = strlen(str);

	SIZE extent;
	std::wstring win_str = unicode_utils::utf8_to_utf16(str,NULL);
	::GetTextExtentPoint32(hdc, win_str.c_str(), win_str.length(), &extent);
	//::GetTextExtentPoint32(hdc, str, len, &extent);

	int dx, dy;

	if (w != -1)
		dx = x + (w - extent.cx)/2;
	else
		dx = x;

	if (h != -1)
		dy = y + (h - extent.cy)/2;
	else
		dy = y;

	::TextOut(hdc, dx, dy, win_str.c_str(), win_str.length());
	//::TextOut(hdc, dx, dy, str, len);

	if (out != NULL)
	{
		(*out).left   = dx;
		(*out).right  = dx + extent.cx;
		(*out).top    = dy;
		(*out).bottom = dy + extent.cy;
	}
}
Ejemplo n.º 4
0
void ScreenToClient(HWND hwnd, LPRECT rect)
{
	ASSURE(::IsWindow(hwnd) != FALSE)

	::ScreenToClient(hwnd,  (LPPOINT) rect);
	::ScreenToClient(hwnd, ((LPPOINT) rect) + 1);
}
Ejemplo n.º 5
0
void MemDC::Begin(HDC destDC_, bool enabled_)
{
	ASSURE(destDC_ != NULL)

	destDC = destDC_;
	enabled = enabled_;

	if (enabled)
	{
		::GetClipBox(destDC, &rect);

		hdc = ::CreateCompatibleDC(destDC);

		bitmap = ::CreateCompatibleBitmap(
			destDC, rect.right - rect.left, rect.bottom - rect.top);

		oldBitmap = ::SelectObject(hdc, bitmap);

		::SetWindowOrgEx(hdc, rect.left, rect.top, NULL);
	}
	else
	{
		hdc = destDC;
	}
}
Ejemplo n.º 6
0
BOOL CALLBACK Dialog::DlgProc(
	HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	Dialog* ptr = NULL;

	if (msg == WM_INITDIALOG)
	{
		ptr = (Dialog*) lParam;
		ASSURE(ptr != NULL)

		::SetWindowLong(hwnd, GWL_USERDATA, lParam);
		ptr->hwnd = hwnd;
	}
	else
	{
		// retrieve the lParam value which was originally pased
		// in on the initial creation of the dialog...?
		ptr = (Dialog*) ::GetWindowLong(hwnd, GWL_USERDATA);
	}

	if (ptr != NULL)
		return ptr->OnMsg(msg, wParam, lParam);
	else
		return FALSE;
}
Ejemplo n.º 7
0
void FillRect(HDC hdc, const RECT& rect, const COLORREF color)
{
	ASSURE(hdc != NULL)

	COLORREF old_color = ::SetBkColor(hdc, color);
	::ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
	::SetBkColor(hdc, old_color);
}
Ejemplo n.º 8
0
CacheReader::CacheReader (SoundCacheItemPtr myCacheItem)
    : _myURI (myCacheItem->getURI()),
      _myCacheItem(myCacheItem),
      _myCurFrame(0),
      _mySampleSink(0)
{
    AC_DEBUG << "CacheReader::CacheReader";
    // We assume that the cache item is ready for playback.
    ASSURE(_myCacheItem->isFull());
    _myCacheItem->incInUseCount();
}
Ejemplo n.º 9
0
// helpers
static
void print_fix_message(const char* msg, unsigned len, FILE* const stream)
{
	const char* const end = msg + len;

	for(const char* s = memchr(msg, SOH, len); s; s = memchr(msg, SOH, end - msg))
	{
		const unsigned n = s - msg;

		ASSURE(fwrite(msg, 1, n, stream) == n && fputc('|', stream) != EOF);
		msg = s + 1;
	}

	len = end - msg;

	if(len > 0)
		ASSURE(fwrite(msg, 1, len, stream) == len);

	ASSURE(putc('\n', stream) != EOF);
}
Ejemplo n.º 10
0
// message array constructor
static
const fix_message_data* make_n_messages(const unsigned n, char** str, unsigned* psize)
{
	fix_message_data* const orders = check_ptr(malloc(n * sizeof(fix_message_data)));
	char* s;
	size_t size;
	FILE* const builder = open_memstream(&s, &size);

	ASSURE(builder);

	for(unsigned i = 0; i < n; ++i)
	{
		gen_new_order_single(orders + i);
		message_to_string(builder, orders + i);
	}

	ASSURE(fclose(builder) == 0);
	*str = s;
	*psize = size;
	return orders;
}
Ejemplo n.º 11
0
static
void add_timestamp_tag(FILE* const builder, unsigned tag, const utc_timestamp* const ts)
{
	ASSURE(fprintf(builder, "%u=%.04u%.02u%.02u-%.02u:%.02u:%.02u.%.03u\x01",
							tag,
							(unsigned)ts->year,
							(unsigned)ts->month,
							(unsigned)ts->day,
							(unsigned)ts->hour,
							(unsigned)ts->minute,
							(unsigned)ts->second,
							(unsigned)ts->millisecond) >= 0);
}
Ejemplo n.º 12
0
static
char* make_message_body(const fix_message_data* const data, unsigned* psize)
{
	char* body;
	size_t size;
	FILE* const builder = open_memstream(&body, &size);

	ASSURE(builder);
	header_to_string(builder, &data->hdr);

	switch(data->hdr.MsgType)
	{
		case 'D':
			new_order_single_to_string(builder, &data->order);
			break;
		default:
			error(EXIT_FAILURE, 0, "Unknown message type '%c'", data->hdr.MsgType);
	}

	ASSURE(fclose(builder) == 0);
	*psize = size;
	return body;
}
Ejemplo n.º 13
0
HFONT DeriveFont(HFONT origFont, bool bold, bool underline, int newSize)
{
	// object to hold the font.
	LOGFONT logfont;

	if (origFont == NULL){
		NONCLIENTMETRICS resultMetrics;
		resultMetrics.cbSize = sizeof(NONCLIENTMETRICS);
		BOOL rs = ::SystemParametersInfo(
			SPI_GETNONCLIENTMETRICS,	// property we want to retrive
			sizeof(NONCLIENTMETRICS),  // the size of the structure we are putting data into
			(PVOID)(&resultMetrics),   // a pointer to the structure to place the data
			0						   // flag to say we are not setting any data, only read.
		);

		ASSURE(rs == TRUE);
		logfont = resultMetrics.lfMessageFont;
		// origFont = (HFONT) ::GetStockObject(DEFAULT_GUI_FONT);
	}else{
		// User has supplied an HFONT object.. so use that to get the font
		::GetObject(origFont, sizeof(LOGFONT), &logfont);
	}

	if (newSize != -1)
	{
		// user has requested the size of the font to be bigger..
		HDC hdc = ::GetDC(NULL);
		logfont.lfHeight = -MulDiv(newSize, ::GetDeviceCaps(hdc, LOGPIXELSY), 72);
		::ReleaseDC(NULL, hdc);
	}

	if (bold){
		logfont.lfWeight = FW_BOLD;
	}

	if (underline){
		logfont.lfUnderline = (BYTE) TRUE;
	}

	return ::CreateFontIndirect(&logfont);
}
Ejemplo n.º 14
0
LRESULT CALLBACK Window::WndProc(
	HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	Window* ptr = NULL;

	if (msg == WM_NCCREATE)
	{
		ptr = (Window*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
		ASSURE(ptr != NULL)

		::SetWindowLong(hwnd, GWL_USERDATA, (LONG) ptr);
		ptr->hwnd = hwnd;
	}
	else
	{
		ptr = (Window*) ::GetWindowLong(hwnd, GWL_USERDATA);
	}

	if (ptr != NULL)
		return ptr->OnMsg(msg, wParam, lParam);
	else
		return ::DefWindowProc(hwnd, msg, wParam, lParam);
}
Ejemplo n.º 15
0
void HyperLink::SetURL(const char* url_)
{
	ASSURE(url_ != NULL)
	// make a std::string copy of the url
	this->url = url_;		
}
Ejemplo n.º 16
0
static
void add_char_tag(FILE* const builder, unsigned tag, const char value)
{
	ASSURE(fprintf(builder, "%u=%c\x01", tag, value) >= 0);
}
Ejemplo n.º 17
0
static
void add_price_tag(FILE* const builder, unsigned tag, const double value)
{
	ASSURE(fprintf(builder, "%u=%.2f\x01", tag, value) >= 0);
}
Ejemplo n.º 18
0
static
void add_long_tag(FILE* const builder, unsigned tag, const long value)
{
	ASSURE(fprintf(builder, "%u=%ld\x01", tag, value) >= 0);
}
Ejemplo n.º 19
0
// tag builders
static
void add_string_tag(FILE* const builder, unsigned tag, const char* const value)
{
	ASSURE(fprintf(builder, "%u=%s\x01", tag, value) >= 0);
}
Ejemplo n.º 20
0
void install_ALTAIRbootROM(void) {
    ASSURE(install_bootrom(bootrom_dsk, BOOTROM_SIZE_DSK, ALTAIR_ROM_LOW, TRUE) == SCPE_OK);
}