| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 728 人关注过本帖
标题:屏幕截取的一段代码,后面的不会写了,请大家指点
只看楼主 加入收藏
yaoguai2005
Rank: 1
等 级:新手上路
帖 子:168
专家分:0
注 册:2005-9-11
收藏
 问题点数:0 回复次数:5 
屏幕截取的一段代码,后面的不会写了,请大家指点
case WM_CREATE:
{
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
SelectObject(hCaptureDC,hCaptureBitmap);
BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY)
}
//到了这里,我就不知道咋写了,我觉得就该把屏幕抓到我的窗口里面去了,
可是事实还是没有成功,请大家指点一下,后面还要加什么语句呢
谢谢了~~~~~~~~~~~~~~~~~
搜索更多相关主题的帖子: 屏幕 nScreenWidth hDesktopDC hCaptureDC 代码 
2006-04-18 22:06
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 

你的想法是完全正确的,但你的做法就不正确了。
void DrawScreen(HDC hdc)
{
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
HGDIOBJ oldobj=SelectObject(hCaptureDC,hCaptureBitmap);

BitBlt(hdc,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY);
SelectObject(hCaptureDC,oldobj);
DeleteDC(hCaptureDC);
}

然后在WM_PAINT:中调用。


=×&D o I p R e E n C g T l X&×=
2006-04-18 23:16
yaoguai2005
Rank: 1
等 级:新手上路
帖 子:168
专家分:0
注 册:2005-9-11
收藏
得分:0 

老大,我还是搞不定啊,是不是还要设个位图BITMAP结构啊,
能不能再给指点一下把

#include <windows.h>
#define ID_TIMER 1

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "WindowsApp";

int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if (!RegisterClassEx (&wincl))
return 0;

hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);

ShowWindow (hwnd, nFunsterStil);

while (GetMessage (&messages, NULL, 0, 0))
{

TranslateMessage(&messages);

DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ int nScreenWidth;
int nScreenHeight;
HWND hDesktopWnd;
HDC hDesktopDC;
HDC hCaptureDC;
HBITMAP hCaptureBitmap;
HGDIOBJ oldobj;
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
SetTimer(hwnd, ID_TIMER, 1000, NULL);
return 0;
case WM_TIMER:
// case WM_CREATE:
{
nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
hDesktopWnd = GetDesktopWindow();
hDesktopDC = GetDC(hDesktopWnd);
hCaptureDC = CreateCompatibleDC(hDesktopDC);
hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
oldobj=SelectObject(hCaptureDC,hCaptureBitmap);
InvalidateRect(hwnd,NULL,FALSE);
BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY);
InvalidateRect(hwnd,NULL,FALSE);
break;
}
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);

BitBlt(hdc,0,0,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,hCaptureDC,0,0,SRCCOPY);
EndPaint(hwnd, &ps);
break;
}

case WM_DESTROY:
SelectObject(hCaptureDC,oldobj);
DeleteDC(hCaptureDC);

PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}


2006-04-19 10:38
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 

不能在WM_CREATE里画图。在WM_CREATE里画图因为框架还没有生成,画图是没有任何意义的。
所以要在WM_PAINT里画图。
还有一点:你在WM_CREATE里想得到顶窗口,又是因为顶窗口(你的程序就是顶窗口)还没有生成,
也是没有意义的。

#include <windows.h>
#define ID_TIMER 1

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "WindowsApp";
void DrawScreen(HDC hdc);
int WINAPI
WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;

wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;

wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if (!RegisterClassEx (&wincl))
return 0;

hwnd = CreateWindowEx (
0,
szClassName,
"Windows App",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);

ShowWindow (hwnd, nFunsterStil);

while (GetMessage (&messages, NULL, 0, 0))
{

TranslateMessage(&messages);

DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK
WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ /*int nScreenWidth;
int nScreenHeight;
HWND hDesktopWnd;
HDC hDesktopDC;
HDC hCaptureDC;
HBITMAP hCaptureBitmap;
HGDIOBJ oldobj;*/
HDC hdc;
PAINTSTRUCT ps;
switch (message)
{
case WM_CREATE:
SetTimer(hwnd, ID_TIMER, 1000, NULL);
return 0;
case WM_TIMER:
// case WM_CREATE:
/* {
nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
hDesktopWnd = GetDesktopWindow();
hDesktopDC = GetDC(hDesktopWnd);
hCaptureDC = CreateCompatibleDC(hDesktopDC);
hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
oldobj=SelectObject(hCaptureDC,hCaptureBitmap);
InvalidateRect(hwnd,NULL,FALSE);
BitBlt(hCaptureDC,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY);
InvalidateRect(hwnd,NULL,FALSE);
break;
}*/
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
DrawScreen(hdc);
//BitBlt(hdc,0,0,ps.rcPaint.right-ps.rcPaint.left,ps.rcPaint.bottom-ps.rcPaint.top,hCaptureDC,0,0,SRCCOPY);
EndPaint(hwnd, &ps);
break;
}

case WM_DESTROY:
//SelectObject(hCaptureDC,oldobj);
//DeleteDC(hCaptureDC);

PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

void DrawScreen(HDC hdc)
{
int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HWND hDesktopWnd = GetDesktopWindow();
HDC hDesktopDC = GetDC(hDesktopWnd);
HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
HBITMAP hCaptureBitmap =CreateCompatibleBitmap(hDesktopDC,
nScreenWidth, nScreenHeight);
HGDIOBJ oldobj=SelectObject(hCaptureDC,hCaptureBitmap);

BitBlt(hdc,0,0,nScreenWidth,nScreenHeight,hDesktopDC,0,0,SRCCOPY);
SelectObject(hCaptureDC,oldobj);
DeleteDC(hCaptureDC);
}


=×&D o I p R e E n C g T l X&×=
2006-04-19 11:02
yaoguai2005
Rank: 1
等 级:新手上路
帖 子:168
专家分:0
注 册:2005-9-11
收藏
得分:0 

真是没说的了,老大,
太感谢你了,
为了这个,我研究了3本书,10天时间,
还下载了好多程序
可没有一个有你这样直接有效的,
我得在下面好好的领会才行
感动啊


2006-04-19 11:11
mengkeli
Rank: 1
等 级:新手上路
帖 子:21
专家分:0
注 册:2006-3-15
收藏
得分:0 

老大太猛了,境界不一样啊......老大学了多少年了?

2006-04-20 10:41
快速回复:屏幕截取的一段代码,后面的不会写了,请大家指点
数据加载中...
 
   



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

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