HGE Homepage Relish Games
Innovative indie games and indie game development
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

HGE in child window is crashing on System_Initiate() (edit)

 
Post new topic   Reply to topic    Relish Games Forum Index -> HGE Game Engine
View previous topic :: View next topic  
Author Message
radishes



Joined: 21 Nov 2004
Posts: 76
Location: Seattle, USA

PostPosted: Sat Jun 30, 2007 5:53 pm    Post subject: HGE in child window is crashing on System_Initiate() (edit) Reply with quote

I'm posting my complete code here in the hopes that someone can tell me what I'm doing wrong to get HGE to run in a child window (hwndHGE in this case).


Code:

#define SCREEN_X 1024
#define SCREEN_Y 768

#include <windows.h>
#include <hge.h>
#include <hgeresource.h>
#include <string>
#include "resource.h"

using namespace std;

HGE* hge = 0;
hgeResourceManager* g_pRes = NULL;




LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);


// This function will be called by HGE once per frame.
bool FrameFunc()
{

   // Continue execution
   return false;
}



// This function will be called by HGE when
// the application window should be redrawn.
// Put your rendering code here.
bool RenderFunc()
{
   // Begin rendering quads.
   // This function must be called
   // before any actual rendering.
   hge->Gfx_BeginScene();

   // Clear screen with black color
   hge->Gfx_Clear(0);



   // End rendering and update the screen
   hge->Gfx_EndScene();

   // RenderFunc should always return false
   return false;
}





int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int iCmdShow)
{

   HWND    hwndTool;   // handle to toolbar window
   HWND    hwndHGE;   // handle to HGE's parent window

   MSG       msg;
   WNDCLASS wndclass;
   char szToolbarName[] = "Zip SE Toolbar";
   char szHGEName[] = "HGE Workspace";

   wndclass.style         = CS_HREDRAW | CS_VREDRAW;
   wndclass.lpfnWndProc   = ToolProc;
   wndclass.cbClsExtra      = 0;
   wndclass.cbWndExtra      = 0;
   wndclass.hInstance      = hInstance;
   wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
   wndclass.hCursor      = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground   = (HBRUSH)(COLOR_BTNFACE+1);;
   wndclass.lpszMenuName   = MAKEINTRESOURCE(IDR_TOOLMENU);
   wndclass.lpszClassName   = szToolbarName;

   if ( !RegisterClass(&wndclass) )
   {
      MessageBox(NULL, "Unable to open the toolbar window!", szToolbarName, MB_ICONERROR);
      return 0;
   }

   hwndTool = CreateWindowEx(WS_EX_CLIENTEDGE,
                  szToolbarName,
                  szToolbarName,
                  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                  16, 128,
                  256, 768,
                  NULL,
                  NULL,
                  hInstance,
                  NULL);


    if(hwndTool == NULL)
    {
        MessageBox(NULL, "Tool Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }

   ShowWindow(hwndTool, iCmdShow);
   UpdateWindow(hwndTool);


   wndclass.lpfnWndProc   = HGEProc;
   wndclass.lpszClassName  = szHGEName;

   if ( !RegisterClass(&wndclass) )
   {
      MessageBox(NULL, "Unable to open the HGE window!", szToolbarName, MB_ICONERROR);
      return 0;
   }

   hwndHGE = CreateWindowEx(WS_EX_CLIENTEDGE,
                  szHGEName,
                  szHGEName,
                  WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                  300, 128,
                  1024, 768,
                  hwndTool,
                  NULL,
                  hInstance,
                  NULL);

   if (hwndHGE == NULL)
   {
      MessageBox(NULL, "HGE Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   ShowWindow(hwndHGE, iCmdShow);
   UpdateWindow(hwndHGE);



   // Get HGE interface
   hge = hgeCreate(HGE_VERSION);

   // Set up log file, ini file, frame function, render function and window title
   hge->System_SetState(HGE_LOGFILE, "zip.se.log");
   hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
   hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
   hge->System_SetState(HGE_TITLE, "SE");
   hge->System_SetState(HGE_USESOUND, false);   // with this set, we don't need bass.dll
   // Set up video mode
   hge->System_SetState(HGE_WINDOWED, true);
   hge->System_SetState(HGE_SCREENWIDTH, SCREEN_X);
   hge->System_SetState(HGE_SCREENHEIGHT, SCREEN_Y);
   hge->System_SetState(HGE_SCREENBPP, 32);
   // misc
   hge->System_SetState(HGE_SHOWSPLASH, false);
   hge->System_SetState(HGE_HIDEMOUSE, false);
   // set up parent window
   hge->System_SetState(HGE_HWNDPARENT, hwndHGE );

   hge->System_Initiate();   // crashes here



   while (1)
   {
      if(hge->System_GetState(HGE_HWND))
         hge->System_Start();
   
      if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
         if(msg.message == WM_QUIT) break;
         TranslateMessage(&msg);
         DispatchMessage(&msg);
      }
   }



   
   return msg.wParam;
}







LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   HDC         hdc;
   PAINTSTRUCT   ps;


   switch (msg)
   {
   case WM_CREATE:   
   


      return 0;

   case WM_PAINT:
   //   hdc = BeginPaint(hwnd, &ps);
   //   EndPaint(hwnd, &ps);
      return 0;
 
   case WM_DESTROY:

      return 0;

   default:
      return DefWindowProc(hwnd, msg, wParam, lParam);
      
   }

   return 0;
}









LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   HDC         hdc;
   PAINTSTRUCT   ps;
   static HWND   s_hwndListEnts;
   static HWND s_hwndConsole;

   switch (msg)
   {
   case WM_CREATE:   
      {
                  
        HMENU hMenu, hSubMenu;

        hMenu = CreateMenu();

        hSubMenu = CreatePopupMenu();
        AppendMenu(hSubMenu, MF_STRING, ID_FILE_LOADRES, "Load &Resource File...");
      AppendMenu(hSubMenu, MF_STRING | MF_GRAYED, ID_FILE_LOADENT, "Load &Entity File...");
      AppendMenu(hSubMenu, MF_STRING | MF_GRAYED, ID_FILE_LOADSCR, "Load S&creen File...");
        AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");

        SetMenu(hwnd, hMenu);


      s_hwndListEnts = CreateWindow("listbox", NULL,
                              WS_CHILD | WS_VISIBLE | LBS_STANDARD,
                              12,12,
                              128, 384,
                              hwnd, (HMENU)ID_TB_LISTENTS,
                              (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                              NULL);

      s_hwndConsole = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT,
                           5,700,240, 20,
                           hwnd,
                           (HMENU)ID_TB_CONSOLE,
                           (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
                           NULL);
      }
      return 0;

   case WM_PAINT:
      hdc = BeginPaint(hwnd, &ps);
      EndPaint(hwnd, &ps);
      return 0;

   case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
      
   }

   return DefWindowProc(hwnd, msg, wParam, lParam);
}




Last edited by radishes on Mon Jul 02, 2007 7:12 pm; edited 3 times in total
Back to top
View user's profile Send private message Visit poster's website
radishes



Joined: 21 Nov 2004
Posts: 76
Location: Seattle, USA

PostPosted: Sat Jun 30, 2007 6:02 pm    Post subject: Reply with quote

By the way, my system log reports nothing

Quote:

HGE Started..

HGE version: 1.70
Date: 30.06.2007, 10:52:39

Application: SE
OS: Windows 5.1.2600
Memory: 1047916K total, 382192K free


My FrameFunc is empty and my RenderFunc just clears the screen.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Relish Games Forum Index -> HGE Game Engine All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group