|
John Theal wrote:
Is there and easy way to send data to and Excel worksheet
from an MFC application?
For example, if I have an open excel worksheet, can I send data
from a separate application to that worksheet with a small amount of
code/effort?
It depends of what you want to do. Just make a search on MSDN[^] with "HOWTO automation Excel", or have a look at Article ID: Q178749 and Article ID: Q178781 (in MSDN) and you will have a good start.
~RaGE();
|
|
|
|
|
We need to capture view, when a dialog box is being displayed. we are not getting the information of the view which is below the dialog box.
could anybody please help to solve this problem.
thanx.
|
|
|
|
|
What is not working ? What did you try ? How is your code ? What is returned by GetActiveView() ?
~RaGE();
|
|
|
|
|
I'm coding an MFC MDI doc/view simple sound editor called Asaph.
There are 2 menu resources: the IDR_MAINFRAME one for when there are no open docs, and the IDR_ASAPHTYPE one used when a doc is open.
I want to be able to dynamically add menu items (using CMenu::InsertMenu()) for things like plugins, to the IDR_ASAPHTYPE menu.
Even tho the applicatiopn starts with a new blank doc, when CMainFrame::OnCreate() is called, GetMenu() still returns the CMenu created from IDR_MAINFRAME.
When is the doc menu loaded and how I can I access it to add the items ?
My only idea so far is to do it from the the document class in the first call to OnNewDocument() or OnOpenDocument() but that seems like a bit of a hack fix.
Cheers, Rowan
|
|
|
|
|
In order to write registry keys etc., I want t use the details entered in the version part of a resource (such as CompanyName).
The question is, how do I read this ?
Thanks.
Elaine
The tigress is here
|
|
|
|
|
Here you go
bool GetDllVersion ( LPTSTR szDllFilename, std::string& sProductVersion )
{
DWORD dwHandle, dwInfoSize;
BYTE* pBuffer;
void* pvVersion;
UINT uBufLen;
dwInfoSize = GetFileVersionInfoSize ( szDllFilename, &dwHandle );
if ( 0 == dwInfoSize )
return false;
pBuffer = new BYTE [dwInfoSize];
if ( NULL == pBuffer )
return false;
__try
{
if ( 0 == GetFileVersionInfo ( szDllFilename, dwHandle, dwInfoSize, pBuffer
return false;
if ( 0 == VerQueryValue ( pBuffer, _T("\\StringFileInfo\\040904B0\\ProductVersion"),
&pvVersion, &uBufLen ))
return false;
sProductVersion = (LPCTSTR) pvVersion;
}
__finally
{
delete [] pBuffer;
}
return true;
}
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Thanks Mike, but that is to get the version number of an external DLL.
I was trying to avoid redundant information in my project by reading the CompanyName string from the resource and using that to build the registry key entry. This would include ProductName.
Elaine
The tigress is here
|
|
|
|
|
That's what the code does, reads the version resource from a binary (it doesn't have to be a DLL, you can pass the filename of your EXE). Just change the "ProductVersion" part in the VerQueryValue() call to the field you want to read.
--Mike--
Latest blog entry: *drool* (Alyson) [May 10]
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Is this a valid check to see if a file has been opened?
ofstream NodeOrig;
NodeOrig.open("NodeOrig.txt", ios::out);
if ( !NodeOrig.is_open() )
throw "Could not open original node data file.\n";
|
|
|
|
|
If you are sure the target file path is correct and the file not corrupted, then Yes.
~RaGE();
|
|
|
|
|
Maybe this is a bit more robust?
ofstream NodeOrig;
NodeOrig.open("NodeOrig.txt", ios::out);
if ( NodeOrig.fail() )
throw "Could not open original node data file.\n";
or maybe I should be checking flags?
Eg:
if(FileStream.rdstate() == ios::eofbit)
cout << "End of file!\n";
if(FileStream.rdstate() == ios::badbit)
cout << "Fatal I/O error!\n";
if(FileStream.rdstate() == ios::failbit)
cout << "Non-fatal I/O error!\n";
if(FileStream.rdstate() == ios::goodbit)
cout << "No errors!\n";
|
|
|
|
|
Maybe just?
if(FileStream.fail())
{
throw ...
}
|
|
|
|
|
the problem is : where should i put the lines of drawing ? in OnPaint() only? what else should i do ?
i wish to draw the titlebar of one SDI program. but i met some problems.
here is how i do it as following:
i add lines in the CMainFrame::OnPaint() :
<br />
CFrameWnd::OnPaint();<br />
<br />
if (IsIconic()) return;<br />
<br />
RECT stRect1;<br />
<br />
::GetWindowRect(m_hWnd, &stRect1);<br />
<br />
CRgn m_rgn0;<br />
m_rgn0.CreateRectRgn(0,8,stRect1.right-stRect1.left,stRect1.bottom- stRect1.top);<br />
<br />
SetWindowRgn(m_rgn0,1);<br />
<br />
<br />
RECT stRect;<br />
<br />
CRect rect;<br />
<br />
<br />
CDC *pDC;<br />
pDC = GetWindowDC();<br />
<br />
<br />
<br />
<br />
::GetWindowRect(m_hWnd, &stRect);<br />
<br />
<br />
<br />
rect.SetRect(0,0,stRect.right - stRect.left,stRect.bottom - stRect.top);<br />
<br />
HDC hDC = ::GetWindowDC(m_hWnd);<br />
<br />
HPEN hPen;<br />
hPen = CreatePen(PS_INSIDEFRAME, 1* GetSystemMetrics(SM_CXBORDER), <br />
RGB(123, 200, 243));<br />
<br />
CPen pen;<br />
<br />
pen.CreatePen(PS_INSIDEFRAME, 1* GetSystemMetrics(SM_CXBORDER), <br />
RGB(123, 220, 233));<br />
<br />
<br />
pDC->SelectObject(&pen);<br />
<br />
<br />
<br />
<br />
<br />
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);<br />
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));<br />
<br />
stRect.bottom = stRect.bottom-stRect.top;<br />
stRect.right = stRect.right-stRect.left;<br />
<br />
int btm = stRect.bottom;<br />
<br />
CRgn m_rgn6,m_rgn5,m_rgn7;<br />
<br />
m_rgn6.CreateRectRgn(0,0,4,stRect.bottom);<br />
m_rgn5.CreateRectRgn(stRect.right -4,0,stRect.right,stRect.bottom);<br />
m_rgn7.CreateRectRgn(0,stRect.bottom-4,stRect.right,stRect.bottom);<br />
<br />
stRect.left = 0 ;<br />
stRect.top = 0 ;<br />
stRect.bottom = 29;<br />
<br />
<br />
<br />
m_rgn2.CreateRectRgn(stRect.left,stRect.top,stRect.right,stRect.bottom);<br />
<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn,RGN_DIFF);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn6,RGN_OR);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn5,RGN_OR);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn7,RGN_OR);<br />
<br />
SelectClipRgn(hDC,HRGN(m_rgn2));<br />
<br />
<br />
CBrush brush;<br />
<br />
brush.CreateSolidBrush(RGB(255,255,255));<br />
<br />
<br />
<br />
<br />
FillRgn(hDC,HRGN(m_rgn2),HBRUSH(brush));<br />
<br />
brush.CreateStockObject(NULL_BRUSH);<br />
<br />
int i = 0;<br />
<br />
for (i; i < btm;i)<br />
{<br />
MoveToEx(hDC,0,i,NULL);<br />
LineTo(hDC,stRect.right,i); <br />
i += 2;<br />
}<br />
<br />
hPen = CreatePen(PS_INSIDEFRAME, 2* GetSystemMetrics(SM_CXBORDER), <br />
RGB(33, 120, 120));<br />
<br />
SelectObject(hDC, hPen);<br />
<br />
MoveToEx(hDC,2,28,NULL);<br />
LineTo(hDC,stRect.right-2,28);<br />
<br />
<br />
MoveToEx(hDC,3,28,NULL);<br />
LineTo(hDC,3,btm-3);<br />
<br />
MoveToEx(hDC,stRect.right-3,28,NULL);<br />
LineTo(hDC,stRect.right-3,btm-3);<br />
<br />
MoveToEx(hDC,3,btm-4,NULL);<br />
LineTo(hDC,stRect.right-3,btm-4);<br />
<br />
<br />
MoveToEx(hDC,0,0,NULL);<br />
LineTo(hDC,0,btm);<br />
<br />
MoveToEx(hDC,stRect.right,0,NULL);<br />
LineTo(hDC,stRect.right,btm);<br />
<br />
<br />
::ReleaseDC(m_hWnd,hDC);<br />
<br />
SelectObject(hDC, hOldPen);<br />
SelectObject(hDC, hOldBrush);<br />
<br />
DeleteObject(hPen);<br />
DeleteObject(hDC);
it works well at most times, but when the window lost focus or reactiviate, it doesn't redraw. when u drag this window, it doesn't redraw after it moves from top-outside area back, either.
Jiang
|
|
|
|
|
|
Try also the invalidate in OnEraseBackground() only, this should catch the three previous cases.
~RaGE();
|
|
|
|
|
Try to Invalidate() your window titlebar rect in OnActivate() , OnKillFocus() and OnMoving()
~RaGE();
|
|
|
|
|
OnPaint() is used to paint the client area. The title bar is a non-client area. Look up (search) WM_NCPAINT or OnNcPaint(). You could also try searching for "owner drawn title bar" here or on the www.
Trust in the code Luke. Yea right!
|
|
|
|
|
I am designing a software to collect and organize web pages catched from internet and the drafts created user himself. In my first model, i store them in file system. But there are so many little gif/jpg that will waste disk space and not easy to manage. I hope there is a way to pack them into a single file or database.
The first thing into my mind is a zip file, but i dont know whether it is efficient enough for delete and insert frequently.
The second one is a ole docfile, it is said to be a file with directory structure inside. But i have very limit knowledge about it, hope somebody can tell me whether it is fit for my usage.
The third one is some object databases, i know zope is a good one, but it is build on python. Hope you can introduce some good c/c++ object database for me.
Thank you!
|
|
|
|
|
I know something about docfile. A DOCFile is literally a file-system inside a file. There's 2 classes to know about:
* IStorage -- acts like a directory
* IStream -- acts like a file.
(1) Create a DOCFILE with a method like: StgCreateDocfile(). This allocates your root IStorage object.
(2) Create an IStream for each file you want stored. Use IStorage::CreateStream().
if you want to create a directory within the file, then use IStorage::CreateStorage().
Make sure to call the Release() method on each object. Since this is COM, you cannot delete the objects you request. You must release() them and hope they clean themselves up.
DOCFILE's do not self compact themselves. To do compaction of the file, I think you have to just create a new docfile, and use IStorage::CopyTo to copy to the new one.
It's been about 5 years since I've done this, but I assume nothing here has changed.
-p
|
|
|
|
|
I have a problem mapping the WM_NCHITTEST message.
In my App I have derived a class from CStatic in order
to develop some specific functionalities (I also need
to know when the mouse is on my CStatic control and where
it is).
So I'd like to map WM_NCHITTEST message into my derived
class using the afx_msg UINT OnNcHitTest(CPoint point)
method.
I've associated an instance of my class to a CStatic control being part of the main window and using the Spy++
application I have seen that WM_NCHITTEST message is sent
to my control but OnNcHitTest method is not called !!!
Where is the problem ?
Thanks a lot !!!
|
|
|
|
|
You have to use SetCapture() first.
~RaGE();
|
|
|
|
|
But... if I use SetCapture all buttons in the main window
doesn't works !!! Is it true ? I've seen this...
|
|
|
|
|
Yes, that's true. I think you should better use afx_msg void OnNcMouseMove( UINT nHitTest, CPoint point ); and afx_msg void OnNcLButtonDown( UINT nHitTest, CPoint point ); which, as for them, do not require capture of the mouse.
~RaGE();
|
|
|
|
|
Hi All,
I'm having a bit of trouble adding derived objects of CObject to a CObArray object. I get the following error:
error C2243: 'type cast' : conversion from 'DoobyObj *__w64 ' to 'CObject *' exists, but is inaccessible
This is just a test for a later prject (hence the stupid class name). I need the DoobyObj class to inherit from CObject class so that I can serialize the CObArray object.
The error occurs on the Add line:
void SerObject::addDoobyObject(DoobyObj dO)
{
obaObjects.Add(&dO); //CObArray
resetIndex();
}
Here is the definition of DoobyObj:
class DoobyObj : CObject
{
public:
DECLARE_SERIAL( DoobyObj )
DoobyObj();
void Serialize(CArchive& archive );
CString dooby;
};
Can anyone solve my problem??
Thanks,
Donal
|
|
|
|
|
Are you compiling for 64-bit Windows, by any chance? I'm not sure MFC works with 64-bit Windows yet... It might, but that may be the reason
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|