(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
05-18-24 05:27 AM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - [WinAPI] Making custom messages New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-08-06 01:36 AM Link | Quote
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.
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6299 days
Last view: 6299 days
Posted on 01-08-06 03:03 AM Link | Quote
You mean send a message to another window? Just call SendMessage(), or PostMessage() if you can't wait for it to be processed.
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-08-06 01:23 PM Link | Quote
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.
Vertex
Newcomer


 





Since: 01-08-06
From: Philippines

Last post: 6704 days
Last view: 6704 days
Posted on 01-08-06 10:50 PM Link | Quote
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?
sloat



 





Since: 11-18-05
From: Delaware, US

Last post: 6401 days
Last view: 6401 days
Posted on 01-09-06 01:41 AM Link | Quote
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.
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-09-06 09:43 PM Link | Quote
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.
neotransotaku

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-11-06 04:16 AM Link | Quote
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()
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6299 days
Last view: 6299 days
Posted on 01-11-06 09:44 PM Link | Quote
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

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-11-06 11:53 PM Link | Quote
What's the benefit of using RedrawWindow() versus InvalidateRect()?
HyperHacker

Star Mario
Finally being paid to code in VB! If only I still enjoyed that. <_<
Wii #7182 6487 4198 1828


 





Since: 11-18-05
From: Canada, w00t!
My computer's specs, if anyone gives a damn.
STOP TRUNCATING THIS >8^(

Last post: 6299 days
Last view: 6299 days
Posted on 01-12-06 12:40 AM Link | Quote
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

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-12-06 01:17 AM Link | Quote
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...
sloat



 





Since: 11-18-05
From: Delaware, US

Last post: 6401 days
Last view: 6401 days
Posted on 01-12-06 07:14 PM Link | Quote
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

Sledge Brother
Liberated from school...until MLK day








Since: 11-17-05
From: In Hearst Field Annex...

Last post: 6300 days
Last view: 6298 days
Posted on 01-13-06 03:18 AM Link | Quote
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



 





Since: 11-18-05
From: Delaware, US

Last post: 6401 days
Last view: 6401 days
Posted on 01-13-06 08:09 PM Link | Quote
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.
Add to favorites | Next newer thread | Next older thread
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 414.55 kB (max 525.30 kB)