1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
#define ID_B_PARLER 0
#define ID_B_QUITTER 1
#define ID_B_PROPOS 2
#define IDB_BOUTA 3000
#define IDB_BOUTS 3100
#include <windows.h>
#include <string.h>
#include "PluginDefinition.h"
#include "menuCmdID.h"
#include "Scintilla.h"
#include "resource.h"
INT_PTR CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam);
INT_PTR HandleWmCommand(HWND Dlg, WORD controlId, WORD notificationCode, HWND hContol);
bool setCommand(size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit);
void pluginInit(HANDLE hModule);
void pluginCleanUp();
void commandMenuCleanUp();
void SaisieTexte( char bufNom [],char bufDefaut [] );
//Variables globales
FuncItem funcItem[nbFunc];
HINSTANCE instance;
NppData nppData;
HWND hwndList, edit1, edit2;
char bufNom [256]; // Un buffer pour stocker le nom de la variable globale à ajouter
char bufDefaut [256]; // Un buffer pour stocker la valeur par défaut de la variable
char bufType [256]; // Un buffer pour stocker le type de la variable
int element; // pour les items
int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
instance = hInstance;
commandMenuInit();
}
else if(dwReason == DLL_PROCESS_DETACH)
{
pluginCleanUp();
}
return TRUE;
}
void pluginInit(HANDLE hModule)
{
}
void pluginCleanUp()
{
}
//----------------------------------------------//
//-- DEFINITION DU MENU --//
//----------------------------------------------//
void commandMenuInit()
{
setCommand(0, TEXT("Déclarations"), VarGlob, NULL, false);
}//commandMenuInit()
void commandMenuCleanUp()
{
}
bool setCommand(size_t index, TCHAR *cmdName, PFUNCPLUGINCMD pFunc, ShortcutKey *sk, bool check0nInit)
{
if (index >= nbFunc)
return false;
if (!pFunc)
return false;
lstrcpy(funcItem[index]._itemName, cmdName);
funcItem[index]._pFunc = pFunc;
funcItem[index]._init2Check = check0nInit;
funcItem[index]._pShKey = sk;
return true;
}
// Fonctions de profil extern "C" __declspec(dllexport)
extern "C" __declspec(dllexport) void setInfo(NppData notpadPlusData)
{
nppData = notpadPlusData;
commandMenuInit();
}
extern "C" __declspec(dllexport) const TCHAR * getName()
{
return NPP_PLUGIN_NAME;
}
extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *nbF)
{
*nbF = nbFunc;
return funcItem;
}
extern "C" __declspec(dllexport) void beNotified(SCNotification * notifyCode)
{
}
extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam)
{/*
if (Message == WM_MOVE)
{
::MessageBox(NULL, "move", "", MB_OK);
}
*/
return TRUE;
}
#ifdef UNICODE
extern "C" __declspec(dllexport) BOOL isUnicode()
{
return TRUE;
}
#endif //UNICODE
//----------------------------------------------//
//-- DEFINITIONS DES FONCTIONS --//
//----------------------------------------------//
void VarGlob ()
{
//création de la fenetre principale
HWND hDlg = CreateDialog(instance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC)MainProc);
ShowWindow(hDlg,SW_SHOW);
MSG msg;
while(GetMessage(&msg,NULL,0,0)==TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//VarGlob()
INT_PTR HandleWmCommand(HWND Dlg, WORD controlId, WORD notificationCode, HWND hContol)
{
INT_PTR bRet = TRUE;
switch(controlId)
{
case IDOK:
// recupere le texte des edits
SendMessage(edit1, WM_GETTEXT, 256, (LPARAM)bufNom);
SendMessage(edit2, WM_GETTEXT, 256, (LPARAM)bufDefaut);
//On réinitialise les champs à zero pour la propretée
SendMessage(edit1, WM_SETTEXT, 256, (LPARAM)"");
SendMessage(edit2, WM_SETTEXT, 256, (LPARAM)"");
//Vérifie que le nom de la variable a été inséré
if (strlen(bufNom) < 1) {
MessageBox(Dlg, TEXT("Il manque le nom de la variable"), TEXT("Erreur"), MB_OK);
break; }
//On récupère l'indice de l'élèment choisi dans la CB
element = SendMessage(hwndList, CB_GETCURSEL, 0,0);
//Vérifie que le type a été choisi
if (element == -1){
MessageBox(Dlg,TEXT("Aucun type sélectionné"), TEXT("Erreur"), MB_OK);
break;}
//TEST A SUPPRIMER
// Il permet de vérifier que les variables sont bien récupérées
// ajoute item au combobox
LRESULT val;
char bufCB [256];
SendMessage(hwndList, CB_GETITEMDATA, element,(LPARAM)bufCB);
val = SendMessage(hwndList, CB_GETLBTEXT,element, 0);
SendMessage(hwndList, CB_ADDSTRING, 0,(LPARAM)bufNom);
SendMessage(hwndList, CB_ADDSTRING, 0,(LPARAM)bufDefaut);
SendMessage(hwndList, CB_ADDSTRING, 0,(LPARAM)bufCB);
SaisieTexte(bufNom, bufDefaut);
break;
case IDCANCEL:
EndDialog(Dlg,IDCANCEL);
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
INT_PTR CALLBACK MainProc(HWND Dlg,UINT message,WPARAM wParam,LPARAM lParam)
{
INT_PTR bRet = TRUE;
//INT_PTR Select;
switch(message)
{
case WM_COMMAND:
bRet = HandleWmCommand(Dlg, LOWORD(wParam), HIWORD(wParam), (HWND)lParam);
break;
case WM_INITDIALOG:
//créations des items dans la cb
hwndList = GetDlgItem(Dlg, IDC_COMBO1 );
SendMessage(hwndList, CB_ADDSTRING, 0, (LONG)TEXT("Numerique"));
SendMessage(hwndList, CB_ADDSTRING, 0, (LONG)TEXT("Boolean"));
SendMessage(hwndList, CB_ADDSTRING, 0, (LONG)TEXT("Chaine"));
//récupérations des handle pour les edits
edit1 = GetDlgItem(Dlg, IDC_EDIT1 );
edit2 = GetDlgItem(Dlg, IDC_EDIT3 );
break;
default:
bRet = FALSE;
break;
}
return bRet;
}
// Permet d'inserer dans le texte les valeurs saisies
void SaisieTexte( char bufNom [] ,char bufDefaut [] )
{
int tailleNom = strlen(bufNom);
int tailleVal = strlen(bufDefaut);
/*
++tailleNom;
bufNom[tailleNom + 1] = '\0';*/
SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, 9, (LPARAM)"Declare (");
SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, tailleNom, (LPARAM)bufNom);
SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, 3, (LPARAM)" , ");
SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, tailleVal, (LPARAM)bufDefaut);
SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, 3, (LPARAM)" )");
::SendMessage(nppData._scintillaMainHandle, SCI_ADDTEXT, strlen("\r"), (LPARAM)"\r");
}//SaisieTexte() |
Partager