|
The easiest way is to add a WM_ERASEBKGND handler to the window class. In response to the
message, draw the background in the color of your choice:
BOOL CMyFrameWnd::OnEraseBkgnd(CDC* pDC)
{
CBrush bkBrush(RGB(0xFF,0x00,0x00));
pDC->SelectObject(bkBrush);
CRect CliRect;
GetClientRect(&CliRect);
pDC->PatBlt(CliRect.left, CliRect.top, CliRect.Width(), CliRect.Height(), PATCOPY);
return TRUE;
}
Another way is to register a window class (instead of using the default) and in the WNDCLASS
struct set the hbrBackground member to a brush of the desired color.
Note that if your main frame has a view in it then you need to do this in the view class, not the
frame class.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I add OnEraseBkgnd as you suggest in my main frame class, and when I launch my window application I see the red back ground flash quickly and then back to white back ground. Do you know why? Thanks
|
|
|
|
|
gurucplusplus wrote: Do you know why?
Yes, because you should have done it in the view class
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I got it. Thanks. But I have another question. I want to draw lines and rectangle box as overlay to exiting image display on main window frame. How can I do it? I currently can drawing lines, rectangle box on my image as I use mouse left and right mouse buttons. but what I did is to draw onto the image but not on graphic overlay frame. Thanks.
|
|
|
|
|
As with the background, if you have a view in the frame then you do your drawing there instead of
on the frame window - otherwise it will be "covered" by the view window like when you saw the
frame background window flash.
Typically, you'd do your drawing in response to a WM_PAINT message, after the image has been
drawn. If it's a CView-derived class, overriding OnDraw() may be a more appropriate place,
especially if the base class draws the image in OnDraw().
Either way, this means you need to store the coordinates (or whatever info is necessary) to redraw
everything every time repainting is necessary (when WM_PAINT is received).
How is the image being rendered in your case?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I am new to MFC/VisualC++ 6.0. Can you point me few examples of how to draw graphic overlay in MFC?
|
|
|
|
|
Do you have an image that's already being drawn? If so, how is being done? With a little
more specifics I think I can give you a more specific example
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I load the image from disk using IPicture renderring. This is my OnDraw(CDC* pDC) from CView class:
CMyDoc* pDoc = this->GetDocument();
ASSERT_VALID(pDoc);
HPALETTE hPal;
pDoc->m_pPicture->get_hPal(reinterpret_cast<ole_handle *="">(&hPal));
CPalette *pPalOld = NULL;
if (hPal != NULL)
{
TRACE(_T("CXpiProView::OnDraw - RealizePalette\n"));
pPalOld = pDC->SelectPalette(CPalette::FromHandle(hPal), FALSE);
pDC->RealizePalette();
}
RECT rc;
this->GetClientRect(&rc);
// display picture using IPicture::Render
pDoc->m_pPicture->Render(pDC->GetSafeHdc(),pDoc->m_sizeInPix.cx,
pDoc->m_sizeInPix.cy,0,pDoc->m_sizeInHiMetric.cy,
pDoc->m_sizeInHiMetric.cx,-pDoc->m_sizeInHiMetric.cy,&rc);
|
|
|
|
|
I have a number of very mature applications and I'm taking the big leap to Vista and Visual Studio 2005. Previously I used VC6 and XP. I got VS2005 installed with SP2. Got my application to compile and execute. So far so good.
I need to have the application run on XP, NT, etc. Previously with VC6 this was no problem. I just copied the EXE and the correct MFC DLLs to the target machine and it all worked. From windows 98 and on it all worked fine.
Problem is something isn't the same and I don't know the magic. I complied my app with VS2005, copied the EXE and the two MFC DLLs (MFC80.DLL and MSVCRT.DLL) to my XP machine and when I try and start it up, the obscure message "The application failed to initialize properly (0xc0000142)" appears.
Anyone know what this means and how to fix whatever the heck is wrong?
Kimberly
|
|
|
|
|
hcatech wrote: Anyone know what this means and how to fix whatever the heck is wrong?
See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You need to run the vcredist_x86.exe installer on the other machine.
|
|
|
|
|
Thanks Mike.
I installed the windows installer on the XP machine and then downloaded and ran the vcredist exe you recommended. All appeared to go well. Problem is the application still doesn't work. The message I get is:
"The application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem"
It's just a single EXE and all this shouldn't be this hard....
Any ideas?
|
|
|
|
|
Did you use the redist installer that matches your version of VS? There are two - original and SP1.
|
|
|
|
|
You can just copy the .dll's that you want but you have to put them into directories with their manifests. For example, (from here[^])
to include Microsoft.VC80.MFC.dll you need to copy the \Microsoft.VC80.MFC directory from %VCINSTALLDIR%\redist\ into the loacl application directory like:
<br />
\bin\<br />
myApplication.exe<br />
\Microsoft.VC80.MFC<br />
This works on XP but I don't think it works on earlier OSs. A simple way to install is to create a setup project in VS2005.
Peter
"Until the invention of the computer, the machine gun was the device that enabled humans to make the most mistakes in the smallest amount of time."
|
|
|
|
|
Hi,
What do I need to do so that the CRuntimeClass addresses known to my Regular DLL correspond to the CRuntimeClass addresses known to a CObject-derived object passed to the DLL from an application?
Here's the details of my problem (forgive the verbosity)...
I needed to control access to an object used by multiple threads. I used the Microsoft-documented CMutex/CSingleLock approach. Here's what my object class sort of looks like:
class MyThreadSafeResource
{
public:
MyThreadSafeResource(CString dllFileName);
void start();
void someMethod();
private:
static UINT run(LPVOID p);
CMutex m_lock;
HINSTANCE m_dll;
};
MyThreadSafeResource::MyThreadSafeResource(CString dllFileName)
{
// Load the passed DLL.
m_dll = ::LoadLibrary(dllFileName);
}
void MyThreadSafeResource::start()
{
CSingleLock singleLock(&m_lock);
singleLock.Lock();
// Spawn a worker thread
::AfxBeginThread(run, this);
}
void MyThreadSafeResource::someMethod()
{
CSingleLock singleLock(&m_lock); // POINT X
singleLock.Lock();
...
}
UINT MyThreadSafeResource::run(LPVOID)
{
MyThreadSafeResource* resource = (MyThreadSafeResource*)p;
// Call the function exposed by the DLL.
typedef void (*ExternalFunction)(LPVOID p);
ExternalFunction dllFunc = (ExternalFunction)::GetProcAddress(m_dll, "dllFunc");
dllFunc(resource);
return 0;
}
Here's what my exported DLL function sort of looks like:
extern "C"
{
__declspec(dllexport) bool dllFunc(LPVOID p)
{
MyThreadSafeResource* resource = (MyThreadSafeResource*)p;
resource->someMethod();
...
}
}
From my application's main thread I create a new instance of my resource class and "start" it:
MyThreadSafeResource resource = new MyThreadSafeResource("C:\TEMP\MYDLL.DLL");
resource->start();
At first, everything goes well... my resource object loads the DLL successfully, in the "start" method my worker thread is created successfully, my object is passed to the worker thread successfully, the worker thread calls the function within my DLL successfully, my object is passed to the DLL function successfully.
Its when the DLL function calls a method in my passed object that things go bad. My application abends at "POINT X" with the following message:
Unhandled exception at 0x00643185 in MyApplication.exe: 0xC0000005:
Access violation reading location 0x00c85edc.
It appears that the called method's CSingleLock construction is failing when it tries to ensure that the passed CMutex object is derived from CSyncObject. Here's the call stack at the time of failure:
MyDll.dll!CRuntimeClass::IsDerivedFrom(const CRuntimeClass * pBaseClass=0x101a1e9c) Line 174 C++
MyDll.dll!CObject::IsKindOf(const CRuntimeClass * pClass=0x101a1e9c) Line 45 C++
MyDll.dll!CSingleLock::CSingleLock(CSyncObject * pObject=0x00b87878, int bInitialLock=0) Line 90 + 0xd C++
MyDll.dll!MyThreadSafeResource::someMethod() Line 126 + 0x11 C++
MyDll.dll!dllFunc(void * p=0x00b87830) Line 52 + 0x8 C++
MyApplication.exe!MyThreadSafeResource::run(void * p=0x00b87830) Line 238 + 0x9 C++
MyApplication.exe!_AfxThreadEntry(void * pParam=0x0012f194) Line 114 + 0xd C++
MyApplication.exe!_threadstartex(void * ptd=0x00b87a58) Line 241 + 0xd C
kernel32.dll!7c80b683()
Any thoughts? Any and all help appreciated.
Thanks!
Peter
|
|
|
|
|
Are you sure the pointer (to the passed object) the DLL is using is valid?
If so, what does your DllMain() function look like?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I figured out my problem... me.
I just had to add the AFX_MANAGE_STATE macro at the beginning of the exported function in my DLL:
AFX_MANAGE_STATE(AfxGetStaticModuleState())
Just standard "DLL using MFC" stuff. It's obviously been way too long since I've worked with this stuff.
Peter
|
|
|
|
|
Cool
Extension DLL Hell!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
hello everyone
I want to Find all computers in a network... But these computers are not in a group using network setup wizard...
IpEnum and xLanInfo doesn't work.
please help me.
Thank u
Every new thing you learn,Gives you a new personality.
|
|
|
|
|
Have you tried NetServerEnum() ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm writing a file manipulation program, and was wondering in your experience what is the most efficient buffer size to load at a time and manipulate. Would this simply be based on the largest chunk of memory I am willing to allocate on the system, or can smaller buffers produce faster results? Speed is important because I could be converting several thousand files at a time.
Thanks,
Dustin
|
|
|
|
|
How much overhead would it be to first iterate the list of files, look for the largest file, and allocate that much memory?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The biggest problem would not neccesarily be the overhead, but the allocation itself. What happens if I run accross a 2GB file? I'm actually attemting to write an encryption program, more as an experiment than anything, and do not know the make up of the files I will be opening.
|
|
|
|
|
Dustin Henry wrote: What happens if I run accross a 2GB file?
Indeed that would be a problem.
Dustin Henry wrote: I'm actually attemting to write an encryption program...
What does the encryption algorithm require (in terms of input)?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am actually using my own random number generator to randomly convert each byte of data based on an initial seed, so the only requirement is that I process the data in order.
|
|
|
|