-
August 13th, 2015, 09:14 AM
#1
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?
-
August 13th, 2015, 09:21 AM
#2
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
-
August 13th, 2015, 09:28 AM
#3
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.
-
August 13th, 2015, 10:11 AM
#4
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
-
August 13th, 2015, 10:24 AM
#5
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.2)
-
August 13th, 2015, 10:42 AM
#6
Re: edit box changes color
 Originally Posted by VictorN
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.
-
August 13th, 2015, 10:49 AM
#7
Re: edit box changes color
 Originally Posted by 2kaud
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.
-
August 13th, 2015, 11:03 AM
#8
Re: edit box changes color
 Originally Posted by user125
... 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
-
August 13th, 2015, 11:10 AM
#9
Re: edit box changes color
 Originally Posted by VictorN
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.
-
August 13th, 2015, 11:12 AM
#10
Re: edit box changes color
Try to call the default procedure for edit box.
Victor Nijegorodov
-
August 13th, 2015, 01:11 PM
#11
Re: edit box changes color
 Originally Posted by user125
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.2)
-
August 13th, 2015, 03:27 PM
#12
Re: edit box changes color
 Originally Posted by 2kaud
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.
-
August 14th, 2015, 07:02 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|