| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 612 人关注过本帖
标题:高手请进,图片时显时无?
只看楼主 加入收藏
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
结帖率:33.33%
收藏
 问题点数:0 回复次数:5 
高手请进,图片时显时无?

#include <stdAfx.h>
#include "resource.h"
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow);

LRESULT CALLBACK WinProc(HWND hWnd,
UINT message,
WPARAM wParam, LPARAM lParam );
HWND hWnd; //窗口句柄
int x,y,x1,y1;//窗口宽与高
HBITMAP hBm1,hBm2;
BITMAP bm;
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE;
MSG msg;

hBm1=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
hBm2=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));
for (;;)//消息循环1
{
if(PeekMessage(&msg,NULL, 0, 0, PM_REMOVE))
{

if(msg.message== WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//消息循环1
return msg.wParam;
}

static BOOL InitWindow(HINSTANCE hInstance, int nCmdShow )
{

WNDCLASS wc;
wc.style=NULL;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.cbClsExtra=0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(192,192,192)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";
RegisterClass(&wc);//注册窗口
//按所给参数创造窗口
hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,
0,0,
x=400, //GetSystemMetrics( SM_CXSCREEN )此函数返回屏幕宽度
y=400, //GetSystemMetrics( SM_CYSCREEN )此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}//end initWindows

LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc,hdcmem;
PAINTSTRUCT ps;
switch( message )
{
case WM_CREATE:
hdc=GetDC(hWnd);
ReleaseDC(hWnd,hdc);
break;
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0; //处理完一个消息后返回0
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
hdcmem=CreateCompatibleDC(hdc);
MoveToEx(hdc,x/10,y/10,NULL);
LineTo(hdc,(int)(x*0.9),(int)(y/10));
LineTo(hdc,(int)(x*0.9),(int)(y*0.9));
LineTo(hdc,(int) x/10,(int) (y*0.9));
LineTo(hdc,(int) x/10,(int) y/10);
MoveToEx(hdc,(int) (x/10+x*0.8/3),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3),(int)(y*0.9));
MoveToEx(hdc,(int) (x/10+x*0.8/3*2),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3*2),(int)( y*0.9));
MoveToEx(hdc,(int) x/10,(int) (y/10+y*0.8/3),NULL);
LineTo(hdc,(int)( x*0.9),(int) (y/10+y*0.8/3));
MoveToEx(hdc,(int) (x/10),(int)(y/10+y*0.8/3*2),NULL);
LineTo(hdc,(int )(x*0.9),(int)(y/10+y*0.8/3*2));
// TextOut(hdc,x/10,y/10,"●",2);
SelectObject(hdcmem,hBm1);
BitBlt(hdc,x/10-10,y/10-11,21,22,hdcmem,0,0,SRCCOPY);就是它时显时无
EndPaint(hWnd,&ps);
break;
case WM_CLOSE: //准备退出
DestroyWindow( hWnd ); //释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY: //如果窗口被人释放…
PostQuitMessage( 0 ); //给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}

搜索更多相关主题的帖子: 图片 message include 
2005-11-09 15:30
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 

以下程序做了些少修改.在我的机器里OK!


#include "stdafx.h"
#include "resource.h"

int x=400,y=400;
HBITMAP hBm1,hBm2;
BITMAP bm;
// Global Variables:
HINSTANCE hInst; // current instance

// Foward declarations of functions included in this code module:
BOOL InitWindow(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
// Initialize global strings

hBm1=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
hBm2=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));

// Perform application initialization:
if (!InitWindow (hInstance, nCmdShow))
{
return FALSE;
}
// Main message loop:
for(;;)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if(msg.message==WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}


BOOL InitWindow(HINSTANCE hInstance, int nCmdShow)
{

HWND hWnd;
WNDCLASS wc;

wc.style = NULL;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(192,192,192)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";

RegisterClass(&wc);
hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,
0, 0, x, y, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{

PAINTSTRUCT ps;
HDC hdc,hdcmem;
switch (message)
{
case WM_CREATE:
break;
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
hdcmem=CreateCompatibleDC(hdc);
MoveToEx(hdc,x/10,y/10,NULL);
LineTo(hdc,(int)(x*0.9),(int)(y/10));
LineTo(hdc,(int)(x*0.9),(int)(y*0.9));
LineTo(hdc,(int) x/10,(int) (y*0.9));
LineTo(hdc,(int) x/10,(int) y/10);
MoveToEx(hdc,(int) (x/10+x*0.8/3),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3),(int)(y*0.9));
MoveToEx(hdc,(int) (x/10+x*0.8/3*2),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3*2),(int)( y*0.9));
MoveToEx(hdc,(int) x/10,(int) (y/10+y*0.8/3),NULL);
LineTo(hdc,(int)( x*0.9),(int) (y/10+y*0.8/3));
MoveToEx(hdc,(int) (x/10),(int)(y/10+y*0.8/3*2),NULL);
LineTo(hdc,(int )(x*0.9),(int)(y/10+y*0.8/3*2));
SelectObject(hdcmem,hBm1);
BitBlt(hdc,x/10-10,y/10-11,48,48,hdcmem,0,0,SRCCOPY);//就是它时显时无
DeleteDC(hdcmem); //删除暂存设备场景
EndPaint(hWnd, &ps);
break;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}


=×&D o I p R e E n C g T l X&×=
2005-11-10 17:13
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 
Bjarne 谢谢了,回头我再调试一下。

长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2005-11-11 10:27
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 

#include <stdAfx.h>
#include "resource.h"
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow);

LRESULT CALLBACK WinProc(HWND hWnd,
UINT message,
WPARAM wParam, LPARAM lParam );
HWND hWnd; //窗口句柄
int x=400,y=400;//窗口宽与高
HBITMAP hBm1,hBm2;
BITMAP bm;
HINSTANCE hInst; //这一句是什么意思
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE;
MSG msg;

hBm1=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
hBm2=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));
for (;;)//消息循环1
{
if(PeekMessage(&msg,NULL, 0, 0, PM_REMOVE))
{

if(msg.message== WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//消息循环1
return msg.wParam;
}

static BOOL InitWindow(HINSTANCE hInstance, int nCmdShow )
{

WNDCLASS wc;
wc.style=NULL;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.cbClsExtra=0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(192,192,192));
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";
RegisterClass(&wc);//注册窗口

hInst = hInstance; // 这一句有用么?
//按所给参数创造窗口
hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,
0,0,
x=400, //GetSystemMetrics( SM_CXSCREEN )此函数返回屏幕宽度
y=400, //GetSystemMetrics( SM_CYSCREEN )此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}//end initWindows

LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc,hdcmem;
PAINTSTRUCT ps;
switch( message )
{
case WM_CREATE:
hdc=GetDC(hWnd);
ReleaseDC(hWnd,hdc);
break;
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0; //处理完一个消息后返回0
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
RECT rt;
GetClientRect(hWnd, &rt);//这两句是什么意思?
hdcmem=CreateCompatibleDC(hdc);
MoveToEx(hdc,x/10,y/10,NULL);
LineTo(hdc,(int)(x*0.9),(int)(y/10));
LineTo(hdc,(int)(x*0.9),(int)(y*0.9));
LineTo(hdc,(int) x/10,(int) (y*0.9));
LineTo(hdc,(int) x/10,(int) y/10);
MoveToEx(hdc,(int) (x/10+x*0.8/3),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3),(int)(y*0.9));
MoveToEx(hdc,(int) (x/10+x*0.8/3*2),(int) y/10,NULL);
LineTo(hdc,(int) (x/10+x*0.8/3*2),(int)( y*0.9));
MoveToEx(hdc,(int) x/10,(int) (y/10+y*0.8/3),NULL);
LineTo(hdc,(int)( x*0.9),(int) (y/10+y*0.8/3));
MoveToEx(hdc,(int) (x/10),(int)(y/10+y*0.8/3*2),NULL);
LineTo(hdc,(int )(x*0.9),(int)(y/10+y*0.8/3*2));//上面正常显示,刷新也正常
SelectObject(hdcmem,hBm1);
BitBlt(hdc,x/10-10,y/10-11,21,22,hdcmem,0,0,SRCCOPY);//第一次运行时不显示,被别的窗口覆盖后,再激活,才正常显示
DeleteDC(hdcmem); //删除暂存设备场景
EndPaint(hWnd,&ps);
break;
case WM_CLOSE: //准备退出
DestroyWindow( hWnd ); //释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY: //如果窗口被人释放…
PostQuitMessage( 0 ); //给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}

问题解决了大部分,不过第一次运行时不显示图片,被别的窗口覆盖后,再激活,才正常显示


长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2005-11-11 11:32
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 
在我的机器里一切正常,没有任何问题呀!(真是怪事)

=×&D o I p R e E n C g T l X&×=
2005-11-11 12:21
lisypro
Rank: 4
等 级:业余侠客
威 望:3
帖 子:695
专家分:216
注 册:2005-9-25
收藏
得分:0 

我已调好么,谢谢你了,关键在于UpdateWindow(hWnd)的调用


长期承接管理系统
代做各种vb/ / vc小程序
QQ:82341763
手机:13623290828
群号 11619730
2005-11-12 16:44
快速回复:高手请进,图片时显时无?
数据加载中...
 
   



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

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