- •Int pascal WinMain (hinstance hInst, hinstance hPreInst,
- •If(!hPreInst)
- •Int pascal WinMain (hinstance hInst, hinstance hPreInst,
- •If(!hPreInst)
- •ValidateRect(hWnd, null);
- •ValidateRect(hWnd, null);
- •ValidateRect(hWnd, null);
- •If(!hPreInst) {
- •ValidateRect(hWnd, null);
- •If(!hPreInst){
- •If(!hPreInst){
- •ValidateRect(hWnd, null);
- •If(!hPreInst){
- •If(!hPreInst){
- •ValidateRect(hWnd, null);
- •If(!hPreInst){
- •ValidateRect(hWnd, null);
- •If(!hPreInst){
- •ValidateRect(hWnd, null);
- •If(!hPreInst){
- •// Resource.H
- •If(!hPreInst)
Int pascal WinMain (hinstance hInst, hinstance hPreInst,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wcSwp;
If(!hPreInst)
{
wcSwp.lpszClassName = szProgName;
wcSwp.hInstance = hInst;
wcSwp.lpfnWndProc = WindowProc;
wcSwp.hCursor = LoadCursor(hInst, szCursorName);
wcSwp.hIcon = LoadIcon(hInst, szProgName);
wcSwp.lpszMenuName = szApplName;
wcSwp.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wcSwp.style = CS_HREDRAW|CS_VREDRAW;
wcSwp.cbClsExtra = 0;
wcSwp.cbWndExtra = 0;
if(!RegisterClass (&wcSwp))
return FALSE;
}
hwnd= CreateWindow(szProgName, "C Pie Chart Program",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, (HWND)NULL, (HMENU)NULL,
(HINSTANCE) hInst, (LPVOID) NULL);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
BOOL PASCAL AboutDlgProc(HWND hdlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
switch(messg)
{
case WM_INITDIALOG:
break;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hdlg, TRUE);
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
BOOL PASCAL PieDlgProc(HWND hdlg, UINT messg, WPARAM wParam, LPARAM lParam)
{
switch(messg)
{
case WM_INITDIALOG:
return FALSE;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
GetDlgItemText(hdlg,DM_TITLE,szTString,80);
iWedgesize[0] = GetDlgItemInt(hdlg, DM_P1, NULL, 0);
iWedgesize[1] = GetDlgItemInt(hdlg, DM_P2, NULL, 0);
iWedgesize[2] = GetDlgItemInt(hdlg, DM_P3, NULL, 0);
iWedgesize[3] = GetDlgItemInt(hdlg, DM_P4, NULL, 0);
iWedgesize[4] = GetDlgItemInt(hdlg, DM_P5, NULL, 0);
iWedgesize[5] = GetDlgItemInt(hdlg, DM_P6, NULL, 0);
iWedgesize[6] = GetDlgItemInt(hdlg, DM_P7, NULL, 0);
iWedgesize[7] = GetDlgItemInt(hdlg, DM_P8, NULL, 0);
iWedgesize[8] = GetDlgItemInt(hdlg, DM_P9, NULL, 0);
iWedgesize[9] = GetDlgItemInt(hdlg, DM_P10, NULL, 0);
EndDialog(hdlg, TRUE);
break;
case IDCANCEL:
EndDialog(hdlg, FALSE);
break;
default:
return FALSE;
}
break;
default:
return FALSE;
}
return TRUE;
}
LONG FAR PASCAL WindowProc(HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
HBRUSH hBrush;
static FARPROC lpfnAboutDlgProc;
static FARPROC lpfnPieDlgProc;
static HWND hInst1, hInst2;
static short xClientView, yClientView;
unsigned int iTotalWedge[maxnumwedge+1];
int i, iNWedges;
iNWedges = 0;
for(i = 0; i < maxnumwedge; i++)
{
if(iWedgesize[i] != 0) iNWedges++;
}
iTotalWedge[0] = 0;
for(i = 0; i < iNWedges; i++)
iTotalWedge[i+1] = iTotalWedge[i] + iWedgesize[i];
switch(messg)
{
case WM_SIZE:
xClientView = LOWORD(lParam);
yClientView = HIWORD(lParam);
break;
case WM_CREATE:
hInst1 = ((LPCREATESTRUCT) lParam) -> hInstance;
hInst2 = ((LPCREATESTRUCT) lParam) -> hInstance;
lpfnAboutDlgProc = MakeProcInstance(AboutDlgProc, hInst1);
lpfnPieDlgProc = MakeProcInstance(PieDlgProc, hInst2);
break;
case WM_COMMAND:
switch(wParam)
{
case IDM_ABOUT:
DialogBox(hInst1, "AboutDlgBox", hWnd, lpfnAboutDlgProc);
break;
case IDM_INPUT:
DialogBox(hInst2, "PieDlgBox", hWnd, lpfnPieDlgProc);
InvalidateRect(hWnd, NULL, TRUE);
UpdateWindow(hWnd);
break;
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
break;
default:
break;
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// начало рисования
SetMapMode(hdc, MM_ISOTROPIC);
SetWindowExtEx(hdc, 500, 500, NULL);
SetViewportExtEx(hdc, xClientView, -yClientView, NULL);
SetViewportOrgEx(hdc, xClientView / 2, yClientView / 2, NULL);
// подписи к диограмме
if(xClientView > 200)
TextOut(hdc, strlen(szTString) * (-8/2),
240, szTString, strlen(szTString));
for(i = 0; i < iNWedges; i++)
{
hBrush = CreateSolidBrush(lColor[i]);
SelectObject(hdc, hBrush);
Pie(hdc, -200, 200, 200, -200, (short)(radius * cos(2 * pi * iTotalWedge[i]/
iTotalWedge[iNWedges])),
(short)(radius * sin(2 * pi * iTotalWedge[i]/
iTotalWedge[iNWedges])),
(short)(radius * cos(2 * pi * iTotalWedge[i+1]/
iTotalWedge[iNWedges])),
(short)(radius * sin(2*pi * iTotalWedge[i+1]/
iTotalWedge[iNWedges])));
}
// конец рисования
