CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2015
    Posts
    8

    edit box changes color

    I have created edit box, and placed it onto my main window, and everything works like it should; edit box appears on specified location, with white background, and black text. But when I include this edit box in my window proc like this:

    Code:
    SetWindowLong(edit_box_hwnd, GWL_WNDPROC, (LONG_PTR)myWindowProc);
    edit box appears black, thus the text becomes invisible. I didn't process any messages to my edit box, inside the window proc, so the change of color has been done beyond my code.
    Anyone experienced this behaviour ? And how to fix this?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: edit box changes color

    Why do you want to implement your own window procedure for this edit box? Is it some non-standard one?
    Last edited by VictorN; August 13th, 2015 at 09:25 AM.
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2015
    Posts
    8

    Re: edit box changes color

    It is custom window proc for my main window's child windows. Newest of them is this edit box. This procedure existed before this edit box. Edit box is the last created control on my main window.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: edit box changes color

    But you don't "process any messages" to youredit box "inside the window proc". Then why do you set it for this control?
    Victor Nijegorodov

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: edit box changes color

    What does myWindowProc() actually do? It could be helpful if you posted the code.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Aug 2015
    Posts
    8

    Re: edit box changes color

    Quote Originally Posted by VictorN View Post
    But you don't "process any messages" to youredit box "inside the window proc". Then why do you set it for this control?
    Great question. Actually, I want to write the WM_LBUTTONDOWN code for this edit box. But before I do that, I want to know why is my edit box black when I just use SetWindowLong.

  7. #7
    Join Date
    Aug 2015
    Posts
    8

    Re: edit box changes color

    Quote Originally Posted by 2kaud View Post
    What does myWindowProc() actually do? It could be helpful if you posted the code.
    myWindowProc mostly responds to mouse clicks on child controls. And it works fine.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: edit box changes color

    Quote Originally Posted by user125 View Post
    ... But before I do that, I want to know why is my edit box black when I just use SetWindowLong.
    I guess it is because your procedure does not handle WM_PAINT for edit box.
    Victor Nijegorodov

  9. #9
    Join Date
    Aug 2015
    Posts
    8

    Re: edit box changes color

    Quote Originally Posted by VictorN View Post
    I guess it is because your procedure does not handle WM_PAINT for edit box.
    You 're right; It doesn't handle anything for edit box, yet. I've just set the procedure as it's window proc, and it changed color. I would like to know what I should do in WM_PAINT to restore my edit box to its default appearance.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: edit box changes color

    Try to call the default procedure for edit box.
    Victor Nijegorodov

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: edit box changes color

    Quote Originally Posted by user125 View Post
    myWindowProc mostly responds to mouse clicks on child controls. And it works fine.
    Probably not. That's why you have the issue. Within myWindowProc() for messages not handled (and for those handled but you also want to be handled by the control) you need to call the default procedure for the specific control using CallWindowProc(). This is the value returned from SetWindowLong(GWL_WNDPROC).

    See https://msdn.microsoft.com/en-us/lib...lassing_window for an example.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #12
    Join Date
    Aug 2015
    Posts
    8

    Re: edit box changes color

    Quote Originally Posted by 2kaud View Post
    Probably not. That's why you have the issue. Within myWindowProc() for messages not handled (and for those handled but you also want to be handled by the control) you need to call the default procedure for the specific control using CallWindowProc(). This is the value returned from SetWindowLong(GWL_WNDPROC).

    See https://msdn.microsoft.com/en-us/lib...lassing_window for an example.
    Sorry, but I 've always had CallWindowProc() within myWindowProc. I have several completely functional controls handled by this procedure. Only this newest one, the edit box, have this unexpected behaviour. I probably have to write something in WM_PAINT or similar.
    Last edited by user125; August 13th, 2015 at 03:36 PM.

  13. #13
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: edit box changes color

    the answer is pretty Obvious imo.
    you have an error in your myWindowProc causing that effect.

    likely becuase yuou only implemented the few messages you'r einterested in and none of the others
    if you replace the messageprocedure, you're responsible to make sure ALL of the message get handled properly.
    Either by handlign everything yourself, or by making sure you call the old handler for anything you don't.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured