114 lines
2.7 KiB
C++
114 lines
2.7 KiB
C++
#include "compileconfig.h"
|
|
#include "winmain.h"
|
|
|
|
/*!
|
|
\file mainwin.cpp
|
|
\brief There's defined the entry point to the application
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
here our application starts
|
|
*/
|
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
|
{
|
|
GetPrgRes()->SetInstance(hInstance);
|
|
GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en);
|
|
GetPrgRes()->SetNameOfConfigurationFile();
|
|
GetPrgRes()->ReadFromFile();
|
|
|
|
INITCOMMONCONTROLSEX common_ctrl;
|
|
common_ctrl.dwSize = sizeof(common_ctrl);
|
|
common_ctrl.dwICC = ICC_WIN95_CLASSES;
|
|
|
|
if( !InitCommonControlsEx(&common_ctrl) )
|
|
return ShowError( Languages::cant_init_common_controls );
|
|
|
|
if( !GetPrgRes()->GetThreadController()->Init() )
|
|
return ShowError( Languages::cant_init_calculations );
|
|
|
|
unsigned int thread_id;
|
|
uintptr_t thread_handle;
|
|
if( (thread_handle = _beginthreadex(0,0,CalculationsProcedure, 0, 0, &thread_id)) == 0 )
|
|
return ShowError( Languages::cant_create_thread );
|
|
|
|
CreateDialog( hInstance, MAKEINTRESOURCE(IDD_MAIN_DIALOG), 0, MainWindowProc);
|
|
|
|
if( !GetPrgRes()->GetMainWindow() )
|
|
return ShowError( Languages::cant_create_main_window );
|
|
|
|
|
|
// there's the main loop of messages here
|
|
MainMessagesLoop();
|
|
|
|
GetPrgRes()->SaveToFile();
|
|
CloseHandle( (HANDLE)thread_handle );
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
/*!
|
|
it displays a message box with an error
|
|
(it's only used during initiation)
|
|
*/
|
|
int ShowError( Languages::GuiMsg error_code )
|
|
{
|
|
MessageBox(0, GetPrgRes()->GetLanguages()->GuiMessage( error_code ),
|
|
GetPrgRes()->GetLanguages()->GuiMessage( Languages::message_box_error_caption ),
|
|
MB_ICONERROR);
|
|
|
|
return static_cast<int>( error_code );
|
|
}
|
|
|
|
|
|
/*!
|
|
the main loop of messages
|
|
*/
|
|
void MainMessagesLoop()
|
|
{
|
|
MSG msg;
|
|
|
|
while( GetMessage(&msg,0,0,0) )
|
|
{
|
|
bool sended = false;
|
|
|
|
// firt we try to send our message to dialogs
|
|
// (the dialogs on the tab control)
|
|
for(unsigned int i=0 ; i<GetPrgRes()->HowManyTabWindows() && !sended ; ++i)
|
|
{
|
|
if( IsDialogMessage(GetPrgRes()->GetTabWindow(i), &msg) )
|
|
sended = true;
|
|
}
|
|
|
|
// if it's not a message to any of our dialogs we send it
|
|
// to the main window (it's a dialog as well)
|
|
if( !sended )
|
|
{
|
|
if( !IsDialogMessage(GetPrgRes()->GetMainWindow(), &msg) )
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/*!
|
|
the window-procedure for the main window
|
|
*/
|
|
BOOL CALLBACK MainWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
static Messages messages;
|
|
|
|
if( messages.Empty() )
|
|
// initiation
|
|
MainWindowFunctions::CreateMainMessagesTable(messages);
|
|
|
|
// in the Messages class we're using the std::map
|
|
// so that we have the logarythmic time to find the special function to call
|
|
return messages.Call(message, hWnd, message, wParam, lParam);
|
|
}
|