Skip to main content
gamedev.net
🔒 Locked

Dialog Box

Started by brekehan 3 replies 950+ views
Original Post
brekehan
brekehan
This is more Windows orientated, but thought maybe I could get an answer here. I made a dialog box to get my graphics settings. However, when I switched to 64 bit, my dialog box never gets displayed at all. It receives a WM_SETFONT, followed immediatly by a WM_DESTROY message. The return code is -1, but GetLastError returns 0. So I have no idea why it is destroying itself right off. It works fine in win32! I changed all the types to the best of my knowledge. What could cause this? Link to my question on MSDN forums: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/45989a10-2785-486d-94ae-4f1f3e1ca651
Evil Steve
Evil Steve
You're not trying to put a HWND in an int or anything are you? I think HWNDs are 64-bit on a 64-bit system, whereas ints remain 32-bits.

Can we see a minimal example?
brekehan
brekehan
Nah, the only thing I play with is the paramter I am passing at the time of the call. It is a 'this' pointer and the type for DialogBoxParam's argument is a LPARAM. I checked sizeof and they are both 64 bits.

My base dialog class:

//----------------------------------------------------------------------------------------------------------------------class BaseModalDialog{public:   /**    * Constructor   **/   BaseModalDialog();   /**   * Destructor   **/   virtual ~BaseModalDialog();protected:      /**   * Creates the dialog   *   * @param instance - instance of the application that owns the dialog   * @param templateName - name of an included dialog template resource   * @param parent - handle to the parent window of the dialog   *   * @return int - result from EndDialog when the dialog exits   *   **/   INT_PTR Init(HINSTANCE instance, const char * templateName, HWND parent);   /**   * Initializes all the controls in the dialog   **/   virtual void InitComponents() = 0;   /**    * The dialog message procedure for the base dialog   *   * This procedure will foward dialog messages to the ModalDlgProc of the class instance that created the dialog   *   * @param hwnd - handle to the dialog to whom the message was sent   * @param message - the message sent to the dialog   * @param lparam - additional message information   * @param wparam - additional message information   *   * @return BOOL - TRUE if it was handled, otherwise FALSE   */   static INT_PTR CALLBACK BaseModalDlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);   /**   * Dialog message procedure for derived classes   *   * Derived classes should override this method to process any dialog message they are interested in   *   * @param hwnd - handle to the dialog to whom the message was sent   * @param message - the message sent to the dialog   * @param lparam - additional message information   * @param wparam - additional message information   *   * @return LRESULT - TRUE if the message was handled, otherwise false.   **/   virtual INT_PTR ModalDlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);   HWND m_hwnd;            // Handle to the dialog};} // namespace common_lib_cpisz#endif


#include "BaseModalDialog.h"// Common Lib Includes#include "BaseException.h"// Standard Includes#include <sstream>namespace common_lib_cpisz{//-----------------------------------------------------------------------------BaseModalDialog::BaseModalDialog()   :   m_hwnd(NULL){}//-----------------------------------------------------------------------------BaseModalDialog::~BaseModalDialog(){}//-----------------------------------------------------------------------------INT_PTR BaseModalDialog::Init(HINSTANCE instance, const char * templateName, HWND parent){   DLGPROC procedure;   INT_PTR result = DialogBoxParam(instance,                                    templateName,                                   parent,                                   BaseModalDlgProc,                                   reinterpret_cast<LPARAM>(this));   if( result == 0 || result == -1 )   {      DWORD err = GetLastError();   }   return result;}//-----------------------------------------------------------------------------INT_PTR CALLBACK BaseModalDialog::BaseModalDlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){   if( message == WM_INITDIALOG )   {      // Store a pointer to the object owning this dialog      BaseModalDialog * obj = reinterpret_cast<BaseModalDialog *>(lparam);      SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(obj));      // Store a handle to the dialog      obj->m_hwnd = hwnd;      // Initialize the dialogs components      obj->InitComponents();   }   // Retrieve a pointer to the object owning this dialog   BaseModalDialog * obj = reinterpret_cast<BaseModalDialog *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));   // Pass the message to derived classes   INT_PTR result = false;   if( obj )   {      result = obj->ModalDlgProc(hwnd, message, wparam, lparam);   }      return result;}//-----------------------------------------------------------------------------INT_PTR BaseModalDialog::ModalDlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam){   return false;}} // namespace common_lib_cpisz


My derived dialog class:

#ifndef GRAPHICSCONFIGDLG_H#define GRAPHICSCONFIGDLG_H// EngineX Includes#include "Core/DisplayModeEnumerator.h"#include "Core/DisplayMode.h"// Common Lib Includes#include "BaseModalDialog.h"//--------------------------------------------------------------------------------class GraphicsConfigDlg : public common_lib_cpisz::BaseModalDialog{public:   /**   * Constructor   */   GraphicsConfigDlg(DisplayMode & result);	   /**   * Deconstructor   */   ~GraphicsConfigDlg();   /**   * Creates the dialog   *   * @param instance - instance of the application that owns the dialog   * @param templateName - name of an included dialog template resource   * @param parent - handle to the parent window of the dialog   *   * @return int - any value returned from EndDialog when the dialog exits   *   **/   INT_PTR Run(HINSTANCE instance);   void InitComponents() {}private:   /**   * Graphics Config Dialog Procedure   */   INT_PTR ModalDlgProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);         /**   * The display mode that is a result of the users selections   **/   DisplayMode & m_displayMode;};#endif


#include "GraphicsConfigDlg.h"#include "resource.h"// Common Lib Includes#include "BaseException.h"// Windows Includes#include <commctrl.h>// Standard Includes#include <sstream>#include <cassert>using namespace common_lib_cpisz;//-----------------------------------------------------------------------------GraphicsConfigDlg::GraphicsConfigDlg(DisplayMode & result)   :   BaseModalDialog(),   m_displayMode(result){}//-----------------------------------------------------------------------------GraphicsConfigDlg::~GraphicsConfigDlg(){}//-----------------------------------------------------------------------------INT_PTR GraphicsConfigDlg::Run(HINSTANCE instance){   return BaseModalDialog::Init(instance, MAKEINTRESOURCE(IDD_GRAPHICS_CONFIG), NULL);}//----------------------------------------------------------------------INT_PTR GraphicsConfigDlg::ModalDlgProc(HWND dlg, UINT message, WPARAM wparam, LPARAM lparam){   switch(message)   {      case WM_COMMAND:      {         switch(LOWORD(wparam))         {            // Button - OK            case IDOK:            {               EndDialog(dlg, 0);               return true;            }            default:            {               break;            }         }         break;      }      default:      {         break;      }   }   return false;}


Calling code and entry point:

//----------------------------------------------------------------------int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR, INT){   // Get display mode   DisplayMode displayMode;   try   {      GraphicsConfigDlg configDlg(displayMode); // The graphics config dialog      configDlg.Run(instance);                  // Run the dialog	}   catch(BaseException & error)   {      error.MsgBox();      return 1;   }   return 0;}
Endurion
Endurion
Surely not related, but the Windows functions do not use the C++ bool (true/false) but their defines (TRUE/FALSE). You should return those.

Still, that won't be the actual problem.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Evil Steve
Evil Steve
If DialogBoxParam() returns -1 and GetLastError() returns 0, that usually means that the dialog proc failed.
Are you getting a WM_INITDIALOG message?

What is on your dialog? If you have anything like a Rich Edit control, you need to make sure the DLL is loaded for it - and a 64-bit app can't load 32-bit DLLs, so you need to make sure that any custom controls in a DLL have a 64-bit version of the DLL.

Also, moving to General Programming.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.