分類:[C/C++]
2010/04/05(Mon) 23:42:30 編集(投稿者)
C++、Win32APIでクリックした点を順番に直線で結ぶプログラムを組みたいのですがうまくいきません
何がおかしいんでしょうか?
どなたか助けてください
#include<windows.h>
#define AN TEXT("SampleWindow")
int pc=0;
LRESULT CALLBACK WindowProc(
HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam
){
HDC hdc;
PAINTSTRUCT ps;
POINT pt[255]={};
TCHAR str[255];
switch(uMsg){
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
//if(pc<=0)return 0;
hdc = BeginPaint(hWnd,&ps);
//if(pc>=1){
MoveToEx(hdc,pt[0].x,pt[0].y,NULL);
for(int i=1;i<pc;i++){
LineTo(hdc,pt[i].x,pt[i].y);
}
//}
EndPaint(hWnd,&ps);
return 0;
case WM_LBUTTONDOWN:
pt[pc].x=LOWORD(lParam);
pt[pc].y=HIWORD(lParam);
hdc = GetDC(hWnd);
wsprintf(str,"pt[%d]=(%d,%d)",pc,pt[pc].x,pt[pc].y);
TextOut(hdc,15,15,str,lstrlen(str));
ReleaseDC(hWnd,hdc);
pc+=1;
return 0;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR lpCmdLine,
int nCmdShow
){
WNDCLASS wc;
MSG msg;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)COLOR_BACKGROUND + 1;
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hInstance;
wc.lpfnWndProc=WindowProc;
wc.lpszClassName=AN;
wc.lpszMenuName=NULL;
wc.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wc))return 0;
if(CreateWindow(
AN,TEXT(__FILE__),
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL)==NULL)return 0;
while(GetMessage(&msg,NULL,0,0)>0){
DispatchMessage(&msg);
}
return msg.wParam;
}