home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1546 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.0 KB  |  80 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!microsoft!wingnut!stevesi
  3. From: stevesi@microsoft.com (Steven Sinofsky)
  4. Subject: Re: Mixing Windows API code & MFC
  5. Message-ID: <1992Aug28.012713.29214@microsoft.com>
  6. Date: 28 Aug 92 01:27:13 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Aug26.044944.11302@csus.edu>
  9. Distribution: na
  10. Lines: 66
  11.  
  12.  
  13.  
  14. Be sure that your callback is FAR PASCAL, even if you make it a 
  15. static member of a C++ class.
  16.  
  17. The following replaces the use of the MFC C++ class CModalDialog
  18. with direct Windows API calls.
  19.  
  20.  
  21. BOOL FAR PASCAL AboutBox(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
  22. {
  23.     switch (nMsg)
  24.     {
  25.         case WM_INITDIALOG:
  26.             return TRUE;
  27.         case WM_COMMAND:
  28.             ::EndDialog(hDlg, TRUE);
  29.             return TRUE;
  30.             break;
  31.         default:
  32.             return FALSE;
  33.     }
  34. }
  35.  
  36. void CMainWindow::OnAbout()
  37. {
  38.     FARPROC lpAbout = ::MakeProcInstance((FARPROC)AboutBox, 
  39.             AfxGetInstanceHandle());
  40.     ::DialogBox(AfxGetResourceHandle(), "AboutBox", NULL, (DLGPROC)AboutBox);
  41.     FreeProcInstance((FARPROC)AboutBox);    
  42. }
  43.  
  44. In article <1992Aug26.044944.11302@csus.edu> vpcsc7@sfsuvax1.sfsu.edu (Dan Tauber) writes:
  45. >I am trying to use an API window procedure in a MFC application
  46. >to handle the About box.  I have the help/about message mapped to the
  47. >main windows' OnAbout method.  Whenever this code executes, I get a
  48. >GP fault when it calls the Windows API ::DialogBox function.
  49. >
  50. >{
  51. >DLGPROC lpfnAbout = (DLGPROC) ::MakeProcInstance(
  52. >                   (FARPROC) ::AboutBox, hInst);
  53. >::DialogBox(hInst, "DT_ABOUT", m_hWnd, lpfnAbout);
  54. >::FreeProcInstance((FARPROC)lpfnAbout);
  55. >}
  56. >
  57. >hInst is a global handle that I initialize with the
  58. >AfxGetInstanceHandle() function when the program starts.  m_hWnd
  59. >is the CWnd member function that holds the handle to the window.
  60. >I also export the AboutBox funtion in the def file.
  61. >
  62. >Can anyone help?
  63. >
  64. >Thanks
  65. >
  66. >Dan
  67. >tauber@futon.sfsu.edu
  68.  
  69.  
  70. -- 
  71. Steven Sinofsky
  72. stevesi@microsoft.com
  73. Disclaimer: I don't speak for Microsoft, BillG does that.
  74.  
  75.  
  76. -- 
  77. Steven Sinofsky
  78. stevesi@microsoft.com
  79. Disclaimer: I don't speak for Microsoft, BillG does that.
  80.