#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "resource.h"
#include "afxres.h"
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
HINSTANCE hIns=NULL;
HDC hDC,hDCmem;
HBITMAP hBitmap=NULL;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wc;
wc.style = CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;//GetModuleHandle(0);
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszClassName = "BY KOF";
wc.lpszMenuName = "MY NENU";
hIns = hInstance;
if(!(RegisterClass(&wc)))
{
MessageBox(NULL,"RegisterClass Wrong!!","Error!!",MB_OK);
ExitProcess(0);
return 0;
}
HWND hWnd = CreateWindowEx(WS_EX_TOPMOST|WS_EX_TOOLWINDOW,
"BY KOF","made by kof",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
MSG msg;
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
WaitMessage();
}
UnregisterClass("BY KOF",hInstance);
ExitProcess(0);
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
DeleteObject(hBitmap);
PostQuitMessage(0);
break;
case WM_SIZE:
hDC=GetDC(hWnd);
hBitmap=(HBITMAP)LoadBitmap(hIns,MAKEINTRESOURCE(IDB_BITMAP1));
if(hBitmap==NULL)
{
DeleteObject(hBitmap);
PostQuitMessage(0);
return 0;
}
hDCmem=CreateCompatibleDC(hDC);
SelectObject(hDCmem,hBitmap);
DeleteDC(hDCmem);
ReleaseDC(hWnd,hDC);
return 0;
case WM_PAINT:
PAINTSTRUCT ps;
hDC=BeginPaint(hWnd,&ps);
hDCmem = ::CreateCompatibleDC (hDC);
SelectObject(hDCmem,hBitmap);
BitBlt(hDC,0,0,800,600,hDCmem,0,0,SRCCOPY);
DeleteDC(hDCmem);
EndPaint(hWnd,&ps);
return 0;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
各位前辈告诉我出什么问题了,hBitmap == NULL,最好把完整的代码贴出来,
不要用MFC的,DX也不要.先谢了.