#include "stdafx.h" using namespace ActiveBasic::IDE; using namespace ActiveBasic::IDE::WindowComponents; LRESULT CALLBACK WindowFunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam); void SetupWindow(HWND hwnd); void ResetTextEditFont(HWND hwnd); void CreateProcessWithStdHandle( const std::string &appPath, const std::string &cmdLine, bool isShowWindow = true ) { std::string argsStr = '\"' + appPath + "\" " + cmdLine; STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si,0,sizeof(STARTUPINFO)); si.cb=sizeof(STARTUPINFO); si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; si.wShowWindow = isShowWindow ? SW_SHOW : SW_HIDE; si.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); si.hStdInput = GetStdHandle(STD_INPUT_HANDLE); si.hStdError = GetStdHandle(STD_ERROR_HANDLE); std::vector args( argsStr.c_str(), argsStr.c_str() + argsStr.size() + 1 ); CreateProcess( NULL, &args[0], NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi ); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); } #define MSGFLT_ADD 1 #pragma push_macro("_WIN32_WINNT") #undef _WIN32_WINNT #define _WIN32_WINNT 0x0601 #include #pragma pop_macro("_WIN32_WINNT") #define WM_DWMSENDICONICTHUMBNAIL 0x0323 #define WM_DWMSENDICONICLIVEPREVIEWBITMAP 0x0326 // Windows 7タスクバーにボタンとして表示させるためのウィンドウ。 // 各MDI子ウィンドウ (wndTarget) と1対1に対応する。 class DummyWindowForTaskbarButton : public ATL::CWindowImpl, boost::noncopyable { public: DECLARE_WND_CLASS(TEXT("DummyWindow For Taskbar Button")); BEGIN_MSG_MAP(DummyWindowForTaskbarButton) MESSAGE_HANDLER_EX(WM_DWMSENDICONICTHUMBNAIL, OnDwmSendIconicThumnail) MESSAGE_HANDLER_EX(WM_DWMSENDICONICLIVEPREVIEWBITMAP, OnDwmSendIconicLivePreviewBitmap) MSG_WM_ACTIVATE(OnActivate) END_MSG_MAP() explicit DummyWindowForTaskbarButton(HWND hwndTarget, const char* title) : wndTarget(hwndTarget) { DWORD const WS_EX_NOACTIVATE = 0x08000000; HWND hwndDummy = Create( hOwner, CRect( -32000, -32000, 1, 1 ), title, WS_BORDER | WS_SYSMENU | WS_CAPTION, WS_EX_NOACTIVATE); SetIcon( wndTarget.GetIcon( FALSE ), FALSE ); SetIcon( wndTarget.GetIcon( TRUE ), TRUE ); BOOL iconicRepresentation = TRUE; HRESULT hr; hr = DwmSetWindowAttribute( *this, DWMWA_FORCE_ICONIC_REPRESENTATION, &iconicRepresentation, sizeof iconicRepresentation); BOOL iconicBitmap = TRUE; hr = DwmSetWindowAttribute( *this, DWMWA_HAS_ICONIC_BITMAP, &iconicBitmap, sizeof iconicBitmap); } ~DummyWindowForTaskbarButton() { } private: void OnActivate(UINT state, BOOL /*minimized*/, HWND /*hwndOther*/) { if (state == WA_ACTIVE) { if (ActiveBasic::IDE::Program::mainFrame.IsIconic()) { ActiveBasic::IDE::Program::mainFrame.ShowWindow(SW_RESTORE); } SetForegroundWindow(ActiveBasic::IDE::Program::mainFrame); ActiveBasic::IDE::Program::mainFrame.MDIActivate(wndTarget); wndTarget.Invalidate(FALSE); } } class BitmapMemoryDC : public WTL::CDC, boost::noncopyable { public: explicit BitmapMemoryDC(HBITMAP hbmp) : WTL::CDC(::CreateCompatibleDC(0)), bmp(hbmp), hbmpOld(SelectBitmap(bmp)) { } BitmapMemoryDC(int width, int height, void*& bits) : WTL::CDC(::CreateCompatibleDC(0)), bmp(CreateDIBSection32(m_hDC, width, height, bits)), hbmpOld(SelectBitmap(bmp)) { } ~BitmapMemoryDC() { SelectBitmap(hbmpOld); // この後、CDCとbmpのデストラクタでそれぞれDeleteDCとDeleteObjectがなされる。 } WTL::CBitmap& GetBitmap() { return bmp; } private: WTL::CBitmap bmp; HBITMAP hbmpOld; }; LRESULT OnDwmSendIconicThumnail(UINT, WPARAM, LPARAM lp) { HRESULT hr = SetIconicThumbnail(HIWORD(lp), LOWORD(lp)); return 0; } LRESULT OnDwmSendIconicLivePreviewBitmap(UINT, WPARAM, LPARAM) { HRESULT hr = SetIconicLivePreviewBitmap(); return 0; } HRESULT SetIconicThumbnail(int maximumWidth, int maximumHeight) { int widthBmp, heightBmp; BitmapMemoryDC dcSrc(CreateBitmap(widthBmp, heightBmp)); if (dcSrc) { int width, height; // dcSrcの縦横比に合わせて縮小する if (widthBmp * maximumHeight > maximumWidth * heightBmp) // (widthBmp / heightBmp > maximumWidth / maximumHeight) { width = maximumWidth; height = heightBmp * maximumWidth / widthBmp; } else { height = maximumHeight; width = widthBmp * maximumHeight / heightBmp; } void* pvBits; BitmapMemoryDC dc(width, height, pvBits); if (dc) { StretchBlt(dc, 0, 0, width, height, dcSrc, 0, 0, widthBmp, heightBmp, SRCCOPY); return DwmSetIconicThumbnail(*this, dc.GetBitmap(), DWM_SIT_DISPLAYFRAME); } } return HRESULT_FROM_WIN32(GetLastError()); } HRESULT SetIconicLivePreviewBitmap() { int w, h; WTL::CBitmap bmp(CreateBitmap(w, h)); if (bmp) { POINT pt = {}; wndTarget.MapWindowPoints(hOwner, &pt, 1); pt.y += GetSystemMetrics(SM_CYMENU); return DwmSetIconicLivePreviewBitmap(*this, bmp, &pt, wndTarget.IsZoomed() ? 0 : DWM_SIT_DISPLAYFRAME); } return HRESULT_FROM_WIN32(GetLastError()); } static void SetAlpha(DWORD& pixel) { pixel |= 0xff000000; } HBITMAP CreateBitmap(int& width, int& height) { RECT rcClient; wndTarget.GetClientRect(&rcClient); void* pvBits; BitmapMemoryDC dc(rcClient.right, rcClient.bottom, pvBits); if (dc) { int wndNum = GetWndNum(wndTarget); if (wndNum != -1) { CPoint origin(0, 0); wndTarget.ClientToScreen( &origin ); CRect rcWindow; wndTarget.GetWindowRect( rcWindow ); origin -= rcWindow.TopLeft(); dc.SetWindowOrg( origin ); // クライアント領域の(0, 0)がビットマップの(0, 0)になるよう合わせる wndTarget.Print( dc, PRF_CHECKVISIBLE | PRF_ERASEBKGND | PRF_CHILDREN | PRF_CLIENT ); width = rcClient.right; height = rcClient.bottom; DWORD* pdwBits = static_cast(pvBits); std::for_each(pdwBits, pdwBits + width * height, SetAlpha); return dc.GetBitmap().Detach(); } } return 0; } // 32ビットトップダウンのDIBセクションを作る補助 static HBITMAP CreateDIBSection32(HDC hdc, int width, int height, void*& pb) { BITMAPINFO bi; ZeroMemory(&bi.bmiHeader, sizeof bi.bmiHeader); bi.bmiHeader.biSize = sizeof bi.bmiHeader; bi.bmiHeader.biWidth = width; bi.bmiHeader.biHeight = -height; // トップダウンDIBにする必要があるらしい bi.bmiHeader.biPlanes = 1; bi.bmiHeader.biBitCount = 32; return CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &pb, 0, 0); } CWindow wndTarget; }; class TaskbarList { typedef boost::shared_ptr DummyWindowForTaskbarButtonPtr; typedef std::map WindowMap; public: TaskbarList(HWND hwndFrame) : wndFrame(hwndFrame) { HRESULT hr = taskbarList.CoCreateInstance( CLSID_TaskbarList ); if ( FAILED( hr ) ) { return; } HRESULT hr2 = taskbarList->HrInit(); if ( FAILED( hr2 ) ) { taskbarList.Release(); return; } } void RegisterTab(HWND hwndChild, const char* title) { assert( hwndChild ); if (taskbarList) { assert( windowMap.find(hwndChild) == windowMap.end() ); DummyWindowForTaskbarButtonPtr p(new DummyWindowForTaskbarButton(hwndChild, title)); windowMap.insert(std::make_pair(hwndChild, p)); //タスクバーボタンに追加 HRESULT hr = taskbarList->RegisterTab(*p, wndFrame); } } void RegisterTab(HWND hwndChild) { ATL::CWindow wnd = hwndChild; ATL::CString title; wnd.GetWindowText(title); RegisterTab(hwndChild, title); } void UnregisterTab(HWND hwndChild) { if (taskbarList) { WindowMap::iterator it = windowMap.find(hwndChild); assert( it != windowMap.end() ); HRESULT hr = taskbarList->UnregisterTab(*it->second); it->second->DestroyWindow(); windowMap.erase( it ); } } void InvalidateIconicBitmaps(HWND hwndChild) { DwmInvalidateIconicBitmaps(*mapAt(hwndChild)); } void SetTabActivate(HWND hwndChild) { if (taskbarList) { taskbarList->SetTabActive(*mapAt(hwndChild), wndFrame, 0); } } void SetTabOrder( HWND hwndChild, HWND hwndInsertBefore ) { if (taskbarList) { taskbarList->SetTabOrder(*mapAt(hwndChild), hwndInsertBefore ? static_cast(*mapAt(hwndInsertBefore)) : 0); } } private: DummyWindowForTaskbarButtonPtr mapAt(HWND hwndChild) { DummyWindowForTaskbarButtonPtr p = windowMap[hwndChild]; assert(p); return p; } CWindow wndFrame; ATL::CComPtr taskbarList; WindowMap windowMap; }; MainFrame::MainFrame() : TaskbarButtonCreated( RegisterWindowMessage( TEXT("TaskbarButtonCreated") ) ) { if ( TaskbarButtonCreated != 0 ) { typedef BOOL WINAPI CWMF(UINT, DWORD); HMODULE hmodUser = GetModuleHandle( TEXT("user32.dll") ); assert( hmodUser != 0 ); if ( CWMF* pcwmf = reinterpret_cast( GetProcAddress( hmodUser, "ChangeWindowMessageFilter" ) ) ) { pcwmf(TaskbarButtonCreated, MSGFLT_ADD); pcwmf(WM_DWMSENDICONICTHUMBNAIL, MSGFLT_ADD); pcwmf(WM_DWMSENDICONICLIVEPREVIEWBITMAP, MSGFLT_ADD); } } } void MainFrame::Resized() { int width_owner,height_owner; int height_Rebar; int height_MdiClient; RECT rect,StatusRect,RebarRect; this->GetClientRect( &rect ); width_owner=rect.right; height_owner=rect.bottom; //Rebar SendMessage(pobj_Rebar->hRebar,WM_SIZE,0,MAKELONG(width_owner,height_owner)); ::UpdateWindow(pobj_Rebar->hRebar); //Status bar #define STATUSBAR_PARTS_NUM 5 int sb_size[STATUSBAR_PARTS_NUM]; sb_size[0]=width_owner-340; sb_size[1]=width_owner-220; sb_size[2]=width_owner-120; sb_size[3]=width_owner-50; sb_size[4]=width_owner; extern HWND hStatusBar; ::SendMessage(hStatusBar,SB_SETPARTS,STATUSBAR_PARTS_NUM,(LPARAM)sb_size); ::SendMessage(hStatusBar,WM_SIZE,0,MAKELONG(width_owner,height_owner)); ::UpdateWindow(hStatusBar); //Status bar int height_Statusbar; SendMessage(hStatusBar,SB_GETRECT,0,(LPARAM)&StatusRect); height_Statusbar=StatusRect.bottom; ::GetWindowRect(pobj_Rebar->hRebar,&RebarRect); height_Rebar=RebarRect.bottom-RebarRect.top+2; int height_dv; //Width of Debugger View int height_cv; //Width of Compiler View height_dv=0; height_cv=0; #ifndef THETEXT extern BOOL bClipCompileView; if(bClipCompileView){ if(pobj_Debugger->IsDebuggerView()){ //デバッガビューが表示されているとき height_dv=pobj_nv->height_ClipDebuggerView+LEVER_THICK; } extern HWND hCompileView; if(hCompileView){ //コンパイラビューが表示されているとき height_cv=pobj_nv->height_ClipCompileView+LEVER_THICK; } } #endif int width_pjv=0; //Width of Project View if(pobj_nv->bClipProjectView){ extern HWND hProjectView; if(::IsWindowVisible(hProjectView)){ //プロジェクトビューが表示されているとき width_pjv=pobj_nv->width_ClipProjectView+LEVER_THICK; } } int width_SideWeb=0; if( pobj_SideWeb ) { if(pobj_SideWeb->bShow){ width_SideWeb=pobj_nv->width_WebSearchView+LEVER_THICK; } } //MDIクライアントの高さ height_MdiClient=height_owner-( height_Rebar+ height_dv+ height_cv+ height_Statusbar ); //タブコントロール int tab_height; if(TabCtrl_GetItemCount(pobj_MainTab->hTab)==0) tab_height=0; else{ RECT rc; TabCtrl_GetItemRect(pobj_MainTab->hTab,0,&rc); tab_height=rc.bottom-rc.top; } ::MoveWindow(pobj_MainTab->hTab, width_pjv, height_Rebar, width_owner-width_pjv-width_SideWeb, tab_height, 1); //MDIクライアント ::MoveWindow( hClient, width_pjv, height_Rebar+tab_height, width_owner-width_pjv-width_SideWeb, height_MdiClient-tab_height, 1 ); if( pobj_SideWeb ) { if(pobj_SideWeb->bShow){ //SideWeb pobj_SideWeb->resize( width_owner - pobj_nv->width_WebSearchView, height_Rebar, pobj_nv->width_WebSearchView, height_MdiClient); } else pobj_SideWeb->resize(0,0,0,0); } if(width_pjv){ //プロジェクトビュー extern HWND hProjectView; ::MoveWindow(hProjectView, 0, height_Rebar, pobj_nv->width_ClipProjectView, height_MdiClient, 1); ::InvalidateRect(hProjectView,NULL,0); } if(height_dv){ #ifndef THETEXT //デバッガビュー pobj_Debugger->resize( 0, height_Rebar+height_MdiClient+LEVER_THICK, width_owner, pobj_nv->height_ClipDebuggerView); #endif } if(height_cv){ //コンパイラビュー extern HWND hCompileView; ::MoveWindow(hCompileView, 0, height_Rebar+height_MdiClient+height_dv+LEVER_THICK, width_owner, pobj_nv->height_ClipCompileView, 1); } } void MainFrame::OpenWebBrowser( const std::string &url ) { ShellExecute(m_hWnd,"open",url.c_str(),"",NULL,SW_SHOWNORMAL); } void MainFrame::OpenExplorer( const std::string &filepath ) { CreateProcessWithStdHandle( "explorer", "/select,\"" + filepath + "\"" ); } ::LRESULT MainFrame::OnCreate( ::CREATESTRUCT const* ) { // ウィンドウエリアマネージャに親ウィンドウを登録 wam.SetParentWnd( m_hWnd ); RECT rect; GetClientRect( &rect ); // MDIベースを作成 // フレームウィンドウのビューウィンドウを作成 int indexOfWindowSubMenu = pobj_MainMenu->FindSubMenuIndex( "ウィンドウ(&W)" ); HMENU hWindowSubMenu = NULL; if( indexOfWindowSubMenu != -1 ) { hWindowSubMenu = GetSubMenu( pobj_MainMenu->hMenu, indexOfWindowSubMenu ); } CreateMDIClient( hWindowSubMenu ); wam.AddMdiClientWindow( m_hWndClient ); // TODO: hClientを廃止し、m_hWndClientに統一すること extern HWND hClient; hClient = m_hWndClient; // メッセージループにメッセージフィルタとアイドルハンドラを追加 CMessageLoop* pLoop = Program::_Module.GetMessageLoop(); pLoop->AddMessageFilter(this); pLoop->AddIdleHandler(this); extern HWND hOwner; hOwner = m_hWnd; extern WNDPROC oldMainFrameWndProc; oldMainFrameWndProc = (WNDPROC)::SetWindowLongPtr( hOwner, GWLP_WNDPROC, reinterpret_cast(WindowFunc) ); SetupWindow(hOwner); //テキストエディタフォント設定 ResetTextEditFont(hOwner); return 0; } void MainFrame::OnSize(UINT nType, CSize size) { this->Resized(); } BOOL MainFrame::OnQueryEndSession(UINT nSource, UINT uLogOff) { OnClose(); return TRUE; } void MainFrame::OnClose() { extern BOOL bSearchingClasses; if(bSearchingClasses){ pobj_ClassTreeView->bCloseSwitch=1; return; } //コンパイラビューを閉じる extern HWND hCompileView; if( hCompileView && ::IsWindow( hCompileView ) ) { SendMessage(hCompileView,WM_COMMAND,IDCANCEL,0); } //次回起動時にMDIウィンドウを最大化させるかを判定 HWND hChild=::GetWindow(hClient,GW_CHILD); pobj_nv->bMDIZoomed=::IsZoomed(hChild); //プロジェクトを閉じる if( projectInfo.IsOpened() ){ if(!projectInfo.Close()) return; } //MDIウィンドウの保存確認 hChild=::GetWindow(hClient,GW_CHILD); while(hChild){ if(!DocumentModifyCheck(hChild)) return; hChild=::GetNextWindow(hChild,GW_HWNDNEXT); } KillTimer(ID_TIMER_BACKUP); //ProjectViewの位置を保存、ProjectViewを破棄 extern HWND hProjectView; extern HWND hProjectView_ToolWindow; ::GetWindowRect(hProjectView_ToolWindow,&pobj_nv->rectProjectView); ::DestroyWindow(hProjectView); ::DestroyWindow(hProjectView_ToolWindow); //Rebarの位置を保存、Rebarを破棄 delete pobj_Rebar; pobj_Rebar=0; //タブコントロールを破棄 delete pobj_MainTab; pobj_MainTab=0; //SideWebを破棄 delete pobj_SideWeb; pobj_SideWeb=0; //メインウィンドウの最大化有無、座標を保存 if(IsZoomed()) pobj_nv->bWindowMax=1; else if(!IsIconic()){ pobj_nv->bWindowMax=0; GetWindowRect(&pobj_nv->StartupWindowRect); } hChild=::GetWindow(hClient,GW_CHILD); while(hChild){ CloseDocWindow(GetWndNum(hChild)); ::DestroyWindow(hChild); hChild=::GetWindow(hClient,GW_CHILD); } EndProjectEditor(); //ProjectEditorの情報を保存 //エディタ用フォントを破棄 extern HFONT hFont_TextEdit,hFont_HyperLink_TextEdit; if(hFont_TextEdit) DeleteObject(hFont_TextEdit); if(hFont_HyperLink_TextEdit) DeleteObject(hFont_HyperLink_TextEdit); DestroyWindow(); } void MainFrame::OnDestroy() { ::PostQuitMessage( 0 ); } void backup(void *dummy); void MainFrame::OnTimer( UINT_PTR id ) { switch( id ) { case ID_TIMER_BACKUP: _beginthread( backup, 0, 0 ); break; #ifndef THETEXT case ID_DEBUGSAFTY: { //BasicCompiler.exeが強制終了しているかどうかを検証 extern CDebugger *pobj_Debugger; pobj_Debugger->SaftyCheck(); break; } #endif } } void ResetState_EditMenu(void); void MainFrame::OnDrawClipboard() { ResetState_EditMenu(); } void MenuAdvice(WPARAM msg); void MainFrame::OnMenuSelect( UINT nItemID, UINT nFlags, HMENU menu ) { MenuAdvice( nItemID ); } void MainFrame::OnInitMenu( HMENU menu ) { extern CNonVolatile *pobj_nv; extern CSubMenuEx *pobj_FileHistoryMenu; pobj_nv->pobj_History->ResetFileMenu(pobj_FileHistoryMenu,1); #ifndef THETEXT extern CSubMenuEx *pobj_ProjectHistoryMenu; pobj_nv->pobj_ProjectHistory->ResetFileMenu(pobj_ProjectHistoryMenu,0); #endif } void MainFrame::OnMeasureItem( int nIDCtl, LPMEASUREITEMSTRUCT lpMI ) { if(lpMI->CtlType==ODT_MENU){ SIZE size; CMenuItemData *pobj_MenuItemData; pobj_MenuItemData=(CMenuItemData *)lpMI->itemData; if(pobj_MenuItemData->pobj_ThisMenu->hMenu==pobj_MainMenu->hMenu){ //メインメニューの親アイテム pobj_MainMenu->GetItemSize(pobj_MenuItemData->item_index,&size); lpMI->itemWidth = size.cx; lpMI->itemHeight = size.cy; } else{ //メインメニューにぶらさがるサブメニュー pobj_MenuItemData->pobj_ThisMenu->GetItemSize(pobj_MenuItemData->item_index,&size); lpMI->itemWidth = size.cx; lpMI->itemHeight = size.cy; } } } void MainFrame::OnDrawItem( int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct ) { if(lpDrawItemStruct->CtlType==ODT_MENU){ if(!pobj_MainMenu) return; CMenuItemData *pobj_MenuItemData; pobj_MenuItemData=(CMenuItemData *)lpDrawItemStruct->itemData; if(pobj_MainMenu->hMenu==pobj_MenuItemData->pobj_ThisMenu->hMenu){ //メインメニューの親アイテム pobj_MainMenu->OwnerDrawMenu(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, (lpDrawItemStruct->itemState&ODS_SELECTED)!=0, pobj_MenuItemData->item_index); } else{ //メインメニューにぶらさがるサブメニュー pobj_MainMenu->OwnerDrawSubMenu(pobj_MenuItemData->pobj_ThisMenu->hMenu, lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, (lpDrawItemStruct->itemState&ODS_SELECTED)!=0, pobj_MenuItemData->item_index); } } } LRESULT MainFrame::OnNotify( int idCtrl, LPNMHDR pnmh ) { NMPGCALCSIZE *lpCalcSize; NMPGSCROLL *lpScroll; if(!pnmh) return 0; LPTOOLTIPTEXT TipText=(LPTOOLTIPTEXT)pnmh; if(TipText->hdr.code==TTN_NEEDTEXT) ShowToolTipText(TipText); extern HWND hStandardToolbarPager; extern HWND hDebuggerToolbarPager; if(pobj_Rebar){ //レバーオブジェクトが存在するとき if(pnmh->hwndFrom==pobj_Rebar->hRebar&&pnmh->code==RBN_HEIGHTCHANGE){ this->Resized(); return 0; } } if(pnmh->hwndFrom==hStandardToolbarPager){ if(pnmh->code==PGN_CALCSIZE){ lpCalcSize=(LPNMPGCALCSIZE)pnmh; if(lpCalcSize->dwFlag==PGF_CALCWIDTH) lpCalcSize->iWidth=BMPNUM_STANDARDTOOLBAR*23+SEPNUM_STANDARDTOOLBAR*8; } else if(pnmh->code==PGN_SCROLL){ lpScroll=(LPNMPGSCROLL)pnmh; lpScroll->iScroll=20; } } else if(pnmh->hwndFrom==hDebuggerToolbarPager){ if(pnmh->code==PGN_CALCSIZE){ lpCalcSize=(LPNMPGCALCSIZE)pnmh; if(lpCalcSize->dwFlag==PGF_CALCWIDTH) lpCalcSize->iWidth=BMPNUM_DEBUGGERTOOLBAR*23+SEPNUM_DEBUGGERTOOLBAR*8; } else if(pnmh->code==PGN_SCROLL){ lpScroll=(LPNMPGSCROLL)pnmh; lpScroll->iScroll=20; } } if(pobj_MainTab){ if(pnmh->hwndFrom==pobj_MainTab->hTab){ if(pnmh->code==TCN_SELCHANGE) pobj_MainTab->SelChangeEvent(); if(pnmh->code==NM_RCLICK){ TCHITTESTINFO tcHitTest; GetCursorPos(&tcHitTest.pt); ::ScreenToClient(pobj_MainTab->hTab,&tcHitTest.pt); int index = TabCtrl_HitTest(pobj_MainTab->hTab,&tcHitTest); if( index == -1 ) return 0; TabCtrl_SetCurSel(pobj_MainTab->hTab,index); pobj_MainTab->SelChangeEvent(); ///////////////////// // メニューを表示 ///////////////////// HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); //保存コマンドの文字列をセット char temporary[1024], temp2[1024]; MENUITEMINFO mii; mii.cbSize=sizeof(MENUITEMINFO); mii.fMask=MIIM_TYPE; mii.dwTypeData=temporary; mii.fType=MFT_STRING; if(!MdiInfo[WndNum]->path.empty()){ _splitpath(MdiInfo[WndNum]->path.c_str(),NULL,NULL,temporary,temp2); lstrcat(temporary,temp2); lstrcat(temporary," を保存(&S)"); } else{ lstrcpy(temporary,"保存(&S)"); } extern HMENU hTabMenu; SetMenuItemInfo(hTabMenu,IDM_SAVE,FALSE,&mii); /*「絶対パスをコピー」「フォルダを開く」「ファイルを削除」 コマンドを場合によって無効化にする */ if(!MdiInfo[WndNum]->path.empty()){ EnableMenuItem(hTabMenu,IDM_PATH_COPY,MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hTabMenu,IDM_FOLDER_OPEN,MF_BYCOMMAND|MF_ENABLED); EnableMenuItem(hTabMenu,IDM_DELETE_FILE,MF_BYCOMMAND|MF_ENABLED); } else{ EnableMenuItem(hTabMenu,IDM_PATH_COPY,MF_BYCOMMAND|MF_GRAYED); EnableMenuItem(hTabMenu,IDM_FOLDER_OPEN,MF_BYCOMMAND|MF_GRAYED); EnableMenuItem(hTabMenu,IDM_DELETE_FILE,MF_BYCOMMAND|MF_GRAYED); } POINT MousePos; GetCursorPos(&MousePos); TrackPopupMenu(hTabMenu,TPM_LEFTALIGN|TPM_RIGHTBUTTON,MousePos.x,MousePos.y,0,hOwner,NULL); } } } if(pobj_SideWeb){ if(pnmh->hwndFrom==pobj_SideWeb->hTab&&pnmh->code==TCN_SELCHANGE){ pobj_SideWeb->SelChangeEvent(); } } return 0; } void MainFrame::OnDropFiles( HDROP hDropInfo ) { int max = DragQueryFile(hDropInfo,static_cast(-1),0,0); for(int i=0;iGetClientRect( &rect ); dc.FillRect( &rect, GetSysColorBrush( COLOR_3DFACE ) ); } ::LRESULT MainFrame::OnShowSourceLine( ::UINT msg, ::WPARAM wParam, ::LPARAM lParam, ::BOOL& handled ) { char temporary[1024]; //エラー部分を反転表示 DWORD AccBytes; { sprintf(temporary,"%s\\pgm.tmp",ActiveBasic::Common::Environment::GetUserAppDir().c_str()); ATL::CHandle fh(CreateFile(temporary,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL)); if(fh==INVALID_HANDLE_VALUE){ fh.Detach(); return 0; } ReadFile(fh,temporary,MAX_PATH,&AccBytes,NULL); } temporary[AccBytes]=0; HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum = -1; while(hChild){ WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ if(lstrcmpi(MdiInfo[WndNum]->path.c_str(),temporary)==0) break; } hChild=::GetNextWindow(hChild,GW_HWNDNEXT); } if(!hChild){ hChild=OpenFileWithExtension(temporary); WndNum=GetWndNum(hChild); } if(WndNum==-1) return 0; //ウィンドウを最前面に表示 ::BringWindowToTop(hChild); ::UpdateWindow(hChild); const char *pTemp=MdiInfo[WndNum]->pMdiTextEdit->buffer; //行の先頭インデックスを取得(取得する行の番号はwParamで渡される) int i,i2; for(i=0,i2=0;;i++){ if(i2>=(int)wParam) break; if(pTemp[i]=='\0') break; if(pTemp[i]=='\r'&&pTemp[i+1]=='\n'){ i++; i2++; } } POINT pos; pos.x=i; //行の終端インデックスを取得 for(;;i++){ if(pTemp[i]=='\0') break; if(pTemp[i]=='\r'&&pTemp[i+1]=='\n') break; } pos.y=i; //行を選択する TextEdit_SetSel(WndNum,pos.x,pos.y,TRUE); return 0; } ::LRESULT MainFrame::OnTaskbarButtonCreated( ::UINT msg, ::WPARAM, ::LPARAM ) { if ( msg == 0 ) { // 念のため確認 return 0; } taskbarList.reset(new TaskbarList(*this)); return 0; } void MainFrame::AddChildWindow( HWND hwndChild ) { if (taskbarList) { taskbarList->RegisterTab( hwndChild ); } } void MainFrame::DeleteChildWindow( HWND hwndChild ) { if (taskbarList) { taskbarList->UnregisterTab( hwndChild ); } } void MainFrame::ActivateChildWindow( HWND hwndChild ) { if (taskbarList) { taskbarList->SetTabActivate( hwndChild ); } } void MainFrame::SetTabOrder( HWND hwndChild, HWND hwndInsertBefore ) { if (taskbarList) { taskbarList->SetTabOrder( hwndChild, hwndInsertBefore ); } } void MainFrame::InvalidateBitmap( HWND hwndChild ) { if (taskbarList) { taskbarList->InvalidateIconicBitmaps( hwndChild ); } } void MainFrame::OnCmdNew( UINT uNotifyCode, int nID, CWindow wndCtl ) { #ifdef THETEXT NewTextEditWindow(NULL,WNDTYPE_TEXT); return; #else int FileType; BOOL bAddToProject; char temporary[MAX_PATH]; FileType = ActiveBasic::Resource::DialogBoxAlt(hResInst, IDD_NEWFILE, hOwner, DlgNewFile); if(FileType==-1) return; if(FileType&0x00008000){ bAddToProject=1; FileType&=0x0FFF; extern char NewFileName[MAX_PATH]; lstrcpy(temporary,NewFileName); if(!strstr(temporary,".")) lstrcat(temporary,".ab"); lstrcpy( temporary, projectInfo.GetWorkDir().GetFullPath( temporary ).c_str() ); } else bAddToProject=0; switch(FileType){ case FT_BASICPROGRAM: //Basicプログラム case FT_SUBPROGRAM: if(bAddToProject){ WriteBuffer(temporary,0,0); NewTextEditWindow(temporary,WNDTYPE_BASIC); Project_File_Insert(temporary); } else NewTextEditWindow(NULL,WNDTYPE_BASIC); break; case FT_PROJECT: DlgNewProjectWizard(hOwner); break; case FT_TEXT: NewTextEditWindow(NULL,WNDTYPE_TEXT); break; case FT_HTML: NewTextEditWindow(NULL,WNDTYPE_HTML); break; case FT_ICON: NewIconEditWindow(NULL); break; } #endif } void MainFrame::OnCmdOpen( UINT uNotifyCode, int nID, CWindow wndCtl ) { //"ファイルを指定してください" extern const LPCSTR DefFileFilter; char temporary[1024]; if(!GetFilePathDialog(m_hWnd,temporary,DefFileFilter,STRING_FILEOPENTITLE_DEFAULT,TRUE)) return; OpenFileWithExtension( temporary ); } void MainFrame::OnCmdClose( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); if(::IsWindow(hChild)) SendMessage(hChild,WM_CLOSE,0,0); } void MainFrame::OnCmdProjectOpen( UINT uNotifyCode, int nID, CWindow wndCtl ) { //"プロジェクト ファイルを指定して下さい" extern const LPCSTR ProjectFileFilter; char temporary[1024]; if(!GetFilePathDialog(m_hWnd,temporary,ProjectFileFilter,STRING_FILEOPENTITLE_PROJECT,TRUE)) { return; } projectInfo.Load(temporary); } void MainFrame::OnCmdProjectSave( UINT uNotifyCode, int nID, CWindow wndCtl ) { projectInfo.Save(); } void MainFrame::OnCmdProjectClose( UINT uNotifyCode, int nID, CWindow wndCtl ) { projectInfo.Close(); } void MainFrame::OnCmdProjectFolderOpen( UINT uNotifyCode, int nID, CWindow wndCtl ) { ShellExecute(m_hWnd,"explore",projectInfo.GetWorkDir().GetPath().c_str(),NULL,NULL,SW_SHOWNORMAL); } void MainFrame::OnCmdSave( UINT uNotifyCode, int nID, CWindow wndCtl ) { SaveDocument(::GetWindow(hClient,GW_CHILD),NULL); } void MainFrame::OnCmdNewSave( UINT uNotifyCode, int nID, CWindow wndCtl ) { //"保存先のファイルを指定してください" extern const LPCSTR DefFileFilter; char temporary[1024]; if(!GetFilePathDialog(m_hWnd,temporary,DefFileFilter,STRING_FILESAVETITLE_DEFAULT,FALSE)) return; SaveDocument(::GetWindow(hClient,GW_CHILD),temporary); } void MainFrame::OnCmdCodeSave( UINT uNotifyCode, int nID, CWindow wndCtl ) { //文字コードを指定して保存 DialogBox(hResInst,MAKEINTRESOURCE(IDD_CODE_SAVE),m_hWnd,nkfDlgCodeSave); } void MainFrame::OnCmdAllSave( UINT uNotifyCode, int nID, CWindow wndCtl ) { foreach( MDIINFO *mi, MdiInfo ){ if(mi->hwnd) SaveDocument(mi->hwnd,NULL); } if( projectInfo.IsOpened() ) { projectInfo.Save(); } } void MainFrame::OnCmdPageSet( UINT uNotifyCode, int nID, CWindow wndCtl ) { //ページ設定 obj_Page.SetupDlg(); } void MainFrame::OnCmdPreview( UINT uNotifyCode, int nID, CWindow wndCtl ) { //プレビュー(Pro版のみ) Preview(); } void MainFrame::OnCmdPrintOut( UINT uNotifyCode, int nID, CWindow wndCtl ) { //印刷 Printout(); } void MainFrame::OnCmdExit( UINT uNotifyCode, int nID, CWindow wndCtl ) { SendMessage(WM_CLOSE); } void MainFrame::OnCmdUndo( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); if(!hChild) return; int WndNum=GetWndNum(hChild); if( IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType) ) { TextEdit_UndoCommand(WndNum); } else if( MdiInfo[WndNum]->DocType == WNDTYPE_RAD ) { Rad_UndoCommand(WndNum); } else if( MdiInfo[WndNum]->DocType == WNDTYPE_ICONEDIT ) { IconEdit_UndoCommand(WndNum); } } void MainFrame::OnCmdRedo( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); if(!hChild) return; int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)) TextEdit_RedoCommand(WndNum); else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD) Rad_RedoCommand(WndNum); else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT) IconEdit_RedoCommand(WndNum); } void MainFrame::OnCmdCut( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ HWND hEdit=::GetWindow(hChild,GW_CHILD); CHARRANGE CharRange; TextEdit_GetSel(WndNum,&CharRange); HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,CharRange.cpMax-CharRange.cpMin+1); char *pTemp=(char *)GlobalLock(hGlobal); memcpy(pTemp,MdiInfo[WndNum]->pMdiTextEdit->buffer+CharRange.cpMin,CharRange.cpMax-CharRange.cpMin); pTemp[CharRange.cpMax-CharRange.cpMin]=0; GlobalUnlock(hGlobal); //クリップボードに保存 OpenClipboard(); EmptyClipboard(); SetClipboardData(CF_TEXT,hGlobal); CloseClipboard(); //選択文字列を消去 SendMessage(hEdit,WM_KEYDOWN,VK_DELETE,0); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD){ ActiveBasic::PM::WindowInfo *pWindowInfo = GetWndInfo(MdiInfo[WndNum]->path); int indexOfWndInfo = GetWndInfoNum(MdiInfo[WndNum]->path); //クリップボードに格納するためのデータを用意する pWindowInfo->childWindowInfos[MdiInfo[WndNum]->MdiRadInfo->SelectingItem[0]]->pos.x-=17; pWindowInfo->childWindowInfos[MdiInfo[WndNum]->MdiRadInfo->SelectingItem[0]]->pos.y-=10; HGLOBAL hGlobal=Rad_GetChildInfoClipboardData(WndNum,indexOfWndInfo); pWindowInfo->childWindowInfos[MdiInfo[WndNum]->MdiRadInfo->SelectingItem[0]]->pos.x+=17; pWindowInfo->childWindowInfos[MdiInfo[WndNum]->MdiRadInfo->SelectingItem[0]]->pos.y+=10; OpenClipboard(); EmptyClipboard(); extern DWORD dwRadClipboardID; SetClipboardData(dwRadClipboardID,hGlobal); CloseClipboard(); SendMessage(MdiInfo[WndNum]->MdiRadInfo->hRad,WM_COMMAND,IDM_RAD_ITEM_DELETE,0); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){ //クリップボードに格納するためのデータを用意する HGLOBAL hGlobal=IconEdit_GetChildInfoClipboardData(WndNum); if(hGlobal==0) return; OpenClipboard(); EmptyClipboard(); SetClipboardData(CF_BITMAP,hGlobal); CloseClipboard(); DeleteObject(MdiInfo[WndNum]->MdiIconEditInfo->hSelectingBmp); MdiInfo[WndNum]->MdiIconEditInfo->SelectLevel=0; IconEdit_EraseRect(WndNum,&MdiInfo[WndNum]->MdiIconEditInfo->DraggingRect); } } void MainFrame::OnCmdCopy( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ HWND hEdit = ::GetWindow(hChild,GW_CHILD); CHARRANGE CharRange; TextEdit_GetSel(WndNum,&CharRange); HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,CharRange.cpMax-CharRange.cpMin+1); char *pTemp=(char *)GlobalLock(hGlobal); memcpy(pTemp,MdiInfo[WndNum]->pMdiTextEdit->buffer+CharRange.cpMin,CharRange.cpMax-CharRange.cpMin); pTemp[CharRange.cpMax-CharRange.cpMin]=0; GlobalUnlock(hGlobal); //クリップボードに保存 OpenClipboard(); EmptyClipboard(); SetClipboardData(CF_TEXT,hGlobal); CloseClipboard(); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD){ int indexOfWndInfo = GetWndInfoNum(MdiInfo[WndNum]->path); //クリップボードに格納するためのデータを用意する HGLOBAL hGlobal=Rad_GetChildInfoClipboardData(WndNum,indexOfWndInfo); OpenClipboard(); EmptyClipboard(); extern DWORD dwRadClipboardID; SetClipboardData(dwRadClipboardID,hGlobal); CloseClipboard(); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){ //クリップボードに格納するためのデータを用意する HGLOBAL hGlobal=IconEdit_GetChildInfoClipboardData(WndNum); OpenClipboard(); EmptyClipboard(); SetClipboardData(CF_BITMAP,hGlobal); CloseClipboard(); } } void MainFrame::OnCmdPaste( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ HWND hEdit=::GetWindow(hChild,GW_CHILD); //クリップボードを開く OpenClipboard(); HGLOBAL hGlobal=GetClipboardData(CF_TEXT); if(!hGlobal){ CloseClipboard(); return; } char *pTemp; if(pobj_nv->bPasteIndent){ //インデント整形 pTemp=CodeFormatter((char *)GlobalLock(hGlobal)); GlobalUnlock(hGlobal); } else pTemp=(char *)GlobalLock(hGlobal); //テキストエディタの文字列をリプレイス TextEdit_ReplaceUpdateUndoData(WndNum, pTemp, 1, 1); if(pobj_nv->bPasteIndent) HeapDefaultFree(pTemp); else GlobalUnlock(hGlobal); //クリップボードを閉じる CloseClipboard(); //キャレット位置までスクロールする TextEdit_ScrollCaret(WndNum,0); ResetCaretPos(WndNum); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD){ OpenClipboard(); extern DWORD dwRadClipboardID; HGLOBAL hGlobal=GetClipboardData(dwRadClipboardID); if(!hGlobal){ CloseClipboard(); return; } Rad_PasteChildInfoClipboardData(WndNum,hGlobal); CloseClipboard(); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_ICONEDIT){ OpenClipboard(); HGLOBAL hGlobal=GetClipboardData(CF_BITMAP); if(!hGlobal){ CloseClipboard(); return; } IconEdit_PasteChildInfoClipboardData(WndNum,(HBITMAP)hGlobal); CloseClipboard(); } } void MainFrame::OnCmdDelete( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ HWND hEdit=::GetWindow(hChild,GW_CHILD); TextEdit_ReplaceUpdateUndoData(WndNum,"",0,1); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD) SendMessage(MdiInfo[WndNum]->MdiRadInfo->hRad,WM_COMMAND,IDM_RAD_ITEM_DELETE,0); } void MainFrame::OnCmdAllSelect( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); if(IS_DOCUMENT_TEXT(MdiInfo[WndNum]->DocType)){ HWND hEdit=::GetWindow(hChild,GW_CHILD); MdiInfo[WndNum]->pMdiTextEdit->StartCaretPos.x=0; MdiInfo[WndNum]->pMdiTextEdit->StartCaretPos.y=0; GetCaretPosFromBufferIndex( MdiInfo[WndNum]->pMdiTextEdit->buffer, lstrlen(MdiInfo[WndNum]->pMdiTextEdit->buffer), &MdiInfo[WndNum]->pMdiTextEdit->EndCaretPos); ::InvalidateRect(hEdit,NULL,0); ResetState_EditMenu(); } else if(MdiInfo[WndNum]->DocType==WNDTYPE_RAD){ ActiveBasic::PM::WindowInfo *pWindowInfo = GetWndInfo(MdiInfo[WndNum]->path); for( int i3=0; i3(pWindowInfo->childWindowInfos.size()); i3++ ) { MdiInfo[WndNum]->MdiRadInfo->SelectingItem[i3] = i3; } DrawRadWindow(WndNum,pWindowInfo); } } void MainFrame::OnCmdFind( UINT uNotifyCode, int nID, CWindow wndCtl ) { ActiveBasic::Resource::DialogBoxAlt(hResInst, IDD_FIND, m_hWnd, DlgFind); } void MainFrame::OnCmdPermutation( UINT uNotifyCode, int nID, CWindow wndCtl ) { ActiveBasic::Resource::DialogBoxAlt(hResInst, IDD_PERMUTATION, m_hWnd, DlgPermutation); } void MainFrame::OnCmdConvertX( UINT uNotifyCode, int nID, CWindow wndCtl ) { TextEdit_Convert( nID ); } #ifdef THETEXT void MainFrame::OnCmdStringCount( UINT uNotifyCode, int nID, CWindow wndCtl ) { DialogBoxParam(hResInst,MAKEINTRESOURCE(IDD_STRING_COUNT),m_hWnd,DlgStringCount,0); } void MainFrame::OnCmdSelStringCount( UINT uNotifyCode, int nID, CWindow wndCtl ) { DialogBoxParam(hResInst,MAKEINTRESOURCE(IDD_STRING_COUNT),m_hWnd,DlgStringCount,1); } #endif void MainFrame::OnCmdProjectView( UINT uNotifyCode, int nID, CWindow wndCtl ) { extern HWND hProjectView; bool isCheck = false; if(pobj_nv->bClipProjectView){ if(::IsWindowVisible(hProjectView)){ ::ShowWindow(hProjectView,SW_HIDE); } else{ ::ShowWindow(hProjectView,SW_SHOW); isCheck = true; } } else{ extern HWND hProjectView_ToolWindow; if(::IsWindowVisible(hProjectView_ToolWindow)){ ::ShowWindow(hProjectView_ToolWindow,SW_HIDE); } else{ ::ShowWindow(hProjectView_ToolWindow,SW_SHOW); ::ShowWindow(hProjectView,SW_SHOW); isCheck = true; } } pobj_MainMenu->CheckMenu(IDM_PROJECTVIEW,isCheck); //再配置 this->Resized(); ::ShowWindow(hClient,SW_SHOW); } void MainFrame::OnCmdProjectOption( UINT uNotifyCode, int nID, CWindow wndCtl ) { DlgProjectOptionSetting( m_hWnd ); } void MainFrame::OnCmdTopMost( UINT uNotifyCode, int nID, CWindow wndCtl ) { if(pobj_MainMenu->IsCheck(IDM_TOPMOST)){ SetWindowPos( HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); pobj_MainMenu->CheckMenu(IDM_TOPMOST,0); } else{ SetWindowPos( HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); pobj_MainMenu->CheckMenu(IDM_TOPMOST,1); } } void ResetState_ViewMenu(void); void MainFrame::OnCmdRightTurn( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_nv->bRightTurn^=1; ResetState_ViewMenu(); //トップのウィンドウを再描画 RedrawAllWindow(); } void MainFrame::OnCmdSet( UINT uNotifyCode, int nID, CWindow wndCtl ) { DlgOptionSetting( m_hWnd ); } #ifndef THETEXT void MainFrame::OnCmdDebug( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024], temp2[1024], temp3[1024]; if(pobj_Debugger->IsDebugging()){ pobj_Debugger->DebugContinue(); return; } HWND hChild = ::GetWindow(hClient,GW_CHILD); if( projectInfo.IsOpened() ){ //プロジェクトが開かれている場合 if(!SetProjectToRun()) return; //デバッグ用のコマンドライン及び実行可能ファイル(DLLのみ) sprintf(temporary,"%s\r\n%s",projectInfo.szExePath,projectInfo.szCmdLine); sprintf(temp2,"%s\\pgm.tmp",ActiveBasic::Common::Environment::GetUserAppDir().c_str()); { ATL::CHandle hFile(CreateFile(temp2,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_TEMPORARY,NULL)); if(hFile==INVALID_HANDLE_VALUE){ hFile.Detach(); MessageBox(TEXT("デバッグ用ファイルを開けませんでした。")); return; } DWORD dwAccessBytes; WriteFile(hFile,temporary,lstrlen(temporary),&dwAccessBytes,NULL); } //ソースファイル名をtemp2へ lstrcpy( temp2, projectInfo.fileSystem.root.files[0].GetFullPath().c_str() ); //出力ファイル名をtemp3へ lstrcpy(temp3,projectInfo.lpszOutput_Debug); lstrcpy( temp3, projectInfo.GetWorkDir().GetFullPath( temp3 ).c_str() ); if(IsNeedCompileForProject(1)) sprintf(temporary,"\"%s\" \"%s\" /debug /run /wnd:%p",temp2,temp3,m_hWnd); else sprintf(temporary,"\"%s\" \"%s\" /run /wnd:%p",temp2,temp3,m_hWnd); // DLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll ) { lstrcat(temporary," /dll"); } // SLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Sll ) { lstrcat(temporary," /static_library"); } //Unicodeオプション if(projectInfo.dwOption & PJ_OP_UNICODE) lstrcat(temporary," /unicode"); //ブレークポイントをセーブ projectInfo.pobj_DBBreakPoint->SaveToTempFile(); } else{ //単独ソースコード if(!SetRunning(hChild)) return; if(IsNeedCompile(MdiInfo[GetWndNum(hChild)]->path,1)) sprintf(temporary,"\"%s\" /debug /run /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd); else sprintf(temporary,"\"%s\" /run /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd); //ブレークポイントをセーブ extern CDBBreakPoint *pobj_DBBreakPoint; pobj_DBBreakPoint->SaveToTempFile(); } //コンパイルビューをクリップするかどうか extern BOOL bClipCompileView; if(bClipCompileView){ lstrcat(temporary," /clip_compile_view"); //コンパイラビューを閉じる extern HWND hCompileView; if(hCompileView==(HWND)-1) return; if(hCompileView){ hChild=hCompileView; hCompileView=(HWND)-1; SendMessage(hChild,WM_COMMAND,IDCANCEL,0); } //重複起動防止のため hCompileView=(HWND)-1; } //インクルードディレクトリ sprintf(temp2," /include_dir:\"%s\"",pobj_nv->GetIncludeDirFullPath().c_str()); lstrcat(temporary,temp2); extern ActiveBasic::Common::Platform::EnumType selectingPlatform; CreateProcessWithStdHandle( ActiveBasic::Common::Environment::GetCompilerExePath( selectingPlatform ), temporary, false ); } void MainFrame::OnCmdDebugCompile( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024], temp2[1024], temp3[1024]; HWND hChild=::GetWindow(hClient,GW_CHILD); if( projectInfo.IsOpened() ){ //プロジェクトが開かれている場合 if(!SetProjectToRun()) return; //ソースファイル名をtemp2へ lstrcpy( temp2, projectInfo.fileSystem.root.files[0].GetFullPath().c_str() ); //出力ファイル名をtemp3へ lstrcpy(temp3,projectInfo.lpszOutput_Debug); lstrcpy( temp3, projectInfo.GetWorkDir().GetFullPath( temp3 ).c_str() ); sprintf(temporary,"\"%s\" \"%s\" /debug /wnd:%p",temp2,temp3,m_hWnd); //DLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll ) { lstrcat(temporary," /dll"); } // SLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Sll ) { lstrcat(temporary," /static_library"); } //Unicodeオプション if(projectInfo.dwOption & PJ_OP_UNICODE) lstrcat(temporary," /unicode"); } else{ //単独ソースコード if(!SetRunning(hChild)) return; sprintf(temporary,"\"%s\" /debug /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd); } //コンパイルビューをクリップするかどうか extern BOOL bClipCompileView; if(bClipCompileView){ lstrcat(temporary," /clip_compile_view"); //コンパイラビューを閉じる extern HWND hCompileView; if(hCompileView==(HWND)-1) return; if(hCompileView){ hChild=hCompileView; hCompileView=(HWND)-1; if( ::IsWindow( hChild ) ) { SendMessage(hChild,WM_COMMAND,IDCANCEL,0); } } //重複起動防止のため hCompileView=(HWND)-1; } //インクルードディレクトリ sprintf(temp2," /include_dir:\"%s\"",pobj_nv->GetIncludeDirFullPath().c_str()); lstrcat(temporary,temp2); extern ActiveBasic::Common::Platform::EnumType selectingPlatform; CreateProcessWithStdHandle( ActiveBasic::Common::Environment::GetCompilerExePath( selectingPlatform ), temporary, false ); } void MainFrame::OnCmdAttach( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024], temp2[1024]; int idProcess; DWORD dwPlatform; idProcess = ActiveBasic::Resource::DialogBoxAlt(hResInst, IDD_ATTACH, m_hWnd, DlgAttach, reinterpret_cast(&dwPlatform)); if(idProcess==0) return; sprintf(temporary,"/attach:%08x /wnd:%p",idProcess,m_hWnd); //コンパイルビューをクリップするかどうか extern BOOL bClipCompileView; if(bClipCompileView){ lstrcat(temporary," /clip_compile_view"); //コンパイラビューを閉じる extern HWND hCompileView; if(hCompileView==(HWND)-1) return; if(hCompileView){ HWND hChild=hCompileView; hCompileView=(HWND)-1; SendMessage(hChild,WM_COMMAND,IDCANCEL,0); } //重複起動防止のため hCompileView=(HWND)-1; } //インクルードディレクトリ sprintf(temp2," /include_dir:\"%s\"",pobj_nv->GetIncludeDirFullPath().c_str()); lstrcat(temporary,temp2); ActiveBasic::Common::Platform::EnumType platform; if(dwPlatform==IMAGE_FILE_MACHINE_I386) { platform = ActiveBasic::Common::Platform::X86; } else if(dwPlatform==IMAGE_FILE_MACHINE_AMD64) { platform = ActiveBasic::Common::Platform::X64; } else { throw; } extern ActiveBasic::Common::Platform::EnumType selectingPlatform; CreateProcessWithStdHandle( ActiveBasic::Common::Environment::GetCompilerExePath( platform ), temporary, false ); } void MainFrame::OnCmdReleaseCompile( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024], temp2[1024], temp3[1024]; HWND hChild=::GetWindow(hClient,GW_CHILD); if( projectInfo.IsOpened() ){ //プロジェクトが開かれている場合 if(!SetProjectToRun()) return; //ソースファイル名をtemp2へ lstrcpy( temp2, projectInfo.fileSystem.root.files[0].GetFullPath().c_str() ); //出力ファイル名をtemp3へ lstrcpy(temp3,projectInfo.lpszOutput_Release); lstrcpy( temp3, projectInfo.GetWorkDir().GetFullPath( temp3 ).c_str() ); sprintf(temporary,"\"%s\" \"%s\" /wnd:%p",temp2,temp3,m_hWnd); //DLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll ) { lstrcat(temporary," /dll"); } // SLLオプション if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Sll ) { lstrcat(temporary," /static_library"); } //Unicodeオプション if(projectInfo.dwOption & PJ_OP_UNICODE) lstrcat(temporary," /unicode"); } else{ //単独ソースコード if(!SetRunning(hChild)) return; sprintf(temporary,"\"%s\" /wnd:%p",MdiInfo[GetWndNum(hChild)]->path.c_str(),m_hWnd); } //コンパイルビューをクリップするかどうか extern BOOL bClipCompileView; if(bClipCompileView){ lstrcat(temporary," /clip_compile_view"); //コンパイラビューを閉じる extern HWND hCompileView; if(hCompileView==(HWND)-1) return; if(hCompileView){ hChild=hCompileView; hCompileView=(HWND)-1; if( ::IsWindow( hChild ) ) { SendMessage(hChild,WM_COMMAND,IDCANCEL,0); } } //重複起動防止のため hCompileView=(HWND)-1; } //インクルードディレクトリ sprintf(temp2," /include_dir:\"%s\"",pobj_nv->GetIncludeDirFullPath().c_str()); lstrcat(temporary,temp2); extern ActiveBasic::Common::Platform::EnumType selectingPlatform; CreateProcessWithStdHandle( ActiveBasic::Common::Environment::GetCompilerExePath( selectingPlatform ), temporary, false ); } void MainFrame::OnCmdReleaseRun( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024], temp2[1024], temp3[1024]; HWND hChild=::GetWindow(hClient,GW_CHILD); if( projectInfo.IsOpened() ){ /* //プロジェクトが開かれている場合 if(!SetProjectToRun()) return; //必要であればリリースコンパイル if(IsNeedCompileForProject(0)) SendMessage(WM_COMMAND,IDM_RELEASECOMPILE,0);*/ if( projectInfo.GetModuleType() == ActiveBasic::Common::TargetModuleType::Dll ) { lstrcpy(temporary,projectInfo.szExePath); } else{ lstrcpy(temporary,projectInfo.lpszOutput_Debug); lstrcpy( temporary, projectInfo.GetWorkDir().GetFullPath( temporary ).c_str() ); } } else{ /* //必要であればリリースコンパイル if(!SetRunning(hChild)) return; if(IsNeedCompile(MdiInfo[GetWndNum(hChild)]->path,0)) SendMessage(WM_COMMAND,IDM_RELEASECOMPILE,0);*/ //単独ソースコード _splitpath(MdiInfo[GetWndNum(hChild)]->path.c_str(),temporary,temp2,temp3,NULL); lstrcat(temporary,temp2); lstrcat(temporary,temp3); lstrcat(temporary,".exe"); } //インクルードディレクトリ sprintf(temp2," /include_dir:\"%s\"",pobj_nv->GetIncludeDirFullPath().c_str()); lstrcat(temporary,temp2); ShellExecute(m_hWnd,"open",temporary,NULL,NULL,SW_SHOWNORMAL); } void MainFrame::OnCmdStepIn( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Debugger->StepIn(); } void MainFrame::OnCmdStepOver( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Debugger->StepOver(); } void MainFrame::OnCmdStepCursor( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Debugger->StepToCursor(); } void MainFrame::OnCmdBreakPoint( UINT uNotifyCode, int nID, CWindow wndCtl ) { if( projectInfo.IsOpened() ){ projectInfo.pobj_DBBreakPoint->Event_BreakPoint(); } else{ extern CDBBreakPoint *pobj_DBBreakPoint; pobj_DBBreakPoint->Event_BreakPoint(); } } void MainFrame::OnCmdDebugStop( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Debugger->DebugStop(); } void MainFrame::OnCmdDebugPause( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Debugger->DebugPause(); } #endif // not THETEXT void MainFrame::OnCmdWebLink( UINT uNotifyCode, int nID, CWindow wndCtl ) { switch( nID ) { #ifndef THETEXT case IDM_COMMUNITY: OpenWebBrowser( "http://www.activebasic.com/forum/" ); break; case IDM_COMMU_SEARCH: OpenWebBrowser( "http://www.activebasic.com/forum/search.php" ); break; case IDM_COMMU_PM: OpenWebBrowser( "http://www.activebasic.com/forum/privmsg.php?folder=inbox" ); break; case ID_COMMU_FORUM1: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=1" ); break; case ID_COMMU_FORUM2: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=2" ); break; case ID_COMMU_FORUM3: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=5" ); break; case ID_COMMU_FORUM4: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=3" ); break; case ID_COMMU_FORUM5: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=6" ); break; case ID_COMMU_FORUM6: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=8" ); break; case ID_COMMU_FORUM7: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=4" ); break; case ID_COMMU_FORUM8: OpenWebBrowser( "http://www.activebasic.com/forum/viewforum.php?f=7" ); break; case IDM_AB_WEBSITE: OpenWebBrowser( "http://www.activebasic.com/" ); break; case IDM_ACTBDL: OpenWebBrowser( "http://www.activebasic.com/activebasic5/download.htm" ); break; #else case IDM_DSHOMEPAGE: OpenWebBrowser( "http://www.discoversoft.net/" ); break; #endif // not THETEXT default: throw; } } void MainFrame::OnCmdTopics( UINT uNotifyCode, int nID, CWindow wndCtl ) { char temporary[1024]; #ifdef THETEXT sprintf(temporary,"%sTopics\\index.html",pj_editor_Dir); ShellExecute(m_hWnd,"open",temporary,NULL,NULL,SW_SHOWNORMAL); #else sprintf(temporary,"%sBasicHelp.chm",pj_editor_Dir); HtmlHelp(NULL,temporary,HH_DISPLAY_TOPIC,0); #endif } void MainFrame::OnCmdAbout( UINT uNotifyCode, int nID, CWindow wndCtl ) { ActiveBasic::Resource::DialogBoxAlt(hResInst, IDD_ABOUT, m_hWnd, DialogAbout); } void MainFrame::OnCmdDocSelectBand( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Rebar->ChangeRebarBand(ID_DOCCOMBO); } void MainFrame::OnCmdStandardBand( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Rebar->ChangeRebarBand(ID_STANDARDTOOLBAR); } void MainFrame::OnCmdReleaseBand( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Rebar->ChangeRebarBand(ID_RELEASETOOLBAR); } void MainFrame::OnCmdDebugBand( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Rebar->ChangeRebarBand(ID_DEBUGGERTOOLBAR); } void MainFrame::OnCmdSelectCompilerBand( UINT uNotifyCode, int nID, CWindow wndCtl ) { pobj_Rebar->ChangeRebarBand(ID_SELECTCOMPILERCOMBO); } void MainFrame::OnCmdNoGripper( UINT uNotifyCode, int nID, CWindow wndCtl ) { if(pobj_nv->bNoGripper) pobj_nv->bNoGripper=0; else pobj_nv->bNoGripper=1; //レバーコントロールを再生成 pobj_Rebar->ResetRebar(); //メニュー状態を設定 ResetState_DocMenu(); } void MainFrame::OnCmdResetRebar( UINT uNotifyCode, int nID, CWindow wndCtl ) { //"ツールバーの配置をすべて初期状態に戻します。\nよろしいですか?" if( MessageBox(STRING_TOOLBAR_RESET,APPLICATION_NAME,MB_OKCANCEL|MB_ICONEXCLAMATION) == IDCANCEL ) { return; } //レバーコントロールを再生成 pobj_Rebar->ResetInitRebar(); //メニュー状態を設定 ResetState_DocMenu(); } void MainFrame::OnCmdAllCloseOmitMyself( UINT uNotifyCode, int nID, CWindow wndCtl ) { //このウィンドウ以外をすべて閉じる(&A) HWND hChild=::GetWindow(hClient,GW_CHILD); foreach ( MDIINFO *mi, MdiInfo ){ if ( mi->hwnd == hChild ){ continue; } if(mi->hwnd){ ::PostMessage( mi->hwnd, WM_CLOSE, 0, 0 ); //foreachの最中に削除されるとイテレータが回らないのでSendを使っていない。 } } } void MainFrame::OnCmdPathCopy( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); //絶対パスをコピー HGLOBAL hGlobal=(char *)GlobalAlloc(GMEM_MOVEABLE,MdiInfo[WndNum]->path.size()+1); char *pTemp=(char *)GlobalLock(hGlobal); lstrcpy(pTemp,MdiInfo[WndNum]->path.c_str()); GlobalUnlock(hGlobal); //クリップボードに保存 OpenClipboard(); EmptyClipboard(); SetClipboardData(CF_TEXT,hGlobal); CloseClipboard(); } void MainFrame::OnCmdFolderOpen( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); OpenExplorer( MdiInfo[WndNum]->path ); } void MainFrame::OnCmdDeleteFile( UINT uNotifyCode, int nID, CWindow wndCtl ) { HWND hChild=::GetWindow(hClient,GW_CHILD); int WndNum=GetWndNum(hChild); char temporary[1024], temp2[1024]; _splitpath(MdiInfo[WndNum]->path.c_str(),NULL,NULL,temporary,temp2); lstrcat(temporary,temp2); lstrcat(temporary," をごみ箱に移動して閉じます。よろしいですか?"); if(MessageBox(temporary,APPLICATION_NAME,MB_OKCANCEL|MB_ICONQUESTION)==IDCANCEL) return; //ゴミ箱へ SHFILEOPSTRUCT fo; fo.hwnd=m_hWnd; fo.wFunc=FO_DELETE; fo.pFrom =MdiInfo[WndNum]->path.c_str(); fo.pTo="\0"; fo.fFlags =FOF_ALLOWUNDO|FOF_NOCONFIRMATION; SHFileOperation(&fo); //閉じる MdiInfo[WndNum]->pMdiTextEdit->UnModify(); SendMessage(MdiInfo[WndNum]->hwnd,WM_CLOSE,0,0); } void MainFrame::OnCmdColor( UINT uNotifyCode, int nID, CWindow wndCtl ) { static COLORREF colorUser=RGB(255,255,255); switch( nID ) { case IDM_USER_COLOR: { CHOOSECOLOR cc; COLORREF CusColors[16]={ RGB(255,255,255), RGB(0,0,0), RGB(128,128,128), RGB(192,192,192), RGB(128,0,0), RGB(255,0,0), RGB(128,128,0), RGB(255,255,0), RGB(0,128,0), RGB(0,255,0), RGB(0,128,128), RGB(0,255,255), RGB(0,0,128), RGB(0,0,255), RGB(128,0,128), RGB(255,0,255)}; cc.lStructSize=sizeof(CHOOSECOLOR); cc.hwndOwner=m_hWnd; cc.rgbResult=colorUser; cc.lpCustColors=CusColors; cc.Flags=CC_RGBINIT|CC_FULLOPEN; if(!ChooseColor(&cc)){ return; } colorUser=cc.rgbResult; } case IDM_GRAY: case IDM_WHITE: case IDM_RED: case IDM_GREEN: case IDM_BLUE: case IDM_YELLOW: { HWND hChild=::GetWindow(hClient,GW_CHILD); TC_ITEM tcItem; tcItem.mask=TCIF_PARAM; if(nID==IDM_GRAY) tcItem.lParam=TABCOLOR_GRAY; if(nID==IDM_WHITE) tcItem.lParam=TABCOLOR_WHITE; if(nID==IDM_RED) tcItem.lParam=TABCOLOR_RED; if(nID==IDM_GREEN) tcItem.lParam=TABCOLOR_GREEN; if(nID==IDM_BLUE) tcItem.lParam=TABCOLOR_BLUE; if(nID==IDM_YELLOW) tcItem.lParam=TABCOLOR_YELLOW; if(nID==IDM_USER_COLOR) tcItem.lParam=colorUser; TabCtrl_SetItem(pobj_MainTab->hTab, TabCtrl_GetCurSel(pobj_MainTab->hTab), &tcItem); ::InvalidateRect(pobj_MainTab->hTab,NULL,0); break; } default: throw; } }