MFC Custom Edit Control not displayed

technoway 241 Reputation points
2022-03-25T02:19:45.087+00:00

The attached sample program has an incomplete dialog window. It's just to demonstrate a custom edit control.

The dialog has two edit controls. One is a custom control derived from CEdit, and the other is a regular CEdit control. The regular control shows up.

I tried adding OnDrawItem after modifying the style to be owner-drawn, and that method is call. It's still not displaying anything. That code is currently commented-out.

I'm not sure what is wrong. I suspect it might be the wrong rectangle when I create the window, although I've played with that to no avail.

I have looked at the CTRLTEST Microsoft example.

Note, the commented-out OnDrawItem method in the dialog class is to draw a button, and the code was copied from a codeproject project. I just wanted to see something displayed.

I have code in a zip file to upload. Hopefully a way to upload that code will appear after I submit this question.

Again, I had to use tags that don't apply to get three tags. The only one that applies is C++.

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. RLWA32 51,536 Reputation points
    2022-03-26T15:26:17.543+00:00

    The initial code had several issues. I made a number of changes to get it working and inserted some comments. In addition to the use of the custom control in the dialog template I also showed creating it dynamically in the application's About dialog.

    The revised VS2022 solution can be obtained from OneDrive at https://1drv.ms/u/s!AmnqrCFBv4nDgh-jPL4Fd335LpQm?e=pobJts

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. technoway 241 Reputation points
    2022-03-27T01:09:42.813+00:00

    Thank you.
    I changed the RegisterClassWindow function to a static function before sending the code, and forgot to change the calling sites. I feel stupid about that.

    Otherwise, I had no idea how to solve this. I didn't realize the needed modification to the RegisterClassWindow function, nor did I realize that OnCtlColor would not be called. I did use reflection with controls a very long time ago. I've forgotten most of that.

    Thank you very much!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.