回复 34楼 有容就大
另一场谁胜出还不知道呢。。呵呵,得看看结果。奥哥很多的人都看好,
不过偶觉得赛场上的事,还是有变数,比如说昨天虽然奥哥虽然赢了,但有几局运气还是不怎么好,白球都有落袋的情况出现。
程序代码:
/*
通过本程序,你可以了解到,DC(Device Context)倒底是什么,设备环境仅仅是一个环境。
在windows程序中,你不可能指望在窗口里显示的内容会在下一刻还保留在那里。
所以需要用WM_PAINT事件里把窗口中的内容恢复出来,这是程序应该做的事,而不是系统要做
的事。
*/
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
//////////////////////////////////////////////////////////
const PTCHAR szClass1 = _T("SourceWindow");
const PTCHAR szClass2 = _T("DesWindow");
const PTCHAR szCaption1 = _T("请尝试用别的窗口覆盖本窗口!");
const PTCHAR szCaption2 = _T("本窗口图像拷贝自另一窗口");
const PTCHAR szText = _T("Win32 Assmebly, Simple and pwerful!");
HINSTANCE hHandle = 0;
HWND hWin1;
HWND hWin2;
//////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
void CALLBACK ProcTimer(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);
void on_paint(HWND, HDC);
void on_close(HWND);
//////////////////////////////////////////////////////////
//程序入口
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdLine, int nShow)
{
MSG msg;
WNDCLASS wnd;
UINT hTimer;
hHandle = hInst;
memset(&wnd, 0, sizeof(wnd) );
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.hInstance = hInst;
wnd.lpfnWndProc = WndProc;
wnd.lpszClassName = szClass1;
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.hbrBackground = (HBRUSH) COLOR_WINDOW + 1;
RegisterClass(&wnd);
hWin1 = CreateWindow(szClass1,
szCaption1,
WS_OVERLAPPEDWINDOW,
450, 100, 300, 300,
0,
0,
hInst,
0);
ShowWindow(hWin1, SW_SHOWNORMAL);
UpdateWindow(hWin1);
wnd.lpszClassName = szClass2;
RegisterClass(&wnd);
hWin2 = CreateWindow(szClass2,
szCaption2,
WS_OVERLAPPEDWINDOW,
100, 100, 300, 300,
0,
0,
hInst,
0);
ShowWindow(hWin2, SW_SHOWNORMAL);
UpdateWindow(hWin2);
hTimer = SetTimer(0, 0, 100, ProcTimer);
while( GetMessage(&msg , NULL, 0, 0) >0 )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
KillTimer(0, hTimer);
return (int)msg.wParam;
}
//消息回调过程
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_PAINT:
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
on_paint(hwnd, hdc);
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
on_close(hwnd);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
//定时器回调过程
void CALLBACK ProcTimer(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
HDC hDc1, hDc2;
RECT stRect;
hDc1 = GetDC(hWin1);
hDc2 = GetDC(hWin2);
GetClientRect(hWin1, &stRect);
BitBlt(hDc2, 0, 0, stRect.right, stRect.bottom, hDc1, 0, 0, SRCCOPY);
ReleaseDC(hWin1, hDc1);
ReleaseDC(hWin2, hDc2);
}
void on_close(HWND hwnd)
{
if(IDYES == MessageBox(hwnd, _T("真的要退出吗?"), _T("您确定么?"), MB_YESNO) )
{
DestroyWindow(hwnd);
PostQuitMessage(0);
}
}
void on_paint(HWND hwnd, HDC hdc)
{
RECT stRect;
if(hwnd == hWin1)
{
GetClientRect(hwnd, &stRect);
DrawText(hdc, szText, -1, &stRect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
}