当前位置: 首页>>代码示例>>C++>>正文


C++ Exception::get_message_and_stack_trace方法代码示例

本文整理汇总了C++中Exception::get_message_and_stack_trace方法的典型用法代码示例。如果您正苦于以下问题:C++ Exception::get_message_and_stack_trace方法的具体用法?C++ Exception::get_message_and_stack_trace怎么用?C++ Exception::get_message_and_stack_trace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::get_message_and_stack_trace方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Exception

ExceptionDialog_Impl::ExceptionDialog_Impl(Exception &e, HWND owner)
: window_handle(0), frame(0), text_label(0), ok_button(0)
{
	if (owner == 0)
		owner = GetDesktopWindow();

	WNDCLASSEX class_desc = { 0 };
	class_desc.cbSize = sizeof(WNDCLASSEX);
	class_desc.style = 0;
	class_desc.hbrBackground = CreateSolidBrush(RGB(240,240,240));
	class_desc.lpfnWndProc = &ExceptionDialog_Impl::static_window_proc;
	class_desc.lpszClassName = L"ExceptionDialog";
	ATOM class_atom = RegisterClassEx(&class_desc);

	HINSTANCE instance = (HINSTANCE)GetModuleHandle(0);

	DWORD ex_style = WS_EX_DLGMODALFRAME;
	DWORD style = WS_POPUPWINDOW|WS_CAPTION;
	HWND window_handle = CreateWindowEx(ex_style, L"ExceptionDialog", L"Unhandled Exception", style, CW_USEDEFAULT, CW_USEDEFAULT, 320, 240, 0, 0, instance, this);
	if (window_handle == 0)
		throw Exception("CreateWindowEx failed");

	std::wstring text = StringHelp::utf8_to_ucs2(e.get_message_and_stack_trace());

	frame = CreateWindowEx(0, L"STATIC", L"", WS_VISIBLE|WS_CHILD|SS_LEFT|SS_EDITCONTROL|SS_NOPREFIX, 0, 0, 100, 50, window_handle, 0, instance, 0);
	text_label = CreateWindowEx(0, L"STATIC", text.c_str(), WS_VISIBLE|WS_CHILD|SS_LEFT|SS_EDITCONTROL|SS_NOPREFIX|SS_NOTIFY, 0, 0, 100, 50, window_handle, 0, instance, 0);
	ok_button = CreateWindowEx(0, L"BUTTON", L"OK", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 0, 0, 50, 10, window_handle, 0, instance, 0);

	int point_size = 9;
	font = CreateFont(-(point_size * 96 + 36) / 72, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, L"Segoe UI");
	SendMessage(frame, WM_SETFONT, (WPARAM)font, 0);
	SendMessage(text_label, WM_SETFONT, (WPARAM)font, 0);
	SendMessage(ok_button, WM_SETFONT, (WPARAM)font, 0);

	RECT rect = { 0,0,0,0 };
	HDC dc = GetDC(text_label);
	int old_map_mode = SetMapMode(dc, MM_TEXT);
	HGDIOBJ old_font = SelectObject(dc, font);
	DrawText(dc, text.data(), text.length(), &rect, DT_CALCRECT|DT_LEFT|DT_TOP|DT_NOPREFIX);
	SelectObject(dc, old_font);
	SetMapMode(dc, old_map_mode);
	ReleaseDC(text_label, dc);

	RECT owner_box = { 0,0,0,0 };
	GetWindowRect(owner, &owner_box);

	int width = clan::min(rect.right, (long int)800) + 50;
	int height = clan::min(rect.bottom, (long int)600) + 100;
	SetWindowPos(window_handle, 0, (owner_box.left + owner_box.right - width) / 2, (owner_box.top + owner_box.bottom - height) / 2, width, height, SWP_NOZORDER);

	RECT client_box = { 0,0,0,0 };
	GetClientRect(window_handle, &client_box);

	int button_width = 88;
	int button_height = 26;
	SetWindowPos(ok_button, 0, client_box.right - button_width - 11, client_box.bottom - 48 + button_height / 2, button_width, button_height, SWP_NOZORDER);

	int text_bottom = client_box.bottom - 48;
	SetWindowPos(frame, 0, 0, 0, client_box.right, text_bottom, SWP_NOZORDER);
	SetWindowPos(text_label, 0, 11, 11, client_box.right - 22, text_bottom - 11 - 7, SWP_NOZORDER);

	ShowWindow(window_handle, SW_SHOW);
	SetFocus(ok_button);
}
开发者ID:eoma,项目名称:gm-engine,代码行数:64,代码来源:exception_dialog.cpp


注:本文中的Exception::get_message_and_stack_trace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。