-
GDI and MFC
Can anyone explain to me how to use GDI functions in an MFC project..?
Some simple examples with changing backgrounds and drawing simple rectagles..? Anyone..?
...I've been trying to do it myself, but it doesn't work, unless I put the code into the OnPaint function, but OnPaint works only when the window is created as far as I understand...
...I wasted the whole day yesterday to find any info which I one who never worked with GDI could understand - nothing, nothing understandable, reminds me the book of Liberty, where he says 'here's an example of a simple list' and gives 5 pages of code instead of a real simple example...classes instead of 1...is it the way of saying 'look how clever I am'..? Bah...
...by now you are probably thinking what the **** I want...I want a simple explanation how to use GDI in MFC projects...for sometimes it works, sometimes it doesn't, sometimes I fill a rectagle with a needed color, but when the window is not active, the color disappeares...
I don't get it...*hits the table with the head*
-
*You* can call onpaint whenever. Onidle is a good place. Its automatically called when the window is min/maxed or another window uncovers it, couple of other times. I don't know about gdi, but there are some pretty good direct draw examples out there.
-
Hmm...let us say that OnPaint the bg of the main window changes to black, if I want to change it to yellow when a button is pressed, how can I call OnPaint again to do that..? That function takes 0 parameters...
-
I think you should be able to do the gdi code in the button handler and then explicitly call onpaint() at the end of the button and that should work, if not, something is wrong.
-
...the color I use to change the bg on button pressed, written in the button handler
void CColorDlg::OnButton()
{
CPaintDC dc(this);
CBrush b;
RECT t;
b.CreateSolidBrush(RGB(0,0,0));
GetClientRect(&t);
dc.FillRect(&t,&b);
}
...it gives me no errors as well as no results...on the other hand if I put it into the OnPaint function body - the bg will be red from the very beginning...
...I just don't get what am I doing wrong...
-
void CColorDlg::OnButton()
{
CPaintDC dc(this);
CBrush b;
RECT t;
b.CreateSolidBrush(RGB(0,0,0));
GetClientRect(&t);
dc.FillRect(&t,&b);
OnPaint(); //did you add this line? and it does nothing? and they have the same 'this'?
}
if that did not do it, throw in a updatewindow or updatedialogitem and see if that clears it up. ?? I don't really know but it *should* work after one of these changes.
-
*sigh*
...all painting seem to be done in the OnPaint function...
...thence to change the bg color I have to declare
RECT t;
CBrush b;
in the dialog class, then in OnPaint function write:
void CWhateverDlg::OnPaint()
{
CPaintDC dc(this);
GetClientRect(&t);
dc.Rectangle(t.left,t.top,t.right,t.bottom);
dc.FillRect(&t,&b);
}
and on button:
void CWhateverDlg::OnButton()
{
b.CreateSolidBrush(RGB(255,0,0));
this->InvalidateRect(0);
}
...then it works...otherwise - no...
-
I remember doing that now... onpaint called invalidaterect(everything) which forced onpaint to execute in a tight loop, as fast as it could go. It either had everything hardcoded or accessed say, an rgb array that was a class member (modified wherever) to know what to paint. I never got far into that before I switched to direct draw/ d3d and open gl (gl first, directx later). There should be a better way to use the gdi, but I never found one and really needed more power than it offered.
please post it if you figure out the proper way to do the gdi... assuming that this is not the best way...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks