📄 8queuetu.c
字号:
#include "MyAssert.h"
#include "EightQueens.h"
#include<windows.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define problemSize 8
long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
//program starting.
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
//Core message looping
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//main wndProc function: message looping
long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
int* arr;
FILE* outputFile;
LPPOINT myPoint;
assertF((outputFile=fopen("outputFile","wb"))!=NULL,"output file error");
int i,j;
int posX,posY;
int step=20;
POINT points[6]={{100,212},{70,227},{70,250},{130,250},{130,227},{100,212}};
switch(iMessage)
{
case WM_PAINT:
//First draw,a black line
hDC=BeginPaint(hWnd,&PtStr);
hPen=(HPEN)GetStockObject(NULL_PEN);//get empty brush
SelectObject(hDC,hPen);
hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hDC,hBrush);
LineTo(hDC,50,50);//draw line
DeleteObject(hPen);//delete first brush
hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));//create pen
SelectObject(hDC,hPen);
step=50;
posX=50;
posY=50;
arr=NQueensProblemStack(problemSize,outputFile);
for(i=0;i<10;i++)
{
MoveToEx(hDC,posX,posY+(i-1)*step,NULL);
LineTo(hDC,posX+400,posY+(i-1)*step);
}
for(j=0;j<10;j++)
{
MoveToEx(hDC,posX+(j-1)*step,posY,NULL);
LineTo(hDC,posX+(j-1)*step,posY+400);
}
j=1;
for(i=0;i<8;i++)
{
Ellipse(hDC,posX+arr[i]*50,posY+(j-1)*50,posX+(arr[i]+1)*50,posY+j*50);
j++;
}
DeleteObject(hPen);
DeleteObject(hBrush);
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}
}
//Init the Window to show out.
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinFill",
"填充示例程序",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//Set wndClass Propertity
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndClass;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndClass.hIcon=LoadIcon(NULL,"END");
wndClass.hInstance=hInstance;
wndClass.lpfnWndProc=WndProc;
wndClass.lpszClassName="WinFill";
wndClass.lpszMenuName=NULL;
wndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&wndClass);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -