I was trying to send mouse positions to my status bar in
a larger program. I could not get them to write more than
one position to the status bar, then it stops changing.

To test why, I wrote a small window using one "Do Paint"
function first. I still got only one position print out
but nothing more. I then put in a "Do Paint1" and "2".
The WM_MOUSEMOVE would print out either "1" or "2" but not
both. It will print both lines if I keep it all in one
function. I would like to know why it won't run two
functions, one after another.

I'm sure I'm doing something dumb but I can't come up
with why I only get one position print and why a
second WM_MOUSEMOVE message doesn't seem to do anything.
I'm assuming that as the mouse moves, the program
should get more WM_MOUSEMOVE messages. I cut off the
returns in 1, 2, and then the case. No change. I can't
figure out why MMove will only do one and not both of
my functions either. It's all got to be tied together
some how.

I'm running AMD with SP1. Here's the case.

case WM_MOUSEMOVE:


wsprintf(szBuff1,"%s x=%04d y=%04d","Cursor Location",
LOWORD(lParam),HIWORD(lParam));
wsprintf(szBuff2,"%06s %04X %s x=%04d y=%04d","Msg = ",
message,"    ",LOWORD(lParam),HIWORD(lParam));
DoPaint1(hwndMain);
DoPaint2(hwndMain);
return 0;

and here's the 1 and 2.

HWND DoPaint1(HWND hwndMain)
{
GetWindowRect(hwndMain,&rc);
hDC = GetDC(hwndMain);
hDC = BeginPaint(hwndMain,&ps);
TextOut(hDC,124,50,szBuff1,29);
EndPaint(hwndMain, &ps);
ReleaseDC(hwndMain,hDC);
UpdateWindow(hwndMain);
ZeroMemory(szBuff1,sizeof(szBuff1));
return 0;
}


HWND DoPaint2(HWND hwndMain)
{
GetWindowRect(hwndMain,&rc);
hDC = GetDC(hwndMain);
hDC = BeginPaint(hwndMain,&ps);
TextOut(hDC,124,90,szBuff2,30);
EndPaint(hwndMain, &ps);
ReleaseDC(hwndMain,hDC);
UpdateWindow(hwndMain);
ZeroMemory(szBuff2,sizeof(szBuff2));
return 0;
}

If anyone wants the whole test program, I can zip it
and e-mail it on request. It's just a single window
with the above. Very basic. I put in the ZeroMem to
see what that would do. It did nothing.

Don't call WM_PAINT handlers directly - use InvalidatRect to add the specified rectangle to the update region for the next paint cycle; if you need to force the paint then you can follow the InvalidateRect with an UpdateWindow, or just cut to the quick with RedrawWindow. But InvalidateRect is usually good enough. Calling any of these functions within a WM_PAINT handler is never a very good idea; use it/them in your WM_MOUSEMOVE handler.

For your status bar, send an SB_SETTEXT message to update the text to the relevant part of that control.

I think I may have confused the issue based on the above reply. Instead of calling my functions "DoPaint", I should have called them "DoChaChaCha" I am doing some painting in the function but I am not doing it in the Case WM_Paint.

I am not having trouble getting the coordinates to my status bar. I am having trouble getting more than one update after the first one. This is true whether I paint the text in my temporary window or in my large program that has a status bar in it. It's not getting a second WM_MOUSEMOVE or getting it to do anything that is causing my problem.

Actually the confusion is caused by using BeginPaint...EndPaint as these implicitly make the containing function a WM_PAINT handler in that they shouldn't actually be used in any other context, see BeginPaint for details(GetDC is redundant in that context, too; you'd use that to get a device context outwith a WM_PAINT handler).

Try:

case WM_MOUSEMOVE:
  wsprintf(szBuff1,"%s x=%04d y=%04d","Cursor Location",
  LOWORD(lParam),HIWORD(lParam));
  wsprintf(szBuff2,"%06s %04X %s x=%04d y=%04d","Msg = ",
  message," ",LOWORD(lParam),HIWORD(lParam));
  InvalidateRect(hwndMain, 0, TRUE);
  return 0;

case WM_PAINT:
  hDC = BeginPaint(hwndMain,&ps);
    TextOut(hDC,124,50,szBuff1,lstrlen(szBuff1));
    TextOut(hDC,124,90,szBuff2,lstrlen(szBuff2));
  EndPaint(hwndMain, &ps);
  return 0;
}

which should hopefully produce the desired results. If you still have difficulties with the update of the status bar control then it would probably be useful to post the smallest working example that reproduces the problem.

Your suggestion worked like a charm.

After seeing so many viewers looking at my thread I
thought maybe I would have to put the source code in
so people could understand what I was talking about.
Obviously not for a sharp dude, you nailed it on first
try with minimum info.

I put my little test program together because I was
having 2 problems chasing me. I didn't want to have
to plow through lots of code if I went into SoftIce
to chase them down. Since you smashed my first problem
I thought I might as well bounce my second one off
you also.

When I "CreateMenu", a handle for one does not return
as expected. I get an error message that reads:
"The system cannot find the file specified".

I usually compile using Borland BCC32 but I get the error
using "cl" from my DDK too so it's not a compiler problem.

If you don't mind and if I can find your e-mail address in
your profile, I'll shoot you the source code. You may need
it to duplicate the problem to see it. If I can't find your
addrress, e-mail me at [email removed] and I'll send you
the code.

please send me the whole test program..my id is..
[email removed]

commented: Thanks for playing, though -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.