Ejemplo n.º 1
0
void ZStackObjectSelector::setSelection(ZStackObject *obj, bool selecting)
{
  if (selecting) {
    selectObject(obj);
  } else {
    deselectObject(obj);
  }
}
Ejemplo n.º 2
0
void ZSelector<T>::setSelection(T obj, bool selecting)
{
    if (selecting) {
        selectObject(obj);
    } else {
        deselectObject(obj);
    }
}
Ejemplo n.º 3
0
bool Bitmap::loadBitmap(LPCTSTR pszFilename)
{
    // Loads a BMP image and stores it in the Bitmap object.

    HANDLE hImage = LoadImage(GetModuleHandle(0), pszFilename, IMAGE_BITMAP, 0,
                              0, LR_CREATEDIBSECTION | LR_LOADFROMFILE);

    if (!hImage)
        return false;

    BITMAP bitmap = {0};

    if (!GetObject(hImage, sizeof(bitmap), &bitmap))
    {
        DeleteObject(hImage);
        return false;
    }

    HDC hImageDC = CreateCompatibleDC(0);

    if (!hImageDC)
    {
        DeleteObject(hImage);
        return false;
    }

    SelectObject(hImageDC, hImage);

    int h = (bitmap.bmHeight < 0) ? -bitmap.bmHeight : bitmap.bmHeight;

    if (create(bitmap.bmWidth, h))
    {
        selectObject();

        if (!BitBlt(dc, 0, 0, width, height, hImageDC, 0, 0, SRCCOPY))
        {
            destroy();
            DeleteDC(hImageDC);
            DeleteObject(hImage);
            return false;
        }

        deselectObject();
    }

    DeleteDC(hImageDC);
    DeleteObject(hImage);
    return true;
}
Ejemplo n.º 4
0
void Bitmap::destroy()
{
    deselectObject();

    if (hBitmap)
    {
        DeleteObject(hBitmap);
        hBitmap = 0;
    }

    if (dc)
    {
        DeleteDC(dc);
        dc = 0;
    }

    width = height = pitch = 0;
    m_hPrevObj = 0;
    m_pBits = 0;
}
Ejemplo n.º 5
0
bool Bitmap::loadDesktop()
{
    // Takes a screen capture of the current Windows desktop and stores
    // the image in the Bitmap object.

    HWND hDesktop = GetDesktopWindow();

    if (!hDesktop)
        return false;

    int desktopWidth = GetSystemMetrics(SM_CXSCREEN);
    int desktopHeight = GetSystemMetrics(SM_CYSCREEN);
    HDC hDesktopDC = GetDCEx(hDesktop, 0, DCX_CACHE | DCX_WINDOW);

    if (!hDesktopDC)
        return false;

    if (!create(desktopWidth, desktopHeight))
    {
        ReleaseDC(hDesktop, hDesktopDC);
        return false;
    }

    selectObject();

    if (!BitBlt(dc, 0, 0, width, height, hDesktopDC, 0, 0, SRCCOPY))
    {
        destroy();
        ReleaseDC(hDesktop, hDesktopDC);
        return false;
    }

    deselectObject();
    ReleaseDC(hDesktop, hDesktopDC);
    return true;
}
Ejemplo n.º 6
0
bool Bitmap::loadPicture(LPCTSTR pszFilename)
{
    // Loads an image using the IPicture COM interface.
    // Supported image formats: BMP, EMF, GIF, ICO, JPG, WMF, TGA.
    //
    // Based on code from MSDN Magazine, October 2001.
    // http://msdn.microsoft.com/msdnmag/issues/01/10/c/default.aspx

    // IPicture interface doesn't support TGA files.
    if (_tcsstr(pszFilename, _T(".TGA")) || _tcsstr(pszFilename, _T(".tga")))
        return loadTarga(pszFilename);

    HRESULT hr = 0;
    HANDLE hFile = 0;
    HGLOBAL hGlobal = 0;
    IStream *pIStream = 0;
    IPicture *pIPicture = 0;
    BYTE *pBuffer = 0;
    DWORD dwFileSize = 0;
    DWORD dwBytesRead = 0;
    LONG lWidth = 0;
    LONG lHeight = 0;

    if (!m_logpixelsx && !m_logpixelsy)
    {
        HDC hScreenDC = CreateCompatibleDC(GetDC(0));

        if (!hScreenDC)
            return false;

        m_logpixelsx = GetDeviceCaps(hScreenDC, LOGPIXELSX);
        m_logpixelsy = GetDeviceCaps(hScreenDC, LOGPIXELSY);
        DeleteDC(hScreenDC);
    }

    hFile = CreateFile(pszFilename, FILE_READ_DATA, FILE_SHARE_READ, 0,
                       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    if (hFile == INVALID_HANDLE_VALUE)
        return false;

    if (!(dwFileSize = GetFileSize(hFile, 0)))
    {
        CloseHandle(hFile);
        return false;
    }

    if (!(hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, dwFileSize)))
    {
        CloseHandle(hFile);
        return false;
    }

    if (!(pBuffer = reinterpret_cast<BYTE*>(GlobalLock(hGlobal))))
    {
        GlobalFree(hGlobal);
        CloseHandle(hFile);
        return false;
    }

    if (!ReadFile(hFile, pBuffer, dwFileSize, &dwBytesRead, 0))
    {
        GlobalUnlock(hGlobal);
        GlobalFree(hGlobal);
        CloseHandle(hFile);
        return false;
    }

    GlobalUnlock(hGlobal);
    CloseHandle(hFile);

    if (FAILED(CreateStreamOnHGlobal(hGlobal, FALSE, &pIStream)))
    {
        GlobalFree(hGlobal);
        return false;
    }

    if (FAILED(OleLoadPicture(pIStream, 0, FALSE, IID_IPicture,
                              reinterpret_cast<LPVOID*>(&pIPicture))))
    {
        pIStream->Release();
        GlobalFree(hGlobal);
        return false;
    }

    pIStream->Release();
    GlobalFree(hGlobal);

    pIPicture->get_Width(&lWidth);
    pIPicture->get_Height(&lHeight);

    width = MulDiv(lWidth, m_logpixelsx, HIMETRIC_INCH);
    height = MulDiv(lHeight, m_logpixelsy, HIMETRIC_INCH);

    if (!create(width, height))
    {
        pIPicture->Release();
        return false;
    }

    selectObject();
    hr = pIPicture->Render(dc, 0, 0, width, height, 0, lHeight, lWidth, -lHeight, 0);
    deselectObject();

    pIPicture->Release();
    return (SUCCEEDED(hr)) ? true : false;
}