Wine >> C/C++ >> Dialog >> Painting
StretchBlt
參考資訊:
1. win32
2. petzold
3. tutorial
4. examples_win32
main.c
#include <stdbool.h> #include <windows.h> HWND hWin = NULL; WNDPROC defWndProc = NULL; LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: DestroyWindow(hWnd); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_PAINT: const char *pMsg = "Test"; PAINTSTRUCT ps = {0}; HDC hdc = BeginPaint(hWnd, &ps); HFONT font = CreateFont(18, 0, 0, 0, FW_BOLD, false, false, false, 0, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial"); SetTextColor(hdc, RGB(0x00, 0x00, 0xff)); SetBkMode(hdc, TRANSPARENT); SelectObject(hdc, font); DrawText(hdc, pMsg, strlen(pMsg), &ps.rcPaint, DT_SINGLELINE); StretchBlt(hdc, 50, 50, 200, 200, hdc, 0, 0, 30, 30, SRCCOPY); EndPaint(hWnd, &ps); DeleteObject(font); break; } return CallWindowProc(defWndProc, hWnd, uMsg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { hWin = CreateWindow(WC_DIALOG, "main", WS_OVERLAPPEDWINDOW, 0, 0, 300, 300, NULL, NULL, NULL, NULL); defWndProc = (WNDPROC)SetWindowLongPtr(hWin, GWLP_WNDPROC, (long int)WndProc); ShowWindow(hWin, SW_SHOW); MSG msg = {0}; while (GetMessage(&msg, NULL, 0, 0)) { DispatchMessage(&msg); } ExitProcess(0); return 0; }
編譯、執行
$ winegcc main.c -o main -lgdi32 $ wine ./main.exe