Thanks for the answer, spiltter seems to be an easier example indeed.
In the meantime, i crafted out a new try, this time a little hex-dispaly on a wxScrolledWindow. Only the part of the file that is actually displayed is read.
Three is, however, a wired problem:
if i click on the scrollbar and drag it around, it`s all good, but if i scroll down using the mouse-wheel, the window is not correctly redrawn - see attached pic.
Scrolling UP using the mouse-wheel works fine... :S
Additionally, this is using quiet some CPU power, probably because i am not handling the re-drawing in an efficient way.
When using windows GDI, i can call InvalidateRect() followed by UpdateWindow(), which re-draws the window very efficiently. Is there such a mechanism in wxw?
Code: Select all
#include "MyWindow.h"
#define MAX_LINES 100
MyWindow::MyWindow(const wxString& title)
: wxFrame(NULL, ID_TEST, title, wxDefaultPosition, wxSize(500, 500) )
{
CreateStatusBar(1);
MyScrolledWindow* wnd = new MyScrolledWindow(this, wxID_ANY, 0,0,-1,-1,wxVSCROLL|wxHORIZONTAL |wxRETAINED
, 16, 16 , 500, 500, true);
}
void MyWindow::OnQuit(wxCommandEvent &event)
{
Close(true);
}
#define offsz 75
#define datasz (16*16)
#define btnheigth 15
HANDLE hfile;
int row = 0;
MyScrolledWindow::MyScrolledWindow(wxWindow* parent, wxWindowID id,
int xpos, int ypos,
int width, int height,
long style, int pixperunitX, int pixperunitY,
int nounitsX, int nounitsY, bool refresh)
:wxScrolledWindow(parent,id,wxPoint(xpos,ypos),wxSize(width, height), style)
{
hfile = CreateFile(L"E:\\torr2\\crulesdec28.mp4", GENERIC_READ, 0, 0, OPEN_EXISTING, 0,0);
int sz = GetFileSize(hfile,0) / 16;
SetScrollbars(16,16,1,sz,0,0,true);
}
void MyScrolledWindow::OnBack(wxEraseEvent &event)
{
return;
}
void MyScrolledWindow::OnPaint(wxPaintEvent &event)
{
//wxPaintDC dc(this);
wxBufferedPaintDC dc(this);
//////////////////////////////////////////////////////////////////////////
int gvx,gvy;
GetViewStart(&gvx, &gvy);
int ppux,ppuy;
GetScrollPixelsPerUnit(&ppux,&ppuy);
gvy *= ppuy;
int offset = gvy;
int clrx,clry;
GetClientSize(&clrx, &clry);
int linecount = clry /16;
byte* buff = (byte*)malloc(linecount * 16);
ZeroMemory(buff,linecount*16);
DWORD rd;
SetFilePointer(hfile,offset,0,FILE_BEGIN);
ReadFile(hfile,buff,linecount*16,&rd,0);
//////////////////////////////////////////////////////////////////////////
wxPen pn = *wxBLACK_PEN;
pn.SetWidth(0);
pn.SetStyle(wxTRANSPARENT);
const int lineh = 16;
const int charw = 16;
dc.SetPen(pn);
dc.SetBrush(*wxWHITE_BRUSH);
dc.DrawRectangle(0,0,clrx,clry);
wxString f;
dc.SetPen(*wxBLACK_PEN);
for(int i=0; i<linecount; i++)
{
int idx = i*16 + 0;
f.Printf("%.2hX %.2hX %.2hX %.2hX %.2hX %.2hX %.2hX %.2hX "
"%.2hX %.2hX %.2hX %.2hX %.2hX %.2hX %.2hX %.2hX",
buff[idx],buff[idx+1],buff[idx+2],buff[idx+3],buff[idx+4],buff[idx+5],buff[idx+6],buff[idx+7],
buff[idx+8],buff[idx+9],buff[idx+10],buff[idx+11],buff[idx+12],buff[idx+13],buff[idx+14],buff[idx+15]);
dc.DrawLabel(f,wxRect(0*charw+offsz,i*lineh,16*charw,lineh),wxALIGN_CENTER);
f.Printf("%.8X",offset+i*16);
dc.DrawLabel(f,wxRect(0,i*16,offsz,16),wxALIGN_CENTER);
}
free(buff);
}
void MyScrolledWindow::OnMouse(wxMouseEvent &event)
{
//...
//Refresh(true);
event.Skip();
}
BEGIN_EVENT_TABLE(MyScrolledWindow, wxScrolledWindow)
//EVT_SCROLLWIN(MyScrolledWindow::OnScroll)
EVT_PAINT(MyScrolledWindow::OnPaint)
EVT_ERASE_BACKGROUND(MyScrolledWindow::OnBack)
//EVT_SIZING(MyScrolledWindow::OnSizeing)
EVT_MOUSE_EVENTS(MyScrolledWindow::OnMouse)
END_EVENT_TABLE()