Example of running HGE in a child window
  • radishesradishes July 2007
    Here's the complete code of one method of running HGE in a child window. This example loads a toolbar window and a workspace window, and then initiates HGE in the workspace window. This code comes from my current HGE project. I've created a map editor tool and this is the skeleton of that code. Any improvements to this code are welcome.

    A screenshot of this sample program can be viewed at http://radishes.org/images/hge_child.png

    ( The following paragraph is no longer true as of HGE version 1.8 )

    One caveat is that this code will crash with the HGE 1.7 version hge.dll file, which is currently the newest HGE. This was discussed here: http://relishgames.com/forum/viewtopic.php?t=2651 and DaiShiva came up with the resolution, which requires recompiling HGE. The new hge.dll file, which differs from Official HGE by only 1 line of code, has been compiled by me and is available at http://radishes.org/hge.dll. This problem may be fixed in a future version of HGE. This code compiles and runs fine for me, as long as the recompiled 1.7 hge.dll is used.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    #include <windows.h>
    #include <hge.h>
     
    HGE* hge = 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[] = "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 = NULL;
    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);
     
    RECT hgeClient;
    GetClientRect(hwndHGE, &hgeClient);
     
    // Get HGE interface
    hge = hgeCreate(HGE_VERSION);
     
    hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
    hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
    hge->System_SetState(HGE_USESOUND, false); // with this set, we don't need bass.dll
    hge->System_SetState(HGE_WINDOWED, true);
    hge->System_SetState(HGE_SCREENWIDTH, hgeClient.right);
    hge->System_SetState(HGE_SCREENHEIGHT, hgeClient.bottom);
    hge->System_SetState(HGE_SCREENBPP, 32);
    hge->System_SetState(HGE_HIDEMOUSE, false);
    hge->System_SetState(HGE_HWNDPARENT, hwndHGE ); // set parent window
     
    if (hge->System_Initiate() )
    {
     
    // game objects which depend on HGE can be initialized here, before we enter the main loop
     
    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);
    }
    }
    }
     
    hge->System_Shutdown();
    hge->Release();
     
    return msg.wParam;
    }
     
     
     
     
     
    LRESULT CALLBACK ToolProc(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:
     
    PostQuitMessage(0);
    return 0;
    }
     
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }
     
     
    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;
    }
  • DaiShivaDaiShiva July 2007
    Nice!
  • eggnogeggnog July 2007
    very useful, i was wondering how to do this ;D

    thanks
  • eggnogeggnog August 2007
    How would you go about adding controls to the toolbar window?

    I have done some programming with forms using VC++ express, but the code looks nothing like this.

    What IDE do you use to edit what shows up on the forms? Or is this all just directly coded into the .cpp? If so, where can I learn how to code like this?
  • radishesradishes August 2007
    I hardcoded the toolbar controls. I just followed some examples on the net and used Petzold for backup.

    I haven't looked at HGE code for a little while, but if you are having trouble I could look at my project and post some examples.
  • eggnogeggnog August 2007
    some examples would be really helpful :D

    or even some links to the sites you found useful..

    is this the book you used?

    image

    thanks
  • radishesradishes August 2007
    That is the book that I have. It's not exactly cutting-edge anymore but it is the standard of Win32 API.

    A couple links that I have bookmarked:
    http://msdn2.microsoft.com/en-us/library/ms649779.aspx
    http://www.winprog.org/tutorial/
  • radishesradishes August 2007
    Here is the beginning of my ToolProc function which shows how I manually create the menu, toolbar, and other controls on the tool window. Most or all of the stuff can be created through the IDE's GUI, I know, but nevertheless here is how I have done it manually.

    Note that the Make_Static() function that I use is just a wrapper function to create a static control with some appropriate defaults.

    The rest of the ToolProc is just devoted to stuff like populating the listboxes when they need to be populated, and responding to input in the tool window.

    A screenshot of what the tool window looks like once I have loaded some files in the program: http://radishes.org/images/hge_toolbar.png
    You can see the bad graphics I made for the toolbar :roll: I commented out the edit control, but the intent was/is to use that as a console for running commands in the program.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    LRESULT CALLBACK ToolProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    HDC hdc;
    PAINTSTRUCT ps;
    static HWND s_hwndListScrns;// listbox listing screens of this map
    static HWND s_hwndListEnts; // lisbox listing base entities
    static HWND s_hwndConsole; // text input console
    static HWND s_hwndToolbar; // toolbar
     
    switch (msg)
    {
    case WM_CREATE:
    {
    // create the menus
    HMENU hMenu, hFileMenu, hScreenMenu, hMapMenu;
    hMenu = CreateMenu();
    hFileMenu = CreatePopupMenu();
    AppendMenu(hFileMenu, MF_STRING, ID_FILE_LOADMAP, "&Load Map File...");
    AppendMenu(hFileMenu, MF_STRING, ID_FILE_SAVEMAP, "&Save Map File As...");
    AppendMenu(hFileMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
    AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hFileMenu, "&File");
    hMapMenu = CreatePopupMenu();
    AppendMenu(hMapMenu, MF_STRING, ID_MAP_ATTACHRES, "Attach &Resource File...");
    AppendMenu(hMapMenu, MF_STRING, ID_MAP_ATTACHENT, "Attach &Entity File...");
    AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hMapMenu, "&Map");
    hScreenMenu = CreatePopupMenu();
    AppendMenu(hScreenMenu, MF_STRING, ID_SCREEN_SAVEAS, "Save Current Screen As...");
    AppendMenu(hScreenMenu, MF_STRING, ID_SCREEN_PROPERTIES, "Modify Screen Properties...");
    AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hScreenMenu, "&Screen");
    SetMenu(hwnd, hMenu);
     
    // create controls for the toolbar window
    Make_Static(hwnd, 12, 56, 64, 16, "Screens");
    Make_Static(hwnd, 12, 128+72, 64, 16, "Entities");
    s_hwndListScrns = CreateWindow("listbox", NULL,
    WS_CHILD | WS_VISIBLE | LBS_STANDARD,
    12,72,
    220,128,
    hwnd, (HMENU)ID_TB_LISTSCRNS,
    (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), NULL);
    s_hwndListEnts = CreateWindow("listbox", NULL,
    WS_CHILD | WS_VISIBLE | LBS_STANDARD,
    12,128+72+16,
    220, 200,
    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);*/

    // setup toolbar
    s_hwndToolbar = CreateWindowEx(NULL, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE,
    0,0,0,0, hwnd, (HMENU)ID_TB_TOOLBAR,
    (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE), 0);
    SendMessage(s_hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    SendMessage(s_hwndToolbar, TB_SETBUTTONSIZE, 0, (LPARAM)MAKELONG(40,40) );
    SendMessage(s_hwndToolbar, TB_SETBITMAPSIZE, 0, (LPARAM)MAKELONG(40,40) );
    const int nButtons = 2; // number of buttons on the toolbar
    TBBUTTON tbb[nButtons];
    TBADDBITMAP tbab;
    tbab.hInst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
    tbab.nID = IDB_BITMAP1;
    SendMessage(s_hwndToolbar, TB_ADDBITMAP, 1, (LPARAM)&tbab);
    ZeroMemory(tbb, sizeof(tbb));
    for (int i=0; i<nButtons; i++)
    { // these options are the same for all buttons so set them in a batch
    tbb[i].fsState = TBSTATE_ENABLED;
    tbb[i].fsStyle = TBSTYLE_BUTTON | BTNS_CHECKGROUP;
    }
    tbb[0].iBitmap = 0;
    tbb[0].idCommand = ID_TB_TOOL_SELECT;
    tbb[1].iBitmap = 1;
    tbb[1].idCommand = ID_TB_TOOL_ENTITY;
    SendMessage(s_hwndToolbar, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
    SendMessage(s_hwndToolbar, TB_AUTOSIZE, 0, 0 );
    }
    return 0;
  • radishesradishes August 2007
    Just in case you need it:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    // create a static control, optionally put some text in it, and return a handle to it
    HWND Make_Static(HWND hwndParent, int x, int y, int w, int h, string sText)
    {
    HWND hwndStatic = CreateWindow("static", NULL, WS_CHILD | WS_VISIBLE,
    x, y, w, h, hwndParent, NULL,
    (HINSTANCE)GetWindowLong(hwndParent,GWL_HINSTANCE),
    NULL);
    SetWindowText(hwndStatic, sText.c_str() );
    return hwndStatic;
    }
  • eggnogeggnog August 2007
    sweet, thanks very much for all of that :D

    i will give it a go and let you know how i get on :D
  • eggnogeggnog October 2007
    I've been learning API and was wondering, why do you have this bit:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    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;
    }


    ? Does the HGE PROC actually do anything in this case? I mean we don't have one when making a normal hge appilication..

    could't we just have:
    1
    2
    3
    4
    5
    LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    return DefWindowProc(hwnd, msg, wParam, lParam);
     
    }
  • radishesradishes October 2007
    It's mainly just a skeleton window proc that I use. You are probably right about it being unnecessary. But if one wanted to add a menu or other controls to the HGE workspace window, then the skeleton code is already there and you just have to add a case for WM_COMMAND, or whatever message you want to process.

    Also, for anyone else reading this thread, I believe the modified hge.dll that I refer to in the original post is no longer necessary, as the change log indicates this was fixed in version 1.8.
  • eggnogeggnog October 2007
    Thanks for the reply, I understand it better now :D

    I tested it 1.8, it is fixed now 8)

    I'm getting there with learning api XD the petzold book is so long @_@
  • radishesradishes October 2007
    Yeah, I never "went through it" and read the whole thing. I just use it as reference. There's a lot of stuff in there that I'll surely never use, and equally as much stuff that is pretty out of date.
  • Thanks for the original post, lovely to be able to use win API in combination with hge and other applications when programing tools and editors!

    I've made some minor changes to my own application. Instead of using the tool window I added a menu directly in the HGE window with the thought that I would open dialogs from the menu. But when I open the new dialog window I get an ugly graphical bug where only the items in the new window shows up, but not the window it self. All items in the dialog window is also offset and duplicated.

    Here is a picture of the result

    The red box shows where the dialog window should show up. I've moved my .rc file from the HGE project and tried it in another without HGE and then everything worked fine. I've also tried to turn of the HGE render function with no result.

    Have anyone experienced the same problem or have a theory on what could cause this behaviour?
    Thanks for any input or suggestions :)

    ________________
    Code related to the window message loop and creation of the application
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    #pragma once
    #include "GameManager.h"
    #include "resource.h"
    #include <iostream>
    #include <conio>
    #include <windows>
    #include <stdio>
     
    #include "Box2D.h"
    #include "SDL.h"
     
    HGE *pHGE = 0;
    static HWND hwndHGE; // handle to HGE's parent window
     
    float keyTimer = 1.0f;
    LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    BOOL CALLBACK GeometryProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
     
    //------------------------------------------------------------------------------------//
    bool FrameFunc()
    {
    float deltaTime = pHGE->Timer_GetDelta();
    keyTimer += deltaTime;
     
    // Check for quit condition
    if( pHGE->Input_GetKeyState( HGEK_ESCAPE ) )
    return true;
     
     
    // Uppdate all objects
    GM::Instance().UpdateList( deltaTime );
     
    return false;
    }
     
    //------------------------------------------------------------------------------------//
    // Render all objects
    bool RenderFunc()
    {
    pHGE->Gfx_BeginScene();
    pHGE->Gfx_Clear(0);
     
    // Render gameobjects
    GM::Instance().RenderList();
     
    pHGE->Gfx_EndScene();
     
     
    return false;
    }
     
    //------------------------------------------------------------------------------------//
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR, int iCmdShow )
    {
    // Create a consollwindow for degubtext
    AllocConsole();
    FILE* f;
    freopen_s(&f, "conout$", "w", stdout);
     
    MSG msg;
    WNDCLASS wndclass;
    char szHGEName[] = "HGE Workspace";
     
    wndclass.style = 0; //CS_HREDRAW | CS_VREDRAW
    wndclass.lpfnWndProc = HGEProc;
    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_WINDOW+1);
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = szHGEName;
    wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
     
    if ( !RegisterClass(&wndclass) )
    {
    MessageBox(NULL, "Unable to open the HGE window!", szHGEName, MB_ICONERROR);
    return 0;
    }
     
    hwndHGE = CreateWindowEx(WS_EX_CLIENTEDGE,
    szHGEName,
    szHGEName,
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    300, 128,
    800,632,
    NULL,
    NULL,
    hInstance,
    NULL);
     
    if (hwndHGE == NULL)
    {
    MessageBox(NULL, "HGE Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
    return 0;
    }
     
    ShowWindow(hwndHGE, iCmdShow);
    UpdateWindow(hwndHGE);
     
    RECT hgeClient;
    GetClientRect(hwndHGE, &hgeClient);
     
    // Create a hge instance
    pHGE = hgeCreate( HGE_VERSION );
     
    pHGE->System_SetState(HGE_FRAMEFUNC, FrameFunc);
    pHGE->System_SetState(HGE_RENDERFUNC, RenderFunc);
    pHGE->System_SetState(HGE_USESOUND, false); // with this set, we don't need bass.dll
    pHGE->System_SetState(HGE_WINDOWED, true);
    pHGE->System_SetState(HGE_SCREENWIDTH, hgeClient.right);
    pHGE->System_SetState(HGE_SCREENHEIGHT, hgeClient.bottom);
    pHGE->System_SetState(HGE_SCREENBPP, 32);
    pHGE->System_SetState(HGE_HIDEMOUSE, false);
    pHGE->System_SetState(HGE_HWNDPARENT, hwndHGE ); // set parent window
     
    // Init system and start mainloop
    if( pHGE->System_Initiate() )
    {
    GM::Instance().Init( pHGE );
     
    while(1)
    {
    if(pHGE->System_GetState(HGE_HWND))
    pHGE->System_Start();
     
    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
    if(msg.message == WM_QUIT)
    break;
     
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    }
    // Send an error-message that HGE could not be initialized
    else
    {
    MessageBoxA(NULL, pHGE->System_GetErrorMessage(), "Failed to init HGE",
    MB_OK | MB_ICONERROR | MB_APPLMODAL);
    return true;
     
    }
     
     
    // Cleanup
    pHGE->System_Shutdown();
    pHGE->Release();
    SDL_Quit();
     
    return false;
    }
     
    //_______________________Main window message handle__________________________
    LRESULT CALLBACK HGEProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    HDC hdc;
    PAINTSTRUCT ps;
    DWORD fdwMenu;
     
     
    switch (msg)
    {
    case WM_CREATE:
    break;
     
    //case WM_PAINT:
    // hdc = BeginPaint(hwnd, &ps);
    // EndPaint(hwnd, &ps);
    // break;
     
    case WM_COMMAND:
    {
    switch(LOWORD(wParam))
    {
    case ID_TOOLS_GEOMETRY:
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_GEO), hwnd, GeometryProc);
    break;
     
    case ID_SETTINGS_RUNPHYSICSIMULATION:
    fdwMenu = GetMenuState( GetMenu(hwndHGE), ID_SETTINGS_RUNPHYSICSIMULATION, MF_BYCOMMAND );
    if( !(fdwMenu & MF_CHECKED) )
    {
    CheckMenuItem( GetMenu(hwndHGE), ID_SETTINGS_RUNPHYSICSIMULATION, MF_BYCOMMAND | MF_CHECKED );
    GM::Instance().RunPhysicSimulation( true );
     
    }
    else
    {
    CheckMenuItem( GetMenu(hwndHGE), ID_SETTINGS_RUNPHYSICSIMULATION, MF_BYCOMMAND | MF_UNCHECKED );
    GM::Instance().RunPhysicSimulation( false );
     
    }
    break;
     
    }
    }
    break;
     
    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;
     
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
     
    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
     
    }
     
    return 0;
    }
     
    //____________________________Geometry tool message handle______________________
    BOOL CALLBACK GeometryProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {
    case WM_INITDIALOG:
    return TRUE;
     
    case WM_COMMAND:
    switch(LOWORD(wParam))
    {
    case IDOK:
    EndDialog(hwnd, IDOK);
    break;
    }
    }
     
    return TRUE;
    }
  • sunnyzeng2sunnyzeng2 April 2011
    Can you share your project of VS2005? Just the GUI part. Thanks.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Apply for Membership

In this Discussion

Who's Online (1)