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
|
//Main.cpp
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#define IDC_X_TEXT 2000
#define IDC_Y_TEXT 2005
#define IDC_PROBABILITY_TEXT 2010
#define IDC_CMD_BTN 2015
LRESULT CALLBACK WndProc(HWND hWnd, unsigned int wMsg, WPARAM wParam, LPARAM lParam)
{
switch(wMsg)
{
case WM_CREATE:
{
HINSTANCE hIns=((LPCREATESTRUCT)lParam)->hInstance;
CreateWindowEx(0,L"static",L"Enter x",WS_CHILD|WS_VISIBLE,20,40,80,24,hWnd,(HMENU)-1,hIns,0);
CreateWindowEx(0,L"static",L"Enter y",WS_CHILD|WS_VISIBLE,20,70,80,24,hWnd,(HMENU)-1,hIns,0);
CreateWindowEx(0,L"static",L"Probability",WS_CHILD|WS_VISIBLE,20,100,80,24,hWnd,(HMENU)-1,hIns,0);
CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,40,100,24,hWnd,(HMENU)IDC_X_TEXT,hIns,0);
CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,70,100,24,hWnd,(HMENU)IDC_Y_TEXT,hIns,0);
CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_CHILD|WS_VISIBLE,120,100,100,24,hWnd,(HMENU)IDC_PROBABILITY_TEXT,hIns,0);
CreateWindowEx(0,L"button",L"Calculate",WS_CHILD|WS_VISIBLE,235,55,75,50,hWnd,(HMENU)IDC_CMD_BTN,hIns,0);
return 0;
}
case WM_COMMAND:
{
if(LOWORD(wParam)==IDC_CMD_BTN && HIWORD(wParam)==BN_CLICKED)
{
wchar_t szBuffer[32];
GetWindowText(GetDlgItem(hWnd,IDC_X_TEXT),szBuffer,32);
double x=_wtof(szBuffer);
GetWindowText(GetDlgItem(hWnd,IDC_Y_TEXT),szBuffer,32);
double y=_wtof(szBuffer);
double a = x / y;
double b = a * 100;
swprintf(szBuffer,L"%12.8f",b);
SetWindowText(GetDlgItem(hWnd,IDC_PROBABILITY_TEXT),szBuffer);
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return (DefWindowProc(hWnd, wMsg, wParam, lParam));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
wchar_t szClassName[]=L"Zenga";
WNDCLASSEX wc;
HWND hWnd;
MSG msg;
memset(&wc,0,sizeof(WNDCLASSEX));
wc.lpszClassName = szClassName; wc.lpfnWndProc = WndProc;
wc.cbSize = sizeof (WNDCLASSEX); wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)COLOR_BTNSHADOW;
RegisterClassEx(&wc);
hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,75,75,350,205,HWND_DESKTOP,0,hInstance,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
|