Solved

Urgent:Using a BMP picture to show the Joystick movement!

Posted on 1998-05-14
8
350 Views
Last Modified: 2013-11-20
Hi! When I change the X axis and Y axis position of Joystick, I would like to use a BMP picture from Resoruce editor (LoadBitmap(IDB_XXX) ) to show the Joystick movement. Right now I do understand how to calculate the relative position on the Client area of Windows , so you do not teach me how to do it. My big problem is that I do not know how to erase the BMP picture at the old position and generate this BMP picture at the new position  after Joystick moved. If you could write a piece of code for doing this, and explain it a little, I would be very grateful.
Thank a lot!.
0
Comment
Question by:jennyH
  • 4
  • 4
8 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 50 total points
ID: 1310569
In general this problem is not trivial. Ideally if you bitmap picture is ralatevly small, as small as cursur icon the best way is to use cursor. If it is larger what you need to do is save screen area where you want to display your bitmap into some temporary bitmap using screen DC. Then draw your bitmap on this place. when you need to move your bitmap you first should draw the bitmap you saved back on screen and then repeat the same steps. The problem is if you bitmap is rather large you will get terrible flickering. In this case DirectDraw is the only one way.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1310570
In your view class do this (pseudo code)

Get the old bitmap rect
Set the new bitmap rect
InvalidateRect for the old bitmap rectangle
InvalidateRect for the new bitmap rectangle
UpdateWindows

This should do it.

PS: Please reject the current proposed answer so I can propose this as an answer if you find it more helpful


0
 
LVL 7

Expert Comment

by:galkin
ID: 1310571
If user moves losticj rather fast bitmaps will not be updated since InvalidateRect doesn't update rectangle immediately. This will reasult in tail of bitmaps. moreover he needs to draw bitmap anywhere and InvalidateRect will also result in marking invalidte rectangle for many windows so it will further slow down drawing.
you must directly update bitmaps by obtaining device context of the display. Using GDI BitBlt function is good solution if the bitmap is not large otherwise I told only DD can help
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1310572
Where does he say he needs to "draw bitmap anywhere" ??

I assume he is just drawing it in his view (he talks about client coordinates).  So there will not be 'many windows' to invalidate at all.

It is true that InvalidateRect does not update the view immediatle - it just marks it as dirty.  But the UpdateWindow call will do the repainting of the old and new rectangles.  I don't see how you would end up with this trail of bitmaps you mention.

If you want to avoid flicker and get a smoother display, then an offscreen bitmap for rendering would be the way to go.

Another technique is to render the bitmap with an XOR, so then you just paint the bitmap in the old position then in the new position, and the bitmap will move.  Of course, the colours may look a bit screwy as they are xor'd with the background, but that may be suitable for his application.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Expert Comment

by:galkin
ID: 1310573
Yes, i agree it is not clear that he wants to move bitmap only inside his window client area. But my cooments are still valid. Using your method will cause terrible flickering or rectangle will not be redrwn at all if user moves jostick rather fast.
What I suggest is double buffering and this is the same method used by Windows when you move one window over another. It saves invalide rectangle or region and then blits it back.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1310574
The 'save-under' double buffering you recommend is not really good.  It will resotre the OLD backgroudn (just before the bitmap was drawn at the rect) .. if the background has since changed (eg. you are moving the joystick slowly) then you'll end up with 'rubbish' being repainted .. not the current image.

If you are drawing in your client area only (and not already using directx) then use the invalidate/updatewindow method, and use an offscreen bitmap for rendering (the famouse CMemDC class should help with that .. check it out at http://www.codeguru.com

BTW: I think that your 'double-buffering' (ie save-under) method is NOT used (usually) when moving one window over another in Windows .. instead Windows invalidates and send paint messages.

0
 
LVL 7

Expert Comment

by:galkin
ID: 1310575
I guess while user is moving joystick any windows is not updated. This is at least truth between two speps of moving joystick. I know from my experience that InvalidateRect works extremely slow since it doesn't update rectangle immediately but sets WM_PAINT message in message queue. Taking into account that WM_PAINT message is not processed if there are ohter messages in message queue ans several WM_PAINT messages are combined into single one fast moving of joystick will result in not updating rectangle.
Concerning your comment about invalidating rectangle when moving one window over another you are right. Windows doesn't update invalide rectangle with InvalidateRect when a menu is tracked. It uses the mechanism I mentioned.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1310576
Yes, InvalidateRect marks a rect of the window as requireing update.  These would normally be accumulated as you state.

However, UpdateWindow causes an IMMEDITATE repaint.  So there is not delay.

According to the docs it...

>>>>>>>>>>
Updates the client area by sending a WM_PAINT message if the update region is not empty. The UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. If the update region is empty, WM_PAINT is not sent.
>>>>>>>>>>

Note that it BYPASSES the message queue .. so the usually delayed WM_PAINT handling (when there are no other message etc) is bypassed as well.


I think we now need to here from jennyH so we know what she(?) is wanting to do so we can get a solution for her particular requirements.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Question regarding Copy/Paste 16 91
ORA-01403: no data found 43 89
unable to delete all specified values regedit 38 273
how to monitor remote shell execution on linux 9 97
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now