跑出來的結果老是錯誤
請大大們幫我看看
以下為程式碼:
#include
#include
#include
#include
#include LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int nTopXY(UINT, UINT);
int CountPoint = 0, N =0, i, tt=0;
int Pxy[40][2], p2[40][2], GrahamIndex=0; const char* szAppName = "MyWndClass";
const int nBtn_ID = 1;
const int nBtn2_ID = 2; char szText[60] = "點的個數"; int ccw(int x0,int y0,int x1,int y1,int x2,int y2)
{
int dx1, dx2, dy1, dy2;
dx1=x1-x0;
dy1=y1-y0; // 第一線段的斜率 m1=dy1/dx1
dx2=x2-x0; // 第二線段的斜率 m2=dy2/dx2
dy2=y2-y0;
if(dx1*dy2>dy1*dx2)
return 1;
if(dx1*dy2=0)
M--;
M ;
temp[0]=p[M][0];
temp[1]=p[M][1];// 將不是該凸面體的端點對調
p[M][0]=p[i][0];
p[M][1]=p[i][1];
p[i][0]=temp[0];
p[i][1]=temp[1];
}
return M; // 傳回在凸多邊形上的頂點數
} int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
int wnd_W=420;
int wnd_H=330;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "視窗類別登記失敗!", "發生錯誤!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
szAppName,"XXX",WS_OVERLAPPEDWINDOW,
nTopXY(wnd_W, GetSystemMetrics(SM_CXSCREEN)),
nTopXY(wnd_H, GetSystemMetrics(SM_CYSCREEN)),
wnd_W,wnd_H, NULL, NULL, hInstance, NULL); if(hwnd == NULL) {
MessageBox(NULL, "視窗建立失敗!", "發生錯誤!",MB_ICONEXCLAMATION | MB_OK);
return 0;
} ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
} LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hBtn, hBtn2;
HDC hMyDC;
PAINTSTRUCT ps;
switch(msg) {
case WM_CREATE:
hBtn = CreateWindowEx(
WS_EX_CLIENTEDGE,TEXT("BUTTON"),"清除",
WS_CHILD | WS_BORDER | WS_VISIBLE | BS_DEFPUSHBUTTON ,
0, 0, 205, 30, hwnd,(HMENU) nBtn_ID,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
if(hBtn == NULL) {
MessageBox(NULL, "按鈕建立失敗!", "發生錯誤!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
hBtn2 = CreateWindowEx(
WS_EX_CLIENTEDGE,TEXT("BUTTON"),"執行",
WS_CHILD | WS_BORDER | WS_VISIBLE | BS_DEFPUSHBUTTON ,
205, 0, 205, 30, hwnd,(HMENU) nBtn2_ID,
((LPCREATESTRUCT) lParam)->hInstance, NULL);
if(hBtn == NULL) {
MessageBox(NULL, "按鈕建立失敗!", "發生錯誤!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
return 0;
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case nBtn_ID:
// SendMessage(hwnd,WM_CLOSE,0,0);
tt=CountPoint=N=GrahamIndex=0;
wsprintf(szText,"點的個數:%d",CountPoint);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
break;
case nBtn2_ID:
tt=1;
GrahamIndex=graham_scan(p2, N);
InvalidateRect(hwnd, NULL, TRUE);
return 0;
break;
}
return 0;
break;
case WM_LBUTTONDOWN:
Pxy[CountPoint][0] = LOWORD(lParam);
p2[CountPoint][0] = LOWORD(lParam);
Pxy[CountPoint][1] = HIWORD(lParam);
p2[CountPoint][1] = 350-HIWORD(lParam);
CountPoint ;
N = CountPoint;
InvalidateRect(hwnd, NULL, TRUE);
wsprintf(szText,"點的個數:%d",CountPoint);
UpdateWindow(hwnd);
return 0;
break;
case WM_PAINT:
hMyDC=BeginPaint(hwnd, &ps);
for(i=0 ; i < CountPoint ; i )
Ellipse(hMyDC, Pxy[i][0] 5,Pxy[i][1] 5,Pxy[i][0]-5,Pxy[i][1]-5);
if(tt==1) {
for(i=0 ; i