Solved

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

Posted on 1997-03-15
8
1,654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

627 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