[go: up one dir, main page]

Menu

[333776]: / win32 / winmain.c  Maximize  Restore  History

Download this file

143 lines (110 with data), 5.3 kB

  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
/****************************************************************************
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
}