赞
踩
- #include <windows.h>
- #include <gdiplus.h>
- #pragma comment(lib, "gdiplus.lib")
-
- using namespace Gdiplus;
-
- //声明自定义消息处理函数
- LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
- //绘制PNG窗口
- BOOL UpdateDemoWindows(Image *image);
-
- Gdiplus::GdiplusStartupInput m_gdiplusStartupInput;
- ULONG_PTR m_pGdiToken;
- HWND m_hWnd;
-
- int _tmain(int argc, _TCHAR* argv[])
- {
- GdiplusStartup(&m_pGdiToken, &m_gdiplusStartupInput, NULL);
-
- HINSTANCE hInst;
- hInst = GetModuleHandle(NULL); //获取一个应用程序或动态链接库的模块句柄
- WNDCLASSEX wcx;
- wcx.cbSize = sizeof(wcx);
- wcx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_NOCLOSE;//窗口的风格
- wcx.lpfnWndProc = WindowProc; //采用自定义消息处理函数
- wcx.cbClsExtra = 0; // no extra class memory
- wcx.cbWndExtra = 0; // no extra window memory
- wcx.hInstance = hInst; //当前应用程序的实例句柄
- wcx.hIcon = LoadIcon(NULL,IDI_APPLICATION); //图标风格
- wcx.hCursor = LoadCursor(NULL,IDC_ARROW); //鼠标风格
- wcx.hbrBackground = (HBRUSH)WHITE_BRUSH; //背景色
- wcx.lpszMenuName =NULL; //菜单名
- wcx.lpszClassName = _T("ITSMYOSDCLASS"); //窗口类的名称
- wcx.hIconSm = NULL;
-
- if (!RegisterClassEx(&wcx))
- {
- printf("RegisterClassEx failed");
- return 1;
- }
-
- //窗口在屏幕上的显示位置
- int OSDleft = GetSystemMetrics(SM_CXSCREEN) / 2 - 300;
- int OSDTop = GetSystemMetrics(SM_CYSCREEN) / 2;
-
- m_hWnd = CreateWindowEx(
- WS_EX_LAYERED | WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE,//窗口的扩展风格
- wcx.lpszClassName,//上面注册的类名lpszClassName,要完全一致
- NULL,
- WS_VISIBLE | WS_POPUP,//窗口的风格
- OSDleft,//窗口相对于父级的X坐标
- OSDTop,//窗口相对于父级的Y坐标
- 300,//窗口的宽度
- 300,//窗口的高度
- (HWND)NULL,//没有父窗口,为(HWND)NULL//GetDesktopWindow(),
- (HMENU)NULL,//没有菜单,为NULL
- hInst,//当前应用程序的实例句柄
- (LPVOID)NULL); //没有附加数据,为NULL
-
- if (!m_hWnd)
- {
- printf("CreateWindowEx failed");
- return 1;
- }
- Image* pImage = Image::FromFile(L"demo.png");
- if (pImage->GetLastStatus() == Ok)
- {
- UpdateDemoWindows(pImage);
- }
- delete pImage;
- pImage = NULL;
- //消息循环
- MSG msg;
- while (GetMessage(&msg, (HWND)NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- Gdiplus::GdiplusShutdown(m_pGdiToken);
-
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。