// Edit.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "resource.h" #include #include #include #include #include #define ICI MessageBox(NULL,"","",0) char chn[10000]; char gblFichier[MAX_PATH]; #define MAX_CODE sizeof(str) HINSTANCE hInst; int GetType(char *fichier) { char *ptr=fichier+strlen(fichier)-4; if (strcmp(ptr,".89t")==0) return SF_TEXT; else if (strcmp(ptr,".txt")==0) return SF_TEXT; else if (strcmp(ptr,".rtf")==0) return SF_RTF; return SF_TEXT; } #define Sauve(nom) es.dwError = 0; \ es.pfnCallback = MyWrite; \ type=GetType(nom); \ if (!(es.dwCookie = (DWORD) _lcreat(nom, 0))) \ MessageBox(hDlg,"Fichier inaccessible!","Erreur",MB_ICONERROR); \ else { \ Etat("Enregistrement..."); \ SendDlgItemMessage(hDlg,IDC_RTF,EM_STREAMOUT,type,(LPARAM)&es); \ _lclose(es.dwCookie); \ SendDlgItemMessage(hDlg,IDC_RTF,EM_SETMODIFY,0,0); \ } \ #define Ouvre() es.dwError = 0; \ es.pfnCallback = MyRead; \ type=GetType(fichier); \ if (!(es.dwCookie = (DWORD) _lopen(fichier, OF_READ))) \ MessageBox(hDlg,"Fichier inaccessible!","Erreur",MB_ICONERROR); \ else { \ Etat("Ouverture..."); \ SendDlgItemMessage(hDlg,IDC_RTF,EM_STREAMIN,type,(LPARAM)&es); \ _lclose(es.dwCookie); \ } DWORD CALLBACK MyWrite(DWORD dwCookie, LPBYTE pbBuffer, LONG cb, LONG *pcb) { HFILE hf = (HFILE) dwCookie; if(hf == HFILE_ERROR) return (DWORD) E_FAIL; *pcb = _lwrite(hf, (const char *)pbBuffer, cb); return (DWORD) (*pcb == cb ? NOERROR : E_FAIL); } DWORD CALLBACK MyRead(DWORD dwCookie, LPBYTE pbBuffer, LONG cb, LONG *pcb) { HFILE hf = (HFILE) dwCookie; if(hf == HFILE_ERROR) return (DWORD) E_FAIL; *pcb = _lread(hf, pbBuffer, cb); return (DWORD) (*pcb >= 0 ? NOERROR : (*pcb = 0, E_FAIL)); } /*DWORD CALLBACK MyWrite(DWORD dwCookie, LPBYTE pbBuffer, LONG cb, LONG *pcb) { HFILE hf = (HFILE) dwCookie; if(hf == HFILE_ERROR) return (DWORD) E_FAIL; *pcb = _lwrite(hf, pbBuffer, cb); return (DWORD) (*pcb == cb ? NOERROR : E_FAIL); }*/ #include "fct.h" #include "89t_txt.h" #include "convertion.h" char str[10000]; BOOL Convertit(char *chn) { char c; int e,f,i,n,l; int Police, APolice, Gra, Agra, Ital, AItal, Sou, ASou; char tmpchn[100]; // strcpy(str,chn); // return TRUE; l=0; while( strncmp(chn,"\\pard",5) && *chn) chn++; if (!(*chn)) return FALSE; chn+=5; Police = 1; Gra = 0; Ital = 0; Sou = 0; while(*chn) { debut: if (l>sizeof(str)-10) break; c=*chn++; if (c=='{' || c=='}') { goto debut; } if (c=='\\') { if (*chn == '\\') { chn++; c = '\\'; } else if (strncmp(chn,"par",3)==0) { chn+=3; if (*chn==' ') chn++; goto debut; } else if (strncmp(chn,"tab",3)==0) { chn+=3; str[l++]='\\'; str[l++]='t'; if (*chn==' ') chn++; goto debut; } else if (*chn == '\'') { chn++; e=*chn++; if (e>='a' && e<='f') e-=87; else e-=48; f=*chn++; if (f>='a' && f<='f') f-=87; else f-=48; c = 16*e+f; } else { APolice = Police; Agra = Gra; AItal = Ital; ASou = Sou; c=0; if (*chn == 'b') { chn++; if (*chn=='0') { chn++; Gra=0; } else Gra=1; } else if (*chn=='i') { chn++; if (*chn=='0') { chn++; Ital=0; } else Ital=1; } if (*chn == 'u' && *(chn+1)=='l') { chn+=2; if (strncmp(chn,"none",4)==0) { Sou=0; chn+=4; } else Sou=1; } else if (*chn=='f' && *(chn+1)=='s') { chn+=2; i=0; while(*chn>='0' && *chn<='9') tmpchn[i++]=*chn++; n=atoi(tmpchn); if (n==16) Police=0; else if (n==20) Police=1; else if (n==24) Police=2; } if (Police != APolice) { str[l++]='¨'; str[l++]='F'; str[l++]=Police+'0'; } if (Gra != Agra) { str[l++]='¨'; str[l++]='G'; str[l++]=Gra+'0'; } if (Ital != AItal) { str[l++]='¨'; str[l++]='I'; str[l++]=Ital+'0'; } if (Sou != ASou) { str[l++]='¨'; str[l++]='S'; str[l++]=Sou+'0'; } } if (*chn==' ') chn++; } if (c) str[l++]=c; } str[l]=0; return TRUE; } #define Etat(chne) SetDlgItemText(hDlg,IDC_ETAT,chne) #define GetEtat(chne) GetDlgItemText(hDlg,IDC_ETAT,chne,sizeof(chne)) #define Modifie() (SendDlgItemMessage(hDlg,IDC_RTF,EM_GETMODIFY,0,0)) LRESULT CALLBACK Dlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { EDITSTREAM es; CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); short nWidth, nHeight; int i, type; DWORD dw; static TCHAR strPath[MAX_PATH] = TEXT(""); static TCHAR fichier[MAX_PATH] = TEXT(""); static OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL, // TEXT("Texte standard\0*.txt\0Texte formaté\0*.rtf\0Texte TI89\0*.89t\0\0"), NULL, TEXT("Texte standard\0*.txt\0Texte formaté\0*.rtf\0\0"), NULL, 0, 2, fichier, 100, NULL, 0, strPath, TEXT("Charger un fichier"), OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0, TEXT(".txt"), 0, NULL, NULL }; switch (message) { /* case WM_TIMER: es.dwError = 0; es.pfnCallback = GetText; SendDlgItemMessage(hDlg,IDC_RTF,EM_STREAMOUT,SF_RTF,(LPARAM)&es); if (Convertit(chn)) SetDlgItemText(hDlg,IDC_TXT,str); break;*/ case WM_TIMER: GetEtat(chn); if (strcmp(chn,"Prêt")) Etat("Prêt"); break; case WM_SIZE: nWidth = LOWORD(lParam); // width of client area nHeight = HIWORD(lParam); // height of client area SetWindowPos(GetDlgItem(hDlg,IDC_RTF),HWND_BOTTOM,11,8,nWidth-22,nHeight-36,SWP_NOZORDER); SetWindowPos(GetDlgItem(hDlg,IDC_ETAT),HWND_BOTTOM,11,nHeight-20,nWidth-22,16,SWP_NOZORDER); // SendDlgItemMessage(hDlg,IDC_RTF,EM_REQUESTRESIZE, break; case WM_INITDIALOG: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,0,(LPARAM) &cf); strcpy(cf.szFaceName,"Arial"); cf.yHeight=200; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT,0,(LPARAM)&cf); SetTimer(hDlg,1,100,NULL); SetWindowPos(hDlg,HWND_BOTTOM,100,100,400,260,SWP_NOZORDER); SendDlgItemMessage(hDlg,IDC_RTF,EM_SETUNDOLIMIT,200,0); return TRUE; case WM_INITMENUPOPUP: if (LOWORD(lParam)==1) { //Menu édition dw = (DWORD) SendDlgItemMessage(hDlg, IDC_RTF, EM_CANREDO, 0, 0); EnableMenuItem((HMENU) wParam, IDM_REFAIRE, dw ? MF_ENABLED : MF_GRAYED); if (!dw) { dw = (DWORD) SendDlgItemMessage(hDlg, IDC_RTF, EM_CANUNDO, 0, 0); EnableMenuItem((HMENU) wParam, IDM_ANNULER, dw ? MF_ENABLED : MF_GRAYED); } else EnableMenuItem((HMENU) wParam, IDM_ANNULER, MF_GRAYED); dw = (DWORD) SendDlgItemMessage(hDlg, IDC_RTF, EM_CANPASTE, 0, 0); EnableMenuItem((HMENU) wParam, IDM_COLLER, dw ? MF_ENABLED : MF_GRAYED); } break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_CONVER: strcpy(gblFichier,fichier); DialogBox(hInst,(LPCTSTR)IDD_CVT,hDlg,(DLGPROC)Cvt); break; case IDM_ANNULER: SendDlgItemMessage(hDlg,IDC_RTF,EM_UNDO,0,0); break; case IDM_REFAIRE: SendDlgItemMessage(hDlg,IDC_RTF,EM_REDO,0,0); break; case IDM_COUPER: SendDlgItemMessage(hDlg,IDC_RTF,WM_CUT,0,0); break; case IDM_COPIER: SendDlgItemMessage(hDlg,IDC_RTF,WM_COPY,0,0); break; case IDM_COLLER: SendDlgItemMessage(hDlg,IDC_RTF,WM_PASTE,0,0); break; case IDM_EFFACER: SendDlgItemMessage(hDlg,IDC_RTF,WM_KEYDOWN,(WPARAM)VK_DELETE,0); break; case IDM_NOUVEAU: if (Modifie()) { i=MessageBox(hDlg,"Enregistrer les modifications?","Attention",MB_ICONINFORMATION | MB_YESNOCANCEL); if (i==IDCANCEL) break; if (i==IDYES) { ofn.lpstrTitle="Sauver sous?"; if (GetSaveFileName(&ofn)) { Sauve(fichier); } else break; } } SetDlgItemText(hDlg,IDC_RTF,""); SendDlgItemMessage(hDlg,IDC_RTF,EM_SETMODIFY,0,0); break; case IDM_OUVRIR: if (Modifie()) { i=MessageBox(hDlg,"D'abord enregistrer avant d'ouvrir un autre?","Attention",MB_ICONINFORMATION | MB_YESNOCANCEL); if (i==IDCANCEL) break; if (i==IDYES) { ofn.lpstrTitle="Sauver sous?"; if (GetSaveFileName(&ofn)) { Sauve(fichier); } else break; } } ofn.lpstrTitle="Ouvrir quel fichier?"; if (GetOpenFileName(&ofn)) { Ouvre(); SendDlgItemMessage(hDlg,IDC_RTF,EM_SETMODIFY,0,0); } break; case IDM_SAUVER: if (!(*fichier)) { ofn.lpstrTitle="Sauver sous?"; if (!GetSaveFileName(&ofn)) break; } Sauve(fichier); break; case IDM_SAUVERSOUS: ofn.lpstrTitle="Sauver copie sous?"; if (GetSaveFileName(&ofn)) { Sauve(fichier); } break; case IDCANCEL: if (Modifie()) { i=MessageBox(hDlg,"Enregistrer les modifications?","Attention",MB_ICONINFORMATION | MB_YESNOCANCEL); if (i==IDCANCEL) break; if (i==IDYES) { if (!(*fichier)) { ofn.lpstrTitle="Sauver sous?"; if (!GetSaveFileName(&ofn)) break; } Sauve(fichier); } } EndDialog(hDlg, LOWORD(wParam)); PostQuitMessage(0); return TRUE; case ID_FORMAT_FONTE_PETITE: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.yHeight=160; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; case ID_FORMAT_FONTE_NORMALE: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.yHeight=200; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; case ID_FORMAT_FONTE_GRANDE: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.yHeight=240; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; case IDC_G: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.dwMask|=CFM_BOLD; cf.dwEffects^=CFE_BOLD; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; case IDC_I: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.dwMask|=CFM_ITALIC; cf.dwEffects^=CFE_ITALIC; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; case IDC_S: SendDlgItemMessage(hDlg,IDC_RTF,EM_GETCHARFORMAT,1,(LPARAM) &cf); cf.dwMask|=CFM_UNDERLINE; cf.dwEffects^=CFE_UNDERLINE; SendDlgItemMessage(hDlg,IDC_RTF,EM_SETCHARFORMAT, SCF_SELECTION,(LPARAM) &cf); break; } break; } return FALSE; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // TODO: Place code here. HWND hWnd; HACCEL hAccel; MSG msg; LoadLibrary("riched32.dll"); // Load the RichEdit DLL to activate the RichEdit // InitCommonControls(); hAccel=LoadAccelerators(hInstance,(LPCTSTR)IDR_ACCELERATOR1); hWnd=CreateDialog(hInstance, (LPCTSTR)IDD_DLG, NULL, (DLGPROC)Dlg); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(hWnd, hAccel, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; }