⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bxfiledialog.cpp

📁 一个vc中管理资源文件ID的插件
💻 CPP
📖 第 1 页 / 共 3 页
字号:

	// Move the window to the correct coordinates with SetWindowPos()
	GetParent()->SetWindowPos(NULL, xLeft, yTop, -1, -1,
		SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}

/************************************************************************/
/*  ResolveShortcut														*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      Anatoly Danekin										*/
/*  Description: Resolves the passed shortcut							*/
/*	Revisions:	 														*/
/************************************************************************/
BOOL BXFileDialog::ResolveShortcut(CString& strFile)
{
	HRESULT         hres;
	IShellLink*     psl;
	char            szGotPath[MAX_PATH];
	WIN32_FIND_DATA wfd;
	
	// Get a pointer to the IShellLink interface.
	hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
		IID_IShellLink, (void**)&psl);
	
	if (SUCCEEDED(hres))
	{
		IPersistFile* ppf;
		
		// Get a pointer to the IPersistFile interface.
		hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
		
		if (SUCCEEDED(hres))
		{
			WORD wsz[MAX_PATH];
			
			// Ensure that the string is Unicode.
			MultiByteToWideChar(CP_ACP, 0, (LPCSTR)strFile, -1, wsz,
				MAX_PATH);
			
			// Load the shortcut.
			hres = ppf->Load(wsz, STGM_READ);
			if (SUCCEEDED(hres))
			{
				// Resolve the link.
				hres = psl->Resolve(GetParent()->m_hWnd, SLR_ANY_MATCH);
				if (SUCCEEDED(hres))
				{
					// Get the path to the link target.
					hres = psl->GetPath(szGotPath, MAX_PATH,
						(WIN32_FIND_DATA*)&wfd, SLGP_SHORTPATH );
					if (SUCCEEDED(hres))
						strFile = szGotPath;
				}
			}
			// Release the pointer to the IPersistFile interface.
			ppf->Release();
		}
		
		// Release the pointer to the IShellLink interface.
		psl->Release();
	}
	
	return SUCCEEDED(hres);
}

/************************************************************************/
/*  DrawImage															*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      Wes Rogers												*/
/*  Description: Draws the specified image in the specified rectangle	*/
/*	Revisions:	 														*/
/************************************************************************/
BOOL BXFileDialog::DrawImage(CDC* pDC, CString csFile, CPoint ptCenter,
							 HWND hWnd, CRect rectImage)
{
    if (pDC == NULL || csFile.IsEmpty() || hWnd == NULL)
        return FALSE;
	
    LPPICTURE gpPicture = NULL;
	
    if (LoadPictureFile((LPCTSTR)csFile, &gpPicture))
    {
        //Get width and height of picture
        long hmWidth  = 0;
        long hmHeight = 0;
		
        gpPicture->get_Width(&hmWidth);
        gpPicture->get_Height(&hmHeight);
		
        //Use to get height and width for display
        CRect rectI = rectImage;
        rectI.NormalizeRect();
		
        int nWidth = rectI.Width();
        int nHeight= rectI.Height();
		
        CPoint ptUL(ptCenter.x-(nWidth /2),
			ptCenter.y+(nHeight/2));
		
		RECT rc;
		GetClientRect(&rc);
		
        HRESULT hrP = NULL;
		
        hrP =
			gpPicture->Render(pDC->m_hDC,
			rectImage.left,
			rectImage.top + nHeight - 1,
			nWidth,
			0 - nHeight,
			0,
			0,
			hmWidth,
			hmHeight,
			rectImage);
		
        gpPicture->Release();
		
        if (SUCCEEDED(hrP))
            return TRUE;
    }
	
    return FALSE;
}

/************************************************************************/
/*  LoadPictureFile														*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      Wes Rogers												*/
/*  Description: Loads the specified picture into the passed LPPICTURE	*/
/*	Revisions:	 														*/
/************************************************************************/
BOOL BXFileDialog::LoadPictureFile(LPCTSTR szFile, LPPICTURE* pgpPicture)
{
    // open file
    HANDLE hFile = CreateFile(szFile,
		GENERIC_READ,
		0,
		NULL,
		OPEN_EXISTING,
		0,
		NULL);
	
    if (hFile == INVALID_HANDLE_VALUE)
        return FALSE;
	
    // get file size
    DWORD dwFileSize = GetFileSize(hFile, NULL);
	
    if (dwFileSize == (DWORD)-1)
    {
        CloseHandle(hFile);
        return FALSE;
    }
	
    LPVOID pvData = NULL;
	
    // alloc memory based on file size
    HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
	
    if (hGlobal == NULL)
    {
        CloseHandle(hFile);
        return FALSE;
    }
	
    pvData = GlobalLock(hGlobal);
	
    if (pvData == NULL)
    {
        GlobalUnlock(hGlobal);
        CloseHandle(hFile);
        return FALSE;
    }
	
    DWORD dwBytesRead = 0;
	
    // read file and store in global memory
    BOOL bRead = ReadFile(hFile,
		pvData,
		dwFileSize,
		&dwBytesRead,
		NULL);
	
    GlobalUnlock(hGlobal);
    CloseHandle(hFile);
	
    if (!bRead)
        return FALSE;
	
    LPSTREAM pstm = NULL;
	
    // create IStream* from global memory
    HRESULT hr = CreateStreamOnHGlobal(hGlobal,
		TRUE,
		&pstm);
	
    if (!(SUCCEEDED(hr)))
    {
        if (pstm != NULL)
            pstm->Release();
		
        return FALSE;
    }
	
    else if (pstm == NULL)
        return FALSE;
	
	// Create IPicture from image file
	if (*pgpPicture)
		(*pgpPicture)->Release();
	
    hr = ::OleLoadPicture(pstm,
		dwFileSize,
		FALSE,
		IID_IPicture,
		(LPVOID *)&(*pgpPicture));
	
    if (!(SUCCEEDED(hr)))
    {
		pstm->Release();
        return FALSE;
    }
	
    else if (*pgpPicture == NULL)
    {
		pstm->Release();
        return FALSE;
    }
	
    pstm->Release();
	
    return TRUE;
}

/************************************************************************/
/*  ReSize																*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      David Wulff, Tak^Shoran								*/
/*  Description: Called by the WM_SIZING override to reposition the		*/
/*				 .. dialog's controls.									*/
/*	Revisions:	 														*/
/************************************************************************/
void BXFileDialog::ReSize(int x, int y, int cx, int cy)
{
	CWnd* pWnd;
	CRect rcDlgCl, rcWin, rc1, rc2, rcLoc;
	
	GetClientRect(&rcDlgCl);
	GetWindowRect(&rcWin);
	
	int eRight = rcDlgCl.right - CONTROL_GAP;
	int eLeft = rcDlgCl.left + CONTROL_GAP;
	int eTop = rcDlgCl.top + CONTROL_GAP;
	int eBot = rcDlgCl.bottom - CONTROL_GAP;
	
	// Move preview box
	if (m_bShowPreview)
	{
		CWnd* pListCtrl = GetParent()->GetDlgItem(lst1);
		CRect rcList;
		pListCtrl->GetClientRect(&rcList);
		
		checkBox.SetWindowPos(0, eRight - 98,
			eBot - (CONTROL_GAP * 4) - (22 * 4), 90, 22, SWP_NOZORDER);
		
		PreviewRect.bottom = eBot - (CONTROL_GAP * 5) - (22 * 4);
		PreviewRect.right = eRight - CONTROL_GAP - 3;
		PreviewRect.left = PreviewRect.right - m_nPreviewBoxWidth;
	}
	
	// Move button
	m_btn.GetWindowRect(&rc1);
	ScreenToClient(&rc1);
	
	pWnd = GetParent()->GetDlgItem(IDCANCEL);
	pWnd->GetWindowRect(&rc2);
	ScreenToClient(&rc2);
	
	rc1.left  = rc2.left;
	rc1.right = rc2.right;
	
	m_btn.SetWindowPos(0, rc1.left, rc1.top, rc1.Width(), rc1.Height(),
		SWP_NOZORDER);
	
	// Move outbar
	CWnd* pWndOutLookBar = GetDlgItem(IDC_OUTLOOK_BAR_PLACEHOLDER);
	pWndOutLookBar->GetWindowRect(&rc1);
	ScreenToClient(&rc1);
	
	rc1.bottom = rcDlgCl.Height() - rc1.top;
	
	pWndOutLookBar->SetWindowPos(0, rc1.left, rc1.top, rc1.Width(),
		rc1.Height(), SWP_NOZORDER);

	Invalidate();
}

/************************************************************************/
/*  SetAppearance														*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      David Wulff											*/
/*  Description: Pass in the eAppearance to use	when drawing the dialog	*/
/*				 .. and buttons, etc.									*/
/*	Revisions:	 														*/
/************************************************************************/
void BXFileDialog::SetAppearance(eAppearance eApp)
{
	m_eAppearance = eApp;
	bDotNetUI = (m_eAppearance == eAppearance::APPEARANCE_VSDOTNET);
}



//////////////////////////////////////////////////////////////////////////
// BXFileEdit (: public CEdit)
//////////////////////////////////////////////////////////////////////////

/************************************************************************/
/*  BXFileEdit															*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      David Wulff											*/
/*  Description: Class constructor										*/
/*	Revisions:	 														*/
/************************************************************************/
BXFileEdit::BXFileEdit()
{
}


/************************************************************************/
/*  ~BXFileEdit															*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      David Wulff											*/
/*  Description: Casll destructor										*/
/*	Revisions:	 														*/
/************************************************************************/
BXFileEdit::~BXFileEdit()
{
}

BEGIN_MESSAGE_MAP(BXFileEdit, CEdit)
//{{AFX_MSG_MAP(BXFileEdit)
ON_WM_KEYUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/************************************************************************/
/*  OnKeyUp																*/
/*																		*/
/*  Created:     31:3:2001												*/
/*  Author:      David Wulff											*/
/*  Description: WM_KEYUP handler for the new edit control				*/
/*	Revisions:	 														*/
/************************************************************************/
void BXFileEdit::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if (BXFileDialog::m_bClear)
	{
		SetWindowText(""/*BXFileDialog::m_szFile*/);
		BXFileDialog::m_bClear = FALSE;
		SetSel(0,-1);
	}
	
	CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -