/****************************************************************************
FILE: winmain.c
COMMENTS:
EXPORTED FUNCTIONS:
WinMain
****************************************************************************
LICENSE:
HexTool - a simple program to convert numbers on the fly
Copyright (C) 2003 Ryan Harkin; www.harkin.org/HexTool
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma warning( disable : 4115 ) // disable warning generated when windows.h in included
#pragma warning( disable : 4100 ) // disable warning generated when a function parameter is unused
#include "debug.h"
#include "windows.h" // required for all Windows applications
#include "resource.h" // Required for resource identifiers
#include "register.h"
#include "value.h"
#include "hextooldialog.h"
#include "globalinstancehnd.h"
#include "togglewindow.h"
typedef enum
{
WINDOW_NORMAL, // default HexTool window
WINDOW_ADVANCED, // HexTool window with advanced operations such as Registers, AND, OR, etc...
}
eWindowState;
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
COMMENTS:
Windows recognizes this function by name as the initial entry point
for the program. This function calls the application initialization
routine, if no other instance of the program is running, and always
calls the instance initialization routine. It then executes a message
retrieval and dispatch loop that is the top-level control structure
for the remainder of execution. The loop is terminated when a WM_QUIT
message is received, at which time this function exits the application
instance by returning the value passed by PostQuitMessage().
If this function must abort before entering the message loop, it
returns the conventional value NULL.
****************************************************************************/
int PASCAL WinMain
(
HINSTANCE hInstance, // current instance
HINSTANCE hPrevInstance, // previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show-window type (open/icon)
)
{
MSG msg;
BOOL dlgCreated = FALSE;
BOOL state = WINDOW_ADVANCED; // The initial window state gets toggled and we want to start in normal mode, so set to advanced
int i;
// If the user specified a command line (ANY command line!), start up in advanced mode
if (lpCmdLine[0] != 0)
{
state = WINDOW_NORMAL;
}
// initialise the start values for each register
for (i=0; i < REG_NUM; i++)
{
SetValue(0, i);
}
SetGlobalInstanceHnd(hInstance);
msg.wParam = 0; // Default return value, should DialogBox fail
// We want to do this loop:
// a) the first time through to create the initial window
// b) every time that the dialog closes and the toggle window flag is set.
//
// If the dialog fails to create: S_toggleWindow will not have been set and we will drop out of the loop
do
{
SetToggleWindow(TOGGLE_OFF); // assume that we will not toggle the window unless explicitly set by the dlg proc
if (state == WINDOW_ADVANCED)
{
state = WINDOW_NORMAL;
dlgCreated = DialogBox ( hInstance, "IDD_HEXTOOL", NULL, (DLGPROC)HexToolDialog );
}
else
{
state = WINDOW_ADVANCED;
dlgCreated = DialogBox ( hInstance, "IDD_HEXTOOL_ADVANCED", NULL, (DLGPROC)HexToolDialog );
}
}
while (GetToggleWindow());
// We should only reach this point after it has been requested that the application should close,
// probably by the user clicking on the X/Close icon, ALT-F4 or the Close menu option from the system menu
if (dlgCreated)
{
// Acquire and dispatch messages until a WM_QUIT message is received.
while (GetMessage(&msg, // message structure
NULL, // handle of window receiving the message
0, // lowest message to examine
0)) // highest message to examine
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
}
return (msg.wParam); // Returns the value from PostQuitMessage
}