Solved

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

Posted on 1997-03-15
8
1,629 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

735 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