Code:
#include <windows.h>
#include <math.h>
#include <winuser.h>
#include "resource.h"
#define PI 4 * atan(0.0);
HINSTANCE hInstance;
//HWND hdlg;
HMENU hMenu ;
char* radius = 0;
int ret = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK AboutDlgProc(HWND , UINT, WPARAM, LPARAM);
///////////////////////////////////////////////////////////////////////////////////////////////////
TCHAR szAppName[] = TEXT ("Moment of Inertia Program") ;
///////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_CROSS) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = szAppName ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hMenu = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MENU1));
hwnd = CreateWindow (szAppName, TEXT ("Moment of Inertia Program"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, hMenu, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//int ret;
switch (message)
{
case WM_COMMAND:
switch (LOWORD (wParam))
{
//case IDM_FILE_NEW:
case IDM_FILE_OPEN:
case IDM_FILE_SAVE:
//case IDM_FILE_SAVE_AS:
MessageBeep (0) ;
return 0 ;
case IDM_EXIT:
SendMessage (hwnd, WM_CLOSE, 0, 0) ;
// return 0 ;
InvalidateRect (hwnd, NULL, TRUE) ;
return 0 ;
case ID_SECTIONS_CIRCLE:
ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(ID_CIRCLE_PROPERTIES), hwnd, AboutDlgProc);
return ret ;
case ID_SECTIONS_RECTANGLE:
MessageBox (hwnd, TEXT ("To Do!"),
szAppName, MB_ICONEXCLAMATION | MB_OK) ;
return 0 ;
case ID_HELP_HELP:
MessageBox (hwnd, TEXT ("Help not yet implemented!"),
szAppName, MB_ICONEXCLAMATION | MB_OK) ;
return 0 ;
case ID_ABOUT:
MessageBox (hwnd, TEXT ("Moments of Inertia\n")
TEXT ("Me, 2002"),
szAppName, MB_ICONINFORMATION | MB_OK) ;
return 0 ;
}
break ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HWND hdlg;
//int ret = 0;
int nLen = 0;
LPTSTR buffer = NULL;
buffer[nLen] = NULL;
switch(Message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
hdlg = GetDlgItem(hwnd, IDC_EDIT_RADIUS); // handle to dialog box edit field???
nLen = GetWindowTextLength(hdlg);
GetDlgItemText(hdlg, // handle to dialog box
IDC_EDIT_RADIUS, // control identifier
buffer, // pointer to buffer for text
nLen // maximum size of string
);
radius = buffer; // No error checking yet! atod!
MessageBox(hwnd, "Dialog!", "I'd like to print buffer here", MB_OK | MB_ICONINFORMATION);
}
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}