|
How do I use those in MFC. Sorry, but I'm not going to say I do. I have no idea as to how to begin.
I know the extensions I'll need to find(ie, ".bku", ".sdb", and ".wdb" ) and I know the directory such files will be located (ie, "c:\\Wells\\Program\\DataBases\\SystemDB\\DispatchedWells\\" ).
Think you maybe able to figure out how to use them in MFC?
A C++ programming language novice, but striving to learn
|
|
|
|
|
|
In addition to the other answer... Once you have the name of the file, you pass it to a string and use something like:
szExtension = szFileName.Right(szFileName.ReverseFind('.'));
if ((szExtension == "bku") || (szExtension == "sdb") || (szExtension == "wdb"))
Do whatever you want to do with the files that you are looking for
Hope it helps
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Larry Mills Sr wrote: How do I use those in MFC.
What's wrong with CFileFind ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
This is exactly what I needed. I was not even aware it was part of MFC. Thank you very, very much. it works perfectly. Thanks.
A C++ programming language novice, but striving to learn
|
|
|
|
|
I wrote the following lines in order to draw a bitamp on DC created by BYTE* array:
#define BPP 32
// Initialize the bitmapinfo header
int nBitmapInfoSize = sizeof(BITMAPINFOHEADER) ;
memset(&m_bitmapInfo, 0, m_nBitmapInfoSize);
// Save size for drawing later.
int nBitPP = BPP / 8;
int nImageWidth = nWidth;
int nImageHeight = nHeight;
int nImageSize = nImageWidth * nImageHeight * nBitPP;
// Allocate memory for byte array and initialize it
BYTE* pbtImageArray = new BYTE [nImageSize];
memset(m_pbtImageArray, 0x0000, nImageSize);
for (int i = 0; i < nImageSize - nBitPP; i+=nBitPP)
{
pbtImageArray[i] = 0x0000;
pbtImageArray[i+1] = 0x0000;
pbtImageArray[i+2] = 255;
pbtImageArray[i+3] = 0x0000;
}
// Populate bitmapinfo header
BITMAPINFO bitmapInfo; // Bitmap info
bitmapInfo.bmiHeader.biSize = nBitmapInfoSize;
bitmapInfo.bmiHeader.biWidth = nImageWidth;
bitmapInfo.bmiHeader.biHeight = nImageHeight;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = BPP;
bitmapInfo.bmiHeader.biSizeImage = nImageSize;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
// Create bitamp
HBITMAP hbmp = CreateDIBSection( pCDC->GetSafeHdc(),
&bitmapInfo,
DIB_RGB_COLORS,
(void**)pbtImageArray,
NULL,
0);
HDC hBitmapDC = CreateCompatibleDC(pCDC->GetSafeHdc() );
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, hbmp);
StretchBlt( pCDC->GetSafeHdc(), nWindowX, nWindowY, nWindowWidth,
nWindowHeight, // Destination
hBitmapDC , nRegionX, nRegionY, nRegionWidth,
nRegionHeight, // Source
SRCCOPY);
SelectObject(m_hBitmapDC, hOldBitmap);
Do you know why this draw black image and not my BYTE* array?
Thanks!![Rose | [Rose]](https://www.codeproject.com/script/Forums/Images/rose.gif)
|
|
|
|
|
When doing this type of drawing for the first time and getting errors, you should check your return values, especially for CreateDIBSection. This can indicate where the problem occurs. I would also provide values for all the fields in the BITMAPINFO header structure. I'm assuming that all the other variables that you didn't explain, are correctly initialized values of some MFC class that you are using, and that the values are correct.
I don't use MFC, but you might read this: Drawing a View[^]
The article states: "A device context is a Windows data structure that contains information about the drawing attributes of a device such as a display or a printer. All drawing calls are made through a device-context object. For drawing on the screen, OnDraw is passed a CPaintDC object. For drawing on a printer, it is passed a CDC object set up for the current printer."
modified on Sunday, May 18, 2008 6:27 PM
|
|
|
|
|
 Mostly your order is wrong, you do not need to allocate the byte array, CreateDIBSection does that for you, the pbtImageArray pointer you are passing in is the output, not the input
So more along the lines of
#define BPP 32
int nBitPP = BPP / 8;
int nImageWidth = nWidth;
int nImageHeight = nHeight;
int nImageSize = nImageWidth * nImageHeight * nBitPP;
BITMAPINFO bitmapInfo;
bitmapInfo.bmiHeader.biSize = nBitmapInfoSize;
bitmapInfo.bmiHeader.biWidth = nImageWidth;
bitmapInfo.bmiHeader.biHeight = nImageHeight;
bitmapInfo.bmiHeader.biPlanes = 1;
bitmapInfo.bmiHeader.biBitCount = BPP;
bitmapInfo.bmiHeader.biSizeImage = nImageSize;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
BYTE* pbtImageArray = NULL;
HBITMAP hbmp = CreateDIBSection( pCDC->GetSafeHdc(), &bitmapInfo, DIB_RGB_COLORS, (void**)&pbtImageArray, NULL, 0);
for (int i = 0; i < nImageSize - nBitPP; i+=nBitPP)
{
pbtImageArray[i] = 0x0000;
pbtImageArray[i+1] = 0x0000;
pbtImageArray[i+2] = 255;
pbtImageArray[i+3] = 0x0000;
}
HDC hBitmapDC = CreateCompatibleDC(pCDC->GetSafeHdc() );
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBitmapDC, hbmp);
StretchBlt( pCDC->GetSafeHdc(),
nWindowX, nWindowY,
nWindowWidth, nWindowHeight,
hBitmapDC ,
nRegionX, nRegionY,
nRegionWidth, nRegionHeight,
SRCCOPY);
SelectObject(m_hBitmapDC, hOldBitmap);
|
|
|
|
|
Thanks! You are right, pbtImageArray is OUTPUT and not input.
I change it to void* pbtImageArray and add:
m_pbtImageArray = (BYTE*)pbtImageArray;
As for the previuse reply:
1) Off course at my original code I add nResult and do all the checks!!!
2) I add initialization for all variables at bitmapinfo.
Thanks you both! ![Rose | [Rose]](https://www.codeproject.com/script/Forums/Images/rose.gif)
|
|
|
|
|
i am using a chart control in my application to plot data.. i can comfortably plot the data but it is taking a long time to plot. how do i optimise the data so that i can plot in a lesser duration. now its taking alomost 6 to 8 mins to plot one data.
i am trying to read line by line now. what are the other ways to get the data?? please give me some leads.
thanks
|
|
|
|
|
Maybe with a bit more info or some code snippet... There can be different reasons for that.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
how many samples or lines are there in your file?
if they are more, then try to reduce them and see.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
We are trying to read Non-Ole File Properties (eg office 2007) using dsofile.dll. We can easily read properties of both Ole(doc file 97,2003) and non-ole(office 2007) using dsofile.dll(com dll). We did not use dsofile com dll because it has to be registered and take reference in the calling C# project. Actually we re-wrote our own dll using visual c++.net. The main interface for reading ole file property is IStoragePropertySet object. Here is the code snippets
// If the file is an OLE Storage DocFile...
if(StgIsStorageFile(m_bstrFileName)==S_OK)
{
IStorage *pStorage = NULL;
IPropertySetStorage *pPropSetStg = NULL;
HRESULT hr;
// Open the document as an OLE compound document.
hr = ::StgOpenStorage(wcFilename, NULL,
STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
}
else
{
//How to get non-ole file properties
}
As I showed the code snippets, there is no problem in getting ole-file properties. What we are struck in is getting non-ole file property.
Here is the code snippets from the original source code of dsofile com dll.
if (StgIsStorageFile(m_bstrFileName) == S_OK)
{
hr = StgOpenStorage(m_bstrFileName, NULL, dwOpenMode, NULL, 0, &m_pStorage);
if (((hr == STG_E_ACCESSDENIED) || (hr == STG_E_SHAREVIOLATION)) &&
(m_dwFlags & dsoOptionOpenReadOnlyIfNoWriteAccess))
{
m_fReadOnly = TRUE;
hr = StgOpenStorage(m_bstrFileName, NULL,
(STGM_READ | STGM_TRANSACTED | STGM_SHARE_DENY_NONE), NULL, 0, &m_pStorage);
}
if (SUCCEEDED(hr))
{
hr = m_pStorage->QueryInterface(IID_IPropertySetStorage, (void**)&m_pPropSetStg);
}
}
else if ((m_dwFlags & dsoOptionOnlyOpenOLEFiles) != dsoOptionOnlyOpenOLEFiles)
{
CLSID clsidMetaHandler = {0};
IPersistFile *prtsf = NULL;
if (DsoGetMetaHandler(m_bstrFileName, &clsidMetaHandler) == S_OK)
{
hr = CoCreateInstance(clsidMetaHandler, NULL, CLSCTX_INPROC, IID_IPersistFile, (void**)&prtsf);
if (SUCCEEDED(hr))
{
hr = prtsf->Load(m_bstrFileName, dwOpenMode);
if (SUCCEEDED(hr))
{
hr = prtsf->QueryInterface(IID_IPropertySetStorage, (void**)&m_pPropSetStg);
if (SUCCEEDED(hr)){ASSIGN_INTERFACE(m_pPrstFile, prtsf);}
}
prtsf->Release();
}
else hr = DSO_E_NODOCUMENTPROPS;
}
else if (v_pfnStgOpenStorageEx)
{
hr = (v_pfnStgOpenStorageEx)(m_bstrFileName, dwOpenMode, STGFMT_FILE, 0, NULL, 0,
IID_IPropertySetStorage, (void**)&m_pPropSetStg);
if ((hr == STG_E_ACCESSDENIED) && (!m_fReadOnly) &&
(m_dwFlags & dsoOptionOpenReadOnlyIfNoWriteAccess))
{
m_fReadOnly = TRUE;
hr = (v_pfnStgOpenStorageEx)(m_bstrFileName, (STGM_READ | STGM_SHARE_EXCLUSIVE), STGFMT_FILE,
0, NULL, 0, IID_IPropertySetStorage, (void**)&m_pPropSetStg);
}
}
We successfully converted the code in italic ie for ole file. We are trying to convert code in bold ie for non-ole but we are not yet success. What we are trying to do is
to read the non-ole file properties using dll instead of com dll(ie dsofile.dll).
We are very much eager to hear you genius guys.
Thank You
Prakash Tandukar
|
|
|
|
|
for non- ole file types we have to get pointer of IID_IPropertySetStorage rather than istorage and the rest will be the same.
only problme here is we cant update office 2007 file type as the file structure of office 2007 file type is bit different.
if you fine any solution for accessing office 2007 do let me know.
if(nFileType == non- ole)
{
hr =SetPropertySetStorage(pszFilePath);
if (hr == S_OK )
{
hr = SetSummaryInfoStorage();
if(FAILED(hr))
{
printf(" Summaryinfo storage failed w/error %08lx", hr);
return hr;
}
hr = SetCustomInfoStorage();
if(FAILED(hr))
{
printf(" Custom storage failed w/error %08lx", hr);
return hr;
}
}
else
{
return hr;
}
}
HRESULT CFileProperties::SetPropertySetStorage(const char * pszFilePath )
{
HRESULT hr = S_OK;
if(pszFilePath == NULL && m_pStorage != NULL)
{
hr = m_pStorage->QueryInterface(IID_IPropertySetStorage, (void **)&m_pPropSetStg);
if(FAILED(hr))
{
printf("QI for IPropertySetStorage failed w/error %08lx", hr);
//Releasing IStorage
m_pStorage->Release();
m_pStorage = NULL;
return hr;
}
}
else if(pszFilePath != NULL && m_pStorage == NULL)
{
// Translate filename to Unicode.
WCHAR wcFilename[1024];
setlocale( LC_ALL, "" );
int i = mbstowcs(wcFilename, pszFilePath , strlen(pszFilePath ));
setlocale( LC_ALL, "C" );
wcFilename[i] = 0;
// Open the document as an OLE compound document.
hr = StgOpenStorageEx( wcFilename,
STGM_READ|STGM_SHARE_DENY_WRITE,
STGFMT_ANY,
0, NULL, NULL,
IID_IPropertySetStorage,
reinterpret_cast<void**>(&m_pPropSetStg) );
if(FAILED(hr))
{
if(hr == STG_E_FILENOTFOUND)
printf("File not found.");
else if(hr == STG_E_FILEALREADYEXISTS)
printf("Not a compound file.");
else
printf("StgOpenStorage() failed w/error %08lx", hr);
return hr;
}
}
return hr;
}
HRESULT CFileProperties::SetSummaryInfoStorage()
{
HRESULT hr = S_FALSE;
if(m_pPropSetStg != NULL)
{
// Create SummaryInformation, getting an IpropertyStorage.
hr= m_pPropSetStg->Create(FMTID_SummaryInformation,
0,
PROPSETFLAG_DEFAULT,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,&m_pSummaryInfoStg);
//propertystorage already exists for SummaryInformation
if(hr == STG_E_FILEALREADYEXISTS )
{
// Open summary information, getting an IpropertyStorage.
hr = m_pPropSetStg->Open(FMTID_SummaryInformation,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &m_pSummaryInfoStg);
if(FAILED(hr))
{
printf("No Summary-Information.\n");
return hr;
}
}
}
return hr;
}
HRESULT CFileProperties::SetCustomInfoStorage( )
{
HRESULT hr = S_FALSE;
if(m_pPropSetStg != NULL)
{
// Create UserDefinedProperties, getting an IpropertyStorage.
hr= m_pPropSetStg->Create(FMTID_UserDefinedProperties,
0,
PROPSETFLAG_DEFAULT,
STGM_READWRITE | STGM_SHARE_EXCLUSIVE,&m_pCustomInfoStg);
//propertystorage already exists for UserDefinedProperties
if(hr == STG_E_FILEALREADYEXISTS )
{
// Open User-Defined-Properties, getting an IpropertyStorage.
hr = m_pPropSetStg->Open(FMTID_UserDefinedProperties,
STGM_READWRITE| STGM_SHARE_EXCLUSIVE, &m_pCustomInfoStg);//| STGM_WRITE
if(FAILED(hr))
{
printf("No User Defined Properties.\n");
return hr;
}
}
}
return hr;
}
hi
|
|
|
|
|
For reading Non ole files(office 2007 files)
if (NonOLEGetMetaHandler(m_bstrFileName, &clsidMetaHandler) == S_OK)
{
CoInitialize(NULL);
// Create instance of the Metadata Handler object...
hr = CoCreateInstance(clsidMetaHandler, NULL, CLSCTX_INPROC, IID_IPersistFile,(void**)&prtsf);
if (SUCCEEDED(hr))
{
// Ask it to load the file for parsing...
hr = prtsf->Load(m_bstrFileName, (STGM_READWRITE | STGM_SHARE_EXCLUSIVE));
if (SUCCEEDED(hr))
{
// If it succeeded, ask for the property set storage...
hr = prtsf->QueryInterface(IID_IPropertySetStorage,(void**)&m_pPropSetStg);
if (SUCCEEDED(hr))
{
//ASSIGN_INTERFACE(m_pPrstFile, prtsf);
// hr= m_pPropSetStg->Create(FMTID_SummaryInformation,
// 0,
// PROPSETFLAG_DEFAULT,
// STGM_READWRITE | STGM_SHARE_EXCLUSIVE,&m_pSummaryInfoStg);
hr = SetSummaryInfoStorage();
if(FAILED(hr))
{
printf(" Summaryinfo storage failed w/error %08lx", hr);
return hr;
}
hr = SetCustomInfoStorage();
if(FAILED(hr))
{
printf(" Custom storage failed w/error %08lx", hr);
return hr;
}
prtsf->Release();
}
}
HRESULT CFileProperties::NonOLEGetMetaHandler(LPCWSTR pwszFile, LPCLSID lpClsid)
{
HRESULT hret = REGDB_E_CLASSNOTREG; // Assume no handler
HKEY hkeyExt, hkeyHandler = NULL;
LPSTR pszExt;
if ((pwszFile == NULL) || (*pwszFile == L'\0') || (lpClsid == NULL))
return E_INVALIDARG;
// Get the extension for the file...
pszExt = NonOLEConvertToMBCS(GetExtensionPart(pwszFile), CP_ACP);
if (pszExt == NULL) return E_OUTOFMEMORY;
// Now get the key that is associated with that extension...
hkeyExt = GetHKCRKey("%s", pszExt);
if (hkeyExt)
{
// Check for the handler under that key...
hkeyHandler = GetHKCRKey("%s\\ShellEx\\PropertyHandler", pszExt);
if (hkeyHandler == NULL)
{
CHAR szType[MAX_PATH];
DWORD dwT, cb = MAX_PATH; szType[0] = '\0';
// If it does exist there, check under the associated type...
if ((RegQueryValue(hkeyExt, NULL, szType, (LONG*)&cb) == ERROR_SUCCESS) && (cb))
{
hkeyHandler = GetHKCRKey("%s\\ShellEx\\PropertyHandler", szType);
if (hkeyHandler == NULL)
{
// If still no handler, you can check for handler on the "perceivedtype", which normally
// is for things like images that can have multiple extensions to single base type...
cb = MAX_PATH; szType[0] = '\0';
if ((RegQueryValueEx(hkeyExt, "PerceivedType", NULL, &dwT, (BYTE*)szType, &cb) == ERROR_SUCCESS) &&
(cb) && (dwT == REG_SZ))
{
hkeyHandler = GetHKCRKey("SystemFileAssociations\\%s\\ShellEx\\PropertyHandler", szType);
}
}
}
}
RegCloseKey(hkeyExt);
}
// If we got a reg key, then there is an handler key, lookup the GUID and provide to the caller...
if (hkeyHandler)
{
CHAR szGUID[80];
DWORD cb = 80; szGUID[0] = '\0';
if ((RegQueryValue(hkeyHandler, NULL, szGUID, (LONG*)&cb) == ERROR_SUCCESS) && (cb))
{
BSTR bstrGuid = NonOLEConvertToBSTR(szGUID, CP_ACP);
if (bstrGuid)
{
hret = CLSIDFromString(bstrGuid, lpClsid);
SysFreeString(bstrGuid);
}
}
RegCloseKey(hkeyHandler);
}
CoTaskMemFree(pszExt);
return hret;
}
hi
|
|
|
|
|
i create an activex with Visual c++6(mfc) and called its property in a vc sample.
i add one new property to AxtiveX but when i run my sample get "invalid number of parameters" error message.
i didnt any change in old property and just add new property with class wizard but get this error.
please help me
|
|
|
|
|
Can you put a bit of code where the error is coming? I guess that if you didn't change anything but you add a new property it is maybe missing something when you call/create your control.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Nelek wrote: Can you put a bit of code where the error is coming?
DISP_PROPERTY_EX(CMyCtrl, "AutoChecking", GetAutoChecking, SetAutoChecking, VT_BOOL)
//=============================================
afx_msg void SetAutoChecking(BOOL bNewValue);
afx_msg BOOL GetAutoChecking();
//=============================================
void CMyCtrl::SetAutoChecking(BOOL bNewValue)
{
bAutoCheck = bNewValue;
SetModifiedFlag();
}
//=============================================
BOOL CMyCtrl::GetAutoChecking()
{
// TODO: Add your property handler here
return bAutoCheck;
}
//=============================================
dispidAutoChecking = 17L,
|
|
|
|
|
Change version of lib.
See MSDN[^] for more information.
Prasad
MS MVP - VC++
|
|
|
|
|
Is it possible for me to use GetControlUnkown() function of CWnd in a static library built with the option of not using MFC
Regards
|
|
|
|
|
Look in the MFC source code and see how it implements that function. MFC is, at its heart, a wrapper for the Win32 API.
Judy
|
|
|
|
|
I want to draw a calendar on desktop.
I use SPI_GETDESKWALLPAPER & SPI_SETDESKWALLPAPER to get & set the wallpaper. But I don't know how to create a bitmap with a specific path & how to copy a bitmap to another bitmap so that we can save the previous desktop. Until now, I just add bitmap to resource & use. So, I don't know how to do. S ome one plz help me ...
|
|
|
|
|
Take a look here[^]
Edit: Changed Link with more precise search
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
modified on Sunday, May 18, 2008 6:36 AM
|
|
|
|
|
If I can find, I won't ask you 
|
|
|
|
|
capint wrote: If I can find, I won't ask you
If you don't say you have already searched we can not adivinate it.
By the way, in that results there are articles that use some things that you will need to make what you want. Just to explain all is a bit large to be done at once. Take a look on the articles, make tests and ask when you have problem in one section. You will easily get the help asking something concrete that you can't solve that something with so much information to be given as your first post.
capint wrote: how to copy a bitmap to another bitmap so that we can save the previous desktop
Take a look into the articles 2,3 and 4 of the search results I gave you. Make a screenshot can be more or less the same as getting the bitmap of the desktop.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|