LRESULT CALLBACK CAutoSnapShot::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CAutoSnapShot *pThis=static_cast<CAutoSnapShot*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); } return TRUE; case WM_TIMER: { CAutoSnapShot *pThis=GetThis(hwnd); // キャプチャ実行 pThis->m_pApp->SaveImage(); } return 0; case WM_DESTROY: { CAutoSnapShot *pThis=GetThis(hwnd); if (pThis->m_fEnabled) ::KillTimer(hwnd,1); // 別にしなくてもいいけど... } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
Uint4 CDBConnParamsBase::GetProtocolVersion(void) const { if (!m_ProtocolVersion) { const string driver_name = GetThis().GetDriverName(); // Artificial intelligence ... switch (GetThis().GetServerType()) { case eSybaseOpenServer: if (NStr::Compare(driver_name, "ftds") == 0) { return 125; } case eSybaseSQLServer: // ftds64 can autodetect tds version by itself. if (NStr::Compare(driver_name, "dblib") == 0) { // Due to the bug in the Sybase 12.5 server, DBLIB cannot do // BcpIn to it using protocol version other than "100". return 100; } default: break; } } return m_ProtocolVersion; }
void PBLineEdit::enttext_handler(char *text) { PBLineEdit* pThis = GetThis(); if (pThis) pThis->EntText_Handler(text); return; }
void XOrderDialog::OnCreate() { // 대화창 UI를 생성한다. // 좌표보존 옵션이면 이 좌표를 백업받는다. XE::VEC2 vPos( 0, 43 ); vPos.x = m_spProp->m_vPos.x; vPos.y = m_spProp->m_vPos.y; if( m_spProp->m_bSavePos ) { // 좌표보존옵션일때 좌표를 백업받는다. s_vSavePos = vPos; } else { // 보존된 좌표가 있으면 그것을 쓴다. if( !s_vSavePos.IsMinus() ) vPos = s_vSavePos; } // 대화창 생성 { if( vPos.y == -1.f ) vPos.y = 43; auto pPropHero = PROP_HERO->GetpProp( m_spProp->m_strTalker ); XSPHero pHero = nullptr; if( XASSERT( pPropHero ) ) { // 영웅얼굴을 그리기위해 현재씬에 영웅객체를 요구한다. pHero = GAME->GetpScene()->GetpHero( pPropHero->idProp ); // _tstring szRes = XE::MakePath( DIR_IMG, pPropHero->strFace ); // pWnd->SetstrFaceRes( szRes ); // 대화창이 시작될때 씬에 이벤트 날림. } // dialog.으로 시작하는 윈도우 모두 삭제,. for( int i = 0; i < 10; ++i ) { auto pWndPrev = GAME->FindWithPrefix( "__dialog." ); // 이 접두사로 시작하는 윈도우를 찾음. if( pWndPrev ) { pWndPrev->SetbDestroy( true ); // 더이상 안나올때까지 반복. } else { break; } } auto pWnd = new XWndOrderDialog( GetThis(), vPos, pPropHero->idProp, pHero ); pWnd->SetstrIdentifierf( "__dialog.%s.%d", GetpSeq()->GetspProp()->m_strIdentifier.c_str(), GetidxOrder() ); m_idsWnd = pWnd->GetstrIdentifier(); auto strText = m_spProp->GetstrText(); XGAME::sReplaceToken( strText, _T( "#nick#" ), ACCOUNT->GetstrName() ); TCHAR szBuff[ 1024 ]; XE::ConvertJosaStr( szBuff, strText ); pWnd->SetstrText( szBuff ); if( m_spProp->m_typeEnd == xFIN_TOUCH ) { pWnd->SetbTouch( true ); } GAME->GetpRootSeq()->Add( pWnd ); // x좌표가 지정되지 않았을때 자동정렬한다. if( vPos.x == -1.f ) pWnd->AutoLayoutHCenter(); GAME->GetpScene()->OnCreateOrderDialog( pPropHero->idProp ); } }
Uint2 CDBInterfacesFileConnParams::GetPort(void) const { const string server_name = GetThis().GetServerName(); records_type::const_iterator it = m_Records.find(server_name); if (it != m_Records.end()) { return it->second.m_Port; } return CDBConnParamsDelegate::GetPort(); }
JSBool JetpackChild::UnregisterReceivers(JSContext* cx, uintN argc, jsval* vp) { ReceiverResult rr; if (!ReceiverCommon(cx, argc, vp, "unregisterReceivers", 1, &rr)) return JS_FALSE; JetpackActorCommon* actor = GetThis(cx); actor->UnregisterReceivers(rr.msgName); return JS_TRUE; }
PrivateD3D10ProviderData::PrivateD3D10ProviderData(DeviceManagerD3D10 *deviceManager, ProviderD3D10Impl *providerD3D10, ProviderBinding *binding) : m_providerBinding(Referrer(GetThis()), binding) , m_d3dDeviceManager(deviceManager) , m_provider(providerD3D10) , m_needFlagsRefresh(false) #ifndef NDEBUG , m_lockedForWrite(false) , m_lockedForReadCount(0) #endif { binding->GetWatch(&m_providerBindingWatch); m_d3dDeviceManager->AddListener(this); }
ObjectBase::~ObjectBase() { // remove the reference in the parent PObjectBase parent = m_parent.lock(); if (parent) { PObjectBase pobj(GetThis()); parent->RemoveChild(pobj); } LogDebug(wxT("delete ObjectBase")); }
JSBool JetpackChild::SendMessage(JSContext* cx, uintN argc, jsval* vp) { MessageResult smr; if (!MessageCommon(cx, argc, vp, &smr)) return JS_FALSE; if (!GetThis(cx)->SendSendMessage(smr.msgName, smr.data)) { JS_ReportError(cx, "Failed to sendMessage"); return JS_FALSE; } return JS_TRUE; }
ObjectBase::~ObjectBase() { s_instances--; // eliminamos la referencia en el padre shared_ptr<ObjectBase> parent = m_parent.lock(); if (parent) { shared_ptr<ObjectBase> pobj(GetThis()); parent->RemoveChild(pobj); } Debug::Print(wxT("delete ObjectBase (%d)"),s_instances); }
JSBool JetpackChild::RegisterReceiver(JSContext* cx, uintN argc, jsval* vp) { ReceiverResult rr; if (!ReceiverCommon(cx, argc, vp, "registerReceiver", 2, &rr)) return JS_FALSE; JetpackActorCommon* actor = GetThis(cx); nsresult rv = actor->RegisterReceiver(cx, rr.msgName, rr.receiver); if (NS_FAILED(rv)) { JS_ReportOutOfMemory(cx); return JS_FALSE; } return JS_TRUE; }
Uint2 CDBConnParamsBase::GetPort(void) const { if (!m_PortNumber) { // Artificial intelligence ... switch (GetThis().GetServerType()) { case eSybaseOpenServer: return 2133U; case eSybaseSQLServer: return 2158U; case eMSSqlServer: return 1433U; default: break; } } return m_PortNumber; }
// ウィンドウプロシージャ // 単にタイマーを処理するだけ LRESULT CALLBACK CSleepTimer::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CSleepTimer *pThis=static_cast<CSleepTimer*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); } return TRUE; case WM_TIMER: { CSleepTimer *pThis=GetThis(hwnd); TVTest::RecordStatusInfo Info; pThis->m_pApp->EnablePlugin(false); // タイマーは一回限り有効 ::KillTimer(hwnd,wParam); // EventCallbackで呼ばれるはずだが、念のため if (pThis->m_fConfirm) { // 確認ダイアログを表示 if (::DialogBoxParam(g_hinstDLL,MAKEINTRESOURCE(IDD_CONFIRM), pThis->m_pApp->GetAppWindow(),ConfirmDlgProc, reinterpret_cast<LPARAM>(pThis))!=IDOK) return 0; } // 録画中はスリープ実行しない if (!pThis->m_pApp->GetRecordStatus(&Info) || Info.Status!=TVTest::RECORD_STATUS_NOTRECORDING) { pThis->m_pApp->AddLog(L"録画中なのでスリープがキャンセルされました。"); return 0; } // スリープ実行 pThis->DoSleep(); } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
string CDBConnParamsBase::GetDriverName(void) const { if (m_DriverName.empty()) { // Return a blessed driver name ... switch (GetThis().GetServerType()) { case eSybaseOpenServer: case eSybaseSQLServer: #ifdef HAVE_LIBSYBASE return "ctlib"; #else return "ftds"; #endif case eMSSqlServer: return "ftds"; default: return "unknown_driver"; } } return m_DriverName; }
CDBConnParams::EServerType CDBInterfacesFileConnParams::GetServerType(void) const { const string server_name = GetThis().GetServerName(); records_type::const_iterator it = m_Records.find(server_name); if (it != m_Records.end()) { switch(it->second.m_Port) { case 2133U: return eSybaseOpenServer; case 2158U: return eSybaseSQLServer; case 1433: return eMSSqlServer; default: break; } } return CDBConnParamsDelegate::GetServerType(); }
JSBool JetpackChild::CreateHandle(JSContext* cx, uintN argc, jsval* vp) { if (argc > 0) { JS_ReportError(cx, "createHandle takes zero arguments"); return JS_FALSE; } HandleChild* handle; JSObject* hobj; PHandleChild* phc = GetThis(cx)->SendPHandleConstructor(); if (!(handle = static_cast<HandleChild*>(phc)) || !(hobj = handle->ToJSObject(cx))) { JS_ReportError(cx, "Failed to construct Handle"); return JS_FALSE; } JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(hobj)); return JS_TRUE; }
JSBool JetpackChild::CallMessage(JSContext* cx, uintN argc, jsval* vp) { MessageResult smr; if (!MessageCommon(cx, argc, vp, &smr)) return JS_FALSE; InfallibleTArray<Variant> results; if (!GetThis(cx)->CallCallMessage(smr.msgName, smr.data, &results)) { JS_ReportError(cx, "Failed to callMessage"); return JS_FALSE; } nsAutoTArray<jsval, 4> jsvals; jsval* rvals = jsvals.AppendElements(results.Length()); if (!rvals) { JS_ReportOutOfMemory(cx); return JS_FALSE; } for (PRUint32 i = 0; i < results.Length(); ++i) rvals[i] = JSVAL_VOID; js::AutoArrayRooter root(cx, results.Length(), rvals); for (PRUint32 i = 0; i < results.Length(); ++i) if (!jsval_from_Variant(cx, results.ElementAt(i), rvals + i)) { JS_ReportError(cx, "Invalid result from handler %d", i); return JS_FALSE; } JSObject* arrObj = JS_NewArrayObject(cx, results.Length(), rvals); if (!arrObj) { JS_ReportOutOfMemory(cx); return JS_FALSE; } JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(arrObj)); return JS_TRUE; }
// ウィンドウプロシージャ // 単にタイマーを処理するだけ LRESULT CALLBACK CDiskRelay::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CDiskRelay *pThis=static_cast<CDiskRelay*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); } return TRUE; case WM_TIMER: { CDiskRelay *pThis=GetThis(hwnd); pThis->CheckFreeSpace(); } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
/* static */ void JetpackChild::ReportError(JSContext* cx, const char* message, JSErrorReport* report) { if (sReportingError) { NS_WARNING("Recursive error reported."); return; } sReportingError = true; js::AutoObjectRooter obj(cx, JS_NewObject(cx, NULL, NULL, NULL)); if (report && report->filename) { jsval filename = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, report->filename)); JS_SetProperty(cx, obj.object(), "fileName", &filename); } if (report) { jsval lineno = INT_TO_JSVAL(report->lineno); JS_SetProperty(cx, obj.object(), "lineNumber", &lineno); } jsval msgstr = JSVAL_NULL; if (report && report->ucmessage) msgstr = STRING_TO_JSVAL(JS_NewUCStringCopyZ(cx, report->ucmessage)); else msgstr = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, message)); JS_SetProperty(cx, obj.object(), "message", &msgstr); MessageResult smr; Variant* vp = smr.data.AppendElement(); JetpackActorCommon::jsval_to_Variant(cx, OBJECT_TO_JSVAL(obj.object()), vp); GetThis(cx)->SendSendMessage(NS_LITERAL_STRING("core:exception"), smr.data); sReportingError = false; }
// ウィンドウプロシージャ LRESULT CALLBACK CEqualizer::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CEqualizer *pThis=static_cast<CEqualizer*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); pThis->m_hwnd=hwnd; pThis->GetColor(); // フォント作成 LOGFONT lf; ::GetObject(::GetStockObject(DEFAULT_GUI_FONT),sizeof(LOGFONT),&lf); lf.lfHeight=-TEXT_HEIGHT; pThis->m_hfont=::CreateFontIndirect(&lf); // ウィンドウを最初に表示した時にイコライザーを有効化する if (!pThis->m_fEnable && !pThis->m_fExecuted) pThis->EnableEqualizer(true); } return 0; case WM_PAINT: { CEqualizer *pThis=GetThis(hwnd); PAINTSTRUCT ps; HBRUSH hbr,hbrOld; HPEN hpen,hpenOld; HFONT hfontOld; COLORREF crOldTextColor; int OldBkMode; RECT rc,rcSlider,rcText; int i; TCHAR szText[16]; ::BeginPaint(hwnd,&ps); hbr=::CreateSolidBrush(pThis->m_crBackColor); ::FillRect(ps.hdc,&ps.rcPaint,hbr); ::DeleteObject(hbr); hbr=::CreateSolidBrush( pThis->m_fEnable?pThis->m_crTextColor: RGB((GetRValue(pThis->m_crTextColor)+GetRValue(pThis->m_crBackColor))/2, (GetGValue(pThis->m_crTextColor)+GetGValue(pThis->m_crBackColor))/2, (GetBValue(pThis->m_crTextColor)+GetBValue(pThis->m_crBackColor))/2)); hpen=::CreatePen(PS_SOLID,1,pThis->m_crTextColor); hpenOld=static_cast<HPEN>(::SelectObject(ps.hdc,hpen)); hbrOld=static_cast<HBRUSH>(::SelectObject(ps.hdc,::GetStockObject(NULL_BRUSH))); hfontOld=static_cast<HFONT>(::SelectObject(ps.hdc,pThis->m_hfont)); crOldTextColor=::SetTextColor(ps.hdc,pThis->m_crTextColor); OldBkMode=::SetBkMode(ps.hdc,TRANSPARENT); // プリアンプ rc.left=WINDOW_MARGIN; rc.top=WINDOW_MARGIN; rc.right=rc.left+SLIDER_WIDTH; rc.bottom=rc.top+SLIDER_HEIGHT; ::Rectangle(ps.hdc,rc.left,rc.top,rc.right,rc.bottom); rcSlider.left=rc.left+2; rcSlider.right=rc.right-2; rcSlider.bottom=rc.bottom-2; rcSlider.top=pThis->CalcSliderPos(pThis->m_CurSettings.PreAmplifier); if (rcSlider.top<rcSlider.bottom) ::FillRect(ps.hdc,&rcSlider,hbr); rcText.left=rc.left-SLIDER_MARGIN/2; rcText.right=rc.right+SLIDER_MARGIN/2; rcText.top=rc.bottom+SLIDER_TEXT_MARGIN; rcText.bottom=rcText.top+TEXT_HEIGHT; ::DrawText(ps.hdc,TEXT("Pre"),-1,&rcText,DT_CENTER | DT_SINGLELINE); // 目盛 rc.left=rc.right+SLIDER_MARGIN; rc.right=rc.left+SLIDER_WIDTH; for (i=-10;i<=10;i+=5) { int y=pThis->CalcSliderPos(i); ::MoveToEx(ps.hdc,rc.left+2,y,NULL); ::LineTo(ps.hdc,rc.right-2,y); } // 各周波数 int Freq=3125; for (i=0;i<NUM_FREQUENCY;i++) { rc.left=rc.right+SLIDER_MARGIN; rc.right=rc.left+SLIDER_WIDTH; ::Rectangle(ps.hdc,rc.left,rc.top,rc.right,rc.bottom); rcSlider.left=rc.left+2; rcSlider.right=rc.right-2; rcSlider.top=pThis->CalcSliderPos(pThis->m_CurSettings.Frequency[i]); if (rcSlider.top<rcSlider.bottom) ::FillRect(ps.hdc,&rcSlider,hbr); rcText.left=rc.left-SLIDER_MARGIN/2; rcText.right=rc.right+SLIDER_MARGIN/2; if (Freq<100000) ::wsprintf(szText,TEXT("%d"),Freq/100); else ::wsprintf(szText,TEXT("%dk"),Freq/(1000*100)); ::DrawText(ps.hdc,szText,-1,&rcText,DT_CENTER | DT_SINGLELINE); Freq*=2; } // ボタンの描画 static const LPCTSTR pszButtonText[NUM_BUTTONS] = { TEXT("On/Off"), TEXT("Flat"), TEXT("Load"), TEXT("Save") }; for (i=0;i<NUM_BUTTONS;i++) { pThis->GetButtonRect(i,&rc); ::Rectangle(ps.hdc,rc.left,rc.top,rc.right,rc.bottom); ::DrawText(ps.hdc,pszButtonText[i],-1,&rc,DT_CENTER | DT_SINGLELINE | DT_VCENTER); } ::DeleteObject(hbr); ::SelectObject(ps.hdc,hpenOld); ::DeleteObject(hpen); ::SelectObject(ps.hdc,hfontOld); ::SetTextColor(ps.hdc,crOldTextColor); ::SetBkMode(ps.hdc,OldBkMode); ::EndPaint(hwnd,&ps); } return 0; case WM_LBUTTONDOWN: { CEqualizer *pThis=GetThis(hwnd); POINT pt; RECT rc; pt.x=GET_X_LPARAM(lParam); pt.y=GET_Y_LPARAM(lParam); if (pt.y>=WINDOW_MARGIN && pt.y<WINDOW_MARGIN+SLIDER_HEIGHT) { for (int i=-1;i<NUM_FREQUENCY;i++) { pThis->GetSliderRect(i,&rc); if (::PtInRect(&rc,pt)) { // スライダ int Pos=pThis->MapSliderPos(pt.y); if (i<0) pThis->m_CurSettings.PreAmplifier=Pos; else pThis->m_CurSettings.Frequency[i]=Pos; if (pThis->m_fEnable) { pThis->ApplySettings(); ::InvalidateRect(hwnd,&rc,TRUE); } else { pThis->EnableEqualizer(true); } ::UpdateWindow(hwnd); pThis->m_CurSlider=i; ::SetCapture(hwnd); break; } } } else { for (int i=0;i<NUM_BUTTONS;i++) { pThis->GetButtonRect(i,&rc); if (::PtInRect(&rc,pt)) { // ボタンが押された pThis->OnButtonPush(i); break; } } } } return 0; case WM_LBUTTONUP: if (::GetCapture()==hwnd) // スライダのドラッグ終了 ::ReleaseCapture(); return 0; case WM_MOUSEMOVE: if (::GetCapture()==hwnd) { // スライダのドラッグ CEqualizer *pThis=GetThis(hwnd); int Pos=pThis->MapSliderPos(GET_Y_LPARAM(lParam)); if (pThis->m_CurSlider<0) { if (pThis->m_CurSettings.PreAmplifier==Pos) return 0; pThis->m_CurSettings.PreAmplifier=Pos; } else { if (pThis->m_CurSettings.Frequency[pThis->m_CurSlider]==Pos) return 0; pThis->m_CurSettings.Frequency[pThis->m_CurSlider]=Pos; } RECT rc; pThis->GetSliderRect(pThis->m_CurSlider,&rc,true); ::InvalidateRect(hwnd,&rc,TRUE); ::UpdateWindow(hwnd); pThis->ApplySettings(); } return 0; case WM_SETCURSOR: if (LOWORD(lParam)==HTCLIENT) { // カーソル設定 CEqualizer *pThis=GetThis(hwnd); DWORD Pos=::GetMessagePos(); POINT pt; RECT rc; pt.x=GET_X_LPARAM(Pos); pt.y=GET_Y_LPARAM(Pos); ::ScreenToClient(hwnd,&pt); for (int i=-1;i<NUM_FREQUENCY;i++) { pThis->GetSliderRect(i,&rc); if (::PtInRect(&rc,pt)) { ::SetCursor(::LoadCursor(NULL,IDC_HAND)); return TRUE; } } for (int i=0;i<NUM_BUTTONS;i++) { pThis->GetButtonRect(i,&rc); if (::PtInRect(&rc,pt)) { ::SetCursor(::LoadCursor(NULL,IDC_HAND)); return TRUE; } } } break; case WM_SYSCOMMAND: if ((wParam&0xFFF0)==SC_CLOSE) { // 閉じる時はプラグインを無効にする // (勝手に閉じるとTVTestとの整合性が取れなくなるため) CEqualizer *pThis=GetThis(hwnd); pThis->m_pApp->EnablePlugin(false); return TRUE; } break; case WM_DESTROY: { CEqualizer *pThis=GetThis(hwnd); // 後始末 ::DeleteObject(pThis->m_hfont); // ウィンドウ位置保存 RECT rc; ::GetWindowRect(hwnd,&rc); pThis->m_WindowPosition.x=rc.left; pThis->m_WindowPosition.y=rc.top; pThis->m_hwnd=NULL; } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
LRESULT CALLBACK CTextInputCtrl::s_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HIMC himc; CTextInputCtrl *ptic; switch (message) { case WM_CREATE: SetThis(hwnd, ((CREATESTRUCT *)lParam)->lpCreateParams); SetTimer(hwnd, TIMERID_CARET, GetCaretBlinkTime(), NULL); GetThis(hwnd)->OnCreate(hwnd, wParam, lParam); break; case WM_PAINT: ptic = GetThis(hwnd); hdc = BeginPaint(hwnd, &ps); if (ptic) ptic->OnPaint(hdc); EndPaint(hwnd, &ps); break; case WM_KEYDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnKeyDown(wParam, lParam); break; case WM_LBUTTONDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnLButtonDown(wParam, lParam); break; case WM_LBUTTONUP: ptic = GetThis(hwnd); if (ptic) ptic->OnLButtonUp(wParam, lParam); break; case WM_RBUTTONDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnRButtonDown(wParam, lParam); break; case WM_RBUTTONUP: ptic = GetThis(hwnd); if (ptic) ptic->OnRButtonUp(wParam, lParam); break; case WM_MOUSEMOVE: ptic = GetThis(hwnd); if (ptic) ptic->OnMouseMove(wParam, lParam); break; case WM_SETFOCUS: // // Level 2 Support // ptic = GetThis(hwnd); if (ptic) { ptic->_editor.SetCompositionForm(); ptic->SetCompositionFont(); } break; case WM_IME_STARTCOMPOSITION: // // Level 2 Support // ptic = GetThis(hwnd); if (ptic) { ptic->_editor.OnStartComposition(); ptic->_editor.SetCompositionForm(); ptic->SetCompositionFont(); } // If it is a near caret IME, we should keep Level 2 path. if (IsNearCaretIME()) { return DefWindowProc(hwnd, message, wParam, lParam); } break; case WM_IME_COMPOSITION: himc = ImmGetContext(hwnd); if (himc) { BOOL fNearCaret = IsNearCaretIME(); if (lParam & GCS_RESULTSTR) { LONG nSize = ImmGetCompositionString(himc, GCS_RESULTSTR, NULL, 0); if (nSize) { LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, nSize + sizeof(WCHAR)); if (psz) { ImmGetCompositionString(himc, GCS_RESULTSTR, psz, nSize); ptic = GetThis(hwnd); if (ptic) { ptic->_editor.InsertResultAtComposition(psz); ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont); ptic->_editor.SetCompositionForm(); ptic->_editor.SetInterimCaret(FALSE); InvalidateRect(hwnd, NULL, TRUE); } LocalFree(psz); } } } if ((lParam & GCS_COMPSTR) && !fNearCaret) { LONG lDeltaStart = ImmGetCompositionString(himc, GCS_DELTASTART, NULL, 0); LONG lCursorPos = ImmGetCompositionString(himc, GCS_CURSORPOS, NULL, 0); LONG lSize = ImmGetCompositionString(himc, GCS_COMPSTR, NULL, 0); LONG lAttrSize = ImmGetCompositionString(himc, GCS_COMPATTR, NULL, 0); LONG lClauseInfoSize = ImmGetCompositionString(himc, GCS_COMPCLAUSE, NULL, 0); if (lSize) { BYTE *prgAttr = NULL; LONG *prgClauseInfo = NULL; LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, lSize + sizeof(WCHAR)); if (lAttrSize) prgAttr = (BYTE *)LocalAlloc(LPTR, lAttrSize + sizeof(BYTE)); if (lClauseInfoSize) prgClauseInfo = (LONG *)LocalAlloc(LPTR, lClauseInfoSize + sizeof(LONG)); if (psz) { if (ImmGetCompositionString(himc, GCS_COMPSTR, psz, lSize)) { if (prgAttr) { if (!ImmGetCompositionString(himc, GCS_COMPATTR, prgAttr, lAttrSize)) { prgAttr = NULL; lAttrSize = 0; } } if (prgClauseInfo) { if (!ImmGetCompositionString(himc, GCS_COMPCLAUSE, prgClauseInfo, lClauseInfoSize)) { prgClauseInfo = NULL; lClauseInfoSize = 0; } } ptic = GetThis(hwnd); if (ptic) { ptic->_editor.UpdateComposition(psz, lDeltaStart, lCursorPos, prgAttr, lAttrSize, prgClauseInfo, lClauseInfoSize); ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont); ptic->_editor.SetCompositionForm(); InvalidateRect(hwnd, NULL, TRUE); } } LocalFree(psz); } if (prgAttr) LocalFree(prgAttr); if (prgClauseInfo) LocalFree(prgClauseInfo); } if (lParam & CS_INSERTCHAR) { WCHAR sz[2]; sz[0] = (WCHAR)wParam; sz[1] = L'\0'; ptic->_editor.SetInterimCaret(TRUE); ptic->_editor.UpdateComposition(sz, 0, 0, NULL, 0, NULL, 0); ptic->_editor.MoveSelectionToComposition(); ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont); ptic->_editor.SetCompositionForm(); InvalidateRect(hwnd, NULL, TRUE); } } ImmReleaseContext(hwnd, himc); // If it is a near caret IME, we should keep Level 2 path. if ((lParam & GCS_COMPSTR) && fNearCaret) { lParam &= ~(GCS_RESULTCLAUSE | GCS_RESULTREADCLAUSE | GCS_RESULTREADSTR | GCS_RESULTSTR); return DefWindowProc(hwnd, message, wParam, lParam); } } break; case WM_IME_ENDCOMPOSITION: // The composition ends. ptic = GetThis(hwnd); if (ptic) { // We need to clear the attributes. // There is a case that the composition string is canceled and it did not // completed (GCS_RESULTSTR did not come). ptic->_editor.ClearAttrAndClauseInfo(); ptic->_editor.UpdateLayout(&ptic->_lfCurrentFont); InvalidateRect(hwnd, NULL, TRUE); } // If it is a near caret IME, we should keep Level 2 path. if (IsNearCaretIME()) { return DefWindowProc(hwnd, message, wParam, lParam); } break; case WM_IME_NOTIFY: if (wParam == IMN_OPENCANDIDATE) { ptic = GetThis(hwnd); if (ptic) { ptic->_editor.SetCandidateForm(); } } return DefWindowProc(hwnd, message, wParam, lParam); case WM_IME_SETCONTEXT: return DefWindowProc(hwnd, message, wParam, lParam & ~ISC_SHOWUICOMPOSITIONWINDOW); case WM_IME_REQUEST: switch (wParam) { case IMR_QUERYCHARPOSITION: { ptic = GetThis(hwnd); if (ptic) { ptic->_editor.QueryCharPosition((IMECHARPOSITION *)lParam); return 1; } } case IMR_DOCUMENTFEED: { ptic = GetThis(hwnd); if (ptic) { return ptic->_editor.OnDocumentFeed((RECONVERTSTRING *)lParam); } } case IMR_RECONVERTSTRING: { ptic = GetThis(hwnd); if (ptic) { return ptic->_editor.OnReconvertString((RECONVERTSTRING *)lParam); } } case IMR_CONFIRMRECONVERTSTRING: { ptic = GetThis(hwnd); if (ptic) { return ptic->_editor.OnConfirmReconvertString((RECONVERTSTRING *)lParam); } } } break; case WM_IME_CHAR: // // wParam is a character of the result string. // if we don't want to receive WM_CHAR message for this character, // we should not call DefWindowProc(). // return DefWindowProc(hwnd, message, wParam, lParam); case WM_CHAR: // // wParam is a character of the result string. // switch ((WCHAR)wParam) { case 0x08: case 0x0a: return 0; default: break; } ptic = GetThis(hwnd); if (ptic) { WCHAR wc[2]; wc[0] = (WCHAR)wParam; wc[1] = L'\0'; ptic->_editor.InsertAtSelection(wc); InvalidateRect(hwnd, NULL, TRUE); } break; case WM_TIMER: if (wParam == TIMERID_CARET) { ptic = GetThis(hwnd); if (ptic) { HDC hdc = GetDC(hwnd); ptic->_editor.BlinkCaret(hdc); ReleaseDC(hwnd, hdc); } } break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
// ウィンドウプロシージャ LRESULT CALLBACK CLogoList::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs = reinterpret_cast<LPCREATESTRUCT>(lParam); CLogoList *pThis = static_cast<CLogoList*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pThis)); pThis->m_hwnd = hwnd; pThis->m_hwndList = ::CreateWindowEx(0, TEXT("LISTBOX"), NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT, 0, 0, 0, 0, hwnd, NULL, g_hinstDLL, NULL); pThis->GetColors(); pThis->GetServiceList(); // アイテムの大きさを設定する pThis->m_ServiceNameWidth = 120; ::SendMessage(pThis->m_hwndList, LB_SETITEMHEIGHT, 0, 36 + ITEM_MARGIN * 2); int Width = pThis->m_ServiceNameWidth + ITEM_MARGIN * 2 + LOGO_MARGIN * 6; for (int i = 0; i < 6; i++) Width += LogoSizeList[i].Width; ::SendMessage(pThis->m_hwndList, LB_SETHORIZONTALEXTENT, Width, 0); for (size_t i = 0; i < pThis->m_ServiceList.size(); i++) ::SendMessage(pThis->m_hwndList, LB_ADDSTRING, 0, reinterpret_cast<LPARAM>(pThis->m_ServiceList[i])); // 更新用タイマー設定 ::SetTimer(hwnd, TIMER_UPDATELOGO, 60 * 1000, NULL); } return 0; case WM_SIZE: { CLogoList *pThis = GetThis(hwnd); ::MoveWindow(pThis->m_hwndList, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE); } return 0; case WM_DRAWITEM: // ロゴのリストのアイテムを描画 { CLogoList *pThis = GetThis(hwnd); LPDRAWITEMSTRUCT pdis = reinterpret_cast<LPDRAWITEMSTRUCT>(lParam); HBRUSH hbr = ::CreateSolidBrush(pThis->m_crBackColor); ::FillRect(pdis->hDC, &pdis->rcItem, hbr); ::DeleteObject(hbr); if ((int)pdis->itemID < 0 || pdis->itemID >= pThis->m_ServiceList.size()) return TRUE; const CServiceInfo *pService = pThis->m_ServiceList[pdis->itemID]; HFONT hfontOld = static_cast<HFONT>(::SelectObject(pdis->hDC, ::GetStockObject(DEFAULT_GUI_FONT))); int OldBkMode = ::SetBkMode(pdis->hDC, TRANSPARENT); COLORREF OldTextColor = ::SetTextColor(pdis->hDC, pThis->m_crTextColor); RECT rc; rc.left = pdis->rcItem.left + ITEM_MARGIN; rc.top = pdis->rcItem.top + ITEM_MARGIN; rc.right = rc.left + pThis->m_ServiceNameWidth; rc.bottom = pdis->rcItem.bottom - ITEM_MARGIN; ::DrawText(pdis->hDC, pService->m_szServiceName, -1, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_END_ELLIPSIS); ::SetTextColor(pdis->hDC, OldTextColor); ::SetBkMode(pdis->hDC, OldBkMode); ::SelectObject(pdis->hDC, hfontOld); HDC hdcMemory = ::CreateCompatibleDC(pdis->hDC); HGDIOBJ hOldBitmap = ::GetCurrentObject(hdcMemory, OBJ_BITMAP); int x = rc.right + LOGO_MARGIN; for (int i = 0; i < 6; i++) { if (pService->m_hbmLogo[i] != NULL) { ::SelectObject(hdcMemory, pService->m_hbmLogo[i]); ::BitBlt(pdis->hDC, x, rc.top + ((rc.bottom - rc.top) - LogoSizeList[i].Height) / 2, LogoSizeList[i].Width, LogoSizeList[i].Height, hdcMemory, 0, 0, SRCCOPY); } x += LogoSizeList[i].Width + LOGO_MARGIN; } if (::GetCurrentObject(hdcMemory, OBJ_BITMAP) != hOldBitmap) ::SelectObject(hdcMemory, hOldBitmap); ::DeleteDC(hdcMemory); } return TRUE; case WM_TIMER: // ロゴの更新 if (wParam == TIMER_UPDATELOGO) { CLogoList *pThis = GetThis(hwnd); if (pThis->UpdateLogo()) ::RedrawWindow(pThis->m_hwndList, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW); } return 0; case WM_SYSCOMMAND: if ((wParam & 0xFFF0) == SC_CLOSE) { // 閉じる時はプラグインを無効にする CLogoList *pThis = GetThis(hwnd); pThis->m_pApp->EnablePlugin(false); return TRUE; } break; case WM_NCDESTROY: { CLogoList *pThis = GetThis(hwnd); // ウィンドウ位置の記憶 RECT rc; ::GetWindowRect(hwnd, &rc); pThis->m_WindowPosition.Left = rc.left; pThis->m_WindowPosition.Top = rc.top; pThis->m_WindowPosition.Width = rc.right - rc.left; pThis->m_WindowPosition.Height = rc.bottom - rc.top; pThis->m_hwnd = NULL; pThis->m_hwndList = NULL; pThis->ClearServiceList(); } return 0; } return ::DefWindowProc(hwnd, uMsg, wParam, lParam); }
LRESULT CALLBACK CVideoRenderer_EVR::VideoWndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { CVideoRenderer_EVR *pThis=static_cast<CVideoRenderer_EVR*>( reinterpret_cast<LPCREATESTRUCT>(lParam)->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); } return 0; case WM_SIZE: { CVideoRenderer_EVR *pThis=GetThis(hwnd); if (pThis->m_pRenderer) { IMFVideoDisplayControl *pDisplayControl=GetVideoDisplayControl(pThis->m_pRenderer); if (pDisplayControl) { RECT rc; ::SetRect(&rc,0,0,LOWORD(lParam),HIWORD(lParam)); pDisplayControl->SetVideoPosition(NULL,&rc); } } } return 0; case WM_CHAR: case WM_DEADCHAR: case WM_KEYDOWN: case WM_KEYUP: case WM_SYSCHAR: case WM_SYSDEADCHAR: case WM_SYSKEYDOWN: case WM_SYSKEYUP: case WM_MOUSEACTIVATE: case WM_NCLBUTTONDBLCLK: case WM_NCLBUTTONDOWN: case WM_NCLBUTTONUP: case WM_NCRBUTTONDBLCLK: case WM_NCRBUTTONDOWN: case WM_NCRBUTTONUP: case WM_NCMBUTTONDBLCLK: case WM_NCMBUTTONDOWN: case WM_NCMBUTTONUP: case WM_NCMOUSEMOVE: { CVideoRenderer_EVR *pThis=GetThis(hwnd); if (pThis->m_hwndMessageDrain!=NULL) { ::PostMessage(pThis->m_hwndMessageDrain,uMsg,wParam,lParam); return 0; } } break; case WM_LBUTTONDBLCLK: case WM_LBUTTONDOWN: case WM_LBUTTONUP: case WM_RBUTTONDBLCLK: case WM_RBUTTONDOWN: case WM_RBUTTONUP: case WM_MBUTTONDBLCLK: case WM_MBUTTONDOWN: case WM_MBUTTONUP: case WM_MOUSEMOVE: { CVideoRenderer_EVR *pThis=GetThis(hwnd); if (pThis->m_hwndMessageDrain!=NULL) { POINT pt; pt.x=GET_X_LPARAM(lParam); pt.y=GET_Y_LPARAM(lParam); ::MapWindowPoints(hwnd,pThis->m_hwndMessageDrain,&pt,1); ::PostMessage(pThis->m_hwndMessageDrain,uMsg,wParam,MAKELPARAM(pt.x,pt.y)); return 0; } } break; case WM_SETCURSOR: if (LOWORD(lParam)==HTCLIENT) { CVideoRenderer_EVR *pThis=GetThis(hwnd); ::SetCursor(pThis->m_fShowCursor?::LoadCursor(NULL,IDC_ARROW):NULL); return TRUE; } break; case WM_DESTROY: { CVideoRenderer_EVR *pThis=GetThis(hwnd); pThis->m_hwndVideo=NULL; } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
// ダイアログプロシージャ INT_PTR CALLBACK CTSInfo::DlgProc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { CTSInfo *pThis=reinterpret_cast<CTSInfo*>(lParam); ::SetProp(hDlg,PROP_NAME,pThis); pThis->m_hwnd=hDlg; pThis->m_hbrBack=::CreateSolidBrush(pThis->m_pApp->GetColor(L"PanelBack")); pThis->m_crTextColor=pThis->m_pApp->GetColor(L"PanelText"); } return TRUE; case WM_TIMER: { // 情報更新 CTSInfo *pThis=GetThis(hDlg); pThis->UpdateItems(); } return TRUE; case WM_CTLCOLORSTATIC: // 項目の背景色を設定 { CTSInfo *pThis=GetThis(hDlg); HDC hdc=reinterpret_cast<HDC>(wParam); ::SetBkMode(hdc,TRANSPARENT); ::SetTextColor(hdc,pThis->m_crTextColor); return reinterpret_cast<INT_PTR>(pThis->m_hbrBack); } case WM_CTLCOLORDLG: // ダイアログの背景色を設定 { CTSInfo *pThis=GetThis(hDlg); return reinterpret_cast<INT_PTR>(pThis->m_hbrBack); } case WM_COMMAND: if (LOWORD(wParam)==IDCANCEL) { // 閉じる時はプラグインを無効にする CTSInfo *pThis=GetThis(hDlg); pThis->m_pApp->EnablePlugin(false); return TRUE; } break; case WM_DESTROY: { CTSInfo *pThis=GetThis(hDlg); ::KillTimer(hDlg,1); if (pThis->m_hbrBack!=NULL) { ::DeleteObject(pThis->m_hbrBack); pThis->m_hbrBack=NULL; } ::RemoveProp(hDlg,PROP_NAME); } return TRUE; } return FALSE; }
LRESULT CALLBACK CTextInputCtrl::s_WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; CTextInputCtrl *ptic; switch (message) { case WM_CREATE: SetThis(hwnd, ((CREATESTRUCT *)lParam)->lpCreateParams); SetTimer(hwnd, TIMERID_CARET, GetCaretBlinkTime(), NULL); GetThis(hwnd)->OnCreate(hwnd, wParam, lParam); break; case WM_DESTROY: ptic = GetThis(hwnd); if (ptic) { ptic->OnDestroy(); } break; case WM_SETFOCUS: ptic = GetThis(hwnd); if (ptic) { ptic->OnSetFocus(wParam, lParam); } break; case WM_PAINT: ptic = GetThis(hwnd); hdc = BeginPaint(hwnd, &ps); if (ptic) ptic->OnPaint(hdc); EndPaint(hwnd, &ps); break; case WM_KEYDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnKeyDown(wParam, lParam); break; case WM_LBUTTONDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnLButtonDown(wParam, lParam); break; case WM_LBUTTONUP: ptic = GetThis(hwnd); if (ptic) ptic->OnLButtonUp(wParam, lParam); break; case WM_RBUTTONDOWN: ptic = GetThis(hwnd); if (ptic) ptic->OnRButtonDown(wParam, lParam); break; case WM_RBUTTONUP: ptic = GetThis(hwnd); if (ptic) ptic->OnRButtonUp(wParam, lParam); break; case WM_MOUSEMOVE: ptic = GetThis(hwnd); if (ptic) ptic->OnMouseMove(wParam, lParam); break; case WM_IME_COMPOSITION: if (lParam & GCS_RESULTSTR) { HIMC himc = ImmGetContext(hwnd); if (himc) { LONG nSize = ImmGetCompositionString(himc, GCS_RESULTSTR, NULL, 0); if (nSize) { LPWSTR psz = (LPWSTR)LocalAlloc(LPTR, nSize + sizeof(WCHAR)); if (psz) { ImmGetCompositionString(himc, GCS_RESULTSTR, psz, nSize); LocalFree(psz); } } } ImmReleaseContext(hwnd, himc); // // If we don't want to receive WM_IME_CHAR or WM_CHAR with // this result string, we should not call DefWindowProc() // with GCS_RESULTSTR, GCS_RESULTREADSTR, GCS_RESULTCLAUSE and // GCS_RESULTREADCLAUSE flags. // // lParam &= ~(GCS_RESULTCLAUSE | // GCS_RESULTREADCLAUSE | // GCS_RESULTREADSTR | // GCS_RESULTSTR); // if (!lParam) // break; // } return DefWindowProc(hwnd, message, wParam, lParam); case WM_IME_CHAR: // // wParam is a character of the result string. // if we don't want to receive WM_CHAR message for this character, // we should not call DefWindowProc(). // return DefWindowProc(hwnd, message, wParam, lParam); case WM_CHAR: // // wParam is a character of the result string. // switch ((WCHAR)wParam) { case 0x08: case 0x0a: return 0; default: break; } ptic = GetThis(hwnd); if (ptic) { WCHAR wc[2]; wc[0] = (WCHAR)wParam; wc[1] = L'\0'; ptic->_editor.InsertAtSelection(wc); InvalidateRect(hwnd, NULL, TRUE); } break; case WM_TIMER: if (wParam == TIMERID_CARET) { ptic = GetThis(hwnd); if (ptic) { HDC hdc = GetDC(hwnd); ptic->_editor.BlinkCaret(hdc); ReleaseDC(hwnd, hdc); } } break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
CDBConnParams::EServerType CCPPToolkitConnParams::GetServerType(void) const { EServerType type = GetServerType(GetThis().GetServerName()); return (type == eUnknown) ? CDBConnParamsDelegate::GetServerType() : type; }
LRESULT CALLBACK CSpectrumAnalyzer::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CSpectrumAnalyzer *pThis=static_cast<CSpectrumAnalyzer*>(pcs->lpCreateParams); // ウィンドウハンドルからthisを取得できるようにする ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); pThis->m_hwnd=hwnd; // メモリ確保 pThis->m_pBuffer=new short[FFT_SIZE]; pThis->m_pFFTBuffer=new double[FFT_SIZE]; for (int i=0;i<FFT_SIZE;i++) pThis->m_pFFTBuffer[i]=0.0; pThis->m_pFFTWorkBuffer=new int[2+(int)sqrt((double)(FFT_SIZE/2))+10]; pThis->m_pFFTWorkBuffer[0]=0; pThis->m_pFFTSinTable=new double[FFT_SIZE/2]; pThis->m_pPower=new double[FFT_SIZE/2+1]; pThis->m_BufferUsed=0; pThis->m_BufferPos=0; // 音声コールバックを登録 pThis->m_pApp->SetAudioCallback(AudioCallback,pThis); // 表示更新用タイマの設定 ::SetTimer(hwnd,1,200,NULL); } return TRUE; case WM_PAINT: { CSpectrumAnalyzer *pThis=GetThis(hwnd); PAINTSTRUCT ps; HPEN hpen,hpenOld; int x,y,i; ::BeginPaint(hwnd,&ps); HBRUSH hbr=::CreateSolidBrush(pThis->m_crBackColor); ::FillRect(ps.hdc,&ps.rcPaint,hbr); ::DeleteObject(hbr); RECT rc; ::GetClientRect(hwnd,&rc); // グリッドを描く hpen=::CreatePen(PS_SOLID,1,pThis->m_crGridColor); hpenOld=static_cast<HPEN>(::SelectObject(ps.hdc,hpen)); for (i=1;i<10;i++) { y=rc.bottom*i/10; ::MoveToEx(ps.hdc,ps.rcPaint.left,y,NULL); ::LineTo(ps.hdc,ps.rcPaint.right,y); } // db値計算 const double EPSILON = 0.0000001; const int LEVELS=100; const int Width=(int)(12000.0/LEVELS/FREQ_UNIT); double dbTable[LEVELS]; pThis->m_FFTLock.Lock(); pThis->m_pPower[0]=POW2(pThis->m_pFFTBuffer[0]); for (int i=1;i<FFT_SIZE/2;i++) { pThis->m_pPower[i]=POW2(pThis->m_pFFTBuffer[i*2])+ POW2(pThis->m_pFFTBuffer[i*2+1]); } pThis->m_pPower[FFT_SIZE/2]=POW2(pThis->m_pFFTBuffer[1]); for (int i=0;i<LEVELS;i++) { double db=0.0; for (int j=0;j<Width;j++) { db+=pThis->m_pPower[i*Width+j]; } db/=Width; if (db<EPSILON) db=EPSILON; db=log10(db)*10.0; if (db<0.0) db=0.0; dbTable[i]=db; } pThis->m_FFTLock.Unlock(); // ロックする時間を出来るだけ短くするために描画処理は後回しにする // スペクトラムを描く hpen=::CreatePen(PS_SOLID,1,pThis->m_crSpectrumColor); ::DeleteObject(::SelectObject(ps.hdc,hpen)); for (int i=0;i<LEVELS;i++) { x=rc.right*i/(LEVELS-1); y=rc.bottom-1-(int)((double)rc.bottom*dbTable[i]/40.0); if (i==0) ::MoveToEx(ps.hdc,x,y,NULL); else ::LineTo(ps.hdc,x,y); } ::DeleteObject(::SelectObject(ps.hdc,hpenOld)); ::EndPaint(hwnd,&ps); } return 0; case WM_TIMER: ::InvalidateRect(hwnd,NULL,TRUE); return 0; case WM_SYSCOMMAND: if ((wParam&0xFFF0)==SC_CLOSE) { // 閉じる時はプラグインを無効にする CSpectrumAnalyzer *pThis=GetThis(hwnd); pThis->m_pApp->EnablePlugin(false); return TRUE; } break; case WM_DESTROY: { CSpectrumAnalyzer *pThis=GetThis(hwnd); // 音声コールバックを登録解除 pThis->m_pApp->SetAudioCallback(NULL); // メモリ開放 SAFE_DELETE_ARRAY(pThis->m_pBuffer); SAFE_DELETE_ARRAY(pThis->m_pFFTBuffer); SAFE_DELETE_ARRAY(pThis->m_pFFTWorkBuffer); SAFE_DELETE_ARRAY(pThis->m_pFFTSinTable); SAFE_DELETE_ARRAY(pThis->m_pPower); // ウィンドウ位置保存 RECT rc; ::GetWindowRect(hwnd,&rc); pThis->m_WindowPosition.Left=rc.left; pThis->m_WindowPosition.Top=rc.top; pThis->m_WindowPosition.Width=rc.right-rc.left; pThis->m_WindowPosition.Height=rc.bottom-rc.top; ::KillTimer(hwnd,1); // 別にしなくてもいいけど... pThis->m_hwnd=NULL; } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }
// RAGE AGAINST THE VIRTUAL MACHINE =) gmThread::State gmThread::Sys_Execute(gmVariable * a_return) { register union { const gmuint8 * instruction; const gmuint32 * instruction32; }; register gmVariable * top; gmVariable * base; gmVariable * operand; const gmuint8 * code; if(m_state != RUNNING) return m_state; #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_isBroken) { if(m_machine->m_isBroken(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT // make sure we have a stack frame GM_ASSERT(m_frame); GM_ASSERT(GetFunction()->m_type == GM_FUNCTION); // cache our "registers" gmFunctionObject * fn = (gmFunctionObject *) GM_MOBJECT(m_machine, GetFunction()->m_value.m_ref); code = (const gmuint8 *) fn->GetByteCode(); if(m_instruction == NULL) instruction = code; else instruction = m_instruction; top = GetTop(); base = GetBase(); // // start byte code execution // for(;;) { #ifdef GM_CHECK_USER_BREAK_CALLBACK // This may be defined in gmConfig_p.h // Check external source to break execution with exception eg. Check for CTRL-BREAK // Endless loop protection could be implemented with this, or in a similar manner. if( gmMachine::s_userBreakCallback && gmMachine::s_userBreakCallback(this) ) { GMTHREAD_LOG("User break. Execution halted."); goto LabelException; } #endif //GM_CHECK_USER_BREAK_CALLBACK switch(*(instruction32++)) { // // unary operator // #if GM_USE_INCDECOPERATORS case BC_OP_INC : case BC_OP_DEC : #endif case BC_BIT_INV : case BC_OP_NEG : case BC_OP_POS : case BC_OP_NOT : { operand = top - 1; gmOperatorFunction op = OPERATOR(operand->m_type, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("unary operator %s undefined for type %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type)); goto LabelException; } break; } // // operator // case BC_OP_ADD : case BC_OP_SUB : case BC_OP_MUL : case BC_OP_DIV : case BC_OP_REM : case BC_BIT_OR : case BC_BIT_XOR : case BC_BIT_AND : case BC_BIT_SHL : case BC_BIT_SHR : case BC_OP_LT : case BC_OP_GT : case BC_OP_LTE : case BC_OP_GTE : case BC_OP_EQ : case BC_OP_NEQ : { operand = top - 2; --top; // NOTE: Classic logic for operators. Higher type processes the operation. register gmType t1 = operand[1].m_type; if(operand->m_type > t1) t1 = operand->m_type; gmOperatorFunction op = OPERATOR(t1, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(t1, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[3] = operand[1]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 4); State res = PushStackFrame(2, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("operator %s undefined for type %s and %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type), m_machine->GetTypeName((operand + 1)->m_type)); goto LabelException; } break; } case BC_GETIND : { operand = top - 2; --top; gmOperatorFunction op = OPERATOR(operand->m_type, (gmOperator) instruction32[-1]); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, (gmOperator) instruction32[-1]))) { operand[2] = operand[0]; operand[3] = operand[1]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 4); State res = PushStackFrame(2, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("operator %s undefined for type %s and %s", gmGetOperatorName((gmOperator) instruction32[-1]), m_machine->GetTypeName(operand->m_type), m_machine->GetTypeName((operand + 1)->m_type)); goto LabelException; } break; } case BC_SETIND : { operand = top - 3; top -= 3; gmOperatorFunction op = OPERATOR(operand->m_type, O_SETIND); if(op) { op(this, operand); } else if((fn = CALLOPERATOR(operand->m_type, O_SETIND))) { operand[4] = operand[2]; operand[3] = operand[1]; operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 5); State res = PushStackFrame(3, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } else { GMTHREAD_LOG("setind failed."); goto LabelException; } break; } case BC_NOP : { break; } case BC_LINE : { #if GMDEBUG_SUPPORT if(m_machine->GetDebugMode() && m_machine->m_line) { SetTop(top); m_instruction = instruction; if(m_machine->m_line(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } case BC_GETDOT : { operand = top - 1; gmptr member = OPCODE_PTR(instruction); top->m_type = GM_STRING; top->m_value.m_ref = member; gmType t1 = operand->m_type; gmOperatorFunction op = OPERATOR(t1, O_GETDOT); if(op) { op(this, operand); if(operand->m_type) break; } if(t1 == GM_NULL) { GMTHREAD_LOG("getdot failed."); goto LabelException; } *operand = m_machine->GetTypeVariable(t1, gmVariable(GM_STRING, member)); break; } case BC_SETDOT : { operand = top - 2; gmptr member = OPCODE_PTR(instruction); top->m_type = GM_STRING; top->m_value.m_ref = member; top -= 2; gmOperatorFunction op = OPERATOR(operand->m_type, O_SETDOT); if(op) { op(this, operand); } else { GMTHREAD_LOG("setdot failed."); goto LabelException; } break; } case BC_BRA : { instruction = code + OPCODE_PTR_NI(instruction); break; } case BC_BRZ : { #if GM_BOOL_OP operand = top - 1; --top; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP --top; if(top->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRNZ : { #if GM_BOOL_OP operand = top - 1; --top; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP --top; if(top->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRZK : { #if GM_BOOL_OP operand = top - 1; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP if(top[-1].m_value.m_int == 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_BRNZK : { #if GM_BOOL_OP operand = top - 1; if (operand->m_type > GM_USER) { // Look for overridden operator. gmOperatorFunction op = OPERATOR(operand->m_type, O_BOOL); if (op) { op(this, operand); } else if ((fn = CALLOPERATOR(operand->m_type, O_BOOL))) { operand[2] = operand[0]; operand[0] = gmVariable(GM_NULL, 0); operand[1] = gmVariable(GM_FUNCTION, fn->GetRef()); SetTop(operand + 3); // Return to the same instruction after making the call but it will be testing the results of the call. --instruction32; State res = PushStackFrame(1, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) break; if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { m_machine->Sys_SwitchState(this, KILLED); GM_ASSERT(0); } // operator should not kill a thread return res; } } if(operand->m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #else // !GM_BOOL_OP if(top[-1].m_value.m_int != 0) { instruction = code + OPCODE_PTR_NI(instruction); } else instruction += sizeof(gmptr); #endif // !GM_BOOL_OP break; } case BC_CALL : { SetTop(top); int numParams = (int) OPCODE_INT(instruction); State res = PushStackFrame(numParams, &instruction, &code); top = GetTop(); base = GetBase(); if(res == RUNNING) { #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_call) { m_instruction = instruction; if(m_machine->m_call(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } if(res == SYS_YIELD) return RUNNING; if(res == SYS_EXCEPTION) goto LabelException; if(res == KILLED) { if(a_return) *a_return = m_stack[m_top - 1]; m_machine->Sys_SwitchState(this, KILLED); } return res; } case BC_RET : { PUSHNULL; } case BC_RETV : { SetTop(top); int res = Sys_PopStackFrame(instruction, code); top = GetTop(); base = GetBase(); if(res == RUNNING) { #if GMDEBUG_SUPPORT if(m_debugFlags && m_machine->GetDebugMode() && m_machine->m_return) { m_instruction = instruction; if(m_machine->m_return(this)) return RUNNING; } #endif // GMDEBUG_SUPPORT break; } if(res == KILLED) { if(a_return) *a_return = *(top - 1); m_machine->Sys_SwitchState(this, KILLED); return KILLED; } if(res == SYS_EXCEPTION) goto LabelException; break; } #if GM_USE_FORK // duplicates the current thread and just the local stack frame // and branches around the forked section of code case BC_FORK : { int id; gmThread* newthr = GetMachine()->CreateThread(&id); GM_ASSERT( newthr ); // make sure there is enough room newthr->Touch( m_size - m_base + 2 - GMTHREAD_SLACKSPACE); // copy stack and vars memcpy( newthr->m_stack, &m_stack[ m_base - 2 ], sizeof( gmVariable ) * (m_top - m_base + 2 ) ); newthr->m_top = m_top - m_base + 2; newthr->m_frame = m_machine->Sys_AllocStackFrame(); newthr->m_frame->m_prev = 0; newthr->m_frame->m_returnAddress = 0; newthr->m_frame->m_returnBase = 0; newthr->m_base = 2; newthr->m_instruction = instruction + sizeof(gmptr); // skip branch on other thread newthr->PushInt( GetId() ); instruction = code + OPCODE_PTR_NI( instruction ); // branch top->m_type = GM_INT; top->m_value.m_int = newthr->GetId(); ++top; break; } #endif //GM_USE_FORK case BC_FOREACH : { gmuint32 localvalue = OPCODE_INT(instruction); gmuint32 localkey = localvalue >> 16; localvalue &= 0xffff; // iterator is at tos-1, table is at tos -2, push int 1 if continuing loop. write key and value into localkey and localvalue if(top[-2].m_type != GM_TABLE) { #if GM_USER_FOREACH gmTypeIteratorCallback itrfunc = m_machine->GetUserTypeIteratorCallback(top[-2].m_type); if (!itrfunc) { GMTHREAD_LOG("foreach expression has no iterator function"); goto LabelException; } gmTypeIterator it = (gmTypeIterator) top[-1].m_value.m_int; gmUserObject *obj = (gmUserObject*)GM_MOBJECT(m_machine, top[-2].m_value.m_ref); // Do callback for getnext gmVariable localvar; gmVariable localkeyvar; itrfunc(this, obj, it, &localkeyvar, &localvar); if (it != GM_TYPE_ITR_NULL) { base[localkey] = localkeyvar; base[localvalue] = localvar; top->m_type = GM_INT; top->m_value.m_int = 1; } else { top->m_type = GM_INT; top->m_value.m_int = 0; } top[-1].m_value.m_int = it; ++top; #else //GM_USER_FOREACH (original) GMTHREAD_LOG("foreach expression is not table type"); goto LabelException; #endif //GM_USER_FOREACH } else { GM_ASSERT(top[-1].m_type == GM_INT); gmTableIterator it = (gmTableIterator) top[-1].m_value.m_int; gmTableObject * table = (gmTableObject *) GM_MOBJECT(m_machine, top[-2].m_value.m_ref); gmTableNode * node = table->GetNext(it); top[-1].m_value.m_int = it; if(node) { base[localkey] = node->m_key; base[localvalue] = node->m_value; top->m_type = GM_INT; top->m_value.m_int = 1; } else { top->m_type = GM_INT; top->m_value.m_int = 0; } ++top; } break; } case BC_POP : { --top; break; } case BC_POP2 : { top -= 2; break; } case BC_DUP : { top[0] = top[-1]; ++top; break; } case BC_DUP2 : { top[0] = top[-2]; top[1] = top[-1]; top += 2; break; } case BC_SWAP : { top[0] = top[-1]; top[-1] = top[-2]; top[-2] = top[0]; break; } case BC_PUSHNULL : { PUSHNULL; break; } case BC_PUSHINT : { top->m_type = GM_INT; top->m_value.m_int = OPCODE_INT(instruction); ++top; break; } case BC_PUSHINT0 : { top->m_type = GM_INT; top->m_value.m_int = 0; ++top; break; } case BC_PUSHINT1 : { top->m_type = GM_INT; top->m_value.m_int = 1; ++top; break; } case BC_PUSHFP : { top->m_type = GM_FLOAT; top->m_value.m_float = OPCODE_FLOAT(instruction); ++top; break; } case BC_PUSHSTR : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); ++top; break; } case BC_PUSHTBL : { SetTop(top); top->m_type = GM_TABLE; top->m_value.m_ref = m_machine->AllocTableObject()->GetRef(); ++top; break; } case BC_PUSHFN : { top->m_type = GM_FUNCTION; top->m_value.m_ref = OPCODE_PTR(instruction); ++top; break; } case BC_PUSHTHIS : { *top = *GetThis(); ++top; break; } case BC_GETLOCAL : { gmuint32 offset = OPCODE_INT(instruction); *(top++) = base[offset]; break; } case BC_SETLOCAL : { gmuint32 offset = OPCODE_INT(instruction); // Write barrier old local objects { gmGarbageCollector* gc = m_machine->GetGC(); if( !gc->IsOff() && base[offset].IsReference() ) { gmObject * object = GM_MOBJECT(m_machine, base[offset].m_value.m_ref); gc->WriteBarrier(object); } } base[offset] = *(--top); break; } case BC_GETGLOBAL : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); *top = m_machine->GetGlobals()->Get(*top); ++top; break; } case BC_SETGLOBAL : { top->m_type = GM_STRING; top->m_value.m_ref = OPCODE_PTR(instruction); m_machine->GetGlobals()->Set(m_machine, *top, *(top-1)); --top; break; } case BC_GETTHIS : { gmptr member = OPCODE_PTR(instruction); const gmVariable * thisVar = GetThis(); *top = *thisVar; top[1].m_type = GM_STRING; top[1].m_value.m_ref = member; gmOperatorFunction op = OPERATOR(thisVar->m_type, O_GETDOT); if(op) { op(this, top); if(top->m_type) { ++top; break; } } if(thisVar->m_type == GM_NULL) { GMTHREAD_LOG("getthis failed. this is null"); goto LabelException; } *top = m_machine->GetTypeVariable(thisVar->m_type, top[1]); ++top; break; } case BC_SETTHIS : { gmptr member = OPCODE_PTR(instruction); const gmVariable * thisVar = GetThis(); operand = top - 1; *top = *operand; *operand = *thisVar; top[1].m_type = GM_STRING; top[1].m_value.m_ref = member; --top; gmOperatorFunction op = OPERATOR(thisVar->m_type, O_SETDOT); if(op) { op(this, operand); } else { GMTHREAD_LOG("setthis failed."); goto LabelException; } break; } default : { break; } } } LabelException: // // exception handler // m_instruction = instruction; // spit out error info LogLineFile(); LogCallStack(); // call machine exception handler if(gmMachine::s_machineCallback) { if(gmMachine::s_machineCallback(m_machine, MC_THREAD_EXCEPTION, this)) { #if GMDEBUG_SUPPORT // if we are being debugged, put this thread into a limbo state, waiting for delete. if(m_machine->GetDebugMode() && m_machine->m_debugUser) { m_machine->Sys_SwitchState(this, EXCEPTION); return EXCEPTION; } #endif } } // kill the thread m_machine->Sys_SwitchState(this, KILLED); return KILLED; }
/* * ProfileArgIterator::ProfileArgIterator * * Constructor. Initializes for arg iteration. * * Parameters: * pMetaSig - The signature of the method we are going iterate over * platformSpecificHandle - the value passed to ProfileEnter/Leave/Tailcall * * Returns: * None. */ ProfileArgIterator::ProfileArgIterator(MetaSig * pSig, void * platformSpecificHandle) : m_argIterator(pSig) { WRAPPER_NO_CONTRACT; _ASSERTE(pSig != NULL); _ASSERTE(platformSpecificHandle != NULL); m_handle = platformSpecificHandle; PROFILE_PLATFORM_SPECIFIC_DATA* pData = (PROFILE_PLATFORM_SPECIFIC_DATA*)m_handle; // unwind a frame and get the Rsp for the profiled method to make sure it matches // what the JIT gave us #ifdef _DEBUG { // setup the context to represent the frame that called ProfileEnterNaked CONTEXT ctx; memset(&ctx, 0, sizeof(CONTEXT)); ctx.Rsp = (UINT64)pData->probeRsp; ctx.Rbp = (UINT64)pData->rbp; ctx.Rip = (UINT64)pData->ip; // walk up a frame to the caller frame (called the managed method which // called ProfileEnterNaked) Thread::VirtualUnwindCallFrame(&ctx); _ASSERTE(pData->profiledRsp == (void*)ctx.Rsp); } #endif // _DEBUG // Get the hidden arg if there is one MethodDesc * pMD = FunctionIdToMethodDesc(pData->functionId); if ( (pData->hiddenArg == NULL) && (pMD->RequiresInstArg() || pMD->AcquiresInstMethodTableFromThis()) ) { // In the enter probe, the JIT may not have pushed the generics token onto the stack yet. // Luckily, we can inspect the registers reliably at this point. if (pData->flags & PROFILE_ENTER) { _ASSERTE(!((pData->flags & PROFILE_LEAVE) || (pData->flags & PROFILE_TAILCALL))); if (pMD->AcquiresInstMethodTableFromThis()) { pData->hiddenArg = GetThis(); } else { // The param type arg comes after the return buffer argument and the "this" pointer. int index = 0; if (m_argIterator.HasThis()) { index++; } if (m_argIterator.HasRetBuffArg()) { index++; } pData->hiddenArg = *(LPVOID*)((LPBYTE)pData->profiledRsp + (index * sizeof(SIZE_T))); } } else { EECodeInfo codeInfo((PCODE)pData->ip); // We want to pass the caller SP here. pData->hiddenArg = EECodeManager::GetExactGenericsToken((SIZE_T)(pData->profiledRsp), &codeInfo); } } }
// ウィンドウプロシージャ LRESULT CALLBACK CSignalGraph::WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_CREATE: { LPCREATESTRUCT pcs=reinterpret_cast<LPCREATESTRUCT>(lParam); CSignalGraph *pThis=static_cast<CSignalGraph*>(pcs->lpCreateParams); ::SetWindowLongPtr(hwnd,GWLP_USERDATA,reinterpret_cast<LONG_PTR>(pThis)); pThis->m_hwnd=hwnd; // 更新用タイマの設定 ::SetTimer(hwnd,1,1000,NULL); } return 0; case WM_PAINT: { CSignalGraph *pThis=GetThis(hwnd); PAINTSTRUCT ps; HBRUSH hbr; HPEN hpen,hpenOld; const int ListSize=(int)pThis->m_List.size(); int x,y,i; ::BeginPaint(hwnd,&ps); hbr=::CreateSolidBrush(pThis->m_crBackColor); ::FillRect(ps.hdc,&ps.rcPaint,hbr); ::DeleteObject(hbr); hpenOld=static_cast<HPEN>(::GetCurrentObject(ps.hdc,OBJ_PEN)); // グリッドを描く hpen=::CreatePen(PS_SOLID,1,pThis->m_crGridColor); ::SelectObject(ps.hdc,hpen); for (y=ps.rcPaint.top/10*10;y<ps.rcPaint.bottom;y+=10) { ::MoveToEx(ps.hdc,ps.rcPaint.left,y,NULL); ::LineTo(ps.hdc,ps.rcPaint.right,y); } // ビットレートを描く hpen=::CreatePen(PS_SOLID,1,pThis->m_crBitRateColor); ::DeleteObject(::SelectObject(ps.hdc,hpen)); if (ps.rcPaint.left<WINDOW_WIDTH-ListSize) { x=WINDOW_WIDTH-ListSize; i=0; } else { x=ps.rcPaint.left; i=ps.rcPaint.left-(WINDOW_WIDTH-ListSize); } for (;x<min(ps.rcPaint.right,WINDOW_WIDTH);x++) { y=min(pThis->m_List[i].BitRate,40*1024*1024)*WINDOW_HEIGHT/(40*1024*1024); if (y>0) { ::MoveToEx(ps.hdc,x,WINDOW_HEIGHT-y,NULL); ::LineTo(ps.hdc,x,WINDOW_HEIGHT); } i++; } // 信号レベルを描く hpen=::CreatePen(PS_SOLID,1,pThis->m_crSignalLevelColor); ::DeleteObject(::SelectObject(ps.hdc,hpen)); if (max(ps.rcPaint.left-1,0)<WINDOW_WIDTH-ListSize) { x=WINDOW_WIDTH-ListSize; i=0; } else { x=max(ps.rcPaint.left-1,0); i=x-(WINDOW_WIDTH-ListSize); } for (;x<min(ps.rcPaint.right,WINDOW_WIDTH);x++) { y=min(pThis->m_List[i].SignalLevel,800)*(WINDOW_HEIGHT-1)/800; ::MoveToEx(ps.hdc,x,WINDOW_HEIGHT-1-y,NULL); i++; if (i<ListSize) { y=min(pThis->m_List[i].SignalLevel,800)*(WINDOW_HEIGHT-1)/800; } ::LineTo(ps.hdc,x+1,WINDOW_HEIGHT-1-y); } ::DeleteObject(::SelectObject(ps.hdc,hpenOld)); ::EndPaint(hwnd,&ps); } return 0; case WM_TIMER: { CSignalGraph *pThis=GetThis(hwnd); TVTest::StatusInfo Status; SignalInfo Info; RECT rc; // 情報取得&表示更新 pThis->m_pApp->GetStatus(&Status); Info.SignalLevel=(DWORD)(max(Status.SignalLevel,0.0f)*10.0f); Info.BitRate=Status.BitRate; if (pThis->m_List.size()==WINDOW_WIDTH) pThis->m_List.pop_front(); pThis->m_List.push_back(Info); ::ScrollWindowEx(hwnd,-1,0,NULL,NULL,NULL,NULL,0/*SW_INVALIDATE*/); ::GetClientRect(hwnd,&rc); rc.left=rc.right-2; ::InvalidateRect(hwnd,&rc,TRUE); } return 0; case WM_SYSCOMMAND: if ((wParam&0xFFF0)==SC_CLOSE) { // 閉じる時はプラグインを無効にする CSignalGraph *pThis=GetThis(hwnd); pThis->m_pApp->EnablePlugin(false); return TRUE; } break; case WM_DESTROY: { CSignalGraph *pThis=GetThis(hwnd); ::KillTimer(hwnd,1); // 別にしなくてもいいけど... pThis->m_hwnd=NULL; } return 0; } return ::DefWindowProc(hwnd,uMsg,wParam,lParam); }