ULONG FASTCALL WU32TabbedTextOut(PVDMFRAME pFrame) { ULONG ul; PSZ psz4; PINT p7; register PTABBEDTEXTOUT16 parg16; INT BufferT[256]; GETARGPTR(pFrame, sizeof(TABBEDTEXTOUT16), parg16); GETPSZPTR(parg16->f4, psz4); p7 = STACKORHEAPALLOC(parg16->f6 * sizeof(INT), sizeof(BufferT), BufferT); getintarray16(parg16->f7, parg16->f6, p7); ul = GETLONG16(TabbedTextOut( HDC32(parg16->f1), INT32(parg16->f2), INT32(parg16->f3), psz4, INT32(parg16->f5), INT32(parg16->f6), p7, INT32(parg16->f8) )); STACKORHEAPFREE(p7, BufferT); FREEPSZPTR(psz4); FREEARGPTR(parg16); RETURN(ul); }
/** * @param hdc - drawing context. * @param prcPaint - the rectangle in which the painting is requested. */ void CTextView::DrawTextView(HDC hdc, RECT* prcPaint) { _ASSERTE(g_pResManager != NULL); if (prcPaint == NULL) { RECT rcClient; GetClientRect(m_hwnd, &rcClient); prcPaint = &rcClient; } if (IsRectEmpty(prcPaint)) return; #ifdef USE_MEM_DC int nClientWidth = prcPaint->right - prcPaint->left; int nClientHeight = prcPaint->bottom - prcPaint->top; HBITMAP hbmpMem; hbmpMem = CreateCompatibleBitmap(hdc, nClientWidth, nClientHeight); if (hbmpMem == NULL) return; HDC hdcMem; hdcMem = CreateCompatibleDC(hdc); if (hdcMem == NULL) { DeleteBitmap(hbmpMem); return; } SetViewportOrgEx(hdcMem, -prcPaint->left, -prcPaint->top, NULL); HBITMAP hbmpSafe = SelectBitmap(hdcMem, hbmpMem); #else // CS_PARENTDC sets the clipping rectangle of the child window to that of the parent window // so that the child can draw on the parent. Text view inherits this style from sub-classed // static control. This causes problems with unclipped TabbedTextOut() output. HRGN hrgn = CreateRectRgnIndirect(prcPaint); SelectClipRgn(hdc, hrgn); DeleteRgn(hrgn); HDC hdcMem = hdc; #endif FillRect(hdcMem, prcPaint, g_pResManager->m_hbrWindowBrush); COLORREF rgbOldTextColor = SetTextColor(hdcMem, GetSysColor(COLOR_WINDOWTEXT)); COLORREF rgbOldBackground = SetBkColor(hdcMem, GetSysColor(COLOR_WINDOW)); HFONT hOldFont = g_pResManager->m_hFixedFont ? SelectFont(hdcMem, g_pResManager->m_hFixedFont) : NULL; TEXTMETRIC tmetr; ::GetTextMetrics(hdcMem, &tmetr); DWORD dwNumLines = m_arrLines.GetCount(); DWORD dwTopLineNum = GetScrollPos(m_hwnd, SB_VERT); DWORD dwTopVisLineNum = dwTopLineNum + prcPaint->top / tmetr.tmHeight; if (dwTopVisLineNum < dwNumLines) { int nHorPos = tmetr.tmAveCharWidth - GetScrollPos(m_hwnd, SB_HORZ); int nVertPos = prcPaint->top - prcPaint->top % tmetr.tmHeight; DWORD dwNumVisLines = prcPaint->bottom / tmetr.tmHeight; if (prcPaint->bottom % tmetr.tmHeight) ++dwNumVisLines; DWORD dwBottomVisLineNum = dwTopLineNum + dwNumVisLines - 1; if (dwBottomVisLineNum >= dwNumLines) dwBottomVisLineNum = dwNumLines - 1; for (DWORD dwLineNum = dwTopVisLineNum; dwLineNum <= dwBottomVisLineNum; ++dwLineNum) { CacheLine(dwLineNum); const CLineInfo& rLineInfo = m_arrLines[(int)dwLineNum]; int nTextWidth = LOWORD(TabbedTextOut(hdcMem, nHorPos, nVertPos, m_pTextCache + rLineInfo.m_dwTextStart, rLineInfo.m_dwLength, 0, NULL, -nHorPos)); if (rLineInfo.m_bTruncated) TextOut(hdcMem, nHorPos + nTextWidth, nVertPos, g_szEllipsis, g_dwEllipsisLength); nVertPos += tmetr.tmHeight; } } SetTextColor(hdcMem, rgbOldTextColor); SetBkColor(hdcMem, rgbOldBackground); if (hOldFont) SelectFont(hdcMem, hOldFont); #ifdef USE_MEM_DC BitBlt(hdc, prcPaint->left, prcPaint->top, nClientWidth, nClientHeight, hdcMem, prcPaint->left, prcPaint->top, SRCCOPY); SelectBitmap(hdcMem, hbmpSafe); DeleteDC(hdcMem); DeleteBitmap(hbmpMem); #endif }
void TViewEntryDialog::EvDrawItem (UINT ctrlId, DRAWITEMSTRUCT& drawInfo) #endif { char Buf[128]; // To be sure if ( CurrentEntry == NULL ) return; // To be sure if ( ctrlId != IDC_VE_DUMP_LIST ) return; // If there are no list box items, skip this message. if ( drawInfo.itemID == (UINT)-1 ) return; // Build string to draw strcpy (Buf, ""); if ( drawInfo.itemID == 0 ) { char entryname[9]; strncpy (entryname, CurrentEntry->dir.name, 8); entryname[8] = '\0'; sprintf(Buf, "Contents of entry %s (size = %ld bytes):", entryname, CurrentEntry->dir.size); } else { // Starting Offset in the entry ULONG EntryOffset = (ULONG)(drawInfo.itemID - 1) * NB_HEX_LINE; // Starting Offset in the wad file ULONG WadOffset = CurrentEntry->dir.start + EntryOffset; // Number of chars for this line USHORT NbChars = min(NB_HEX_LINE, (USHORT)(CurrentEntry->dir.size - EntryOffset)); // Bytes of the line unsigned char HexBuf[NB_HEX_LINE]; // Line len int len; int i; BasicWadSeek (CurrentEntry->wadfile, WadOffset); // Dump offset len = sprintf(Buf, "%06lX:\t", EntryOffset); // 16 hex values for (i = 0 ; i < NbChars ; i++) { BasicWadRead (CurrentEntry->wadfile, &(HexBuf[i]), 1); len += sprintf (&Buf[len], "%02X\t", HexBuf[i]); } // Add padding tabs for (; i < NB_HEX_LINE ; i++) len += sprintf(&Buf[len], "\t"); // len += sprintf (&Buf[len], "\t"); // 16 chars for (i = 0 ; i < NbChars ; i++) { char c = HexBuf[i]; if ( ! isprint(c) ) c = ' '; len += sprintf (&Buf[len], "%c", c); } } switch (drawInfo.itemAction) { case ODA_SELECT: case ODA_DRAWENTIRE: { // Retreive the average character width TEXTMETRIC tm; GetTextMetrics(drawInfo.hDC, &tm); // Setup tab stops in HexDump list int TabStops[NB_HEX_LINE+1]; int i; TabStops[0] = 6 * tm.tmAveCharWidth; for (i = 1 ; i < NB_HEX_LINE ; i++) TabStops[i] = TabStops[i-1] + 3 * tm.tmAveCharWidth + 2; TabStops[i] = TabStops[i-1] + 4 * tm.tmAveCharWidth; TabbedTextOut(drawInfo.hDC, drawInfo.rcItem.left, drawInfo.rcItem.top, Buf, strlen(Buf), NB_HEX_LINE+2, TabStops, 0); #if 0 /* Is the item selected? */ if (drawInfo.itemState & ODS_SELECTED) { /* Draw a rectangle around bitmap to indicate the selection. */ DrawFocusRect(drawInfo.hDC, &drawInfo.rcItem); } #endif } break; case ODA_FOCUS: /* * Do not process focus changes. The focus caret (outline * rectangle) indicates the selection. The Which one? (IDOK) * button indicates the final selection. */ break; } }
/************************************************************************ * DoPaint * * - This is the main painting routine. If the program is quitting then * * it returns (we dont want thread clashes due to critical sections * * here and theres no point to repainting when we're exitting). * * - If the buffer is not ready then we wait, and go to sleep. * * - Otherwise the routine paints the screen from the buffer, using the * * selected font and colours * ************************************************************************/ void DoPaint(HWND hWnd,int cxChar,int cyChar) { HDC hDC; // handle for the display device PAINTSTRUCT ps; // holds PAINT information UINT nI; RECT rRect; int startpt,sn; char sl[300]; cyc=cyChar; while(!bufferready) Sleep(0); // wait if filling buffer if(KillThread) return; if(!lastline) { PaintBack(hWnd); return; } EnterCriticalSection(&g_hCs); memset(&ps, 0x00, sizeof(PAINTSTRUCT)); hDC = BeginPaint(hWnd, &ps); // Included as the background is not a pure color //SetBkMode(hDC,TRANSPARENT); switch(g_options.font) { case courierfont: case courierfont10: case courierfont12: if(cf==NULL) SelectObject(hDC,GetStockObject(ANSI_FIXED_FONT)); else SelectObject(hDC,cf); break; case ansifont: SelectObject(hDC,GetStockObject(ANSI_FIXED_FONT)); break; case systemfont: SelectObject(hDC,GetStockObject(SYSTEM_FIXED_FONT)); break; default: SelectObject(hDC,GetStockObject(ANSI_FIXED_FONT)); break; } GetClientRect(hWnd,&rRect); if(hpos>max_length-(rRect.right/cxChar)) hpos=max_length-rRect.right/cxChar; if(rrr!=(unsigned int)rRect.right) { rrr=(unsigned int)rRect.right; SetScrollRange(hWnd,SB_HORZ,0,max_length-rRect.right/cxChar,true); } SetScrollPos(hWnd,SB_HORZ,hpos,true); nScreenRows = rRect.bottom/cyChar; ShowScrollBar (hWnd, SB_VERT, true); ShowScrollBar (hWnd, SB_HORZ, max_length>(rRect.right/cxChar)); startpt=0; SetTextColor(hDC,g_options.textcolor); for(nI=startpt;nI<lastline;nI++) { if((userselonscreen)&&(nI==usersel)) SetBkColor(hDC,g_options.highcolor); else SetBkColor(hDC,g_options.bgcolor); strcpy(sl,&MainBuff[nI*max_length]); sn=strlen(sl); if(sn<max_length) memset(&sl[sn],' ',max_length-sn); sl[max_length]=0; TabbedTextOut(hDC,2-hpos*cxChar,nI*cyChar,sl, max_length,0,NULL,2-hpos*cxChar); } for(nI=lastline;nI<nScreenRows+1;nI++) { if((userselonscreen)&&(nI==usersel)) SetBkColor(hDC,g_options.highcolor); else SetBkColor(hDC,g_options.bgcolor); memset(sl,' ',max_length); sl[max_length]=0; TabbedTextOut(hDC,2-hpos*cxChar,nI*cyChar,sl, max_length,0,NULL,2-hpos*cxChar); } // Inform Windows painting is complete EndPaint(hWnd,&ps); LeaveCriticalSection(&g_hCs); }
static void lstOnDrawSListBoxItems(HWND hwnd, HDC hdc, DWORD dwStyle, PLISTBOXDATA pData, LPRECT pRcPaint) { PLISTBOXITEM plbi; int i; int x = 0, y = 0; int offset; RECT rc; COLORREF bk; int width; GetClientRect(hwnd, &rc); width = rc.right - rc.left; plbi = lstGetItem(pData, pData->itemTop); SelectObject(hdc, GET_WND_FONT(hwnd)); for (i = 0; plbi && i < (pData->itemVisibles + 1); i++) { POINT centPt; int itemHeight = pData->itemHeight; if ((dwStyle & LBS_OWNERDRAWVARIABLE)) { lbAskMeasureItem(hwnd, pData->itemTop + i, &itemHeight); } rc.left = 0; rc.top = y; rc.right = width; rc.bottom = y + itemHeight; centPt.x = width / 2; centPt.y = y + itemHeight / 2; /* GB: ownerdraw */ if (ISOWNERDRAW(dwStyle) && PtInRect(pRcPaint, centPt)) { DRAWITEMSTRUCT drw; lbFillDrawitemstruct(hwnd, hdc, &drw, &rc, ODA_DRAWENTIRE, pData->itemTop + i, plbi); if (!SendMessage (GetParent(hwnd), WM_DRAWITEM, drw.CtlID, (LPARAM) & drw)) FastFillRect(hdc, &rc, WHITE); if (pData->itemTop + i == pData->itemHilighted) { if ((drw.itemState & ODS_FOCUS)) pData->dwFlags |= LBF_FOCUSRECT; else pData->dwFlags &= ~LBF_FOCUSRECT; } } else /* GB: draw only if in update region... */ if (PtInRect(pRcPaint, centPt)) { if (plbi->dwFlags & LBIF_SELECTED) { SetBkColor(hdc, bk = BLUE); SetTextColor(hdc, WHITE); } else { SetBkColor(hdc, bk = WHITE); SetTextColor(hdc, BLACK); } FastFillRect(hdc, &rc, bk); if (dwStyle & LBS_CHECKBOX) { x = LST_INTER_BMPTEXT; if (plbi->dwFlags & LBIF_CHECKED) offset = 0; else if (plbi->dwFlags & LBIF_PARTCHECKED) offset = LST_WIDTH_CHECKMARK << 1; else offset = LST_WIDTH_CHECKMARK; #if 0 /* fix: no bitmap */ FillBoxWithBitmapPart(hdc, x, y + ((itemHeight - LST_HEIGHT_CHECKMARK) >> 1), LST_WIDTH_CHECKMARK, LST_HEIGHT_CHECKMARK, 0, 0, &sg_bmpCheckMark, offset, 0); #endif x += LST_WIDTH_CHECKMARK + LST_INTER_BMPTEXT; } #if 0 /* fix: no icon */ if (dwStyle & LBS_USEICON && plbi->dwData) { DrawIcon(hdc, x, y, itemHeight, itemHeight, (HICON) plbi->dwData); x += itemHeight + LST_INTER_BMPTEXT; } #endif /* jmt: should be SYSTEM_FIXED_FONT because of minigui's GetSysCharXXX() */ #if 0 SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); #endif if ((dwStyle & LBS_USETABSTOPS) != 0) TabbedTextOut(hdc, x + 2 - pData->hoffset, y, plbi->key, -1, pData->nTabStops, pData->pTabStops, -pData->hoffset); else TextOut(hdc, x + 2 - pData->hoffset, y, plbi->key, -1); if (pData->itemTop + i == pData->itemHilighted) { pData->dwFlags &= ~LBF_FOCUSRECT; lstDrawFocusRect(hwnd, hdc, pData, TRUE); } } y += itemHeight; plbi = plbi->next; }
// // FUNCTION: WndProc(HWND, unsigned, WORD, LONG) // // PURPOSE: Processes messages for the main window. // // MESSAGES: // // WM_COMMAND - process the application menu // WM_PAINT - Paint the main window // WM_DESTROY - post a quit message and return // WM_DISPLAYCHANGE - message sent to Plug & Play systems when the display changes // WM_RBUTTONDOWN - Right mouse click -- put up context menu here if appropriate // WM_NCRBUTTONUP - User has clicked the right button on the application's system menu // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; POINT pnt; HMENU hMenu; BOOL bGotHelp; switch (message) { case WM_CREATE: // clear timer flags TimerID = 0; TimerRunning = FALSE; // enable "Start" menu selection hAppMenu = GetMenu (hWnd); hTestMenu = GetSubMenu (hAppMenu, 1); EnableMenuItem (hTestMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem (hTestMenu, IDM_START, MF_BYCOMMAND | MF_ENABLED); break; case WM_COMMAND: wmId = LOWORD(wParam); // Remember, these are... wmEvent = HIWORD(wParam); // ...different for Win32! //Parse the menu selections: switch (wmId) { case IDM_EXIT: DestroyWindow (hWnd); break; case IDM_START: if (!TimerRunning) { TimerID = SetTimer (hWnd, LEAK_TIMER, TIME_INTERVAL, NULL); if (TimerID != 0) { TimerRunning = TRUE; EnableMenuItem (hTestMenu, IDM_START, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem (hTestMenu, IDM_STOP, MF_BYCOMMAND | MF_ENABLED); } else { //unable to start timer MessageBeep (MB_ICONEXCLAMATION); } } InvalidateRect (hWnd, NULL, TRUE); break; case IDM_STOP: if (TimerRunning) { KillTimer (hWnd, LEAK_TIMER); TimerID = 0; TimerRunning = FALSE; EnableMenuItem (hTestMenu, IDM_STOP, MF_BYCOMMAND | MF_GRAYED); EnableMenuItem (hTestMenu, IDM_START, MF_BYCOMMAND | MF_ENABLED); } InvalidateRect (hWnd, NULL, TRUE); break; case IDM_RESET: FreeAllocatedMemory(); InvalidateRect (hWnd, NULL, TRUE); break; case IDM_ABOUT: DialogBox(hInst, "AboutBox", hWnd, (DLGPROC)About); break; case IDM_HELPTOPICS: // Only called in Windows 95 bGotHelp = WinHelp (hWnd, APPNAME".HLP", HELP_FINDER,(DWORD)0); if (!bGotHelp) { MessageBox (GetFocus(), GetStringRes(IDS_NO_HELP), szAppName, MB_OK|MB_ICONHAND); } break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } break; case WM_TIMER: { PMEMORY_ALLOC_BLOCK pMab, pNewMab; pNewMab = (PMEMORY_ALLOC_BLOCK)G_ALLOC (GPTR, ALLOCATION_SIZE); if (pNewMab != NULL) { // save this pointer pNewMab->pNext = NULL; if (mabListHead.pNext == NULL) { // this is the first entry mabListHead.pNext = pNewMab; } else { // go to end of list pMab = mabListHead.pNext; while (pMab->pNext != NULL) pMab = pMab->pNext; pMab->pNext = pNewMab; } InvalidateRect (hWnd, NULL, TRUE); } } break; case WM_RBUTTONDOWN: // RightClick in windows client area... pnt.x = LOWORD(lParam); pnt.y = HIWORD(lParam); ClientToScreen(hWnd, (LPPOINT) &pnt); // This is where you would determine the appropriate 'context' // menu to bring up. Since this app has no real functionality, // we will just bring up the 'Help' menu: hMenu = GetSubMenu (GetMenu (hWnd), 2); if (hMenu) { TrackPopupMenu (hMenu, 0, pnt.x, pnt.y, 0, hWnd, NULL); } else { // Couldn't find the menu... MessageBeep(0); } break; case WM_DISPLAYCHANGE: // Only comes through on plug'n'play systems { SIZE szScreen; DWORD dwBitsPerPixel = (DWORD)wParam; szScreen.cx = LOWORD(lParam); szScreen.cy = HIWORD(lParam); MessageBox (GetFocus(), GetStringRes(IDS_DISPLAYCHANGED), szAppName, 0); } break; case WM_PAINT: { MEMORYSTATUS MemoryStatusData; LONGLONG llInUse; DWORD dwPercentUsed; int nX, nY; LONG lTextOutReturn; int nStringLength; CHAR szOutputString[100]; hdc = BeginPaint (hWnd, &ps); // Add any drawing code here... GlobalMemoryStatus (& MemoryStatusData); llInUse = (LONGLONG)(MemoryStatusData.dwTotalPageFile - MemoryStatusData.dwAvailPageFile + 5 ); llInUse *= 1000; llInUse /= MemoryStatusData.dwTotalPageFile; llInUse /= 10; dwPercentUsed = (DWORD)llInUse; nX = 0; nY = 0; _snprintf_s(szOutputString, 100, _TRUNCATE, "Reported Memory Load: \t%3.1d%%", MemoryStatusData.dwMemoryLoad); nStringLength = lstrlen (szOutputString) * sizeof (CHAR); lTextOutReturn = TabbedTextOut (hdc, nX, nY, szOutputString, nStringLength, 0, NULL, 0); nY += HIWORD (lTextOutReturn); _snprintf_s(szOutputString, 100, _TRUNCATE, "Page file in use: \t%3.1d%%", dwPercentUsed); nStringLength = lstrlen (szOutputString) * sizeof (CHAR); lTextOutReturn = TabbedTextOut(hdc, nX, nY, szOutputString, nStringLength, 0, NULL, 0); nY += HIWORD(lTextOutReturn); EndPaint (hWnd, &ps); } break; case WM_DESTROY: FreeAllocatedMemory(); // Tell WinHelp we don't need it any more... WinHelp(hWnd, APPNAME".HLP", HELP_QUIT,(DWORD)0); PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0); }