Subj : Re: Modal dialog box - how? To : borland.public.cpp.borlandcpp From : David Ayre Date : Wed Jul 07 2004 08:55 am Thanks Bob, That gives me a bit more to have a go at. Cheers, David Bob Gonder wrote: >David Ayre wrote: > >>>How do you start the dialog? >>>Are you using CreateDialog()? >>>If so, then use DialogBox() instead. >> >>Thanks Bob, >> >>I tried that and it does produce a modal dialog box. Only >>problem is that none of the buttons on the box works. >>I tried to use MakeProcInstance as it suggested in the help >>but couldn't find out what to put in the first variable. In >>their example they used ABOUT, but I can't work out what I need to use for my procedure. > >I think maybe calling Window::WndProc isn't such a good idea. > >DialogBox(hInst,MAKEINTRESOURCE(DIALOG_2),hWnd,ErrorsProc) >hInst is the HINSTANCE passed to WinMain by Windows when the program >started. hWnd is the HWND of the calling window. > ># pragma argsused >static BOOL CALLBACK ErrorsProc(HWND hDlg, UINT message, > WPARAM wParam, LPARAM lParam) >{ > switch (message){ > case WM_INITDIALOG: > { DWORD ErrorSize; > DWORD read; > OpenErrorLog(FALSE); > if( INVALID_HANDLE_VALUE != fhErrors ) > { ErrorSize = GetFileSize( fhErrors, NULL ); > >hErrors=GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,ErrorSize+7); > szErrors = (char*)GlobalLock( hErrors ); > >ReadFile(fhErrors,szErrors,ErrorSize,&read,NULL); > >SendDlgItemMessage(hDlg,CM_U_ERRORS,WM_SETTEXT,0,(LPARAM)szErrors); > CloseHandle( fhErrors ); > fhErrors = INVALID_HANDLE_VALUE; > }else{ > >SendDlgItemMessage(hDlg,CM_U_ERRORS,WM_SETTEXT,0,(LPARAM)"NoErrorLog"); > }; > return TRUE; > }; > case WM_PAINT: > return FALSE; /* left Windows paint it */ > case WM_COMMAND: > switch (wParam) > { > case CM_U_OK: /* handle the OK button */ > if( hErrors ) > { GlobalUnlock( hErrors ); > GlobalFree( hErrors ); > hErrors = NULL; > }; > EndDialog( hDlg, TRUE ); > > /* case (whatever button or control you have): > Code to handle the control; > return TRUE; > */ > default: > return TRUE; > }; > case WM_CLOSE: > PostMessage(hDlg,WM_COMMAND,CM_U_OK,0); > default: // Passes it on if unproccessed > break; > }; > return FALSE; /* let Windows handle everything else */ >} > > > .