|
Hosam Aly Mahmoud wrote:
I thought that WM_PAINT would only allow me to draw a certain region of the window, not all of it.
The device context given as a parameter to a WM_PAINT message is set up to only draw to the regions of the window which have been invalidated. By definition, any region that is not invalidated, does not need painting, so you shouldn't have a problem.
Hosam Aly Mahmoud wrote:
Also, the docs said that to make a background (for example a picture) you should handle WM_ERASEBKGND. Am I wrong?
WM_ERASEBKGND is sent whenever InvalidateRect() or InvalidateRgn() are called with fErase=TRUE . If the fErase flag is FALSE , then WM_ERASEBKGND is not sent. It is quite ok to draw the background in WM_PAINT however. In fact, to get true flicker-free drawing, it is the only way.
Ryan "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"
|
|
|
|
|
Many thanks for your reply. I am using Win32 API, so I get the HDC using BeginPaint() . I tried to draw in WM_PAINT, but I get a white background although I have myWndClass.hbrBackground = NULL . Here is my code:
case WM_PAINT:
{
static PAINTSTRUCT ps;
static dc = BeginPaint(hWnd, &ps);
static HDC memDC = CreateCompatibleDC(dc);
static HBITMAP memBitmap = CreateCompatibleBitmap(dc, MainWindowRect.right, MainWindowRect.bottom);
SelectObject(memDC, memBitmap);
FloodFill ( memDC, 20, 20, RGB(255,0,0) );
static HBRUSH oldBrush = (HBRUSH) SelectObject(memDC, myBrush);
Rectangle(memDC, myRect.left, myRect.top, myRect.right, myRect.bottom );
SelectObject(memDC, oldBrush);
BitBlt(dc, 0, 0, MainWindowRect.right, MainWindowRect.bottom,
memDC, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
return 0;
}
case WM_ERASEBKGND:
return 0;
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Remove the static keyword from all of your variable declarations and try again.
Ryan "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"
|
|
|
|
|
I did it but no difference.
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
FloodFill ( memDC, 20, 20, RGB(255,0,0) ); // red background
I should have seen this before...
The colour you pass to FloodFill() is not the colour of the fill. It's the colour of the border. FloodFill() fills the area with the currently selected brush. To fill a rectangle with a given colour, either create a solid brush (CreateSolidBrush() ) and use Rectangle() , or use the ExtTextOut() function to draw opaque text without actually drawing text:
SetBkColor(memDC, RGB(255,0,0));
RECT rect;
ExtTextOut(memDC, 0, 0, ETO_OPAQUE, rect, NULL, 0, NULL); Hope this helps,
Ryan "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"
|
|
|
|
|
Thank you very much! That really helped!
Now I am wondering, if I want to make the background an image, should I do it in response to WM_PAINT too? Why is WM_ERASEBKGND available then? Why did they put it if I should draw in WM_PAINT?
Thank you very much for your patience!
<marquee behavior="alternate">Hosam Aly Mahmoud
|
|
|
|
|
Hosam Aly Mahmoud wrote:
Now I am wondering, if I want to make the background an image, should I do it in response to WM_PAINT too?
Yes. That will work fine
Hosam Aly Mahmoud wrote:
Why is WM_ERASEBKGND available then? Why did they put it if I should draw in WM_PAINT?
There is nothing wrong with using WM_ERASEBKGND for drawing the background. It's simply not possible to do flicker-free drawing using it. I'm not certain why it's there - it's probably been there since Windows 1.0
Ryan "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"
|
|
|
|
|
Ryan Binns wrote:
I'm not certain why it's there
Well, if you "eat" the WM_ERASEBKGND message, return 1, and forward it to the parent window, you can get transparent effects, because you're telling the parent to erase an area, rather than erasing it yourself with the default brush, which is the normal behavior.
This is a neat trick that is played by the Common Controls Toolbar so that it can have a transparent background. It also calls WM_ERASEBACKGND on the parent window whenever it draws anything outside of a WM_PAINT message, so that the background is always erased to the parent's background.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'll have to remember that
Ryan "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"
|
|
|
|
|
Thank you for the information!
Hosam Aly Mahmoud
|
|
|
|
|
Thank you for your replies, your help and all your patience!
Hosam Aly Mahmoud
|
|
|
|
|
Hi,
I've written a program and when I run it for the first time it works, but when I want to run it for the second time, it crashes. Most of the time at a "delete [] ..." or at a "new char[...]". But when I debug it works fine.
The program uses a MySQL database (through MySQL++). Somewhere in the code is a "for()" part (it retrieves the records of a SQL-statement and does something with the values). When I debug it, it only goes one through the loop (retrieves one record), when I compile an optimized exe then it retrieves all the records.
I think this is very weird, does anybody knows the cause of the problem or has a sollution?
Thanks in advance
|
|
|
|
|
Sounds like an uninitialized variable somewhere.
- Mike
|
|
|
|
|
I see what you mean but how can something like this crash on "new ..."?
char* cNewString = NULL;
// cString is not empty
cNewString = new char[strlen(cString) + 1];
-Tom
|
|
|
|
|
Visual C++ is not perfect in reporting the cause of a crash and where the bug resides. One possible cause of delete [] is that the program passes the dynamically allocated array into a function that does not release the memory even after the function has returned.
Kuphryn
|
|
|
|
|
Probably a newbie question but I really want to ask, I have like hundreds of jpg's, gif's and icons need to be shared by multiple application, I heard we can encapsulate all of them into a dll and use that dll to export resource ID's when required by application, but how? Could someone please tell me:
1, what kind of dll I will need to create? Win32 dll? MFC dll? Or others?
2, How do I export resource ID's from a dll?
Thanks a lot.
|
|
|
|
|
putting hundreds of jpgs in a dll is a very bad idea, because it will waste your memory... you won't need them all the same time!
create a folder, put them in there, then create a new dll with 2 exported function: LoadJpg and FreeJpg!
LoadJpg allocates memory and loads the file from disk, FreeJpg frees the memory allocated by LoadJpg!
This is the best way!
Don't try it, just do it!
|
|
|
|
|
Yeah I thought so, but I was just doing some practice, thanks for the suggestion though...
Anyway, I think I have found out the solution already, I created a DLL and included images into that DLL as its resources, then in my executable I read images("resource blocks") from the DLL into my executable process's memory blocks when needed, then draw them on my executable's windows, tested and worked.
|
|
|
|
|
use a normal win32 dll and include the resources there!
then load this dll via LoadLibrary!
now, you can open a bitmap for example by calling LoadBitmap with hInstance of the loaded dll!
Don't try it, just do it!
|
|
|
|
|
I am trying to create an application that is capable of working with multiple document types, each having its own view. In the InitInstance() function I have done the following:
BOOL CTestApp::InitInstance()
{
... Other code
LoadStdProfileSettings(15); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_FIRSTTYPE,
RUNTIME_CLASS(CTypeOneDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeOneView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
CMultiDocTemplate* pDocTemplateT;
pDocTemplateT = new CMultiDocTemplate(IDR_SECTYPE,
RUNTIME_CLASS(CTypeTwoDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CTypeTwoView));
if (!pDocTemplateT)
return FALSE;
AddDocTemplate(pDocTemplateT);
... Other code
I have all appropriate view and document classes in place for these doc templates and the project compiles without any problems. The first doc view is derived from CHTMLView and the second is derived from CRichEditView.
PROBLEM:
I create a new rich edit document, type some text into the view, and save it and then close the document. Then when I open the document I just saved, it appears that the document's contents had never been saved, or if they had, they certainly didn't open properly.
ALSO:
The messagebox that usually automatically pops up when you try to close a doc that has not been saved since its last modification fails to come up like it should.
I believe that these two problems are somehow related. Please help.
This has really got me stuck. Does anyone have any suggestions? Any leads to the problem would definitely be appreciated.
BNEACETP
|
|
|
|
|
|
Thanks for letting me know about the book.
I just ordered it earlier today.
BNEACETP
|
|
|
|
|
I was wondering if it were at all possible to derive a class template from another class template and keep the base class templates arguments abstract. I have looked around and cannot find the answer.
|
|
|
|
|
Mike Roode wrote:
I was wondering if it were at all possible to derive a class template from another class template
template<class T>
class Base
{
};
template<class T>
class Derived : public Base<T>
{
};
Is this what you meant? You can add any additional template parameters required in derived.
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
That is what I was looking for. Thanks for the syntax Andrew.
|
|
|
|
|