Beispiel #1
0
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC			hdc;

    switch (msg)
    {
	case WM_CREATE:
		ClientResize(hWnd, 1000, 450);

		OnWindowCreate(hWnd);
		break;

    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
		{
			cairo_surface_t *surface = cairo_win32_surface_create(hdc);
            cairo_t *cr = cairo_create(surface);

			cairo_surface_t *shell = cairo_image_surface_create_from_png("../res/smatch-shell.png");

			cairo_set_source_surface(cr, shell, 0, 0);
			cairo_paint(cr);

            cairo_surface_finish(surface);
            // Cleanup.
            cairo_destroy(cr);
            cairo_surface_destroy(surface);
		}
		EndPaint(hWnd, &ps);
        break;

	case WM_COMMAND:
		OnCommand(hWnd, msg, wParam, lParam);
		break;

	case WM_DESTROY:
        PostQuitMessage(0);
        break;

    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
        break;
    }

    return 0;
}
Beispiel #2
0
Bool GWinControl::Init(GWinControl* pOwner, u32 Flags, u32 ControlID, char* WindowName)
{
	//	check we havent already created a contorl
	if ( m_Hwnd != NULL )
	{
		GDebug_Break("Control already created\n");
		return FALSE;
	}
	
	//	create control
	Flags |= AdditionalStyleFlags();
	m_StyleFlags	= Flags;

//	HMENU hMenu		= (HMENU)ControlID;
	HMENU hMenu		= (HMENU)NULL;
	HINSTANCE hInstance = GApp::g_HInstance;
	HWND OwnerHwnd	= pOwner ? pOwner->m_Hwnd : m_OwnerHwnd;

	//	reset handle
	m_Hwnd = NULL;

	m_ControlID = ControlID;
	m_pOwnerControl = pOwner;

	//	get resulting hwnd, m_Hwnd is set from the WM_CREATE callback
	HWND ResultHwnd = CreateWindowEx( StyleExFlags(), ClassName(), WindowName, StyleFlags(), m_ClientPos.x, m_ClientPos.y, m_ClientSize.x, m_ClientSize.y, OwnerHwnd, hMenu, hInstance, (void*)this );

	//	if control doesnt get a WM_CREATE (if its a standard windows control) call it
	if ( ResultHwnd != NULL && m_Hwnd == NULL )
	{
		OnWindowCreate( this, ResultHwnd );
	}

	//	failed
	if ( m_Hwnd == NULL || ResultHwnd == NULL || m_Hwnd != ResultHwnd )
	{
		GDebug::CheckWin32Error();
		return FALSE;
	}

	//	control has been created
	OnCreate();

	return TRUE;
}