Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: BlackZeroX en 6 Diciembre 2010, 10:56 am



Título: [SRC] Lineas Aleatorias en la Pantalla
Publicado por: BlackZeroX en 6 Diciembre 2010, 10:56 am
.
Linkear libreria     GDI32

Esto solo es una traduccion de VB6 a C++

Que hace? Solo dibuja miles de lineas aleatoriamente de distintos colores en el monitor ignorando todo ( o casi todo ).

Codigo Original:

(GDI32) Lineas Aleatorias On The Fly (http://infrangelux.hostei.com/index.php?option=com_content&view=article&id=19:artgdi32lineasaleatoriasonthe-fly&catid=12:catgraficos&Itemid=20)

https://foro.elhacker.net/programacion_visual_basic/lineas_al_aire-t281968.0.html;msg1389871#msg1389871

Este codigo trae corregido algunos errores que cometi en vb6... nada graves (el mi blog ya estan corregidos por obvias razones)

Codigo:

Código
  1.  
  2. ////////////////////////////////////////////////////////////////
  3. // Autor: BlackZeroX ( Ortega Avila Miguel Angel )            //
  4. //                                                            //
  5. // Web: http://InfrAngeluX.Sytes.Net/                         //
  6. //                                                            //
  7. // |-> Pueden Distribuir Este Código siempre y cuando         //
  8. // no se eliminen los créditos originales de este código      //
  9. // No importando que sea modificado/editado o engrandecido    //
  10. // o achicado, si es en base a este código                    //
  11. ////////////////////////////////////////////////////////////////
  12.  
  13. #include<iostream>
  14. #include<windows.h>
  15.  
  16. using namespace std;
  17.  
  18. struct tLineas
  19. {
  20.    POINT PuntoIni;
  21.    POINT PuntoEnd;
  22. } *PtLineas;
  23.  
  24.  
  25. HDC     HDC_dest;
  26. RECT    RECT_wmonitor;
  27.  
  28. UINT NumeroAleatorio(UINT *l,UINT *u);
  29. UINT NumeroAleatorio(UINT *l,UINT u);
  30. UINT NumeroAleatorio(UINT l,UINT *u);
  31. UINT NumeroAleatorio(UINT l,UINT u);
  32.  
  33. void Swap(UINT *l,UINT *u);
  34. void Swap(UINT *l,UINT u);
  35. void Swap(UINT l,UINT *u);
  36. void Swap(UINT l,UINT u);
  37.  
  38. VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD);
  39. VOID ProcessMessages();
  40.  
  41. int main()
  42. {
  43.  
  44.    HDC_dest                = GetDC( NULL );
  45.    SetTimer ( NULL , 0 , 10 , (TIMERPROC)TimerProc );
  46.    ProcessMessages();
  47.    ReleaseDC ( NULL , HDC_dest );
  48.    return (1);
  49. }
  50.  
  51. void Swap(UINT *l,UINT *u)
  52. {
  53.    UINT Ptmp = *l;
  54.    *l = *u;
  55.    *u = Ptmp;
  56. }
  57.  
  58. UINT NumeroAleatorio(UINT l,UINT u)
  59. {
  60.    if ( l > u)
  61.        Swap( &l , &u );
  62.    return ( rand()%(u-l+1)+l );
  63. }
  64.  
  65. VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT_PTR idEvent,DWORD dwTime)
  66. {
  67.    tLineas     Linea;
  68.    HPEN        hPen;
  69.  
  70.    RECT_wmonitor.bottom    = GetSystemMetrics( 1 );
  71.    RECT_wmonitor.left      = 1;
  72.    RECT_wmonitor.right     = GetSystemMetrics( 0 );
  73.    RECT_wmonitor.top       = 1;
  74.  
  75.    Linea.PuntoIni.x = NumeroAleatorio((UINT)RECT_wmonitor.left,(UINT)RECT_wmonitor.right);
  76.    Linea.PuntoIni.y = NumeroAleatorio((UINT)RECT_wmonitor.top,(UINT)RECT_wmonitor.bottom);
  77.    Linea.PuntoEnd.x = NumeroAleatorio((UINT)RECT_wmonitor.left,(UINT)RECT_wmonitor.right);
  78.    Linea.PuntoEnd.y = NumeroAleatorio((UINT)RECT_wmonitor.top,(UINT)RECT_wmonitor.bottom);
  79.  
  80.    hPen = CreatePen(0, 1, (COLORREF)NumeroAleatorio((UINT)0,(UINT)3000000));
  81.    DeleteObject(SelectObject(HDC_dest, hPen));
  82.    Ellipse (HDC_dest, Linea.PuntoIni.x - 2, Linea.PuntoIni.y - 2, Linea.PuntoIni.x + 2, Linea.PuntoIni.y + 2);
  83.    Ellipse (HDC_dest, Linea.PuntoEnd.x - 2, Linea.PuntoEnd.y - 2, Linea.PuntoEnd.x + 2, Linea.PuntoEnd.y + 2);
  84.    DeleteObject(hPen);
  85.    hPen = CreatePen(0, 1, (COLORREF)NumeroAleatorio((UINT)0,(UINT)3000000));
  86.    DeleteObject(SelectObject(HDC_dest, hPen));
  87.    MoveToEx (HDC_dest, Linea.PuntoIni.x, Linea.PuntoIni.y, NULL);
  88.    LineTo (HDC_dest, Linea.PuntoEnd.x, Linea.PuntoEnd.y);
  89.    DeleteObject (hPen);
  90. }
  91.  
  92. VOID ProcessMessages()
  93. {
  94.    MSG msg;
  95.    while (GetMessage(&msg, NULL, NULL, NULL) != -1)
  96.        DispatchMessage(&msg);
  97. }
  98.  
  99.  

Temibles Lunas!¡.