Solved

TStatusBar text changes when mouse moves over TEdit

Posted on 2002-05-15
22
492 Views
Last Modified: 2011-09-20
I have an app with a status par divided into several panels.  The panels are updated by drawing on the canvas of the panels in the usual way.  It works fine until I move the mouse pointer over the top of any Tedit or TMemo component.  When this happen, the text in some of the status bar panels changes to display the first three entries of my main menu - i.e. the first one shows 'File', the next one shows
'Open', along with the same glyph that is used on the 'Open' menu entry, and so on.

It also happens sometimes when I click on a button.

Weird...

0
Comment
Question by:rossmcm
  • 9
  • 4
  • 3
  • +4
22 Comments
 
LVL 9

Expert Comment

by:ginsonic
ID: 7012897
Can you post some codes ? I don't understand .
0
 

Author Comment

by:rossmcm
ID: 7012914
the handler that updates the status bar is:

procedure TPDS51EMainForm.StatusBar1DrawPanel(StatusBar: TStatusBar;
  Panel: TStatusPanel; const Rect: TRect);

{  code called when an owner-draw status panel is redrawn.  }

begin
with StatusBar1 do
    begin
    if (Panel = Panels [0]) then                      { USB status panel }
        begin
        if FlashState and USBStatusFlashing [USBStatus] then
            begin
            USBStatusImageList.Draw(StatusBar1.Canvas, Rect.Left + 4, Rect.Top, ord (usStarting));
            end
        else
            begin
            USBStatusImageList.Draw(StatusBar1.Canvas, Rect.Left + 4, Rect.Top, ord (USBStatus));
            end ;

        Canvas.Font.Color := USBStatusColour [USBStatus] ;
        Canvas.TextOut(Rect.left + 30, Rect.top + 2, USBStatusNames [USBStatus]);
        end
    else if (Panel = Panels [1]) then                 { PB panel }
        begin
        Canvas.Font.Color := clBlack ;
        Canvas.TextOut(Rect.left + 4, Rect.top + 2,
          GetCurrentPersonalityBoardName) ;
        end
    else if (Panel = Panels [2]) then                 { Progress Bar and device panel}
        begin
        if (ProgressMsg <> '') then
            begin
            ProgressBar1.Visible := true ;
            ProgressBar1.BoundsRect := Rect ;
            end
        else
            begin
            ProgressBar1.Visible := false ;
            Canvas.Font.Color := clBlack ;
            Canvas.TextOut(Rect.left + 4, Rect.top + 2,
              GetCurrentDeviceName + ' (' +
              FormatEmulationSpeedBrief (CurrentEmulationSpeedMHz) + ', ' +
              FormatVcc (CurrentVcc) + 'V)') ;
            end ;
        end
    else if (Panel = Panels [3]) then                 { emulator status/progress/error panel.  }
        begin
        if (ErrorMsgTimer <> 0) then
            begin
            Canvas.Font.Color := clRed ;
            Canvas.TextOut(Rect.left + 30, Rect.top + 2, ErrorMsg);
            end
        else if (ProgressMsg <> '') then
            begin
            Canvas.Font.Color := clNavy ;
            Canvas.TextOut(Rect.left + 30, Rect.top + 2, ProgressMsg);
            end
        else
            begin
            Canvas.Font.Color := clBlack ;
            Canvas.TextOut(Rect.left + 30, Rect.top + 2, StatusMsg);
            end ;
        end ;
    end ;
end;

....which won't make much sense on its own.  

The project also has a main menu with a file menu, an edit menu, etc.  The first two entries in the file menu are Open Project, snd Reopen Project.  When I move the mouse pointer over any edit box (or any component derived from an edit box such as a spin edit or combo), the text displayed in the status panels [1], [2], and [3] changes to 'File', 'Open Project', and Reopen Project' respectively for as long as the mouse is over the edit box.  As soon as the mouse leaves the edit box the text changes back to what it should be according to the above code - probably because its being refreshed regularly by the app anyway.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7013924
weird .. can't see why
a tip on optimizing the above code :
case Panel.Index of
  0: { USB status panel }
  begin
  ...
  end;

  1: { PB panel }
... and so on :)


where and how do you set the texts (StatusMsg, ErrorMsg, ..)?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7014375
Greetings.  This question is current, others below are not and need your attention.  ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101, Netminder or Mindphaser will return to finalize these if they are still open in 7 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20006596.html
http://www.experts-exchange.com/questions/Q.20073751.html
http://www.experts-exchange.com/questions/Q.20283931.html
http://www.experts-exchange.com/questions/Q.20286300.html
http://www.experts-exchange.com/questions/Q.20301130.html



*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange
0
 

Author Comment

by:rossmcm
ID: 7014989
StatusMsg is set in a timer event

ErrorMsg is set by a call to an error reporting routine.

It's not these variables getting clobbered because if I add code to set them to constant strings just prior to them being painted the problem is still there.
 
The weird thing is that the stuff that is displayed is in a different font and includes the glyph associated with the menu entry that it seems to be getting the text from.  It's as if the owner draw routines for the main menu and the status bar are getting confused.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7015104
hehe realy weird !
sorry I can't help
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7015534
I can't see the problem !?! Is true ... realy weird !
0
 

Expert Comment

by:neld
ID: 7018082
Dont you perhaps have the autohint property of the statusbar set to true.  It seems as if its trying to send a hint to the statusbar when you move over a component.  And maybe because its owner-drawen it gets confused with what to do with the hint ?

all i can think of....

Derrick
0
 

Author Comment

by:rossmcm
ID: 7020761
Had me excited there for aminute, but no, no hint string set and autohint is off.  The problem goes away if the panels in the statusbar are text as opposed to ownerdraw.
0
 

Author Comment

by:rossmcm
ID: 7020770
Aha - found this thread:

http://groups.google.co.nz/groups?hl=en&lr=&ie=UTF8&oe=UTF8&threadm=J8MKkDAP8H8yEwiY%40mimage.demon.co.uk&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF8%26oe%3DUTF8%26q%3Dtstatusbar%2Bhint%2Bmouse%26btnG%3DGoogle%2BSearch

which talks about a similar problem.  It talks about resource files however which I thought would have been managed automatically by Delphi.  Tried deleting the .RES file so D5 would recerate it but same problem.
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7062096
Chances are, the root of this 'weirdness' are not (only) in PanelDraw event.
Can you reproduce this problem in a simple (as smaller as possible) project, and post it?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:rossmcm
ID: 7112810
An update on this weird behaviour:

Just to recap.  The problem only occurs when the cursor hovers above an enabled TEdit or TCombo.  If the TEdit/TCombo is disabled, you have to press the mouse button to get the corruption of the status panels, but if enabled, just hovering is enough.

If I give the TEdits and TCombos a hint and turn AutoHint on, the problem almost goes away - If I hover above a TCombo with an enabled hint, or click in it, the problem does not occur.  If I hover above a TEdit with an enabled hint, the problem occurs _until the hint text pops up_ - once the hint is showing, the status panels display OK.  If I move the mouse so that the hint closes, but still remain above the TEdit, the problem recurs until the hint displays again.

It seems like it related to the hinting.  

Help.  Its driving me nuts.

0
 

Author Comment

by:rossmcm
ID: 7112816
An update on this weird behaviour:

Just to recap.  The problem only occurs when the cursor hovers above an enabled TEdit or TCombo.  If the TEdit/TCombo is disabled, you have to press the mouse button to get the corruption of the status panels, but if enabled, just hovering is enough.

If I give the TEdits and TCombos a hint and turn AutoHint on, the problem almost goes away - If I hover above a TCombo with an enabled hint, or click in it, the problem does not occur.  If I hover above a TEdit with an enabled hint, the problem occurs _until the hint text pops up_ - once the hint is showing, the status panels display OK.  If I move the mouse so that the hint closes, but still remain above the TEdit, the problem recurs until the hint displays again.

It seems like it related to the hinting.  

Help.  Its driving me nuts.

0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7113107
I really can't reproduce the problem
and your delphi version is ?
0
 

Author Comment

by:rossmcm
ID: 7115089
D5 Pro.  I have tried to create a small app that demonstrates it but naturally it behaves fine.
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7115718
OK, I found similar situation. It may very well be that you should install the newest service pack, but in the meantime, you might try the proposed work-around.



Problem description:
--------------------------

Owner-drawn TStatusBar panels sometimes display the text of a menu
item of the same form.


Cause:
-----------------

The owner-drawn TStatusBar triggers a WM_DRAWITEM message on the
parent window.  From Delphi 4 on, this message is also caught by the
TCustomForm.WndProc procedure to allow for owner-drawn menus.  Here is
part of the relevant VCL code:
        ...
      WM_DRAWITEM:
        with PDrawItemStruct(Message.LParam)^ do
          if (CtlType = ODT_MENU) and Assigned(Menu) then
            ...

The problem is that the CtlType field of the DRAWITEMSTRUCT contains
random information when triggered for the TStatusBar, which sometimes
- this depends on the application's memory usage - happens to be the
ODT_MENU value.

CtlType doesn't appear to have a specific value for a status window.
This looks like a Windows bug, but it is actually documented in the
Win32.HLP (search key: "Owner-Drawn Status Windows"):

"When a status window needs to draw an owner-drawn part, it sends the
WM_DRAWITEM message to the parent window. The wParam parameter of the
message is the child window identifier of the status window, and the
lParam parameter is a pointer to a DRAWITEMSTRUCT structure. The
parent window uses the information in the structure to draw the part.
For an owner-drawn part of a status window, DRAWITEMSTRUCT contains
the following information.

Member Description
CtlType Undefined; do not use.
CtlID Child-window identifier of the status window.
itemID Zero-based index of the part to be drawn.
itemAction Undefined; do not use.
itemState Undefined; do not use.
hwndItem Handle to the status window.
hDC Handle to the device context of the status window.
rcItem Coordinates of the window part to be drawn. The coordinates
are relative to the upper left corner of the status window.
itemData Application-defined 32-bit value specified in the
lParam parameter of the SB_SETTEXT message."

 
Work-around:
-----------------------

Override the WndProc method on the form that contains both a TMenu and a TStatusBar and add this code:

  procedure TMyForm.WndProc(var Message: TMessage);
  begin
    with Message do
      case Msg of
        WM_DRAWITEM:
          with PDrawItemStruct(Message.LParam)^ do
            if (CtlType = ODT_MENU) and Assigned(Menu) and
               (hwndItem <> Menu.Handle) then
              CtlType := ODT_STATIC;
      end;
    inherited WndProc(Message);
  end;
0
 

Author Comment

by:rossmcm
ID: 7119501
almost there...

I wasn't sure how to declare the the handler in the form class declaration:

  protected
    procedure WndProc(var Message: TMessage) ; message WM_DRAWITEM ;

gave me a stack overflow. But:

  protected
    procedure WndProc(var Message: TMessage) ; override ;

works OK.  It compiles, runs OK and the statusbar problem is gone, however, the main menu entries don't display at all (no text or glyph).  

0
 
LVL 7

Accepted Solution

by:
Cynna earned 200 total points
ID: 7120228
rossmcm,

> procedure WndProc(var Message: TMessage) ; override

This is correct declaration, leave it like that.



> ..however, the main menu entries don't display at all (no text or glyph).  


Try replacing:

  if (CtlType = ODT_MENU) and Assigned(Menu) and (hwndItem <> Menu.Handle) then CtlType := ODT_STATIC;  

with:

  if (CtlType = ODT_MENU) and not IsMenu(hwndItem) then CtlType := ODT_STATIC;
0
 

Author Comment

by:rossmcm
ID: 7120691
That did it.  Many thanks.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 7126799
Thank you for returning and finalizing this.
Moondancer - EE Moderator
0
 
LVL 7

Expert Comment

by:Cynna
ID: 7127331
No problem.
0
 

Expert Comment

by:praveenthatikonda
ID: 12733825
Hi,
I am working for maintenance project which was in PowerBuilder 8.0. In the main window, i have one menu and tool bar with buttons below the menu and status bar at bottom.

When mouse move over the toolbar buttons, it is showing wrong message for one of the button when mouse over. i was tried to find out the bug to fix and failed.

Anybody could help me ASAP?

praveenthatikonda@yahoo.com
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

15 Experts available now in Live!

Get 1:1 Help Now