📄 oscwnd.cpp
字号:
// oscwnd.cpp : implementation file
#include "stdafx.h"
#include "osc.h"
#include "oscwnd.h"
//#include <math.h> // for HSI conversion
#include "conio.h"
#include "stdlib.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
COscWnd::COscWnd()
{
m_pMemDC = NULL;
m_pWinDC = NULL;
m_pOldPalette = NULL;
m_pOldBitmap = NULL;
}
COscWnd::~COscWnd()
{
}
BEGIN_MESSAGE_MAP(COscWnd, CStatic)
//{{AFX_MSG_MAP(COscWnd)
ON_WM_PAINT()
ON_WM_DESTROY()
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COscWnd Operations
void COscWnd::InitOsc(int nColor)
{
CreatePalette(nColor);
CreateBitmap();
{
CWnd* pActiveWnd = CWnd::GetActiveWindow();
if (pActiveWnd != NULL)
pActiveWnd->SendMessage(WM_QUERYNEWPALETTE);
}
}
CPalette* COscWnd::GetPalette()
{
if (m_Palette.m_hObject != NULL)
return &m_Palette;
else
return NULL;
}
void COscWnd::CreatePalette(int nColor)
{
UINT i;
if (m_Palette.m_hObject != NULL)
m_Palette.DeleteObject();
for(i = 256; i > 0; i--)
{
m_rgbPalette[i].rgbRed = i;
}
for(i = 256; i > 0; i--)
{
m_rgbPalette[i].rgbGreen = i/1.5;
}
for(i = 256; i > 0; i--)
{
m_rgbPalette[i].rgbBlue = i/4;
}
for(int j = 100; j > 0; j--)
{
m_rgbPalette[j].rgbRed = 0;
m_rgbPalette[j].rgbGreen = 255;
m_rgbPalette[j].rgbBlue = 0;
}
LPLOGPALETTE lpLogPal;
lpLogPal = (LPLOGPALETTE) new BYTE[sizeof(LOGPALETTE) + ((255) * sizeof(PALETTEENTRY))];
lpLogPal->palVersion = 0x0300;
lpLogPal->palNumEntries = 256;
for (i = 0; i < 256; i++)
{
lpLogPal->palPalEntry[i].peRed = m_rgbPalette[i].rgbRed;
lpLogPal->palPalEntry[i].peGreen = m_rgbPalette[i].rgbGreen;
lpLogPal->palPalEntry[i].peBlue = m_rgbPalette[i].rgbBlue;
lpLogPal->palPalEntry[i].peFlags = 0;
}
VERIFY( m_Palette.CreatePalette( lpLogPal ) );
delete [] (BYTE *)lpLogPal;
}
CSize COscWnd::GetBitmapSize()
{
if (m_Bitmap.m_hObject == NULL)
return CSize(0,0);
BITMAP bm;
m_Bitmap.GetObject( sizeof(BITMAP), &bm );
return CSize(bm.bmWidth, bm.bmHeight);
}
void COscWnd::CreateBitmap()
{
if (m_pMemDC != NULL)
{
m_pMemDC->SelectObject(m_pOldBitmap);
delete m_pMemDC;
m_pMemDC = NULL;
m_pOldBitmap = NULL;
}
if (m_pWinDC != NULL)
{
m_pWinDC->SelectObject(m_pOldPalette);
delete m_pWinDC;
m_pWinDC = NULL;
m_pOldPalette = NULL;
}
if (m_Bitmap.m_hObject != NULL)
m_Bitmap.DeleteObject();
CSize size;
size.cx=256; //Resolucion en horizontal
size.cy=256; //Resolucion vertical.
LPBITMAPINFO lpbi;
// Fill in the BITMAPINFOHEADER
lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 * sizeof(RGBQUAD))];
lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
lpbi->bmiHeader.biWidth = size.cx;
lpbi->bmiHeader.biHeight = size.cy;
lpbi->bmiHeader.biPlanes = 1;
lpbi->bmiHeader.biBitCount = 8;
lpbi->bmiHeader.biCompression = BI_RGB;
lpbi->bmiHeader.biSizeImage = (64* 8) * 64;
lpbi->bmiHeader.biXPelsPerMeter = 0;
lpbi->bmiHeader.biYPelsPerMeter = 0;
lpbi->bmiHeader.biClrUsed = 0;
lpbi->bmiHeader.biClrImportant = 0;
// Fill in the color table
UINT uUsage = DIB_RGB_COLORS;
m_pWinDC = new CWindowDC(this);
HBITMAP hBitmap = CreateDIBSection( m_pWinDC->m_hDC, lpbi, uUsage, (void **)&m_pBits, NULL, 0 );
delete [] (BYTE *)lpbi;
ASSERT(hBitmap != NULL);
m_Bitmap.Attach( hBitmap );
m_pMemDC = new CDC;
VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) );
m_pOldPalette = m_pWinDC->SelectPalette( &m_Palette, FALSE );
m_pWinDC->RealizePalette();
m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap );
for (int i=0;i<65536;i++) // pantalla apagada
{
m_pBits[i]=255; // 255 para negro
}
}
COscWnd::RenderView(int m_bright)
{
ctrl=0x378;
_outp(ctrl+2, 36); // este seteo serviria para EPP
BYTE* pRow;
{
pRow = m_pBits;
int buffer[300]; // valor pasado para que sobre
for (int e=1;e<257;e=e+2) // lectura de los valores muestreados
{
buffer[e]=_inp(ctrl+4); // lee el puerto paralelo
}
for (e=1;e<257;e=e+2) // conversion de todas las muestras a positivos
{
if (buffer[e]<0) // si el ADC manda>127 viene como negativo
{
buffer[e]=buffer[e]+256;
}
}
for (e=1;e<257;e=e+2) // genera valores intermedios para lograr > resolucion
{
int m_temp1=buffer[e];
int m_temp2=buffer[e+2];
if (m_temp1>m_temp2) // corrector de ruido
{
if (m_temp1-m_temp2>20)
{
m_temp1=m_temp2;
buffer[e]=buffer[e+2];
}
}
if (m_temp2>m_temp1) // corrector de ruido
{
if (m_temp2-m_temp1>20)
{
m_temp1=m_temp2;
buffer[e]=buffer[e+2];
}
}
if (m_temp1>m_temp2)
{
buffer[e+1]=((m_temp1-m_temp2)/2)+m_temp2;
}
if (m_temp2>m_temp1)
{
buffer[e+1]=((m_temp2-m_temp1)/2)+m_temp1;
}
if (m_temp2==m_temp1)
{
buffer[e+1]=m_temp1;
}
}
// Parte que dibuja las cuadriculas y el fondo
for (int f=0;f<65536;f++)
{
m_pBits[f]=150; // 150 para fondo
}
for (int g=0;g<65536;g=g+6400) // cuadricula en x
{
for (int i=0;i<256;i++)
{
pRow[g+i+768]=255;
}
}
for (int l=0;l<256;l=l+27) // cuadricula en y
{
for (int v=0;v<65536;v=v+256)
{
pRow[l+v]=255;
}
}
// **************************************************************
for (int w=0;w<256;w++) // dibuja el bmp en pantalla
{
m_leido=buffer[w];
for (int x=0;x<256;x++) //
{
int z=((256*x)+w);
if (x==m_leido) //
{
pRow[z]=50;
}
}
}
}
return NULL;
}
void COscWnd::PaintFlame(CDC* pDC)
{
CSize size = GetBitmapSize();
m_pWinDC->BitBlt( 0, 0, size.cx, size.cy, m_pMemDC, 0, 0, SRCCOPY );
// m_pWinDC->StretchBlt(0, 0, 512, 512, m_pMemDC,0,0, size.cx , size.cy, SRCCOPY );
//
}
void COscWnd::OnDestroy()
{
CStatic::OnDestroy();
if (m_pMemDC != NULL)
{
m_pMemDC->SelectObject(m_pOldBitmap);
delete m_pMemDC;
m_pMemDC = NULL;
m_pOldBitmap = NULL;
}
if (m_pWinDC != NULL)
{
m_pWinDC->SelectObject(m_pOldPalette);
delete m_pWinDC;
m_pWinDC = NULL;
m_pOldPalette = NULL;
}
if (m_Bitmap.m_hObject != NULL)
m_Bitmap.DeleteObject();
if (m_Palette.m_hObject != NULL)
m_Palette.DeleteObject();
}
void COscWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
PaintFlame(&dc);
}
BOOL COscWnd::OnQueryNewPalette()
{
if (GetPalette() == NULL)
return FALSE;
{
return FALSE;
}
// some changes have been made; invalidate
Invalidate(FALSE);
return TRUE;
}
void COscWnd::Grabar_Archivo()
{
CFileDialog dlg(FALSE, "btx", "*.btx");
if (dlg.DoModal() == IDOK)
{
CFile file;
VERIFY(file.Open (dlg.GetPathName(),CFile::modeCreate | CFile::modeReadWrite));
file.Write (m_pBits,65536);
}
}
void COscWnd::Cargar_Archivo()
{
CFileDialog dlg(TRUE, "btx", "*.btx");
if (dlg.DoModal() == IDOK)
{
CFile file;
VERIFY(file.Open (dlg.GetPathName(),CFile::modeRead));
file.Read (m_pBits,65536);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -