⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memview.cpp

📁 wince host 和 target PCI驱动程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        }
    }
}



void  WINAPI DisplayBytes (
    HDC      hDC,
    RECT     *pRect,
    LPMEMVIEW    lpmv)
{
    UINT      i, iFirst, iLast, y;
    char      szBuf[MAX_PATH];
    LPBYTE    pMem = (LPBYTE)lpmv->lpMem;
    PVOID   startSel,endSel; 

    SelectObject (hDC, hFont);

    y = lpmv->PosV;

    iFirst = y + pRect->top/yChar-1;

    if (iFirst == 0xFFFFFFFFL)
    iFirst = 0;

    iLast = min (y + pRect->bottom/yChar+1, (UINT)lpmv->nLines-1);
    pMem += iFirst << 4;

    if (lpmv->nExtraBytes)
    {
        if(iLast != 0)
            iLast--;
    }

    /* paint complete lines (lines with 16 bytes) */
    y = (iFirst - y) * yChar;
    if(lpmv->nSize >= 16)
    for (i = iFirst; i<=iLast; i++)             // ?????? Originally < only
    {
    GetBytesLine (pMem, i, lpmv->nBase, 16, szBuf);
    if(selectionStart == 0)
    {
        SetTextColor (hDC, GetSysColor(COLOR_WINDOWTEXT));
        SetBkColor(hDC,GetSysColor(COLOR_WINDOW));
    }
    else        // Text selected
    {
        startSel=min(selectionStart,selectionEnd);
        endSel=max(selectionStart,selectionEnd);
        if(pMem >= startSel && pMem <= endSel)
        {
            SetTextColor(hDC,GetSysColor (COLOR_WINDOW));
            SetBkColor(hDC,GetSysColor(COLOR_WINDOWTEXT));
        }
        else
        {
            SetTextColor (hDC, GetSysColor(COLOR_WINDOWTEXT));
            SetBkColor(hDC,GetSysColor(COLOR_WINDOW));
        }
    }
    TextOut (hDC, xChar, LOWORD (y), szBuf, lstrlen (szBuf));
    pMem += 16;
    y += yChar;
    }

    /* paint last partial line if any (line with less than 16 bytes) */
    if (lpmv->nExtraBytes)
    {
    GetBytesLine (pMem, i, lpmv->nBase, lpmv->nExtraBytes, szBuf);
    SetTextColor (hDC, GetSysColor(COLOR_WINDOWTEXT));
    TextOut(hDC, xChar, y, szBuf, lstrlen (szBuf));
    }

    SelectObject(hDC, GetStockObject(SYSTEM_FONT));
}





int  WINAPI GetBytesLine (
    PVOID   pMemory,
    UINT     LineNum,
    DWORD    dwBase,
    int      nBytes,
    char     *szLine)
{
    int          j;
    unsigned char    ch;
    WORD ch2;
    DWORD ch4;
    
    char         szAscii[17]="";
    PBYTE pBytes=(PBYTE)pMemory;
    PWORD pWord=(PWORD)pMemory;
    PDWORD pDWord=(PDWORD)pMemory;

    wsprintf (szLine, "%#08lx  ", dwBase + (LineNum*16));

    if(globaldumptype == 0)     //Byte
    for (j = 0; j < nBytes; j++)
    {
    ch = *pBytes++;
    MemToAscii(ch,szAscii+j);
    wsprintf (szLine, "%s%02X ", (LPSTR)szLine, (WORD)ch);
    }

    if(globaldumptype == 1)         //Word
    for (j = 0; j < nBytes;j+=2)
    {
        ch2 = *pWord++;
        MemToAscii(ch2,szAscii+j);
        wsprintf (szLine, "%s%04X ", (LPSTR)szLine, (WORD)ch2);
    }

    if(globaldumptype == 2)             //Dword
    for (j = 0; j < nBytes;j+=4)
    {
        ch4 = *pDWord++;
        MemToAscii(ch4,szAscii+j);
        wsprintf (szLine, "%s%08X ", (LPSTR)szLine, (DWORD)ch4);
    }

    szAscii[nBytes] = 0;
    return wsprintf(szLine, "%-59s%s", (LPSTR)szLine, (LPSTR)szAscii);
}

void CheckMemUpdate(void)
{
    if(mem != 0)
    {
        if(globaldumptype == 0)
            *(PBYTE)mem=(unsigned char)value;
        else if (globaldumptype == 1)
            *(PWORD)mem=(unsigned short)value;
        else
            *(PDWORD)mem=value;
        mem=0;
        InvalidateRect (hWnd, NULL, FALSE);
    }
}

void ProcessKey(HWND hWnd,WPARAM wParam,MEMVIEW *pmv)
{
    switch(wParam)
    {
                case VK_DOWN:
                    CheckMemUpdate();
                    if((yCaret+1) < pmv->yWin/yChar)
                    {
                        if((yCaret+1) < pmv->nLines)
                            yCaret++;
                    }
                    else
                        SendMessage(hWnd,WM_VSCROLL, SB_LINEDOWN,0L);
                    SetCaretPos(xCaret*xChar,yCaret*yChar);
                    break;
                case VK_UP:
                    CheckMemUpdate();
                    if(yCaret != 0)
                        yCaret--;
                    else
                    {
                        if(pmv->PosV != 0)
                        SendMessage(hWnd,WM_VSCROLL, SB_LINEUP,0L);
                    }
                    SetCaretPos(xCaret*xChar,yCaret*yChar);
                    break;
                case VK_RIGHT:
                    if(globaldumptype == 0)
                    {
                        if(xCaret-13 < 15*3+1)
                        {
                            if(((xCaret-13+2) % 3) == 0)
                            {
                                CheckMemUpdate();
                                xCaret+=2;
                            }
                            else
                                xCaret++;
                        }
                    }
                    else if (globaldumptype == 1)
                    {
                        if(xCaret-13 < 7*5+3)
                        {
                            if(((xCaret-13+2) % 5) == 0)
                            {
                                CheckMemUpdate();
                                xCaret+=2;
                            }
                            else
                                xCaret++;
                        }
                    }
                    else
                    {
                        if(xCaret-13 < 3*9+7)
                        {
                            if(((xCaret-13+2) % 9) == 0)
                            {
                                CheckMemUpdate();
                                xCaret+=2;
                            }
                            else
                                xCaret++;
                        }
                    }
                    SetCaretPos(xCaret*xChar,yCaret*yChar);
                    break;
                case VK_LEFT:
                    if(xCaret == 13)
                        break;
                    if(globaldumptype == 0)
                    {
                        if(((xCaret-13)%3) == 0)
                        {
                            CheckMemUpdate();
                            xCaret-=2;
                        }
                        else
                            xCaret--;
                    }
                    else if (globaldumptype == 1)
                    {
                        if(((xCaret-13)%5) == 0)
                        {
                            CheckMemUpdate();
                            xCaret-=2;
                        }
                        else
                            xCaret--;
                    }
                    else
                    {
                        if(((xCaret-13)%9) == 0)
                        {
                            CheckMemUpdate();
                            xCaret-=2;
                        }
                        else
                            xCaret--;
                    }
                    SetCaretPos(xCaret*xChar,yCaret*yChar);
                    break;
                case VK_HOME:
                    CheckMemUpdate();
                    if(GetKeyState(VK_CONTROL) < 0)     //Ctrl pressed
                        SendMessage(hWnd,WM_VSCROLL, SB_TOP,NULL);
                    else
                    {
                        xCaret=13;
                        SetCaretPos(xCaret*xChar,yCaret*yChar);
                    }
                    break;
                case VK_END:
                    CheckMemUpdate();
                    if(GetKeyState(VK_CONTROL) < 0)     //Ctrl pressed
                        SendMessage(hWnd,WM_VSCROLL, SB_BOTTOM,NULL);
                    else
                    {
                        if(globaldumptype == 0)
                            xCaret=13+15*3;
                        else if(globaldumptype == 1)
                            xCaret=13+7*5;
                        else
                            xCaret=13+3*9;
                        SetCaretPos(xCaret*xChar,yCaret*yChar);
                    }
                    break;

                default:

                    KeyToScrollMsg (hWnd, wParam);
                    break;
            }
}

void CopyClipboard(MEMVIEW *pmv)
{
    PBYTE   startSel,endSel,pMem; 
    HGLOBAL hCopyBuffer;
    PSTR    pCopyBuffer;
    UINT    LineNum;
    char    szLine[100];
    int     strPosition, strLength;
	CWaitCursor wait;   // display wait cursor

    startSel=(PBYTE)min(selectionStart,selectionEnd);
    endSel=(PBYTE)max(selectionStart,selectionEnd);
    if(endSel >= ((BYTE *)pmv->lpMem + pmv->nSize - 16) )
        endSel = (BYTE *)pmv->lpMem + pmv->nSize - 16;
    LineNum=(startSel-(unsigned char *)(pmv->lpMem))/16;
    

        hCopyBuffer=GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
            ( (endSel-startSel)/16+1)*100) ;
        if(hCopyBuffer == NULL)
        {
            AfxMessageBox("Error allocating memory for copying buffer");
            return;
        }
        pCopyBuffer=(PSTR)GlobalLock(hCopyBuffer);
        if(pCopyBuffer == NULL)
        {
            AfxMessageBox("Error locking memory allocated for copying");
            GlobalFree(hCopyBuffer);
            return;
        }

        *pCopyBuffer=0;
        strPosition = 0;
        for(pMem=startSel;pMem<=endSel;pMem+=16,LineNum++)
        {
            strLength = GetBytesLine(pMem,LineNum,pmv->nBase,16,szLine);
            strcpy(pCopyBuffer + strPosition, szLine);
            strcpy(pCopyBuffer + strPosition + strLength, "\r\n");
            strPosition += (strLength + 2);
        }
        OpenClipboard(hWnd);
        EmptyClipboard();
        SetClipboardData(CF_TEXT,hCopyBuffer);
        CloseClipboard();
        GlobalUnlock(hCopyBuffer);
        GlobalFree(hCopyBuffer);
}

void MemToAscii(BYTE number,char* str)
{
    str[0]=((number & 0x7F) >= ' ') ? number : '.';
    str[1]=0;
    return;
}

void MemToAscii(WORD number,char* szAscii)
{
    BYTE ch;
    PBYTE pBytes;
    pBytes=(PBYTE)&number;

    ch=pBytes[0];
    szAscii[0] = ((ch & 0x7F) >= ' ') ? ch : '.';
    ch=pBytes[1];
    szAscii[1] = ((ch & 0x7F) >= ' ') ? ch : '.';
    szAscii[2]=0;
}

void MemToAscii(DWORD number,char* szAscii)
{
    BYTE ch;
    PBYTE pBytes;
    pBytes=(PBYTE)&number;

    ch=pBytes[0];
    szAscii[0] = ((ch & 0x7F) >= ' ') ? ch : '.';
    ch=pBytes[1];
    szAscii[1] = ((ch & 0x7F) >= ' ') ? ch : '.';
    ch=pBytes[2];
    szAscii[2] = ((ch & 0x7F) >= ' ') ? ch : '.';
    ch=pBytes[3];
    szAscii[3] = ((ch & 0x7F) >= ' ') ? ch : '.';
    szAscii[4]=0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -