home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!microsoft!wingnut!stevesi
- From: stevesi@microsoft.com (Steven Sinofsky)
- Subject: Re: Mixing Windows API code & MFC
- Message-ID: <1992Aug28.012713.29214@microsoft.com>
- Date: 28 Aug 92 01:27:13 GMT
- Organization: Microsoft Corporation
- References: <1992Aug26.044944.11302@csus.edu>
- Distribution: na
- Lines: 66
-
-
-
- Be sure that your callback is FAR PASCAL, even if you make it a
- static member of a C++ class.
-
- The following replaces the use of the MFC C++ class CModalDialog
- with direct Windows API calls.
-
-
- BOOL FAR PASCAL AboutBox(HWND hDlg, UINT nMsg, WPARAM wParam, LPARAM lParam)
- {
- switch (nMsg)
- {
- case WM_INITDIALOG:
- return TRUE;
- case WM_COMMAND:
- ::EndDialog(hDlg, TRUE);
- return TRUE;
- break;
- default:
- return FALSE;
- }
- }
-
- void CMainWindow::OnAbout()
- {
- FARPROC lpAbout = ::MakeProcInstance((FARPROC)AboutBox,
- AfxGetInstanceHandle());
- ::DialogBox(AfxGetResourceHandle(), "AboutBox", NULL, (DLGPROC)AboutBox);
- FreeProcInstance((FARPROC)AboutBox);
- }
-
- In article <1992Aug26.044944.11302@csus.edu> vpcsc7@sfsuvax1.sfsu.edu (Dan Tauber) writes:
- >I am trying to use an API window procedure in a MFC application
- >to handle the About box. I have the help/about message mapped to the
- >main windows' OnAbout method. Whenever this code executes, I get a
- >GP fault when it calls the Windows API ::DialogBox function.
- >
- >{
- >DLGPROC lpfnAbout = (DLGPROC) ::MakeProcInstance(
- > (FARPROC) ::AboutBox, hInst);
- >::DialogBox(hInst, "DT_ABOUT", m_hWnd, lpfnAbout);
- >::FreeProcInstance((FARPROC)lpfnAbout);
- >}
- >
- >hInst is a global handle that I initialize with the
- >AfxGetInstanceHandle() function when the program starts. m_hWnd
- >is the CWnd member function that holds the handle to the window.
- >I also export the AboutBox funtion in the def file.
- >
- >Can anyone help?
- >
- >Thanks
- >
- >Dan
- >tauber@futon.sfsu.edu
-
-
- --
- Steven Sinofsky
- stevesi@microsoft.com
- Disclaimer: I don't speak for Microsoft, BillG does that.
-
-
- --
- Steven Sinofsky
- stevesi@microsoft.com
- Disclaimer: I don't speak for Microsoft, BillG does that.
-