Fungsi SetBkMode (wingdi.h)
Fungsi SetBkMode mengatur mode campuran latar belakang dari konteks perangkat yang ditentukan. Mode campuran latar belakang digunakan dengan teks, kuas yang menetas, dan gaya pena yang bukan garis tebal.
Sintaks
int SetBkMode(
[in] HDC hdc,
[in] int mode
);
Parameter
[in] hdc
Handel ke konteks perangkat.
[in] mode
Mode latar belakang. Parameter ini bisa menjadi salah satu nilai berikut.
Nilai | Makna |
---|---|
|
Latar belakang diisi dengan warna latar belakang saat ini sebelum teks, kuas menetas, atau pena digambar. |
|
Latar belakang tetap tidak tersentuh. |
Mengembalikan nilai
Jika fungsi berhasil, nilai pengembalian menentukan mode latar belakang sebelumnya.
Jika fungsi gagal, nilai yang dikembalikan adalah nol.
Keterangan
Fungsi SetBkMode memengaruhi gaya garis untuk garis yang digambar menggunakan pena yang dibuat oleh fungsi CreatePen . SetBkMode tidak memengaruhi garis yang digambar menggunakan pena yang dibuat oleh fungsi ExtCreatePen .
Contoh
Untuk melihat cara membuat latar belakang kuas hatch transparan atau buram, lihat contoh yang ditunjukkan dalam topik CreateHatchBrush .
Contoh berikutnya menggambar string 36 kali, memutarnya 10 derajat berlawanan arah jarang setiap kali. Ini juga mengatur mode latar belakang menjadi transparan untuk membuat teks terlihat.
#include "strsafe.h"
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
RECT rc;
int angle;
HGDIOBJ hfnt, hfntPrev;
WCHAR lpszRotate[22] = TEXT("String to be rotated.");
HRESULT hr;
size_t pcch = 22;
// Allocate memory for a LOGFONT structure.
PLOGFONT plf = (PLOGFONT) LocalAlloc(LPTR, sizeof(LOGFONT));
// Specify a font typeface name and weight.
hr = StringCchCopy(plf->lfFaceName, 6, TEXT("Arial"));
if (FAILED(hr))
{
// TODO: write error handler
}
plf->lfWeight = FW_NORMAL;
// Retrieve the client-rectangle dimensions.
GetClientRect(hWnd, &rc);
// Set the background mode to transparent for the
// text-output operation.
SetBkMode(hdc, TRANSPARENT);
// Draw the string 36 times, rotating 10 degrees
// counter-clockwise each time.
for (angle = 0; angle < 3600; angle += 100)
{
plf->lfEscapement = angle;
hfnt = CreateFontIndirect(plf);
hfntPrev = SelectObject(hdc, hfnt);
//
// The StringCchLength call is fitted to the lpszRotate string
//
hr = StringCchLength(lpszRotate, 22, &pcch);
if (FAILED(hr))
{
// TODO: write error handler
}
TextOut(hdc, rc.right / 2, rc.bottom / 2,
lpszRotate, pcch);
SelectObject(hdc, hfntPrev);
DeleteObject(hfnt);
}
// Reset the background mode to its default.
SetBkMode(hdc, OPAQUE);
// Free the memory allocated for the LOGFONT structure.
LocalFree((LOCALHANDLE) plf);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
Persyaratan
Klien minimum yang didukung | Windows 2000 Professional [hanya aplikasi desktop] |
Server minimum yang didukung | Windows 2000 Server [hanya aplikasi desktop] |
Target Platform | Windows |
Header | wingdi.h (sertakan Windows.h) |
Pustaka | Gdi32.lib |
DLL | Gdi32.dll |