C++ Builder:How can I change WndProc to my own?

Posted on 1997-03-15
Last Modified: 2012-08-13
Before starting my program by Application->Run() method,
I tried to change WndProc to my own by SetClassLong(), but
nothing happend. My own CALLBUCK MyWndProc() did't get
messages. My question is how can I replace address of WndProc in WNDCLASS to my own address for proceeding messages by MyWndProc()? If you can help me, please e-mail
to Thank you.
Question by:alexander031597
  • 4
  • 2
  • 2

Author Comment

ID: 1162037
Edited text of question
LVL 23

Expert Comment

ID: 1162038
Are you using MFC?

LVL 23

Expert Comment

ID: 1162039
I am sorry that I clicked on the wrong button. I just wanted to add a comment.

Author Comment

ID: 1162040
No, I don't use MFC.
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.


Author Comment

ID: 1162041


Expert Comment

ID: 1162042
If you are working with window of your own class, you probably used function RegisterClass(const WNDCLASS* lpWndCls)to register it.
In this case you simply have to assign ---address--- of your WndProc function to lpWndCls->lpfnWndProc before registring the class.
whatever your compiler will accept.

Author Comment

ID: 1162043
Your answer is good for C++ compiler, but we are tolking about C++ Builder compiler. So I didn't use RegisterClass function.
According to Borland's documentation (chapter Handling messages -> Understanding the message-handling system) I should use overriding the handler method. Component Writer's Guide say "You should never need to alter message-dispatch mechanism. All you'll need to do is create message-handling methods." Of course, I know
I should map the methods. But I can't understand why nothing
happened when I changed in WNDCLASS structure address of WndProc
function directly by SetClassLong() function and this address
really was changed, but my WndProc function didn,t receive any messages.


Accepted Solution

LeoV earned 100 total points
ID: 1162044
Tere is easy way: overwrite virtual WindowProc function of your window class.
 The reason you cannot set WindowProc to YourWndProc is that you are not suposed to. when you are working with OWL, you are working with C++ classes, not with Windows classes (I am Sure you know it yourself) so, tere is actually code somewhere, that restres original window procedure and does not let you do stupid things. Or things that Borland considers stupid. If you want to use a hard way and set WindowProc dirrectly, yo have to find a place where C++ class keeps original pointer and change it. I didn't go so far yet.
 By the way, do You speak Russian?

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

758 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

22 Experts available now in Live!

Get 1:1 Help Now