2 zwik  zwik__ 于 2014.01.23 16:28 提问

画一个无标题栏无边框的窗口

窗口是用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(lib, "gdiplus.lib")
#endif
#include

//用于接收应用程序实例句柄
HINSTANCE g_hInstance = 0;
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;

void OnCreate(HWND hWnd)
{
CreateWindowEx( 0, "BUTTON", "OK",
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,
0, 0, 50, 30, hWnd, (HMENU)1000, g_hInstance, NULL );
}
//窗口处理函数(用于处理消息)
LRESULT CALLBACK WndProc(HWND hWnd,UINT 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(hWnd,GWL_EXSTYLE);
SetWindowLong(hWnd,GWL_EXSTYLE,dwExStyle|0x80000);

//绘制内存位图
HDC hdcTemp=GetDC(hWnd);
m_hdcMemory=CreateCompatibleDC(hdcTemp);
HBITMAP hBitMap=CreateCompatibleBitmap(hdcTemp,417,128);
SelectObject(m_hdcMemory,hBitMap);

//使用GDI+载入PNG图片
HDC hdcScreen=::GetDC (hWnd);
RECT rct={0,0};
::GetWindowRect(hWnd,&rct);
POINT ptWinPos={rct.left,rct.top};
Graphics graph(m_hdcMemory);
Image image(L"2.png",TRUE);
graph.DrawImage(&image,0,0,417,128);

//使用UpdateLayerWindow进行窗口透明处理
HMODULE hFuncInst=LoadLibrary("User32.DLL");
typedef BOOL (WINAPI MYFUNC)(HWND,HDC,POINT,SIZE*,HDC,POINT*,COLORREF,BLENDFUNCTION*,DWORD);
MYFUNC UpdateLayeredWindow;
UpdateLayeredWindow=(MYFUNC)GetProcAddress(hFuncInst,"UpdateLayeredWindow");
SIZE sizeWindow={417,128};
POINT ptSrc={0,0};
UpdateLayeredWindow( hWnd,hdcScreen,&ptWinPos,&sizeWindow,m_hdcMemory,&ptSrc,0,&m_Blend,2);
LONG nOldStyle = ::GetWindowLong (hWnd, GWL_STYLE);
::SetWindowLong (hWnd, GWL_STYLE, nOldStyle & ~WS_CAPTION);
::SetWindowPos (hWnd, HWND_TOPMOST, 100,100, 417,128, 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(0,lpClassName,lpWndName,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,g_hInstance,NULL);

return hWnd;
}
//显示窗口
void Display(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
//消息循环
void Message()
{
MSG nMsg = {0};
while(GetMessage(&nMsg,NULL,0,0))
{
TranslateMessage(&nMsg);
DispatchMessage(&nMsg);
}
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
g_hInstance = hInstance;
if(!Register("Main",WndProc))
{
MessageBox(NULL,"Register Fail","Infor",MB_OK);
return 0;
}
HWND hWnd = CreateMain("Main","window");

Display(hWnd);
Message();

return 0;
}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!