Red de conocimiento informático - Conocimiento del nombre de dominio - ¡Urgente! ! Programación C++, ¡entran los expertos! ! Utilice Vc ++ 6.0 para programar un programa que simule la rotación del reloj. Los requisitos son los siguientes:

¡Urgente! ! Programación C++, ¡entran los expertos! ! Utilice Vc ++ 6.0 para programar un programa que simule la rotación del reloj. Los requisitos son los siguientes:

Muestro la fecha digital como título de la ventana, creo un nuevo proyecto de aplicación --win32 en vc++6.0 y luego creo un nuevo archivo C++ e ingreso el siguiente código

#include

#include

#define DOSPI (2*3.14159)

#define IDTIMER 1

#define ANGLE TWOPI/360

LRESULT CALLBACK WindowProc(

HWND hwnd,

UINT uMsg,

WPARAM wParam ,

LPARAM lParam

);

int WINAPI WinMain(

HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow

)

{

TCHAR szClassName[] = TEXT(" analogCloc");

MSG msg;

HWND hwnd;

WNDCLASS wndclass;

wndclass.cbClsExtra = 0;

wndclass.cbWndExtra = 0;

wndclass.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);

wndclass.hCursor = NULL;

wndclass.hIcon = NULL;

wndclass.hInstance = hInstance;

wndclass.lpfnWndProc = WindowProc;

wndclass.lpszClassName = szClassName;

wndclass.lpszMenuName = NULL;

wndclass.style = CS_HREDRAW | CS_VREDRAW ;

::RegisterClass(&wndclass);

hwnd = ::CreateWindow (szClassName,TEXT("Reloj "),WS_OVERLAPPEDWINDOW,

CW_USEDEFAULT,CW_USEDEFAULT,

CW_USEDEFAULT,CW_USEDEFAULT,

NULL, NULL, hInstance, NULL);

::ShowWindow(hwnd,nCmdShow);

::UpdateWindow(hwnd);

while(::GetMessage(&msg,NULL,0,0 ))

{

::TranslateMessage(&msg);

::Dispat

chMessage(&msg);

}

return msg.wParam;

}

void setISOTROPIC(HDC hdc,int cxClient,int cyClient)//Establece el modo de mapeo para que se convierta en el modo de mapeo del sistema de coordenadas cartesianas

{

::SetMapMode(hdc,MM_ISOTROPIC);

: :SetWindowExtEx(hdc,1000,1000,NULL); // La proporción de unidades lógicas a unidades de dispositivo es 1/2

::SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL) ;

::SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL // La coordenada vertical es positiva al subir y negativa al bajar

}

void drawClock (HDC hdc)

{

int x, y, radio

::SelectObject(hdc,::CreateSolidBrush; (RGB(1,148,138)));

for(int i=0;i<360;i+=6)

{

x = (int) (cos(TWOPI/360*i )*900);

y = (int)(sin(TWOPI/360*i)*900);

radio = !(i %5)?40:10;

Elipse(hdc,x-radius,y-radius,x+radius,y+radius);

}

}

void drawHands(HDC hdc,SYSTEMTIME *pst,BOOL hChange)

{

int radio[3] = {500,700,850}; >

int ángulo[3 ];

ángulo[0] = pst->wHora*3pst->wMinuto/12*6

ángulo[1] = pst->wMinuto*6;

ángulo[2] = pst->wSecond*6;

for(int i=hChange?0:2;i<3;i++)

{

MoveToEx(hdc,0,0,NULL);

LineTo(hdc,(int)(radio[i]*cos(ANGLE* (ángulo de 90[i]) )),

(int)(radio[i]*sin(ÁNGULO*(ángulo de 90[i]))));

}

}

LRESULT CALLBACK WindowProc(

HWND hwnd,

mensaje UINT,

WPARAM wParam,

LPARAM lParam

)

{

TCHAR tiempo[40];

PAINTSTRUCT ps;

HDC hdc;

estático int cxClient, cyClient;<

/p>

SYSTEMTIME st;

estático SYSTEMTIME preSt;

BOOL hChange;

switch(mensaje)

{

caso WM_CREATE:

::SetTimer(hwnd,IDTIMER,1000,NULL);

::GetLocalTime(&st);

wsprintf(time,TEXT("%d año %d mes %d día %d hora %d minuto %d segundo"),

st.wAño,

st.wMes,

st.wDía,

st.wHora,

st.wMinuto,

st.wSegundo);

SetWindowText(hwnd,time);

prest = st;

devuelve 0;

caso WM_SIZE:

cxClient = LOWORD (lParam);

cyClient = HIWORD(lParam);

devuelve 0;

caso WM_TIMER:

::GetLocalTime(&st ); //Obtener la hora actual cada vez

hChange = st.wHour!=preSt.wHour||st.wMinute!=preSt.wMinute;

hdc = GetDC( hwnd );

setISOTROPIC(hdc,cxClient,cyClient);

::SelectObject(hdc,::GetStockObject(WHITE_PEN));

drawHands(hdc , &preSt,hChange);

::SelectObject(hdc,::GetStockObject(BLACK_PEN));

drawHands(hdc,&st,TRUE);

ReleaseDC (hwnd,hdc);

wsprintf(time,TEXT("%d año %d mes %d día %d hora %d minuto %d segundo"),

st . wAño,

st.wMes,

st.wDía,

st.wHora,

st.wMinuto,

st.wSecond);

SetWindowText(hwnd,time);

prest = st; // Una vez completada la actualización, registra el estado anterior return 0;

caso WM_KEYDOWN:

caso WM_CHAR:

::DestroyWindow(hwnd);

devuelve 0;

caso WM_PAINT :

hdc = ::BeginPaint(hwnd,&ps);

setISOTROPIC(hdc,cxClient,cy

Cliente);

drawClock(hdc);

drawHands(hdc,&preSt,TRUE

::EndPaint(hwnd,&ps);

devuelve 0;

caso WM_DESTROY:

::PostQuitMessage(0);

devuelve 0;

}

return DefWindowProc(hwnd,message,wParam,lParam);

}