| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 758 人关注过本帖
标题:用WIN GDI 显示 位图的问题
只看楼主 加入收藏
kofex1984
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-6-25
收藏
 问题点数:0 回复次数:0 
用WIN GDI 显示 位图的问题

#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也不要.先谢了.

搜索更多相关主题的帖子: GDI 位图 WIN 
2006-06-25 21:20
快速回复:用WIN GDI 显示 位图的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017289 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved