Pcsnake | Comment adapter le systeme de cryptage pour ce style de programme (je veux crypter hEdit):
Main.c
Code :
- #include <windows.h>
- #include "resource.h"
- HINSTANCE hinst;
- HWND hEdit;
- LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
- BOOL APIENTRY Dialog1Proc(HWND, UINT, WPARAM, LPARAM);
- BOOL APIENTRY Dialog2Proc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- HWND hwnd;
- MSG msg;
- WNDCLASS wc;
- hinst = hinstance;
- wc.style = 0 ;
- wc.lpfnWndProc = MainWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = NULL;
- wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(2));
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = NULL;
- wc.lpszMenuName = "LEMENU";
- wc.lpszClassName = "MaWinClass";
- if(!RegisterClass(&wc)) return FALSE;
- hwnd = CreateWindow("MaWinClass", "Cryptage/décryptage", WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 400, 300,
- NULL, NULL, hinstance, NULL);
- if (!hwnd) return FALSE;
- ShowWindow(hwnd, nCmdShow);
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam;
- }
- /******************************************************************************/
- LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- static HWND hEdit;
- static BOOL EditNotChg = TRUE;
- char txt[256];
- switch (uMsg)
- {
- case WM_CREATE:
- {
- HFONT hFont;
- hEdit = CreateWindow("edit", "Tapez ici votre texte à crypter/décrypter...",
- WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
- 0, 0, 0, 0, hwnd, NULL, hinst, NULL);
- return 0;
- }
- case WM_CLOSE:
- if(EditNotChg ||
- MessageBox(hwnd,"Le texte a été modifié.\r\nEtes vous sûr de \
- vouloir fermer l'application ?"
- ,"Attention",MB_YESNO | MB_ICONQUESTION ) == IDYES)
- DestroyWindow(hwnd);
- return 0;
- case WM_COMMAND:
- if(LOWORD(wParam) == IDM_QUIT) PostMessage(hwnd, WM_CLOSE,0,0);
- if(LOWORD(wParam) == IDM_NEW)
- if(EditNotChg ||
- MessageBox(hwnd,"Le texte a été modifié.\r\nEtes vous sûr de \
- vouloir fermer votre travail ?"
- ,"Attention",MB_YESNO | MB_ICONQUESTION ) == IDYES)
- {
- SendMessage(hEdit,WM_SETTEXT,0,(long)"" );
- EditNotChg = TRUE;
- }
- if(LOWORD(wParam) == IDM_ABOUT)
- DialogBox(hinst, "ABOUT" , hwnd, (DLGPROC)Dialog1Proc);
- if(HIWORD(wParam) == EN_CHANGE) EditNotChg = FALSE;
-
- if(LOWORD(wParam) == IDM_CRYPTE)
- DialogBox(hinst, "CRYPTE" , hwnd, (DLGPROC)Dialog2Proc);
- return 0;
- case WM_SIZE:
- MoveWindow(hEdit, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
-
- default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- }
- /******************************************************************************/
- BOOL APIENTRY Dialog1Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_INITDIALOG:
- return TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDCANCEL || LOWORD(wParam) == IDOK)
- {
- EndDialog(hDlg,0);
- return TRUE;
- }
- default:
- return FALSE;
- }
- }
- /******************************************************************************/
- BOOL APIENTRY Dialog2Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
- {
- static HWND hParent;
- switch (uMsg)
- {
- case WM_INITDIALOG:
- {
- CHAR st[256];
- hParent = (HWND)lParam;
- GetWindowText(hParent, st, 256);
- SetDlgItemText(hDlg, IDE_EDIT1, st);
- }
- return TRUE;
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK )
- {
- CHAR cle[3];
- GetDlgItemText(hDlg, IDE_EDIT1, cle, 3);
- SetWindowText(hEdit,cle);
- EndDialog(hDlg,0);
- return TRUE;
- }
- if (LOWORD(wParam) == IDCANCEL )
- {
- EndDialog(hDlg,0);
- return TRUE;
- }
- default:
- return FALSE;
- }
- }
|
resource.h
Code :
- #define IDM_QUIT 1
- #define IDM_NEW 2
- #define IDM_ABOUT 3
- #define IDM_CRYPTE 4
- #define IDE_EDIT1 101
- #define WM_CRYPTER 201
|
resource.rc;
Code :
- #include <windows.h>
- #include "resource.h"
- 1 ICON icone.ico
- 2 ICON autre.ico
- LEMENU MENU
- BEGIN
- POPUP "Fichier"
- BEGIN
- MENUITEM "&Nouveau", IDM_NEW
- MENUITEM "&Crypter", IDM_CRYPTE
- MENUITEM SEPARATOR
- MENUITEM "&Quitter", IDM_QUIT
- END
- POPUP "Aide"
- BEGIN
- MENUITEM "A propos...", IDM_ABOUT
- END
- END
- ABOUT DIALOG
- 60, 60, 160, 80
- STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
- CAPTION "A propos"
- BEGIN
- DEFPUSHBUTTON "Ok", IDOK, 56, 50, 42, 12
- ICON 2, -1, 20, 15, 32, 32
- LTEXT "Programme de cryptage par Pcsnake", -1, 60, 12, 80, 30
- END
- CRYPTE DIALOG
- 60, 60, 182, 70
- STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
- CAPTION "Clé de cryptage"
- BEGIN
- DEFPUSHBUTTON "OK", IDOK, 36, 42, 42, 12
- PUSHBUTTON "Cancel", IDCANCEL, 96, 42, 42, 12
- EDITTEXT IDE_EDIT1, 88, 15, 74, 12
- LTEXT "Veuillez entrer cotre clé de cryptage", -1, 24, 10, 60, 30
- END
|
---------------
Non pas maintenant
|