?? main.cpp
字號:
if(JEdit)
JEdit->DeleteSel();
SendMessage(hwndChild,WM_LCCHANGED,0,0);
break;
case IDM_SELECTALL:
hwndChild=(HWND)SendMessage(hwndClient,WM_MDIGETACTIVE,0,0L);
JEdit=GetJEDIT(hwndChild);
if(JEdit)
JEdit->SelectAll();
SendMessage(hwndChild,WM_LCCHANGED,0,0);
break;
}
break;
case WM_CLOSE:
for(i=0;i<MDIWndContainer.length();i++)
{
SendMessage(MDIWndContainer[i].hwnd,WM_CLOSE,0,0);
SendMessage(hwnd,WM_MDIDESTROY,(WPARAM)MDIWndContainer[i].hwnd,0);
}
case WM_DESTROY:
SetCurrentDirectory(APPPath);
IniLoad il;
il.Put("javahome",JDKPath);
il.Put("bgcolor",JavaEdit::hBgColor);
il.Put("textcolor",JavaEdit::hTextColor);
il.Put("keywordcolor",JavaEdit::KeywordColor);
il.Put("commentcolor",JavaEdit::CommentColor);
il.Put("initdir",InitDir);
il.Put("classpath",ClassPath);
il.Put("bgimage",JavaEdit::BGFile);
il.Save("ini\\javaconf.ini");
PostQuitMessage (0) ;
return 0 ;
}
return DefFrameProc (hwnd, hwndClient, iMsg, wParam, lParam) ;
}
MDIWnd* GetMDIWnd(HWND hwnd)
{
int i;
for(i=0;i<MDIWndContainer.length();i++)
if(MDIWndContainer[i].hwnd==hwnd)
return &MDIWndContainer[i];
return 0;
}
int GetMDIWndNum(HWND hwnd)
{
int i,j=0;
for(i=0;i<MDIWndContainer.length();i++)
{
if(MDIWndContainer[i].hwnd==hwnd)
return j;
else
if(MDIWndContainer[i].hwnd!=NULL)
j++;
}
return -1;
}
JavaEdit* GetJEDIT(HWND hwnd)
{
int i;
for(i=0;i<MDIWndContainer.length();i++)
if(MDIWndContainer[i].hwnd==hwnd)
return MDIWndContainer[i].JEdit;
return NULL;
}
void SetWndPlacement(HWND hwnd)
{
WINDOWPLACEMENT wndpl;
int MaxMinWnd;
RECT ParentRect;
GetWndRect(&ParentRect);
DC.GetRect(ParentRect);
MaxMinWnd=(ParentRect.right-ParentRect.left)/160;
wndpl.length=sizeof(wndpl);
wndpl.flags=WPF_SETMINPOSITION;
wndpl.showCmd=SW_SHOW;
wndpl.rcNormalPosition.left=15+GetMDIWndNum(hwnd)*20;
wndpl.rcNormalPosition.right=wndpl.rcNormalPosition.left+ParentRect.right-100;
wndpl.rcNormalPosition.top=0+GetMDIWndNum(hwnd)*20;
wndpl.rcNormalPosition.bottom=wndpl.rcNormalPosition.top+ParentRect.bottom-100;
wndpl.ptMinPosition.x=ParentRect.left+(GetMDIWndNum(hwnd)%MaxMinWnd)*160;
wndpl.ptMinPosition.y=ParentRect.bottom-(GetMDIWndNum(hwnd)/MaxMinWnd+1)*(GetSystemMetrics(SM_CYMIN)-3);
SetWindowPlacement(hwnd,&wndpl);
}
LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT iMsg, WPARAM wParam,
LPARAM lParam)
{
JavaEdit *JEdit;
MDIWnd *mdiWnd;
RECT ClientRect;
char WndName[MAX_PATH];
char lc[256];
UINT nHitTest;
int result;
switch (iMsg)
{
case WM_CREATE:
GetClientRect(hwnd,&ClientRect);
JEdit=new JavaEdit(APPPath);
JEdit->CreateEx(hInst,hwnd,ClientRect.left,ClientRect.top,
ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top);
JEdit->ShowWindow(SW_SHOW);
JEdit->UpdateWindow();
GetWindowText(hwnd,WndName,MAX_PATH);
MDIWndContainer.add(MDIWnd(hwnd,WndName,JEdit));
JEdit->OpenFile();
SetWndPlacement(hwnd);
break;
case WM_NCACTIVATE:
EnableMenuItem(GetMenu(Mainhwnd),IDM_FIND,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_REPLACE,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_PASTE,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_COMPILE,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_RUN,MF_BYCOMMAND|MF_ENABLED);
break;
case WM_WINDOWPOSCHANGED:
InitStatusBar(hStatusBar);
break;
case WM_LCCHANGED:
JEdit=GetJEDIT(hwnd);
if(JEdit->IsSelEmpty())
{
EnableMenuItem(GetMenu(Mainhwnd),IDM_CUT,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_COPY,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_DELETE,MF_BYCOMMAND|MF_GRAYED);
}
else
{
EnableMenuItem(GetMenu(Mainhwnd),IDM_CUT,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_COPY,MF_BYCOMMAND|MF_ENABLED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_DELETE,MF_BYCOMMAND|MF_ENABLED);
}
if(JEdit->CanUndo())
EnableMenuItem(GetMenu(Mainhwnd),IDM_UNDO,MF_BYCOMMAND|MF_ENABLED);
else
EnableMenuItem(GetMenu(Mainhwnd),IDM_UNDO,MF_BYCOMMAND|MF_GRAYED);
if(JEdit->CanRedo())
EnableMenuItem(GetMenu(Mainhwnd),IDM_REDO,MF_BYCOMMAND|MF_ENABLED);
else
EnableMenuItem(GetMenu(Mainhwnd),IDM_REDO,MF_BYCOMMAND|MF_GRAYED);
sprintf(lc,"行 %d,列 %d",JEdit->GetLine(),JEdit->GetColumn());
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,(LPARAM)lc);
break;
case WM_NCLBUTTONDBLCLK:
mdiWnd=GetMDIWnd(hwnd);
DefMDIChildProc(hwnd,WM_NCLBUTTONDBLCLK,wParam,lParam);
GetWndRect(&ClientRect);
DC.GetRect(ClientRect);
if(mdiWnd!=NULL)
{
MoveWindow(hwnd,ClientRect.left,ClientRect.top-GetSystemMetrics(SM_CYMIN),
ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top+GetSystemMetrics(SM_CYMIN),
true);
mdiWnd->max=true;
}
return 0;
case WM_NCLBUTTONDOWN:
nHitTest=DefWindowProc(hwnd,WM_NCHITTEST,wParam,lParam);
mdiWnd=GetMDIWnd(hwnd);
DefMDIChildProc(hwnd,WM_NCLBUTTONDOWN,wParam,lParam);
if(nHitTest==HTMAXBUTTON)
{
GetWndRect(&ClientRect);
DC.GetRect(ClientRect);
if(mdiWnd!=NULL)
{
MoveWindow(hwnd,ClientRect.left,ClientRect.top-GetSystemMetrics(SM_CYMIN),
ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top+GetSystemMetrics(SM_CYMIN),
true);
mdiWnd->max=true;
}
}
if(nHitTest==HTMINBUTTON)
{
GetWndRect(&ClientRect);
DC.GetRect(ClientRect);
if(mdiWnd!=NULL&&mdiWnd->max==true)
{
MoveWindow(hwnd,ClientRect.left,ClientRect.top-GetSystemMetrics(SM_CYMIN),
ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top+GetSystemMetrics(SM_CYMIN),
true);
}
}
return 0;
case WM_SAVEFILE:
JEdit=GetJEDIT(hwnd);
if(JEdit!=NULL)
JEdit->SaveFile();
break;
case WM_SETFOCUS:
JEdit=GetJEDIT(hwnd);
if(JEdit!=NULL)
SetFocus(JEdit->m_hWnd);
break;
case WM_SIZE:
GetClientRect(hwnd,&ClientRect);
JEdit=GetJEDIT(hwnd);
if(JEdit!=NULL)
MoveWindow(JEdit->m_hWnd,ClientRect.left,ClientRect.top,
ClientRect.right-ClientRect.left,ClientRect.bottom-ClientRect.top,
true);
InitStatusBar(hStatusBar);
sprintf(lc,"行 %d,列 %d",JEdit->GetLine(),JEdit->GetColumn());
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,(LPARAM)lc);
GetClientRect(Mainhwnd,&ClientRect);
MoveWindow(hStatusBar,ClientRect.left,ClientRect.bottom-20,
ClientRect.right-ClientRect.left,20,true);
break;
case WM_CLOSE:
GetClientRect(hwnd,&ClientRect);
JEdit=GetJEDIT(hwnd);
if(!JEdit->IsSaved())
{
result=MessageBox(hwnd,"文件尚未保存,要保存嗎?","FNotePad",MB_ICONINFORMATION|MB_YESNOCANCEL);
if(result==IDCANCEL) return 0L;
if(result==IDYES)
JEdit->SaveFile();
}
SendMessage(JEdit->m_hWnd,WM_DESTROY,0,0);
mdiWnd=GetMDIWnd(hwnd);
mdiWnd->hwnd=NULL;
EnableMenuItem(GetMenu(Mainhwnd),IDM_CUT,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_COPY,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_PASTE,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_DELETE,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_FIND,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_REPLACE,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_COMPILE,MF_BYCOMMAND|MF_GRAYED);
EnableMenuItem(GetMenu(Mainhwnd),IDM_RUN,MF_BYCOMMAND|MF_GRAYED);
SendMessage(hwnd,WM_DESTROY,0,0);
break;
case WM_QUERYENDSESSION :
case WM_DESTROY :
return 0 ;
}
return DefMDIChildProc (hwnd, iMsg, wParam, lParam) ;
}
void SetClassPath(HWND hwnd)
{
string cp=ClassPath;
string cpitem;
size_t ip;
ip=cp.find(";");
while(ip!=cp.npos)
{
cpitem=cp.substr(0,ip);
SendMessage(hwnd,LB_INSERTSTRING,-1,(LPARAM)cpitem.c_str());
cp=cp.substr(ip+1);
ip=cp.find(";");
}
SendMessage(hwnd,LB_ADDSTRING,0,(LPARAM)cp.c_str());
}
LRESULT CALLBACK SettingProc (HWND hwnd, UINT iMsg, WPARAM wParam,
LPARAM lParam)
{
BROWSEINFO bs;
LPITEMIDLIST lpdl;
char PathName[MAX_PATH];
int index,count;
switch(iMsg)
{
case WM_INITDIALOG:
SetWindowText(GetDlgItem(hwnd,IDC_JDKPATH),JDKPath);
hwndList=CreateWindowEx(WS_EX_CLIENTEDGE,
_T("LISTBOX"),NULL,
WS_CHILD|WS_BORDER|LBS_NOTIFY|WS_VSCROLL|WS_HSCROLL,
20,90,210,100,
hwnd,
(HMENU)10001,
hInst,
NULL);
ShowWindow(hwndList,SW_SHOW);
UpdateWindow(hwndList);
SetClassPath(hwndList);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case 10001:
//如果列表框選擇改變,則讀取用戶選擇表的記錄
switch(HIWORD(wParam))
{
case LBN_SELCHANGE:
index=SendMessage(hwndList, LB_GETCURSEL,
0, 0);
if(index==-1) return 0l;
SendMessage(hwndList,LB_GETTEXT,index,(LPARAM)PathName);
SetDlgItemText(hwnd,IDC_ITEM,PathName);
break;
}
break;
case IDOK:
GetDlgItemText(hwnd,IDC_JDKPATH,JDKPath,MAX_PATH);
count=SendMessage(hwndList,LB_GETCOUNT,0,0);
index=0;
SendMessage(hwndList,LB_GETTEXT,index,(LPARAM)PathName);
if(count!=0)
strcpy(ClassPath,PathName);
else
strcpy(ClassPath,"");
for(index=1;index<count;index++)
{
strcat(ClassPath,";");
SendMessage(hwndList,LB_GETTEXT,index,(LPARAM)PathName);
strcat(ClassPath,PathName);
}
EndDialog(hwnd,0);
break;
case IDCANCEL:
EndDialog(hwnd,0);
break;
case IDC_DIR:
memset(&bs,0,sizeof(bs));
bs.hwndOwner=hwnd;
bs.pidlRoot=NULL;
bs.pszDisplayName=PathName;
bs.lpszTitle="請選擇目錄";
bs.ulFlags=BIF_RETURNONLYFSDIRS;
lpdl=SHBrowseForFolder(&bs);
if(SHGetPathFromIDList(lpdl,PathName))
SetWindowText(GetDlgItem(hwnd,IDC_JDKPATH),PathName);
SetFocus(GetDlgItem(hwnd,IDC_FILENAME));
break;
case IDC_CPDIR:
memset(&bs,0,sizeof(bs));
bs.hwndOwner=hwnd;
bs.pidlRoot=NULL;
bs.pszDisplayName=PathName;
bs.lpszTitle="請選擇目錄";
bs.ulFlags=BIF_RETURNONLYFSDIRS;
lpdl=SHBrowseForFolder(&bs);
if(SHGetPathFromIDList(lpdl,PathName))
SetWindowText(GetDlgItem(hwnd,IDC_ITEM),PathName);
break;
case IDC_ADD:
GetDlgItemText(hwnd,IDC_ITEM,PathName,MAX_PATH);
if(strcmp(PathName,"")==0)
{
MessageBox(hwnd,"不能添加空項目!","警告",MB_OK);
return 0;
}
SendMessage(hwndList,LB_INSERTSTRING,-1,(LPARAM)PathName);
break;
case IDC_UPDATE:
index=SendMessage(hwndList, LB_GETCURSEL,
0, 0);
if(index==-1)
{
MessageBox(hwnd,"請先選擇要修改的項目!","警告",MB_OK);
return 0;
}
SendMessage(hwnd,WM_COMMAND,IDC_DELETE,0);
GetDlgItemText(hwnd,IDC_ITEM,PathName,MAX_PATH);
if(strcmp(PathName,"")==0)
{
MessageBox(hwnd,"不能添加空項目!","警告",MB_OK);
return 0;
}
SendMessage(hwndList,LB_INSERTSTRING,index,(LPARAM)PathName);
break;
case IDC_DELETE:
index=SendMessage(hwndList, LB_GETCURSEL,
0, 0);
if(index==-1) return 0;
SendMessage(hwndList,LB_DELETESTRING,index,0);
break;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd,0);
return 0;
}
return 0;
}
LRESULT CALLBACK NewWndProc (HWND hwnd, UINT iMsg, WPARAM wParam,
LPARAM lParam)
{
BROWSEINFO bs;
LPITEMIDLIST lpdl;
FILE *fp;
char PathName[MAX_PATH];
char FileName[MAX_PATH];
char Driver[MAX_PATH];
switch(iMsg)
{
case WM_INITDIALOG:
_splitpath(InitDir,Driver,PathName,NULL,NULL);
strcat(Driver,PathName);
SetWindowText(GetDlgItem(hwnd,IDC_PATHNAME),Driver);
CheckRadioButton(hwnd,IDC_RADIOFILE,IDC_RADIOWORKSPACE,IDC_RADIOFILE);
CheckRadioButton(hwnd,IDC_SIMCON,IDC_SIMPACK,IDC_SIMCON);
EnableWindow(GetDlgItem(hwnd,IDC_SIMCON),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMCONINPUT),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMAPP),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMPACK),false);
return 0;
case WM_COMMAND:
switch(wParam)
{
case IDOK:
GetDlgItemText(hwnd,IDC_FILENAME,FileName,MAX_PATH);
if(strcmp(FileName,"")==0)
{
MessageBox(hwnd,"文件名不能為空","錯誤",MB_OK|MB_ICONERROR);
SetFocus(GetDlgItem(hwnd,IDC_FILENAME));
return 0l;
}
GetDlgItemText(hwnd,IDC_PATHNAME,PathName,MAX_PATH);
if(IsDlgButtonChecked(hwnd,IDC_RADIOFILE)==BST_CHECKED)
{
sprintf(PathName,"%s%s.java",PathName,FileName);
fp=fopen(PathName,"r");
if(fp!=0)
{
MessageBox(hwnd,"創建文件錯誤,文件已存在!","錯誤",MB_OK|MB_ICONERROR);
fclose(fp);
SetFocus(GetDlgItem(hwnd,IDC_FILENAME));
return 0;
}
fp=fopen(PathName,"w");
if(fp==0)
{
MessageBox(hwnd,"創建文件錯誤,請檢查路徑是否正確!","錯誤",MB_OK|MB_ICONERROR);
return 0;
}
fclose(fp);
}
if(IsDlgButtonChecked(hwnd,IDC_RADIOWORKSPACE)==BST_CHECKED)
{
sprintf(PathName,"%s%s",PathName,FileName);
CreateDirectory(PathName,0);
sprintf(PathName,"%s\\%s.java",PathName,FileName,FileName);
fp=fopen(PathName,"r");
if(fp!=0)
{
MessageBox(hwnd,"創建文件錯誤,文件已存在!","錯誤",MB_OK|MB_ICONERROR);
fclose(fp);
SetFocus(GetDlgItem(hwnd,IDC_FILENAME));
return 0;
}
if(!WriteFile(PathName,FileName,hwnd))
{
MessageBox(hwnd,"創建文件錯誤,請檢查路徑是否正確!","錯誤",MB_OK|MB_ICONERROR);
return 0;
}
}
EndDialog(hwnd,0);
CreateMDIChild(PathName);
break;
case IDCANCEL:
EndDialog(hwnd,0);
break;
case IDC_DIR:
memset(&bs,0,sizeof(bs));
bs.hwndOwner=hwnd;
bs.pidlRoot=NULL;
bs.pszDisplayName=PathName;
bs.lpszTitle="請選擇目錄";
bs.ulFlags=BIF_RETURNONLYFSDIRS;
lpdl=SHBrowseForFolder(&bs);
if(SHGetPathFromIDList(lpdl,PathName))
{
strcat(PathName,"\\");
strcpy(InitDir,PathName);
SetWindowText(GetDlgItem(hwnd,IDC_PATHNAME),PathName);
}
SetFocus(GetDlgItem(hwnd,IDC_FILENAME));
break;
case IDC_RADIOFILE:
EnableWindow(GetDlgItem(hwnd,IDC_SIMCON),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMCONINPUT),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMAPP),false);
EnableWindow(GetDlgItem(hwnd,IDC_SIMPACK),false);
break;
case IDC_RADIOWORKSPACE:
EnableWindow(GetDlgItem(hwnd,IDC_SIMCON),true);
EnableWindow(GetDlgItem(hwnd,IDC_SIMCONINPUT),true);
EnableWindow(GetDlgItem(hwnd,IDC_SIMAPP),true);
EnableWindow(GetDlgItem(hwnd,IDC_SIMPACK),true);
break;
}
return 0;
case WM_CLOSE:
EndDialog(hwnd,0);
return 0;
}
return 0;
}
void CreateMDIChild(char* filename)
{
MDICREATESTRUCT mdicreate ;
mdicreate.szClass = "ChildClass";
mdicreate.szTitle = filename;
mdicreate.hOwner = hInst ;
mdicreate.x = CW_USEDEFAULT;
mdicreate.y = CW_USEDEFAULT ;
mdicreate.cx = CW_USEDEFAULT ;
mdicreate.cy = CW_USEDEFAULT ;
mdicreate.style = WS_THICKFRAME;
mdicreate.lParam = 0 ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -