?? main.cpp
字號:
SendMessage (hwndClient,
WM_MDICREATE, 0,
(LPARAM) (LPMDICREATESTRUCT) &mdicreate) ;
}
bool ShowOpenDialog(HWND hwnd,char* filename,char *filter)
{
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = filter;
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir =InitDir;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
//顯示打開文件對話框
if (GetOpenFileName(&ofn)==TRUE)
{
return true;
}
else
return false;
}
bool ShowSaveDialog(HWND hwnd,char* filename)
{
char defExtention[10]=".txt";
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = "Java文件\0*.java\0";
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = InitDir;
ofn.lpstrDefExt=defExtention;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
// 顯示保存文件對話框
if (GetSaveFileName(&ofn)==TRUE)
{
return true;
}
else
return false;
}
LRESULT CALLBACK OutputProc (HWND hwnd, UINT iMsg, WPARAM wParam,
LPARAM lParam)
{
RECT rect;
switch(iMsg)
{
case WM_CREATE:
DC.GetWndRect(hwnd,&rect);
fdOutput=new FEdit();
fdOutput->CreateEx(hInst,hwnd,rect.left,
rect.top,rect.right-rect.left,
rect.bottom-rect.top);
fdOutput->ShowWindow(SW_SHOW);
fdOutput->UpdateWindow();
break;
case WM_SIZE:
DC.GetWndRect(hwnd,&rect);
MoveWindow(fdOutput->m_hWnd,rect.left,
rect.top,rect.right-rect.left,
rect.bottom-rect.top,true);
break;
case WM_SETFOCUS:
SetFocus(fdOutput->m_hWnd);
break;
case WM_DESTROY:
return 0;
}
return 0;
}
void InitStatusBar(HWND hwnd)
{
RECT rect;
GetClientRect(hwnd,&rect);
MoveWindow(hStatusBar,rect.left,rect.bottom-20,
rect.right,20,true);
HLOCAL hloc;
int *lpParts;
hloc=LocalAlloc(LHND,sizeof(int)*2);
lpParts=(int*)LocalLock(hloc);
lpParts[1]=rect.right;
lpParts[0]=rect.right-160;
SendMessage(hStatusBar,SB_SETPARTS,(WPARAM)2,
(LPARAM)lpParts);
LocalUnlock(hloc);
LocalFree(hloc);
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)0,(LPARAM)"JEdit");
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,(LPARAM)"行 ,列 ");
}
void CompileProg(char *filename)
{
char nCmdLine[2*MAX_PATH];
SECURITY_ATTRIBUTES sa;
STARTUPINFO startUpInfo;
PROCESS_INFORMATION proc;
long ret;
HANDLE hReadPipe=NULL;
HANDLE hWritePipe=NULL;
char CurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,CurDir);
char Driver[MAX_PATH],Dir[MAX_PATH],FileName[MAX_PATH];
_splitpath(filename,Driver,Dir,FileName,NULL);
Dir[strlen(Dir)-1]='\0';
strcat(Driver,Dir);
SetCurrentDirectory(Driver);
sa.nLength=sizeof(sa);
sa.bInheritHandle=true;
sa.lpSecurityDescriptor=NULL;
ret=CreatePipe(&hReadPipe,&hWritePipe,&sa,0);
if(ret==0)
return;
memset(&startUpInfo,0,sizeof(STARTUPINFO));
startUpInfo.cb=sizeof(STARTUPINFO);
startUpInfo.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
startUpInfo.hStdOutput = hWritePipe;
startUpInfo.hStdError = hWritePipe;
startUpInfo.wShowWindow = SW_HIDE;
char CP[MAX_PATH];
sprintf(CP,"classpath=%s",ClassPath);
sprintf(nCmdLine,"%s\\bin\\javac -d \"%s\" \"%s\"",JDKPath,Driver,filename);
ret = CreateProcess( 0, nCmdLine, &sa,&sa,true,
CREATE_NEW_CONSOLE, CP, 0,&startUpInfo, &proc);
if(ret==0)
{
fdOutput->Insert("編譯失敗,請檢查JDK路徑及ClassPath變量設置是否設置正確!");
return;
}
WaitForSingleObject(proc.hProcess,
INFINITE);
CloseHandle(hWritePipe);
DWORD lngBytesRead;
char sBuffer[256];
while(1)
{
ret=ReadFile(hReadPipe, sBuffer, 256, &lngBytesRead, 0);
sBuffer[lngBytesRead]='\0';
DC.PopUp("輸出");
fdOutput->Insert(sBuffer);
if(ret==0)
break;
}
fdOutput->Insert("\n編譯完成...\n");
CloseHandle(proc.hProcess);
CloseHandle(proc.hThread);
CloseHandle(hReadPipe);
SetCurrentDirectory(CurDir);
}
void RunProg(char *filename,bool inapplet)
{
char Dir[MAX_PATH];
char Driver[MAX_PATH];
char FileName[MAX_PATH];
char CurDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH,CurDir);
_splitpath(filename,Driver,Dir,FileName,NULL);
STARTUPINFO startUpInfo;
PROCESS_INFORMATION proc;
long ret;
GetStartupInfo(&startUpInfo);
strcat(Driver,Dir);
SetCurrentDirectory(Driver);
if(!inapplet)
{
::ofstream out("t.bat");
out<<"@echo off"<<endl
<<"set classpath="<<ClassPath<<endl
<<"\""<<JDKPath<<"\\bin\\java"<<"\""<<" \""<<FileName<<"\""<<endl
<<"\""<<APPPath<<"\\bin\\psc.exe\""<<endl
<<"exit"<<endl;
out.close();
ret = CreateProcess( 0,"t.bat", 0,0,true,
CREATE_NEW_CONSOLE, 0, 0,&startUpInfo, &proc);
if(ret==0)
{
fdOutput->Insert("運行失敗,請檢查JDK路徑是否設置正確!");
return;
}
WaitForSingleObject(proc.hProcess,INFINITE);
DeleteFile("t.bat");
}
else
{
char appletFileName[MAX_PATH];
sprintf(appletFileName,"%s.html",FileName);
::ofstream out(FileName);
if(!out)
return;
out<<"<applet code=\""<<FileName<<".class\" width=300 height=300></applet>"<<endl;
out.close();
char CmdLine[MAX_PATH];
sprintf(CmdLine,"%s\\bin\\appletviewer %s",
JDKPath,FileName);
ret = CreateProcess( 0,CmdLine, 0,0,true,
CREATE_NEW_CONSOLE, 0, 0,&startUpInfo, &proc);
if(ret==0)
{
fdOutput->Insert("運行失敗,請檢查JDK路徑是否設置正確!");
return;
}
WaitForSingleObject(proc.hProcess,INFINITE);
}
CloseHandle(proc.hProcess);
CloseHandle(proc.hThread);
SetCurrentDirectory(CurDir);
}
void GetWndRect(RECT *rect)
{
GetClientRect(Mainhwnd,rect);
rect->bottom-=22;
}
LRESULT CALLBACK GotoLineProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int Line;
JavaEdit *JEdit;
HWND hwndChild=(HWND)SendMessage(hwndClient,WM_MDIGETACTIVE,0,0L);
JEdit=GetJEDIT(hwndChild);
switch( message )
{
case WM_INITDIALOG:
SetFocus(GetDlgItem(hWnd,IDC_LINE));
if(JEdit==NULL)
EnableWindow(GetDlgItem(hWnd,IDOK),false);
else
{
Line=JEdit->GetLine();
SetDlgItemInt(hWnd,IDC_LINE,Line,false);
}
HideCaret(JEdit->m_hWnd);
return TRUE;
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDOK:
Line=GetDlgItemInt(hWnd,IDC_LINE,NULL,false);
if(JEdit!=NULL)
JEdit->GotoLine(Line);
case IDCANCEL:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
break;
case WM_CLOSE:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
return FALSE;
}
LRESULT CALLBACK FindProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char Content[256];
bool Up;
bool Icmp;
JavaEdit *JEdit;
HWND hwndChild=(HWND)SendMessage(hwndClient,WM_MDIGETACTIVE,0,0L);
JEdit=GetJEDIT(hwndChild);
switch( message )
{
case WM_INITDIALOG:
CheckRadioButton(hWnd,IDC_UP,IDC_DOWN,IDC_DOWN);
if(JEdit==NULL)
EnableWindow(GetDlgItem(hWnd,IDOK),false);
HideCaret(JEdit->m_hWnd);
return TRUE;
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDOK:
Icmp=true;
Up=false;
GetDlgItemText(hWnd,IDC_SRC,Content,255);
if(strcmp(Content,"")==0)
{
MessageBox(hWnd,"待查找字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
if(IsDlgButtonChecked(hWnd,IDC_UP)==BST_CHECKED)
Up=true;
if(IsDlgButtonChecked(hWnd,IDC_ICMP)==BST_CHECKED)
Icmp=false;
if(JEdit&&!JEdit->Find(Content,Up,Icmp))
{
MessageBox(hWnd,"找不到匹配字符串!",
"查找",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
break;
}
case IDCANCEL:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
break;
case WM_CLOSE:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
return FALSE;
}
LRESULT CALLBACK ReplaceProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
char Src[256];
char Dest[256];
bool Up,Icmp;
JavaEdit *JEdit;
HWND hwndChild=(HWND)SendMessage(hwndClient,WM_MDIGETACTIVE,0,0L);
JEdit=GetJEDIT(hwndChild);
switch( message )
{
case WM_INITDIALOG:
CheckRadioButton(hWnd,IDC_UP,IDC_DOWN,IDC_DOWN);
HideCaret(JEdit->m_hWnd);
if(JEdit==NULL)
{
EnableWindow(GetDlgItem(hWnd,IDFINDNEXT),false);
EnableWindow(GetDlgItem(hWnd,IDREPLACE),false);
EnableWindow(GetDlgItem(hWnd,IDREPLACEALL),false);
}
return TRUE;
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDREPLACE:
Icmp=true;
GetDlgItemText(hWnd,IDC_SRC,Src,255);
if(strcmp(Src,"")==0)
{
MessageBox(hWnd,"待查找字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
GetDlgItemText(hWnd,IDC_DEST,Dest,255);
if(strcmp(Dest,"")==0)
{
MessageBox(hWnd,"替換字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
if(IsDlgButtonChecked(hWnd,IDC_ICMP)==BST_CHECKED)
Icmp=false;
if(JEdit!=NULL&&!JEdit->Replace(Src,Dest,Icmp))
{
MessageBox(hWnd,"無法進行替換!!",
"替換",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
}
else
SendMessage(hWnd,WM_COMMAND,IDFINDNEXT,0L);
break;
case IDREPLACEALL:
Icmp=true;
GetDlgItemText(hWnd,IDC_SRC,Src,255);
if(strcmp(Dest,"")==0)
{
MessageBox(hWnd,"待查找字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
GetDlgItemText(hWnd,IDC_DEST,Dest,255);
if(strcmp(Dest,"")==0)
{
MessageBox(hWnd,"替換字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
if(IsDlgButtonChecked(hWnd,IDC_ICMP)==BST_CHECKED)
Icmp=false;
if(JEdit&&!JEdit->ReplaceAll(Src,Dest,Icmp))
{
MessageBox(hWnd,"找不到匹配的字符串!!",
"替換",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
case IDFINDNEXT:
Icmp=true;
Up=false;
GetDlgItemText(hWnd,IDC_SRC,Src,255);
if(strcmp(Src,"")==0)
{
MessageBox(hWnd,"待查找字符串不能為空!",
"錯誤",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
return 0L;
}
if(IsDlgButtonChecked(hWnd,IDC_ICMP)==BST_CHECKED)
Icmp=false;
if(IsDlgButtonChecked(hWnd,IDC_UP)==BST_CHECKED)
Up=true;
if(JEdit&&!JEdit->Find(Src,Up,Icmp))
{
MessageBox(hWnd,"找不到匹配字符串!!",
"替換",MB_ICONINFORMATION|MB_OK);
SetFocus(GetDlgItem(hWnd,IDC_SRC));
}
break;
case IDCANCEL:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
break;
case WM_CLOSE:
ShowCaret(JEdit->m_hWnd);
EndDialog( hWnd, FALSE );
break;
}
return FALSE;
}
LRESULT CALLBACK AboutProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch( message )
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch( LOWORD( wParam ) )
{
case IDOK:
EndDialog( hWnd, FALSE );
break;
}
break;
case WM_CLOSE:
EndDialog( hWnd, FALSE );
break;
}
return FALSE;
}
bool WriteFile(char* pathname,char *filename,HWND hwnd)
{
FILE* tem;
char FileName[MAX_PATH];
if(IsDlgButtonChecked(hwnd,IDC_SIMCON)==BST_CHECKED)
{
sprintf(FileName,"%s\\templete\\simcon",APPPath);
}
if(IsDlgButtonChecked(hwnd,IDC_SIMCONINPUT)==BST_CHECKED)
{
sprintf(FileName,"%s\\templete\\simconinput",APPPath);
}
if(IsDlgButtonChecked(hwnd,IDC_SIMAPP)==BST_CHECKED)
{
sprintf(FileName,"%s\\templete\\simapp",APPPath);
}
if(IsDlgButtonChecked(hwnd,IDC_SIMPACK)==BST_CHECKED)
{
sprintf(FileName,"%s\\templete\\simpack",APPPath);
}
tem=fopen(FileName,"r");
if(tem==NULL)
{
MessageBox(hwnd,"系統文件丟失,無法創建新文件!","錯誤",
MB_OK|MB_ICONERROR);
return false;
}
FString fs;
int pos;
fs.ReadFile(tem);
while(fs.FindNext("jedit",pos,false))
fs.Replace("jedit",filename,pos,false);
if(!fs.SaveFile(pathname))
return false;
fclose(tem);
return true;
}
LRESULT CALLBACK WorkSpaceProc (HWND, UINT, WPARAM, LPARAM)
{
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -