生活随笔
收集整理的這篇文章主要介紹了
9WinMap 映射
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include <windows.h>#include <iostream>CHAR szText[256] = { 0 };#define PrintLog(x) WriteConsole(g_hStdout, x, strlen(x), NULL, NULL)HINSTANCE g_hInst = NULL; //窗口句柄HANDLE g_hStdout = NULL; //控制臺(tái)句柄//OnPaintvoid OnPaint(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){ PAINTSTRUCT ps = { 0 }; HDC hDC = BeginPaint(hWnd, &ps); Rectangle(hDC, 100, 100, 200, 200); //默認(rèn)情況下是100個(gè)邏輯單位 int nOldMap = SetMapMode(hDC, MM_LOMETRIC);//0.1MM X方向向右,Y方向向上 Rectangle(hDC, 100, -100, 200, -200); //默認(rèn)情況下是100個(gè)邏輯單位 SetMapMode(hDC, nOldMap);//恢復(fù)舊的映射模式 nOldMap = SetMapMode(hDC, MM_HIMETRIC); Rectangle(hDC, 100, -100, 200, -200); //默認(rèn)情況下是100個(gè)邏輯單位 SetMapMode(hDC, nOldMap); nOldMap = SetMapMode(hDC, MM_ISOTROPIC); SetViewportExtEx(hDC, 2, 2, NULL); //屏幕單位 SetWindowExtEx(hDC, 4, 4, NULL); //邏輯單位 SetWindowOrgEx(hDC, 100, 100, NULL); //X和Y偏移100 Rectangle(hDC, 100, 100, 200, 200); //默認(rèn)情況下是100個(gè)邏輯單位 SetMapMode(hDC, nOldMap); EndPaint(hWnd, &ps);}LRESULT CALLBACK WndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam){ switch (nMsg) { case WM_PAINT: OnPaint(hWnd, nMsg, wParam, lParam); break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hWnd, nMsg, wParam, lParam);}BOOL RegisterWnd(LPSTR pszClassName){ WNDCLASSEX wce = { 0 }; wce.cbSize = sizeof(wce); wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hbrBackground = HBRUSH(COLOR_BTNFACE + 1); wce.hCursor = NULL; wce.hIcon = NULL; wce.hIconSm = NULL; wce.hInstance = g_hInst; wce.lpfnWndProc = WndProc; wce.lpszClassName = pszClassName; wce.lpszMenuName = NULL; wce.style = CS_HREDRAW | CS_VREDRAW; ATOM atom = RegisterClassEx(&wce); if (atom == NULL) { return FALSE; } else { return TRUE; }}HWND CreateWnd(LPSTR pszClassName){ HWND hWnd = CreateWindowEx(0, pszClassName, "滅天", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, g_hInst, 0); return hWnd;}void ShowWnd(HWND hWnd){ ShowWindow(hWnd, SW_SHOW); UpdateWindow(hWnd);}void Msg(){ MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }}void ConsoleWnd(){ AllocConsole(); g_hStdout = GetStdHandle(STD_OUTPUT_HANDLE); CHAR szText[] = "Debug start:\n"; WriteConsole(g_hStdout, szText, strlen(szText), NULL, NULL);}int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd){ g_hInst = hInstance; //ConsoleWnd(); RegisterWnd("oooo"); HWND hWnd = CreateWnd("oooo"); ShowWnd(hWnd); Msg(); return 0;}來自為知筆記(Wiz)
轉(zhuǎn)載于:https://www.cnblogs.com/nfking/p/5573167.html
總結(jié)
以上是生活随笔為你收集整理的9WinMap 映射的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。