我對WINAPI相當陌生,我需要一些幫助進行文本輸出。我有寫與功能,然後定期的blit到使用以下功能屏幕的像素的陣列:WinAPI文本輸出C
DWORD WINAPI tickThreadProc(HANDLE handle) {
ShowWindow(hwnd, SW_SHOW);
HDC hdc = GetDC(hwnd);
hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hbmp);
int delay = 1000/fps;
InitPhys();
LoadIMGs();
for (;;) {
onFrame(pixels);
BitBlt(hdc, gLeft, gTop, width, height, hdcMem, 0, 0, SRCCOPY);
// Wait
Sleep(delay);
// Physics
SimPhys();
}
SelectObject(hdcMem, hbmOld);
DeleteDC(hdc);
return 0;
}
void MakeSurface(HWND hwnd) {
BITMAPINFO bmi;
bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height; // Order pixels from top to bottom
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32; // last byte not used, 32 bit for alignment
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 0;
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
bmi.bmiColors[0].rgbBlue = 0;
bmi.bmiColors[0].rgbGreen = 0;
bmi.bmiColors[0].rgbRed = 0;
bmi.bmiColors[0].rgbReserved = 0;
HDC hdc = GetDC(hwnd);
// Create DIB section to always give direct access to pixels
hbmp = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&pixels, NULL, 0);
DeleteDC(hdc);
// Create a new thread to use as a timer
hTickThread = CreateThread(NULL, 0, &tickThreadProc, NULL,0, NULL);
}
此被修改過的一些代碼我在互聯網上找到。像素結構對r,g,b和a有4個整數。
我需要做文本輸出和加載文本的圖片是不切實際的。任何幫助?
像['TextOut'](http://msdn.microsoft.com/en-us/library/windows/desktop/dd145133%28v=vs.85%29.aspx)函數? –
是的,有點。但我不能使用PAINSTRUCT的東西。 –
'PAINSTRUCT':) +1 –