BOOL GBOamView::OnInitDialog() { CDialog::OnInitDialog(); DIALOG_SIZER_START( sz ) DIALOG_SIZER_ENTRY( IDC_OAM_VIEW, DS_SizeX | DS_SizeY ) DIALOG_SIZER_ENTRY( IDC_OAM_VIEW_ZOOM, DS_MoveX) DIALOG_SIZER_ENTRY( IDC_REFRESH, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_SAVE, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_CLOSE, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_COLOR, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_R, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_G, DS_MoveY) DIALOG_SIZER_ENTRY( IDC_B, DS_MoveY) DIALOG_SIZER_END() SetData(sz, TRUE, HKEY_CURRENT_USER, _T("Software\\Emulators\\VisualBoyAdvance\\Viewer\\GBOamView"), NULL); m_sprite.SetWindowText(_T("0")); updateScrollInfo(); m_stretch = regQueryDwordValue(_T("GBOamViewStretch"), 0); if(m_stretch) oamView.setStretch(true); UpdateData(FALSE); paint(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void GBOamView::OnChangeSprite() { CString buffer; m_sprite.GetWindowText(buffer); int n = _ttoi(buffer); if(n < 0 || n > 39) { buffer.Format(_T("%d"), number); m_sprite.SetWindowText(buffer); return; } number = n; paint(); updateScrollInfo(); }
void GBOamView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { switch(nSBCode) { case SB_BOTTOM: number = 39; break; case SB_LINEDOWN: number++; if(number > 39) number = 39; break; case SB_LINEUP: number--; if(number < 0) number = 0; break; case SB_PAGEDOWN: number += 16; if(number > 39) number = 39; break; case SB_PAGEUP: number -= 16; if(number < 0) number = 0; break; case SB_TOP: number = 0; break; case SB_THUMBTRACK: number = nPos; if(number < 0) number = 0; if(number > 39) number = 39; break; } updateScrollInfo(); CString buffer; buffer.Format(_T("%d"), number); m_sprite.SetWindowText(buffer); paint(); }
void MemoryViewer::OnPaint() { CPaintDC dc(this); // device context for painting RECT rect; GetClientRect(&rect); int w = rect.right - rect.left; int h = rect.bottom - rect.top - 6; CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap bitmap, *pOldBitmap; bitmap.CreateCompatibleBitmap(&dc, w, rect.bottom - rect.top); pOldBitmap = memDC.SelectObject(&bitmap); memDC.FillRect(&rect, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); memDC.DrawEdge(&rect, EDGE_ETCHED, BF_RECT); CFont *oldFont = memDC.SelectObject(CFont::FromHandle(font)); fontSize = memDC.GetTextExtent("0", 1); int lines = h / fontSize.cy; displayedLines = lines; updateScrollInfo(lines); u32 addr = address; memDC.SetTextColor(RGB(0,0,0)); u8 data[32]; RECT r; r.top = 3; r.left = 3; r.bottom = r.top+fontSize.cy; r.right = rect.right-3; int line = 0; for(int i = 0; i < lines; i++) { CString buffer; if(addressSize) buffer.Format("%04X", addr); else buffer.Format("%08X", addr); memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX); r.left += 10*fontSize.cx; beginHex = r.left; readData(addr, 16, data); int j; if(dataSize == 0) { for(j = 0; j < 16; j++) { buffer.Format("%02X", data[j]); memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX); r.left += 3*fontSize.cx; } } if(dataSize == 1) { for(j = 0; j < 16; j += 2) { buffer.Format("%04X", data[j] | data[j+1]<<8); memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX); r.left += 5*fontSize.cx; } } if(dataSize == 2) { for(j = 0; j < 16; j += 4) { buffer.Format("%08X", data[j] | data[j+1]<<8 | data[j+2] << 16 | data[j+3] << 24); memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX); r.left += 9*fontSize.cx; } } line = r.left; r.left += fontSize.cx; beginAscii = r.left; buffer.Empty(); for(j = 0; j < 16; j++) { char c = data[j]; if(c >= 32 && c <= 127) { buffer += c; } else buffer += '.'; } memDC.DrawText(buffer, &r, DT_TOP | DT_LEFT | DT_NOPREFIX); addr += 16; if(addressSize) addr &= 0xffff; r.top += fontSize.cy; r.bottom += fontSize.cy; r.left = 3; } CPen pen; pen.CreatePen(PS_SOLID, 1, RGB(0,0,0)); CPen *old = memDC.SelectObject(&pen); memDC.MoveTo(3+fontSize.cx*9, 3); memDC.LineTo(3+fontSize.cx*9, 3+displayedLines*fontSize.cy); memDC.MoveTo(line, 3); memDC.LineTo(line, 3+displayedLines*fontSize.cy); memDC.SelectObject(old); pen.DeleteObject(); memDC.SelectObject(oldFont); dc.BitBlt(0, 0, w, rect.bottom - rect.top, &memDC, 0, 0, SRCCOPY); memDC.SelectObject(pOldBitmap); memDC.DeleteDC(); bitmap.DeleteObject(); }
LRESULT CALLBACK WorkSpaceWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; LONG ix = GetWindowLong(hWnd, GWL_USERDATA); gdioutput *gdi = 0; if (ix < LONG(gdi_extra.size())) gdi = gdi_extra[ix]; if (gdi) { LRESULT res = gdi->ProcessMsg(message, lParam, wParam); if (res) return res; } switch (message) { case WM_CREATE: break; case WM_SIZE: //SCROLLINFO si; //si.cbSize=sizeof(si); //si.fMask=SIF_PAGE|SIF_RANGE; int nHeight; nHeight = HIWORD(lParam); int nWidth; nWidth = LOWORD(lParam); updateScrollInfo(hWnd, *gdi, nHeight, nWidth); /* int maxx, maxy; gdi->clipOffset(nWidth, nHeight, maxx, maxy); si.nMin=0; if (maxy>0) { si.nMax=maxy+nHeight; si.nPos=gdi->GetOffsetY(); si.nPage=nHeight; } else { si.nMax=0; si.nPos=0; si.nPage=0; } SetScrollInfo(hWnd, SB_VERT, &si, true); si.nMin=0; if (maxx>0) { si.nMax=maxx+nWidth; si.nPos=gdi->GetOffsetX(); si.nPage=nWidth; } else { si.nMax=0; si.nPos=0; si.nPage=0; } SetScrollInfo(hWnd, SB_HORZ, &si, true); */ InvalidateRect(hWnd, NULL, true); break; case WM_KEYDOWN: //gdi->keyCommand(; break; case WM_VSCROLL: { int nScrollCode = (int) LOWORD(wParam); // scroll bar value //int hwndScrollBar = (HWND) lParam; // handle to scroll bar int yInc; int yPos=gdi->GetOffsetY(); RECT rc; GetClientRect(hWnd, &rc); int pagestep = max(50, int(0.9*rc.bottom)); switch(nScrollCode) { // User clicked shaft left of the scroll box. case SB_PAGEUP: yInc = -pagestep; break; // User clicked shaft right of the scroll box. case SB_PAGEDOWN: yInc = pagestep; break; // User clicked the left arrow. case SB_LINEUP: yInc = -10; break; // User clicked the right arrow. case SB_LINEDOWN: yInc = 10; break; // User dragged the scroll box. case SB_THUMBTRACK: { // Initialize SCROLLINFO structure SCROLLINFO si; ZeroMemory(&si, sizeof(si)); si.cbSize = sizeof(si); si.fMask = SIF_TRACKPOS; if (!GetScrollInfo(hWnd, SB_VERT, &si) ) return 1; // GetScrollInfo failed yInc = si.nTrackPos - yPos; break; } default: yInc = 0; } scrollVertical(gdi, yInc, hWnd); gdi->storeAutoPos(gdi->GetOffsetY()); break; } case WM_HSCROLL: { int nScrollCode = (int) LOWORD(wParam); // scroll bar value //int hwndScrollBar = (HWND) lParam; // handle to scroll bar int xInc; int xPos=gdi->GetOffsetX(); switch(nScrollCode) { // User clicked shaft left of the scroll box. case SB_PAGEUP: xInc = -80; break; // User clicked shaft right of the scroll box. case SB_PAGEDOWN: xInc = 80; break; // User clicked the left arrow. case SB_LINEUP: xInc = -10; break; // User clicked the right arrow. case SB_LINEDOWN: xInc = 10; break; // User dragged the scroll box. case SB_THUMBTRACK: { // Initialize SCROLLINFO structure SCROLLINFO si; ZeroMemory(&si, sizeof(si)); si.cbSize = sizeof(si); si.fMask = SIF_TRACKPOS; if (!GetScrollInfo(hWnd, SB_HORZ, &si) ) return 1; // GetScrollInfo failed xInc = si.nTrackPos - xPos; break; } //xInc = HIWORD(wParam) - xPos; //break; default: xInc = 0; } SCROLLINFO si; si.cbSize=sizeof(si); si.fMask=SIF_ALL; GetScrollInfo(hWnd, SB_HORZ, &si); if (si.nPage==0) xInc = 0; int a=si.nMax-signed(si.nPage-1) - xPos; if ((xInc = max( -xPos, min(xInc, a)))!=0) { xPos += xInc; RECT ScrollArea, ClipArea; GetClientRect(hWnd, &ScrollArea); ClipArea=ScrollArea; gdi->SetOffsetX(xPos); ScrollWindowEx (hWnd, -xInc, 0, 0, &ClipArea, (HRGN) NULL, (LPRECT) NULL, SW_INVALIDATE|SW_SCROLLCHILDREN); si.cbSize = sizeof(si); si.fMask = SIF_POS; si.nPos = xPos; SetScrollInfo(hWnd, SB_HORZ, &si, TRUE); UpdateWindow (hWnd); } break; } case WM_MOUSEWHEEL: { int dz = GET_WHEEL_DELTA_WPARAM(wParam); scrollVertical(gdi, -dz, hWnd); gdi->storeAutoPos(gdi->GetOffsetY()); } break; case WM_TIMER: if (wParam == 1001) { double autoScroll, pos; gdi->getAutoScroll(autoScroll, pos); SCROLLINFO si; si.cbSize = sizeof(si); si.fMask = SIF_ALL; GetScrollInfo(hWnd, SB_VERT, &si); int dir = gdi->getAutoScrollDir(); int dy = 0; if ((dir<0 && si.nPos <= si.nMin) || (dir>0 && (si.nPos + int(si.nPage)) >= si.nMax)) { autoScroll = -autoScroll; gdi->setAutoScroll(-1); // Mirror double nextPos = pos + autoScroll; dy = int(nextPos - si.nPos); gdi->storeAutoPos(nextPos); //gdi->setData("AutoScroll", -int(data)); } else { double nextPos = pos + autoScroll; dy = int(nextPos - si.nPos); gdi->storeAutoPos(nextPos); //gdi->setData("Discrete", DWORD(nextPos*1e3)); } scrollVertical(gdi, dy, hWnd); } else MessageBox(hWnd, "Runtime exception", 0, MB_OK); break; case WM_ACTIVATE: { int fActive = LOWORD(wParam); if (fActive != WA_INACTIVE) currentFocusIx = ix; return DefWindowProc(hWnd, message, wParam, lParam); } case WM_USER + 2: if (gdi) LoadPage(*gdi, TabType(wParam)); break; case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case 0: break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); RECT rt; GetClientRect(hWnd, &rt); if (gdi && (ps.rcPaint.right|ps.rcPaint.left|ps.rcPaint.top|ps.rcPaint.bottom) != 0 ) gdi->draw(hdc, rt, ps.rcPaint); /*{ HANDLE icon = LoadImage(hInst, (LPCTSTR)IDI_MEOS, IMAGE_ICON, 64, 64, LR_SHARED); DrawIconEx(hdc, 0,0, (HICON)icon, 64, 64, 0, NULL, DI_NORMAL | DI_COMPAT); }*/ EndPaint(hWnd, &ps); break; case WM_ERASEBKGND: return 0; break; case WM_DESTROY: if (ix > 0) { gdi->makeEvent("CloseWindow", "meos", 0, 0, false); gdi_extra[ix] = 0; delete gdi; while(!gdi_extra.empty() && gdi_extra.back() == 0) gdi_extra.pop_back(); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }