Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <commctrl.h>
- #include "resource.h"
- const char g_szClassName[] = "myWindowClass";
- #define IDC_MAIN_EDIT 101
- #define IDC_BUTTON 1000
- #define IDC_STATUSBAR 1001
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- const char* password = "Djoby";
- LPTSTR editText;
- HWND hEdit;
- HWND hText;
- HWND hButton;
- HWND hStatus;
- HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF));
- switch(msg)
- {
- case WM_CREATE:
- {
- hText = CreateWindowEx(0, "STATIC", "Entrez le mot de passe :",
- WS_CHILD | WS_VISIBLE,
- 20, 0, 170, 20, hwnd, 0, GetModuleHandle(NULL) ,0);
- hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "",
- WS_CHILD | WS_VISIBLE | ES_MULTILINE,
- 20, 25, 200, 20, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
- hButton = CreateWindowEx(0, "BUTTON", "OK",
- WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
- 90, 50, 50, 20, hwnd, (HMENU)IDC_BUTTON, GetModuleHandle(NULL) ,0);
- hStatus = CreateWindowEx(0, STATUSCLASSNAME, NULL,
- WS_CHILD | WS_VISIBLE | WS_BORDER,
- 0, 75, 260, 20,
- hwnd, (HMENU)IDC_STATUSBAR, GetModuleHandle(NULL), NULL);
- if(hText == NULL)
- MessageBox(hwnd, "Could not create textControl.", "Error", MB_OK | MB_ICONERROR);
- if(hEdit == NULL)
- MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);
- if(hButton == NULL)
- MessageBox(hwnd, "Could not create button.", "Error", MB_OK | MB_ICONERROR);
- if(hStatus == NULL)
- MessageBox(hwnd, "Could not create statusBar.", "Error", MB_OK | MB_ICONERROR);
- }
- break;
- case WM_COMMAND:
- if(wParam == IDC_BUTTON)
- {
- int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_MAIN_EDIT));
- if(len > 0)
- {
- char* buf;
- buf = (char*)GlobalAlloc(GPTR, len + 1);
- GetDlgItemText(hwnd, IDC_MAIN_EDIT, buf, len + 1);
- editText=buf;
- if(strcmp(buf, password) == 0)
- {
- SetWindowText(GetDlgItem( hwnd, IDC_STATUSBAR ), "Mot de passe correct.");
- }
- else
- {
- SetWindowText(GetDlgItem( hwnd, IDC_STATUSBAR ), "Mot de passe incorrect.");
- }
- GlobalFree((HANDLE)buf);
- }
- }
- break;
- case WM_CTLCOLORDLG:
- return (LONG)g_hbrBackground;
- case WM_CTLCOLORSTATIC:
- {
- HDC hdcStatic = (HDC)wParam;
- SetTextColor(hdcStatic, RGB(0, 0, 0));
- SetBkMode(hdcStatic, TRANSPARENT);
- return (LONG)g_hbrBackground;
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow)
- {
- WNDCLASSEX wc;
- HWND hwnd;
- MSG Msg;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = 0;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- wc.hCursor = NULL;
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = g_szClassName;
- wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
- if(!RegisterClassEx(&wc))
- {
- MessageBox(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- hwnd = CreateWindowEx(
- WS_EX_CLIENTEDGE,
- g_szClassName,
- "Crackme 01",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 260, 150,
- NULL, NULL, hInstance, NULL);
- if(hwnd == NULL)
- {
- MessageBox(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- ShowWindow(hwnd, nCmdShow);
- UpdateWindow(hwnd);
- while(GetMessage(&Msg, NULL, 0, 0) > 0)
- {
- TranslateMessage(&Msg);
- DispatchMessage(&Msg);
- }
- return Msg.wParam;
- }
Add Comment
Please, Sign In to add comment