LRESULT CALLBACK EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HANDLE hwndText; static int sizeX, sizeY; int len, newSizeX, newSizeY; char *str; RECT rect; MINMAXINFO *mmi; int err; switch (message) { case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ Translate(hDlg, DLG_EditTags); hwndText = memo = GetDlgItem(hDlg, OPT_TagsText); SendMessage(hwndText, WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0)); SetDlgItemText(hDlg, OPT_TagsText, editTagsText); EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags); EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags || bookUp); SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0); if (bookUp) { SetDlgItemText(hDlg, OPT_EditTags, _("&Play Move")); SetWindowText(hDlg, _("Edit Book")); SetFocus(hwndText); } else if (canEditTags) { SetWindowText(hDlg, _("Edit Tags")); SetFocus(hwndText); } else { SetWindowText(hDlg, _("Tags")); SetFocus(GetDlgItem(hDlg, IDOK)); } if (!editTagsDialog) { editTagsDialog = hDlg; GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; SendDlgItemMessage( hDlg, OPT_TagsText, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); if (wpTags.x != CW_USEDEFAULT && wpTags.y != CW_USEDEFAULT && wpTags.width != CW_USEDEFAULT && wpTags.height != CW_USEDEFAULT) { WINDOWPLACEMENT wp; EnsureOnScreen(&wpTags.x, &wpTags.y, 0, 0); wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_SHOW; wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0; wp.rcNormalPosition.left = wpTags.x; wp.rcNormalPosition.right = wpTags.x + wpTags.width; wp.rcNormalPosition.top = wpTags.y; wp.rcNormalPosition.bottom = wpTags.y + wpTags.height; SetWindowPlacement(hDlg, &wp); GetClientRect(hDlg, &rect); newSizeX = rect.right; newSizeY = rect.bottom; ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; } } return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case OPT_TagsSave: if (canEditTags) { char *p, *q; /* Read changed options from the dialog box */ len = GetWindowTextLength(hwndText); str = (char *) malloc(len + 1); GetWindowText(hwndText, str, len + 1); p = q = str; while (*q) { if (*q == '\r') q++; else *p++ = *q++; } *p = NULLCHAR; err = 0; if(resPtr) *resPtr = strdup(str); else if(bookUp) SaveToBook(str), DisplayBook(currentMove); else err = ReplaceTags(str, &gameInfo); if (err) DisplayError(_("Error replacing tags."), err); free(str); } if(LOWORD(wParam) == IDOK) TagsPopDown(); return TRUE; case IDCANCEL: case OPT_TagsCancel: TagsPopDown(); return TRUE; case OPT_EditTags: if(bookUp) addToBookFlag = !addToBookFlag; else EditTagsEvent(); return TRUE; default: break; } break; case WM_NOTIFY: // [HGM] vari: cloned from whistory.c if( wParam == OPT_TagsText ) { MSGFILTER * lpMF = (MSGFILTER *) lParam; if( lpMF->msg == WM_RBUTTONDOWN ) { POINTL pt; LRESULT index; pt.x = LOWORD( lpMF->lParam ); pt.y = HIWORD( lpMF->lParam ); index = SendDlgItemMessage( hDlg, OPT_TagsText, EM_CHARFROMPOS, 0, (LPARAM) &pt ); hwndText = GetDlgItem(hDlg, OPT_TagsText); // cloned from above len = GetWindowTextLength(hwndText); str = (char *) malloc(len + 1); GetWindowText(hwndText, str, len + 1); if(bookUp) PlayBookMove(str, index); free(str); /* Zap the message for good: apparently, returning non-zero is not enough */ lpMF->msg = WM_USER; return TRUE; } } break; case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; break; case WM_GETMINMAXINFO: /* Prevent resizing window too small */ mmi = (MINMAXINFO *) lParam; mmi->ptMinTrackSize.x = 100; mmi->ptMinTrackSize.y = 100; break; } return FALSE; }
unsigned __stdcall ThinkThread( LPVOID _p ){ /************************************************************** 思考ルーチンを呼び出すスレッド **************************************************************/ int ret = 0; THINK_INFO info; MOVE* pmove = (MOVE*)_p; MOVE move; MMRESULT tid; int num; int msec_mate = 0; memset( &info, 0, sizeof(THINK_INFO) ); // 定跡を調べる。 if( pbook != NULL ){ ret = pbook->GetMove( pshogi, move ); if( ret != 0 ){ // 定跡の表示 moves.Init(); num = pbook->GetMoveAll( pshogi, moves ); DisplayBook( num, moves ); } } if( ret == 0 ){ // 詰み探索 sikou_flag = 1; // タイマーオン if( limit > 0 ){ // 詰みを調べる時間(最大1秒) msec_mate = limit * 1000 / 10; if( msec_mate > 1000 ){ msec_mate = 1000; } tid = timeSetEvent( msec_mate, 10, timelimit2, 0, TIME_ONESHOT ); } ret = pthink->DfPnSearch( pshogi, &move, NULL, &info, &chudanDfPn ); // タイマーオフ if( limit > 0 ){ timeKillEvent( tid ); } if( ret ){ DisplayResult( &info ); AddProgress( pshogi->GetStrMove( move ).c_str() ); } } if( ret == 0 ){ // 通常探索 sikou_flag = 1; // タイマーオン if( limit > 0 ){ tid = timeSetEvent( limit * 1000 - msec_mate, 10, timelimit, 0, TIME_ONESHOT ); } // 反復深化探索 ret = pthink->Search( pshogi, &move, 32, &info, &chudan, 1 ); // タイマーオフ if( limit > 0 ){ timeKillEvent( tid ); } DisplayResult( &info ); // 投了 if( ret != 0 && presign->bad( info ) ){ ret = 0; } } sikou_flag = 0; if( ret == 0 ) // 指し手がない return (DWORD)0; *(pmove) = move; return (DWORD)1; }