- 注册时间
- 2009-11-24
- 最后登录
- 2019-5-19
⑥精研
- 积分
- 1274

|
- #include <stdio.h>
- #include <windows.h>
- #include <gdiplus.h>
- using namespace Gdiplus;
- HWND g_hWnd;
- Graphics * graphics;
- Bitmap * bitmap;
- Graphics * g_pGraphics;
- HDC hDC;
- GdiplusStartupInput gdiplusStartupInput;
- ULONG_PTR GdiToken;
- char title[255];
- int screenwidth = 640;
- int screenheight = 480;
- int x = 0, y = 0, a = 0;
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- void Render();
- void OnMouseMove(WPARAM wParam, LPARAM lParam);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
- WNDCLASS wndclass;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hInstance = hInstance;
- wndclass.lpfnWndProc = WndProc;
- wndclass.lpszClassName = "DLMEngine";
- wndclass.lpszMenuName = NULL;
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- RegisterClass(&wndclass);
- int x, y, width, height;
- GetPrivateProfileString("Engine", "Title", "Untitled", title, 255, ".\\Config.ini");
- width = GetSystemMetrics(SM_CXDLGFRAME) * 2 + screenwidth;
- height = GetSystemMetrics(SM_CYDLGFRAME) * 2 + screenheight + GetSystemMetrics(SM_CYCAPTION);
- x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
- y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
- g_hWnd = CreateWindow("DLMEngine", title, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, x, y, width, height, NULL, NULL, hInstance, NULL);
- GdiplusStartup(&GdiToken, &gdiplusStartupInput,NULL);
- hDC = GetDC(g_hWnd);
- g_pGraphics = new Graphics(hDC);
- bitmap = new Bitmap(screenwidth, screenheight);
- graphics = Graphics::FromImage(bitmap);
- graphics->SetTextRenderingHint(TextRenderingHintAntiAlias);
- ShowWindow(g_hWnd, SW_SHOWNORMAL);
- MSG msg;
- while(true) {
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- if (msg.message == WM_QUIT) {
- break;
- }
- Render();
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- ReleaseDC(g_hWnd, hDC);
- GdiplusShutdown(GdiToken);
- return 0;
- }
- LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
- switch(uMsg) {
- case WM_PAINT :
- Render();
- return 0;
- case WM_MOUSEMOVE :
- OnMouseMove(wParam, lParam);
- return 0;
- case WM_DESTROY :
- PostQuitMessage(0);
- return 0;
- default :
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- }
- void Render() {
- Font * font = new Font(L"SimHei", 18);
- graphics->Clear(Color::Black);
- graphics->DrawString(L"文字测试", 4, font, PointF(x, y), new SolidBrush(Color::White));
- g_pGraphics->DrawImage(bitmap, 0, 0);
- }
- void OnMouseMove(WPARAM wParam, LPARAM lParam) {
- x = LOWORD(lParam);
- y = HIWORD(lParam);
- a = wParam;
- }
复制代码 需要用到库文件 gdipluse.lib |
|