Register | Login | |||||
Main
| Memberlist
| Active users
| Calendar
| Chat
| Online users Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album |
| |
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: 6432 days Last view: 6430 days |
| ||
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: 6430 days Last view: 6430 days |
| ||
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: 6432 days Last view: 6430 days |
| ||
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: 6835 days Last view: 6835 days |
| ||
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: 6533 days Last view: 6533 days |
| ||
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: 6432 days Last view: 6430 days |
| ||
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:
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: 6432 days Last view: 6430 days |
| ||
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: 6430 days Last view: 6430 days |
| ||
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: 6432 days Last view: 6430 days |
| ||
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: 6430 days Last view: 6430 days |
| ||
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: 6432 days Last view: 6430 days |
| ||
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: 6533 days Last view: 6533 days |
| ||
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: 6432 days Last view: 6430 days |
| ||
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: 6533 days Last view: 6533 days |
| ||
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 | | |