Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include <tchar.h>
- #include <commctrl.h>
- #include <uxtheme.h>
- #include "aesencrypt_gui.h"
- HWND hList=NULL;
- HMENU hMenu, hSubMenu;
- LVCOLUMN LvCol;
- LVITEM LvItem;
- HINSTANCE g_hInst;
- LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
- switch(Message) {
- case WM_CREATE: {
- //------------------ Create Menu ------------------
- HICON hIcon, hIconSm;
- hMenu = CreateMenu();
- WCHAR szText[256];
- hSubMenu = CreatePopupMenu();
- AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, L"&New");
- AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, L"&Open");
- AppendMenu(hSubMenu, MF_STRING, ID_FILE_SAVE, L"&Save");
- AppendMenu(hSubMenu, MF_SEPARATOR, 0, 0);
- AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit");
- AppendMenu(hMenu, MF_STRING | MF_POPUP, hSubMenu, L"&File");
- hSubMenu = CreatePopupMenu();
- AppendMenu(hSubMenu, MF_STRING, ID_EDIT_PREFERENCES, L"&Preferences");
- AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Edit");
- hSubMenu = CreatePopupMenu();
- for (int i = 0; i < C_COLUMNS; i++) {
- LoadString(g_hInst, ID_COLUMN_FILENAME + i, szText, sizeof(szText)/sizeof(szText[0]));
- AppendMenu(hSubMenu, MF_STRING, ID_COLUMN_FILENAME, szText);
- }
- AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Columns");
- hSubMenu = CreatePopupMenu();
- AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, L"&About");
- AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Help");
- SetMenu(hwnd, hMenu);
- //------------------ Create Toolbar ------------------
- HWND hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
- SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
- TBBUTTON tbb[5];
- TBADDBITMAP tbab;
- tbab.hInst = HINST_COMMCTRL;
- tbab.nID = IDB_STD_SMALL_COLOR;
- SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
- ZeroMemory(tbb, sizeof(tbb));
- tbb[0].iBitmap = STD_FILENEW;
- tbb[0].fsState = TBSTATE_ENABLED;
- tbb[0].fsStyle = TBSTYLE_BUTTON;
- tbb[0].idCommand = ID_FILE_NEW;
- tbb[0].iString = L"New";
- tbb[1].iBitmap = STD_FILEOPEN;
- tbb[1].fsState = TBSTATE_ENABLED;
- tbb[1].fsStyle = TBSTYLE_BUTTON;
- tbb[1].idCommand = ID_FILE_OPEN;
- tbb[1].iString = L"Open";
- tbb[2].iBitmap = STD_FILESAVE;
- tbb[2].fsState = TBSTATE_ENABLED;
- tbb[2].fsStyle = TBSTYLE_BUTTON;
- tbb[2].idCommand = ID_FILE_SAVE;
- tbb[2].iString = L"Save";
- tbb[3].fsStyle = TBSTYLE_SEP;
- tbb[4].iBitmap = STD_FILESAVE;
- tbb[4].fsState = TBSTATE_ENABLED;
- tbb[4].fsStyle = TBSTYLE_BUTTON;
- tbb[4].idCommand = ID_FILE_SAVE;
- tbb[4].iString = L"Save";
- SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
- SendMessage(hTool, TB_SETMAXTEXTROWS, 0, 0);
- //------------------ Create ListView ------------------
- RECT rcClient;
- GetClientRect(hwnd, &rcClient);
- hList = CreateWindow(WC_LISTVIEW, "", WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_REPORT | LVS_EDITLABELS | WS_EX_CLIENTEDGE, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hwnd, (HMENU)IDC_LIST, g_hInst, NULL);
- //
- int iCol;
- LVCOLUMN lvc;
- lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
- for (iCol = 0; iCol < C_COLUMNS; iCol++) {
- lvc.iSubItem = iCol;
- lvc.pszText = szText;
- lvc.cx = 100;
- if ( iCol < 2 ) {
- lvc.fmt = LVCFMT_LEFT;
- } else {
- lvc.fmt = LVCFMT_RIGHT;
- }
- LoadString(g_hInst, ID_COLUMN_FILENAME + iCol, szText, sizeof(szText)/sizeof(szText[0]));
- ListView_InsertColumn(hList, iCol, &lvc);
- }
- }
- break;
- case WM_COMMAND:
- switch(LOWORD(wParam)) {
- case ID_FILE_EXIT: {
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- }
- break;
- case ID_EDIT_PREFERENCES: {
- MessageBox(hwnd, L"Preferences selected", L"Info", MB_OK | MB_OK);
- }
- break;
- case ID_FILE_NEW: {
- MessageBox(hwnd, L"New selected", L"Info", MB_OK | MB_OK);
- }
- break;
- case ID_FILE_OPEN: {
- OPENFILENAME ofn;
- WCHAR szFileName[MAX_PATH] = L"";
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hwnd;
- ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
- ofn.lpstrDefExt = L"txt";
- if(GetOpenFileName(&ofn)) {
- MessageBox(hwnd, szFileName, L"Info", MB_OK | MB_OK);
- } else {
- MessageBox(hwnd, L"Cancelled", L"Info", MB_OK | MB_OK);
- }
- }
- break;
- case ID_FILE_SAVE: {
- OPENFILENAME ofn;
- WCHAR szFileName[MAX_PATH] = L"";
- ZeroMemory(&ofn, sizeof(ofn));
- ofn.lStructSize = sizeof(ofn);
- ofn.hwndOwner = hwnd;
- ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
- ofn.lpstrFile = szFileName;
- ofn.nMaxFile = MAX_PATH;
- ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- ofn.lpstrDefExt = "txt";
- if(GetSaveFileName(&ofn)) {
- MessageBox(hwnd, szFileName, L"Info", MB_OK | MB_OK);
- } else {
- MessageBox(hwnd, L"Cancelled", L"Info", MB_OK | MB_OK);
- }
- }
- break;
- }
- break;
- case WM_SIZE: {
- //------------------ Resize Toolbar ------------------
- HWND hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
- SendMessage(hTool, TB_AUTOSIZE, 0, 0);
- //------------------ Resize Window ------------------
- RECT rcTool, rcClient;
- GetWindowRect(hTool, &rcTool);
- int iToolHeight = rcTool.bottom - rcTool.top;
- GetClientRect(hwnd, &rcClient);
- int iEditHeight = rcClient.bottom - iToolHeight;
- HWND hEdit = GetDlgItem(hwnd, IDC_LIST);
- SetWindowPos(hEdit, NULL, 0, iToolHeight, rcClient.right, iEditHeight, SWP_NOZORDER);
- }
- break;
- case WM_CLOSE:
- DestroyWindow(hwnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, Message, wParam, lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
- g_hInst = hInstance;
- WNDCLASSEX wcex;
- static TCHAR szWindowClass[] = L"win32app";
- static TCHAR szTitle[] = L"AES Encypt";
- wcex.cbSize = sizeof(WNDCLASSEX);
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = NULL;
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
- if (!RegisterClassEx(&wcex)) {
- MessageBox(NULL, L"Call to RegisterClassEx failed!", L"AES Encrypt", MB_OK);
- return 1;
- }
- INITCOMMONCONTROLSEX icex;
- icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
- icex.dwICC = ICC_STANDARD_CLASSES;
- InitCommonControlsEx(&icex);
- HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 560, 360, NULL, NULL, hInstance, NULL);
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (int) msg.wParam;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement