问题描述
- 画一个无标题栏无边框的窗口
- 窗口是用gdi+画的
打算是想实现一种想安全卫士之类的窗口 没有默认的标题栏和边框的
现在的情况是 按钮被挡住了 画不出来?代码:
// WinCreate.cpp : Defines the entry point for the application.
//
#include
#include //初始化一下com口
#ifndef ULONG_PTR
#define ULONG_PTR unsigned long*
#include ""GdiPlus.h""
using namespace Gdiplus;
#pragma comment(libgdiplus.lib"")
#endif
#include//用于接收应用程序实例句柄
HINSTANCE g_hInstance = 0;
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;void OnCreate(HWND hWnd)
{
CreateWindowEx( 0BUTTON""OK""
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW
}
//窗口处理函数(用于处理消息)
LRESULT CALLBACK WndProc(HWND hWndUINT nMsg
WPARAM wParam LPARAM lParam)
{switch(nMsg)
{case WM_CREATE:
{
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_pGdiToken &m_gdiplusStartupInput NULL);
BLENDFUNCTION m_Blend;
HDC m_hdcMemory;
//初始化GDI+.
m_Blend.BlendOp=0;
m_Blend.BlendFlags=0;
m_Blend.AlphaFormat=1;
m_Blend.SourceConstantAlpha=255;//窗体样式为0x80000为层级窗体
DWORD dwExStyle=GetWindowLong(hWndGWL_EXSTYLE);
SetWindowLong(hWndGWL_EXSTYLEdwExStyle|0x80000);//绘制内存位图
HDC hdcTemp=GetDC(hWnd);
m_hdcMemory=CreateCompatibleDC(hdcTemp);
HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp417128);
SelectObject(m_hdcMemoryhBitMap);//使用GDI+载入PNG图片
HDC hdcScreen=::GetDC (hWnd);
RECT rct={00};
::GetWindowRect(hWnd&rct);
POINT ptWinPos={rct.leftrct.top};
Graphics graph(m_hdcMemory);
Image image(L""2.png""TRUE);
graph.DrawImage(&image00417128);//使用UpdateLayerWindow进行窗口透明处理
HMODULE hFuncInst=LoadLibrary(""User32.DLL"");
typedef BOOL (WINAPI MYFUNC)(HWNDHDCPOINTSIZE*HDCPOINT*COLORREFBLENDFUNCTION*DWORD);
MYFUNC UpdateLayeredWindow;
UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInstUpdateLayeredWindow"");
SIZE sizeWindow={417128};
POINT ptSrc={00};
UpdateLayeredWindow( hWndhdcScreen&ptWinPos&sizeWindowm_hdcMemory&ptSrc0&m_Blend2);
LONG nOldStyle = ::GetWindowLong (hWnd GWL_STYLE);
::SetWindowLong (hWnd GWL_STYLE nOldStyle & ~WS_CAPTION);
::SetWindowPos (hWnd HWND_TOPMOST 100100 417128 SWP_SHOWWINDOW);DeleteObject(m_hdcMemory);
DeleteObject(hBitMap);
}
break;case WM_DESTROY:
GdiplusShutdown(m_pGdiToken);
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd nMsg wParam lParam);
}
//注册窗口类
BOOL Register(LPSTR lpClassName WNDPROC wndProc)
{
WNDCLASSEX wce = {0};
wce.cbSize = sizeof(wce);
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wce.hCursor = NULL;
wce.hIcon = NULL;
wce.hIconSm = NULL;
wce.hInstance = g_hInstance;
wce.lpfnWndProc = wndProc;
wce.lpszClassName = lpClassName;
wce.lpszMenuName = NULL;
wce.style = CS_HREDRAW | CS_VREDRAW;
ATOM nAtom = RegisterClassEx(&wce);
if(nAtom == 0)
return FALSE;
return TRUE;
}
//创建主窗口
HWND CreateMain(LPSTR lpClassName LPSTR lpWndName)
{
HWND hWnd = CreateWindowEx(0lpClassNamelpWndName
WS_OVERLAPPEDWINDOWCW_USEDEFAULT
CW_USEDEFAULTCW_USEDEFAULTCW_USEDEFAULT
NULLNULLg_hInstanceNULL);return hWnd;
}
//显示窗口
void Display(HWND hWnd)
{
ShowWindow(hWndSW_SHOW);
UpdateWindow(hWnd);
}
//消息循环
void Message()
{
MSG nMsg = {0};
while(GetMessage(&nMsgNULL00))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
}
int APIENTRY WinMain(HINSTANCE hInstance
HINSTANCE hPrevInstance
LPSTR lpCmdLine
int nCmdShow)
{
g_hInstance = hInstance;
if(!Register(""Main""WndProc))
{
MessageBox(NULLRegister Fail""Infor""MB_OK);
return 0;
}
HWND hWnd = CreateMain(""Main""window"");Display(hWnd);
Message();return 0;
}