Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CEditView::Create において SystemParametersInfo 呼び出しが失敗した場合の対策を追加 #527

Merged
merged 3 commits into from
Oct 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions sakura_core/view/CEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,18 @@ BOOL CEditView::Create(

/* キーボードの現在のリピート間隔を取得 */
DWORD dwKeyBoardSpeed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • dwKeyBoardSpeed のデフォルトは const の変数として定義した方がいいと思います。
  • 392行目では直値を使わず、その定義した const の変数を使った方がいいと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8927c9b で、直値を何度も使わずに定数宣言して使うように修正しました。

SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &dwKeyBoardSpeed, 0 );
constexpr DWORD keyboardRepeatSpeedMax = 31; // 0~31の範囲の最大値
if( SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &dwKeyBoardSpeed, 0 ) ){
// 念の為に assert で確認
assert(dwKeyBoardSpeed <= keyboardRepeatSpeedMax);
}
else{
// SystemParametersInfo の呼び出しが失敗した場合は最大値をデフォルト値として設定
constexpr DWORD keyboardRepeatSpeedDefault = keyboardRepeatSpeedMax;
dwKeyBoardSpeed = keyboardRepeatSpeedDefault;
}
/* リピート速度の設定をミリ秒に変換 */
UINT uElapse = 400 - dwKeyBoardSpeed * (400 - 33) / 31;
UINT uElapse = 400 - dwKeyBoardSpeed * (400 - 33) / keyboardRepeatSpeedMax;
/* タイマー起動 */
if( 0 == ::SetTimer( GetHwnd(), IDT_ROLLMOUSE, uElapse, EditViewTimerProc ) ){
WarningMessage( GetHwnd(), LS(STR_VIEW_TIMER) );
Expand Down