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
| #include <windows.h>
#include <string.h>
#include "Display.h"
LRESULT CALLBACK MainWndProc ( HWND hWnd , UINT message , WPARAM wParam , LPARAM lParam )
{
return( DefWindowProc( hWnd,message,wParam,lParam )) ;
}
struct Display::PrivateDisplay
{
PrivateDisplay () { is_init = false ;}
bool is_init ;
HWND hwnd ;
HDC dc ;
HFONT font ;
Vector2D size ;
} ;
Display::Display ()
{
m = new PrivateDisplay ;
}
Display::~Display ()
{
if (m->is_init)
{
DeleteObject( m->font ) ;
DeleteDC( m->dc ) ;
}
delete m ;
}
bool Display::init ( Vector2D pos , Vector2D size )
{
WNDCLASSEX wcx ;
memset( &wcx,0,sizeof( wcx )) ;
wcx.cbSize = sizeof( wcx ) ;
wcx.lpfnWndProc = MainWndProc ;
wcx.lpszClassName = "spam" ;
RegisterClassEx( &wcx ) ;
m->size = size ;
m->hwnd = CreateWindow( wcx.lpszClassName,0,0,pos.x,pos.y,m->size.x,m->size.y,NULL,NULL,NULL,NULL ) ;
m->dc = GetWindowDC( m->hwnd ) ;
m->font = CreateFont( 16,0,0,0,0,FALSE,FALSE,FALSE,0,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE,"Arial" ) ;
ShowWindow ( m->hwnd,TRUE ) ;
UpdateWindow( m->hwnd ) ;
PAINTSTRUCT paintst ;
BeginPaint ( m->hwnd,&paintst ) ;
HBRUSH brush = CreateSolidBrush( RGB( 0,0,0 )) ;
SelectObject( m->dc,brush ) ;
Rectangle ( m->dc,0,0,m->size.x,m->size.y ) ;
DeleteObject( brush ) ;
EndPaint( m->hwnd,&paintst ) ;
m->is_init = true ;
return true ;
}
void Display::line ( Vector2D p0 , Vector2D p1 , int color )
{
PAINTSTRUCT paintst ;
BeginPaint ( m->hwnd,&paintst ) ;
HPEN pen = CreatePen( PS_SOLID,1,RGB( 0,100,200 )) ;
SelectObject( m->dc,pen ) ;
MoveToEx( m->dc,p0.x,p0.y,NULL ) ;
LineTo( m->dc,p1.x,p1.y ) ;
DeleteObject( pen ) ;
EndPaint( m->hwnd,&paintst ) ;
} |
Partager