设为首页收藏本站

新微赢技术网

 找回密码
 注册
搜索
热搜: 回贴
查看: 1792|回复: 4
打印 上一主题 下一主题

屏幕截取的一段代码,后面的不会写了,请大家指点

[复制链接]
跳转到指定楼层
1#
发表于 2009-11-3 01:14:39 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
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)
}
//到了这里,我就不知道咋写了,我觉得就该把屏幕抓到我的窗口里面去了,
可是事实还是没有成功,请大家指点一下,后面还要加什么语句呢
谢谢了~~~~~~~~~~~~~~~~~
5#
发表于 2009-11-3 01:14:49 | 只看该作者
老大太猛了,境界不一样啊......老大学了多少年了?
回复 支持 反对

使用道具 举报

4#
发表于 2009-11-3 01:14:47 | 只看该作者
不能在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);
}
回复 支持 反对

使用道具 举报

3#
发表于 2009-11-3 01:14:45 | 只看该作者
老大,我还是搞不定啊,是不是还要设个位图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;
}
回复 支持 反对

使用道具 举报

2#
发表于 2009-11-3 01:14:41 | 只看该作者
你的想法是完全正确的,但你的做法就不正确了。
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:中调用。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

申请友链|小黑屋|最新主题|手机版|新微赢技术网 ( 苏ICP备08020429号 )  

GMT+8, 2024-11-18 11:47 , Processed in 0.108836 second(s), 9 queries , Gzip On, Memcache On.

Powered by xuexi

© 2001-2013 HaiAn.Com.Cn Inc. 寰耽

快速回复 返回顶部 返回列表