10 #define DEFAULT_PARAM "-t 2 -c 100"
13 #define DrawLine(dc,x1,y1,x2,y2,c) \
15 HPEN hpen = CreatePen(PS_SOLID,0,c); \
16 HPEN horig = SelectPen(dc,hpen); \
17 MoveToEx(dc,x1,y1,NULL); \
19 SelectPen(dc,horig); \
56 LRESULT CALLBACK
WndProc(HWND, UINT, WPARAM, LPARAM);
58 int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
59 PSTR szCmdLine,
int iCmdShow)
61 static char szAppName[] =
"SvmToy";
65 wndclass.cbSize =
sizeof(wndclass);
66 wndclass.style = CS_HREDRAW | CS_VREDRAW;
68 wndclass.cbClsExtra = 0;
69 wndclass.cbWndExtra = 0;
70 wndclass.hInstance = hInstance;
71 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
72 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
73 wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
74 wndclass.lpszMenuName = NULL;
75 wndclass.lpszClassName = szAppName;
76 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
78 RegisterClassEx(&wndclass);
95 CreateWindow(
"button",
"Change", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
97 CreateWindow(
"button",
"Run", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
99 CreateWindow(
"button",
"Clear", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
101 CreateWindow(
"button",
"Save", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
103 CreateWindow(
"button",
"Load", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
106 edit = CreateWindow(
"edit", NULL, WS_CHILD | WS_VISIBLE,
121 while (GetMessage(&msg, NULL, 0, 0)) {
122 TranslateMessage(&msg);
123 DispatchMessage(&msg);
130 OPENFILENAME OpenFileName;
131 memset(&OpenFileName,0,
sizeof(OpenFileName));
134 OpenFileName.lStructSize =
sizeof(OPENFILENAME);
135 OpenFileName.hwndOwner = hWnd;
136 OpenFileName.lpstrFile = filename;
137 OpenFileName.nMaxFile = len;
138 OpenFileName.Flags = 0;
140 return save?GetSaveFileName(&OpenFileName):GetOpenFileName(&OpenFileName);
153 else if(v==2)
return brush2;
160 rect.left = int(p.
x*
XLEN);
161 rect.top = int(p.
y*
YLEN);
162 rect.right = int(p.
x*
XLEN) + 3;
163 rect.bottom = int(p.
y*
YLEN) + 3;
201 Edit_GetLine(
edit, 0, str,
sizeof(str));
205 while (*p && *p !=
'-')
254 while(*p && !isspace(*p)) ++p;
291 int *j =
new int[
XLEN];
293 for (i = 0; i <
XLEN; i++)
303 for(
int i=1; i <
XLEN; i++)
342 prob.
y[i] = q->value;
352 for (i = 0; i <
XLEN; i++)
353 for (j = 0; j <
YLEN; j++) {
372 LRESULT CALLBACK
WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
380 int x = LOWORD(lParam);
381 int y = HIWORD(lParam);
389 hdc = BeginPaint(hwnd, &ps);
396 int id = LOWORD(wParam);
413 FILE *fp = fopen(filename,
"w");
416 Edit_GetLine(
edit, 0, str,
sizeof(str));
418 const char* svm_type_str = strstr(p,
"-s ");
419 int svm_type =
C_SVC;
420 if(svm_type_str != NULL)
421 sscanf(svm_type_str,
"-s %d", &svm_type);
428 fprintf(fp,
"%f 1:%f\n", p->y, p->x);
433 fprintf(fp,
"%d 1:%f 2:%f\n", p->value, p->x, p->y);
445 FILE *fp = fopen(filename,
"r");
450 while(fgets(buf,
sizeof(buf),fp))
454 if(sscanf(buf,
"%d%*d:%lf%*d:%lf",&v,&
x,&y)==3)
459 else if(sscanf(buf,
"%lf%*d:%lf",&y,&
x)==2)
481 return DefWindowProc(hwnd, iMsg, wParam, lParam);