(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
06-01-24 09:57 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - [WinAPI] Making custom messages
  
User name:
Password:
Reply:
 
Options: - -
Quik-Attach:
Preview for more options

Max size 1.00 MB, types: png, gif, jpg, txt, zip, rar, tar, gz, 7z, ace, mp3, ogg, mid, ips, bz2, lzh, psd

UserPost
sloat
Posts: 8/20
double buffering is something you have to do manually, with a memory DC and memory bitmap. you basically draw everything to this memory DC, then use BitBlt to set it to the screen. There are plenty of examples of it on MSDN (if you can find them) or google.
neotransotaku
Posts: 412/1860
How do I know if I'm using double buffering? I've been developing my application with Visual Studio 6 running on a virtual Win2K machine managed by Microsoft's Virtual PC that runs on WinXP...
sloat
Posts: 6/20
InvalidateRect will cause flicker if you're not using double buffering. It can be slow with double buffering. You can try using ScrollWindowEx which has a param for flags for repainting, or if you're using double buffering, you can try ScrollDC. ScrollDC is more for if you don't want to redraw the entire window contents (which is a good thing), but the code to manage a backbuffer and scrolling it will be more complex.
neotransotaku
Posts: 409/1860
RedrawWindow has more power than InvalidateRect, but I'm working within MFC, so I don't need all that power...for now

I pass the actual client part that needs to get redrawn instead of just simply passing in the client rect. I notice that if I give InvalidateRect, the client rect there is flickering when the cursor goes out of view by one line; which is bad...
HyperHacker
Posts: 760/5072
They're actually 2 different things. InvalidateRect just marks an area as needing to be redrawn, while RedrawWindow redraws an area. Also, RedrawWindow has more options, like always generating a WM_PAINT message (even if no actual redrawing occurrs) and redrawing children.
neotransotaku
Posts: 404/1860
What's the benefit of using RedrawWindow() versus InvalidateRect()?
HyperHacker
Posts: 736/5072
Yeah, scrollbars are a pain.

In place of InvalidateRect, you can use RedrawWindow. Just be careful; if you don't handle the paint event right, it'll repaint again and use up all your CPU power. Look into BeginPaint and EndPaint if this happens.
neotransotaku
Posts: 395/1860
Alright, that was a bitch to solve but I have my scrolling working when the cursor goes out of view. Turns out I had to do several things:

1) Set a scroll range with SetScrollRange()
2) Move the thumb to where I want it with SetScrollPos()
3) Actually scroll the window using ScrollWindow()
4) Then redraw the window using InvalidateRect()
neotransotaku
Posts: 373/1860
Turns out I don't need to go down this route to solve my earlier problem. However, I've now run into another scrolling problem.

The following is my code to move a cursor:


void CMyView::MoveCursor(CDC* pDC, DWORD dwNewCursorPos)
{
DWORD dwOldCursorPos = m_dwCursor;
m_dwCursor = dwNewCursorPos;

// Get Old Cursor Rect
RECT rOldCursor;
m_dvHexView->GetCursorRect(pDC, dwOldCursorPos, &rOldCursor);
rOldCursor.top -= 10;
rOldCursor.left -= 10;
rOldCursor.bottom += 10;
rOldCursor.right += 10;

// Get New Cursor Rect
RECT rNewCursor;
m_dvHexView->GetCursorRect(pDC, m_dwCursor, &rNewCursor);
rNewCursor.top -= 10;
rNewCursor.left -= 10;
rNewCursor.bottom += 10;
rNewCursor.right += 10;

// Do necessary scrolling
RECT clip;
pDC->GetClipBox(&clip);

int nDeltaY = 0;
/*
if(clip.bottom < rNewCursor.bottom)
{
nDeltaY = -2 * (int)(m_dvHexView->GetLineHeight(pDC));
ScrollWindow(0, nDeltaY);
}
else if(rNewCursor.top < clip.top)
{
nDeltaY = 2 * m_dvHexView->GetLineHeight(pDC);
ScrollWindow(0, nDeltaY);
}
*/

// Convert to Client (Device) Coordinates
rOldCursor.top -= (clip.top + nDeltaY);
rOldCursor.left -= clip.left;
rOldCursor.bottom -= (clip.top + nDeltaY);
rOldCursor.right -= clip.left;

rNewCursor.top -= (clip.top + nDeltaY);
rNewCursor.left -= clip.left;
rNewCursor.bottom -= (clip.top + nDeltaY);
rNewCursor.right -= clip.left;

InvalidateRect(&rOldCursor);
InvalidateRect(&rNewCursor);
}

In the commented out region is code that tries to scroll the window manually if the cursor is out of view. However, I can't seem to call the right functions to make it work. The result of running the commented code (i.e. calling ScrollWindow) causes scrolling to occur but no redrawing in the areas that are brought in. (Side Note: I still haven't figured out how to call "repaint()" in the WinAPI ). Could anyone point me in the right direction to get scrolling to work? I tried to post my own WM_VSCROLL message but that doesn't seem to work as if I click on the scroll bar, things are correct.
sloat
Posts: 5/20
You don't have to use RegisterWindowMessage unless you need to make sure that the number you use doesn't interfere with some other message. But that would probably only happen if you're subclassing a control.

#define WM_MYMESSAGE WM_USER+0x1337

You can use WM_APP instead if you're really paranoid about duplicate values.
Vertex
Posts: 3/4
I'm not sure if this is what you're talking about, as I don't use MFC due to huge bloat and speed problems- but there is an API called RegisterMessage, is that it?
neotransotaku
Posts: 356/1860
Within the application itself. I have a MVC (Model-View-Controller) setup in my MFC application. I want to preserve this abstraction as much as possible. My situation is this:

The view as a scrollbar that has currently been initialized with SetScrollSizes(MM_TEXT,CSize(0,0)), which basically makes a viewing area of 0. What I would like after the model has loaded in a file, to tell the view to update the viewing area.

I know one solution is to give the model a handle to the viewing object but I don't want to do that. I recall reading there was a way to make your own messages, adding to the ones that already exist in the WinAPI but I don't remember where read that.
HyperHacker
Posts: 669/5072
You mean send a message to another window? Just call SendMessage(), or PostMessage() if you can't wait for it to be processed.
neotransotaku
Posts: 354/1860
I have a need to generate custom messages in WinAPI/MFC. Could anyone point me to a tutorial OR give a quick, general run down of the steps I need? Thanks.
Acmlm's Board - I3 Archive - Programming - [WinAPI] Making custom messages


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.011 seconds; used 359.22 kB (max 417.15 kB)