home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / os / mswindo / programm / misc / 3249 < prev    next >
Encoding:
Text File  |  1992-11-06  |  2.7 KB  |  71 lines

  1. Path: sparky!uunet!ogicse!uwm.edu!ux1.cso.uiuc.edu!mp.cs.niu.edu!uxa.ecn.bgu.edu!garrot.DMI.USherb.CA!trepe00
  2. From: trepe00@DMI.USherb.CA (ERIC TREPANIER)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Re: Typecasting a pointer to member-function to unsigned long
  5. Summary: Subclassing a WndProc with an OWL member function
  6. Keywords: WndProc, OWL, SubClass
  7. Message-ID: <Bx9BEr.n0z@DMI.USherb.CA>
  8. Date: 5 Nov 92 18:59:14 GMT
  9. Article-I.D.: DMI.Bx9BEr.n0z
  10. References: <runehh.97.720902695@dhhalden.no>
  11. Sender: usenet@DMI.USherb.CA (Pour courrier Usenet)
  12. Organization: Universite de Sherbrooke -- Dept. d'Informatique
  13. Lines: 55
  14. Nntp-Posting-Host: roselin
  15.  
  16. In article <runehh.97.720902695@dhhalden.no> runehh@dhhalden.no (RUNE HALFDAN HOLST HUSEBY) writes:
  17. >
  18. >In a project I'm working on, I need to typecast a (far) pointer to a 
  19. >function to an unsigned long (DWORD). I need to do this because the 
  20. >MS Windows API requires me to do such a thing.
  21. >
  22. >This is the line that causes the error:
  23. >
  24. >        SetWindowLong(GetDlgItem(HWindow, ID_TO), GWL_WNDPROC, 
  25. >                                (DWORD)&WCompose::ComboProc);
  26. >
  27. >What I'm trying to do, is to send over a callback function, using a generic 
  28. >function which set a lot of different properties, all the size of a long.
  29. >Thus I need to typecast the function pointer to an unsigned long.
  30.  
  31. It looks like you are trying to subclass a combobox control.  If that is
  32. what you want to do, then there are two things you should be aware of:
  33.  
  34. 1) The new window procedure (WCompose::ComboProc) *MUST* be declared
  35.    "static" in the WCompose object definition, and it *MUST* be a public
  36.    member function.  If done correctly, it should look like this:
  37.  
  38. class WCompose: public TWindow
  39. {
  40.   // protected variables & member functions
  41. public:
  42.   ...
  43.   static CALLBACK _export ComboProc(HWND hwnd, UINT msg,
  44.                                     WPARAM wparam, LPARAM lparam);
  45.   ...
  46. }
  47.  
  48. 2) There is a new file included with BC++ 3.1, "windowsx.h" which contains
  49.    a lot of useful macros, especially if you are using "#define STRICT".
  50.    This file defines a special macro called "SubClassWindow".
  51.    Have a look at the file "win31.doc" in your Borland's DOC directory to
  52.    see how it works exactly.  If I remember correctly:
  53.  
  54. WNDPROC oldWndProc;
  55.  
  56. oldWndProc = SubClassWindow(GetDlgItem(HWindow, ID_TO), WCompose::ComboProc);
  57.  
  58. Now, in your ComboProc, you should make sure that you call oldWndProc for all
  59. messages that you are not processing explicitly.  If you are not using Smart
  60. CallBacks, you'll also need to call MakeProcInstance / FreeProcInstance.
  61.  
  62. If this sounds a bit complicated, email-me and I'll explain in more details.
  63.  
  64.  
  65. Eric
  66. -- 
  67. Eric Trepanier
  68. eric@tgm.CAM.ORG
  69. "Everybody has a right to believe in something.
  70.  I believe I'll have another beer."
  71.