Solved

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

Posted on 1997-03-15
8
1,617 Views
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 jcrsch@game-club.com Thank you.
0
Comment
Question by:alexander031597
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:alexander031597
ID: 1162037
Edited text of question
0
 
LVL 23

Expert Comment

by:chensu
ID: 1162038
Are you using MFC?

0
 
LVL 23

Expert Comment

by:chensu
ID: 1162039
I am sorry that I clicked on the wrong button. I just wanted to add a comment.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:alexander031597
ID: 1162040
No, I don't use MFC.
0
 

Author Comment

by:alexander031597
ID: 1162041

0
 

Expert Comment

by:LeoV
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.
---
lpWndCls->lpfnWndProc=MyWndProc;
or
lpWndCls->lpfnWndProc=&(MyWndProc());
whatever your compiler will accept.
0
 

Author Comment

by:alexander031597
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.

0
 

Accepted Solution

by:
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?
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

840 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