#include <windows.h>
#include <stdio.h>
#define MAX 20
#define TextWidth 200
#define Time1 1
#define Time2 2
#define times 1
#define NO1 1
#define NO2 2
#define ERROR 0
#define NO 0
#define OK 1
int leng=1;
#define DEFAULT 0;
HDC hdc,hdc1,hdc2;
int xw,yw;
int iGame[MAX][MAX];
POINT point;
enum {Default,Player1,Player2}play;
enum {Stop,Play,Paush}plays;
void Init(HWND hwnd);
void paint(int play,int x,int y);
void chagePlayer();
int Look(int x,int y,int play);
void over(HWND hwnd,int play);
void timechage(HWND hwnd);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "五子棋 -WIN32版";
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 (
1,
szClassName,
szClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
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)
{
static HPEN hpen,hpen1,hpen2;
static HBRUSH hbrush,hbrush1,hbrush2;
int x,y;
switch (message) /* handle the messages */
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_F5:
Init(hwnd);
Rectangle(hdc,0,0,100,100); //这个没画刷我知道
for(x=0;x<MAX;x++)
{
for(y=0;y<MAX;y++)
{
Rectangle(hdc,x*100/MAX,y*100/MAX,(x+1)*100/MAX,(y+1)*100/MAX) ;
//如果改为Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX);画不出来小格子啊,为啥??
iGame[x][y]=Default;
}
}
};break;
//case WM_SIZE:x=LOWORD(lParam),y=HIWORD(lParam);
case WM_DESTROY:PostQuitMessage(0);break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
}
void Init(HWND hwnd)
{
hdc1=GetDC(hwnd);
hdc2=GetDC(hwnd);
//初始背景
SelectObject(hdc,CreatePen(0,1,RGB(255,0,0)));
SelectObject(hdc,CreateSolidBrush(RGB(0,0,0)));
//初始玩家一图形
SelectObject(hdc1,CreatePen(0,1,RGB(0,0,0)));
SelectObject(hdc1,CreateSolidBrush(RGB(0,255,0)));
//初始玩家二图形
SelectObject(hdc2,CreatePen(0,1,RGB(0,0,0)));
SelectObject(hdc2,CreateSolidBrush(RGB(0,0,255)));
SetBkMode(hdc,0);
Rectangle(hdc,xw+1,1,xw+30,yw);
Rectangle(hdc,xw+31,29,xw+200,30);
TextOut(hdc,xw+80,10,"五子棋",6);
TextOut(hdc,xw+45,100,"F2 - 开始游戏",13);
TextOut(hdc,xw+45,120,"F3 - 暂停/继续游戏",18);
TextOut(hdc,xw+45,140,"F5 -重新开始游戏",16);
Rectangle(hdc,xw+31,180,xw+200,181);
TextOut(hdc,xw+49,189," 帮助文档 ",15);
TextOut(hdc,xw+45,210,"*建议最大化窗口游戏",19);
TextOut(hdc,xw+45,240," 1) 按 F2启动游戏",18);
TextOut(hdc,xw+45,260," 2) 鼠标点击棋盘",17);
TextOut(hdc,xw+30,320,"注意:滚动条为限制时间",22);
}
问题1:如果hdc有画刷,只能画出一个大格子,其中的小格子画不出,为啥??rectangle函数有什么特别的地方吗?
#include <stdio.h>
#define MAX 20
#define TextWidth 200
#define Time1 1
#define Time2 2
#define times 1
#define NO1 1
#define NO2 2
#define ERROR 0
#define NO 0
#define OK 1
int leng=1;
#define DEFAULT 0;
HDC hdc,hdc1,hdc2;
int xw,yw;
int iGame[MAX][MAX];
POINT point;
enum {Default,Player1,Player2}play;
enum {Stop,Play,Paush}plays;
void Init(HWND hwnd);
void paint(int play,int x,int y);
void chagePlayer();
int Look(int x,int y,int play);
void over(HWND hwnd,int play);
void timechage(HWND hwnd);
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "五子棋 -WIN32版";
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 (
1,
szClassName,
szClassName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
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)
{
static HPEN hpen,hpen1,hpen2;
static HBRUSH hbrush,hbrush1,hbrush2;
int x,y;
switch (message) /* handle the messages */
{
case WM_KEYDOWN:
switch (wParam)
{
case VK_F5:
Init(hwnd);
Rectangle(hdc,0,0,100,100); //这个没画刷我知道
for(x=0;x<MAX;x++)
{
for(y=0;y<MAX;y++)
{
Rectangle(hdc,x*100/MAX,y*100/MAX,(x+1)*100/MAX,(y+1)*100/MAX) ;
//如果改为Rectangle(hdc,x*xw/MAX,y*yw/MAX,(x+1)*xw/MAX,(y+1)*yw/MAX);画不出来小格子啊,为啥??
iGame[x][y]=Default;
}
}
};break;
//case WM_SIZE:x=LOWORD(lParam),y=HIWORD(lParam);
case WM_DESTROY:PostQuitMessage(0);break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
}
void Init(HWND hwnd)
{
hdc1=GetDC(hwnd);
hdc2=GetDC(hwnd);
//初始背景
SelectObject(hdc,CreatePen(0,1,RGB(255,0,0)));
SelectObject(hdc,CreateSolidBrush(RGB(0,0,0)));
//初始玩家一图形
SelectObject(hdc1,CreatePen(0,1,RGB(0,0,0)));
SelectObject(hdc1,CreateSolidBrush(RGB(0,255,0)));
//初始玩家二图形
SelectObject(hdc2,CreatePen(0,1,RGB(0,0,0)));
SelectObject(hdc2,CreateSolidBrush(RGB(0,0,255)));
SetBkMode(hdc,0);
Rectangle(hdc,xw+1,1,xw+30,yw);
Rectangle(hdc,xw+31,29,xw+200,30);
TextOut(hdc,xw+80,10,"五子棋",6);
TextOut(hdc,xw+45,100,"F2 - 开始游戏",13);
TextOut(hdc,xw+45,120,"F3 - 暂停/继续游戏",18);
TextOut(hdc,xw+45,140,"F5 -重新开始游戏",16);
Rectangle(hdc,xw+31,180,xw+200,181);
TextOut(hdc,xw+49,189," 帮助文档 ",15);
TextOut(hdc,xw+45,210,"*建议最大化窗口游戏",19);
TextOut(hdc,xw+45,240," 1) 按 F2启动游戏",18);
TextOut(hdc,xw+45,260," 2) 鼠标点击棋盘",17);
TextOut(hdc,xw+30,320,"注意:滚动条为限制时间",22);
}
问题1:如果hdc有画刷,只能画出一个大格子,其中的小格子画不出,为啥??rectangle函数有什么特别的地方吗?