Jeg har rettet lidt her og der, nu ser det ud til at virke.
Nogle kommentarer:
Man kan ikke bruge GetDlgItemInt til at læse in float, læs texten med GetDlgItemText (eller GetWindowText) og konverter med strtod, eller bedre en stringstream.
Oversæt din kode som C++ kode og få kompileren til at give dig alle de warnings den kan; det giver en del hint om hvor der er problemer.
#include <windows.h>
#include <sstream>
#include <string>
#define ID_STAT1 1000
#define ID_STAT2 1001
#define ID_STAT3 1002
#define ID_STAT4 1003
#define ID_STAT5 1004
#define ID_BUTTON1 1010
#define ID_BUTTON2 1011
#define ID_BUTTON3 1012
#define ID_BUTTON4 1013
#define ID_BUTTON5 1014
#define ID_EDIT1 1020
#define ID_EDIT2 1021
#define ID_EDIT3 1022
#define ID_EDIT4 1023
#define ID_EDIT5 1024
#define ID_FILE_EXIT 1030
#define ID_STUFF_GO 1031
const char g_szClassName[] = "myWindowClass";
HWND button,button2,button3,button4,button5;
HWND stat1,stat2,stat3,stat4,stat5;
HWND edit1,edit2,edit3,edit4,edit5;
int strN,success;
UINT valueFromBox;
HINSTANCE g_hInst;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
{
//Creating statics
stat1 = CreateWindow("Static","N= ",WS_CHILD | SS_LEFT | WS_VISIBLE,0,0,50,23,hwnd,(HMENU)ID_STAT1,g_hInst,0);
stat2 = CreateWindow("Static","I%= ",WS_CHILD | SS_LEFT | WS_VISIBLE,0,25,50,23,hwnd,(HMENU)ID_STAT2,g_hInst,0);
stat3 = CreateWindow("Static","PV= ",WS_CHILD | SS_LEFT | WS_VISIBLE,0,50,50,23,hwnd,(HMENU)ID_STAT3,g_hInst,0);
stat4 = CreateWindow("Static","PMT= ",WS_CHILD | SS_LEFT | WS_VISIBLE,0,75,50,23,hwnd,(HMENU)ID_STAT4,g_hInst,0);
stat5 = CreateWindow("Static","FV= ",WS_CHILD | SS_LEFT | WS_VISIBLE,0,100,50,23,hwnd,(HMENU)ID_STAT5,g_hInst,0);
//Creating Buttons
button = CreateWindow("Button","Solve",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250,0,80,23,hwnd,(HMENU)ID_BUTTON1,g_hInst,0);
button = CreateWindow("Button","Solve",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250,25,80,23,hwnd,(HMENU)ID_BUTTON2,g_hInst,0);
button = CreateWindow("Button","Solve",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250,50,80,23,hwnd,(HMENU)ID_BUTTON3,g_hInst,0);
button = CreateWindow("Button","Solve",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250,75,80,23,hwnd,(HMENU)ID_BUTTON4,g_hInst,0);
button = CreateWindow("Button","Solve",WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,250,100,80,23,hwnd,(HMENU)ID_BUTTON5,g_hInst,0);
//Creating Edits
edit1 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ES_CENTER | ES_NUMBER | WS_VISIBLE, 40,0,125,23, hwnd, (HMENU)ID_EDIT1, GetModuleHandle(NULL), NULL);
edit2 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ES_CENTER | ES_NUMBER | WS_VISIBLE, 40,25,125,23, hwnd, (HMENU)ID_EDIT2, GetModuleHandle(NULL), NULL);
edit3 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ES_CENTER | ES_NUMBER | WS_VISIBLE, 40,50,125,23, hwnd, (HMENU)ID_EDIT3, GetModuleHandle(NULL), NULL);
edit4 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ES_CENTER | ES_NUMBER | WS_VISIBLE, 40,75,125,23, hwnd, (HMENU)ID_EDIT4, GetModuleHandle(NULL), NULL);
edit5 = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", WS_CHILD | ES_CENTER | ES_NUMBER | WS_VISIBLE, 40,100,125,23, hwnd, (HMENU)ID_EDIT5, GetModuleHandle(NULL), NULL);
}
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_STUFF_GO:
MessageBox(hwnd, "You clicked Go!", "Woo!", MB_OK);
break;
//ID_BUTTON1 command
case ID_BUTTON1:
{
valueFromBox = GetDlgItemInt(hwnd, ID_EDIT1, &success, FALSE);
std::stringstream ss;
ss << valueFromBox;
MessageBox(hwnd, ss.str().c_str(), "Woo!", MB_OK);
}
break;
//ID_BUTTON2 command
case ID_BUTTON2:
{
std::string Str;
HWND Edit = GetDlgItem(hwnd, ID_EDIT2);
int Size = GetWindowTextLength(Edit);
Str.resize(Size);
GetWindowText(Edit, &Str[0], Size);
MessageBox(hwnd, Str.c_str(), "WooDoo!", MB_OK);
}
break;
}
break;
case WM_CTLCOLORSTATIC:
{
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(255, 255, 255));
HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(0, 0, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)g_hbrBackground;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0 ; //LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = 0;
wc.lpszClassName = g_szClassName;
wc.hIconSm = 0;
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"A Menu",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 342, 300,
NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}