Advertisement
Guest User

Untitled

a guest
Apr 25th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.58 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <tchar.h>
  5. #include <commctrl.h>
  6. #include <uxtheme.h>
  7. #include "aesencrypt_gui.h"
  8.  
  9. HWND hList=NULL;
  10. HMENU hMenu, hSubMenu;
  11. LVCOLUMN LvCol;
  12. LVITEM LvItem;
  13. HINSTANCE g_hInst;
  14.  
  15. LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
  16.     switch(Message) {
  17.         case WM_CREATE: {
  18.             //------------------ Create Menu ------------------
  19.             HICON hIcon, hIconSm;
  20.             hMenu = CreateMenu();
  21.             WCHAR szText[256];
  22.  
  23.             hSubMenu = CreatePopupMenu();
  24.             AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, L"&New");
  25.             AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, L"&Open");
  26.             AppendMenu(hSubMenu, MF_STRING, ID_FILE_SAVE, L"&Save");
  27.             AppendMenu(hSubMenu, MF_SEPARATOR, 0, 0);
  28.             AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"E&xit");
  29.             AppendMenu(hMenu, MF_STRING | MF_POPUP, hSubMenu, L"&File");
  30.  
  31.             hSubMenu = CreatePopupMenu();
  32.             AppendMenu(hSubMenu, MF_STRING, ID_EDIT_PREFERENCES, L"&Preferences");
  33.             AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Edit");
  34.            
  35.             hSubMenu = CreatePopupMenu();
  36.             for (int i = 0; i < C_COLUMNS; i++) {
  37.                 LoadString(g_hInst, ID_COLUMN_FILENAME + i, szText, sizeof(szText)/sizeof(szText[0]));
  38.                 AppendMenu(hSubMenu, MF_STRING, ID_COLUMN_FILENAME, szText);
  39.             }
  40.             AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Columns");
  41.            
  42.             hSubMenu = CreatePopupMenu();
  43.             AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, L"&About");
  44.             AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Help");
  45.  
  46.             SetMenu(hwnd, hMenu);
  47.            
  48.             //------------------ Create Toolbar ------------------
  49.             HWND hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS, 0, 0, 0, 0, hwnd, (HMENU)IDC_MAIN_TOOL, GetModuleHandle(NULL), NULL);
  50.             SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
  51.             TBBUTTON tbb[5];
  52.             TBADDBITMAP tbab;
  53.             tbab.hInst = HINST_COMMCTRL;
  54.             tbab.nID = IDB_STD_SMALL_COLOR;
  55.             SendMessage(hTool, TB_ADDBITMAP, 0, (LPARAM)&tbab);
  56.             ZeroMemory(tbb, sizeof(tbb));
  57.  
  58.             tbb[0].iBitmap = STD_FILENEW;
  59.             tbb[0].fsState = TBSTATE_ENABLED;
  60.             tbb[0].fsStyle = TBSTYLE_BUTTON;
  61.             tbb[0].idCommand = ID_FILE_NEW;
  62.             tbb[0].iString = L"New";
  63.  
  64.             tbb[1].iBitmap = STD_FILEOPEN;
  65.             tbb[1].fsState = TBSTATE_ENABLED;
  66.             tbb[1].fsStyle = TBSTYLE_BUTTON;
  67.             tbb[1].idCommand = ID_FILE_OPEN;
  68.             tbb[1].iString = L"Open";
  69.  
  70.             tbb[2].iBitmap = STD_FILESAVE;
  71.             tbb[2].fsState = TBSTATE_ENABLED;
  72.             tbb[2].fsStyle = TBSTYLE_BUTTON;
  73.             tbb[2].idCommand = ID_FILE_SAVE;
  74.             tbb[2].iString = L"Save";
  75.            
  76.             tbb[3].fsStyle = TBSTYLE_SEP;
  77.            
  78.             tbb[4].iBitmap = STD_FILESAVE;
  79.             tbb[4].fsState = TBSTATE_ENABLED;
  80.             tbb[4].fsStyle = TBSTYLE_BUTTON;
  81.             tbb[4].idCommand = ID_FILE_SAVE;
  82.             tbb[4].iString = L"Save";
  83.  
  84.             SendMessage(hTool, TB_ADDBUTTONS, sizeof(tbb)/sizeof(TBBUTTON), (LPARAM)&tbb);
  85.             SendMessage(hTool, TB_SETMAXTEXTROWS, 0, 0);
  86.  
  87.             //------------------ Create ListView ------------------
  88.             RECT rcClient;
  89.             GetClientRect(hwnd, &rcClient);
  90.             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);
  91.             //
  92.            
  93.             int iCol;
  94.             LVCOLUMN lvc;
  95.             lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  96.             for (iCol = 0; iCol < C_COLUMNS; iCol++) {
  97.                 lvc.iSubItem = iCol;
  98.                 lvc.pszText = szText;
  99.                 lvc.cx = 100;
  100.                 if ( iCol < 2 ) {
  101.                     lvc.fmt = LVCFMT_LEFT;
  102.                 } else {
  103.                     lvc.fmt = LVCFMT_RIGHT;
  104.                 }
  105.                 LoadString(g_hInst, ID_COLUMN_FILENAME + iCol, szText, sizeof(szText)/sizeof(szText[0]));
  106.                 ListView_InsertColumn(hList, iCol, &lvc);
  107.             }
  108.         }
  109.         break;
  110.         case WM_COMMAND:
  111.             switch(LOWORD(wParam)) {
  112.             case ID_FILE_EXIT: {
  113.                     PostMessage(hwnd, WM_CLOSE, 0, 0);
  114.                 }
  115.             break;
  116.             case ID_EDIT_PREFERENCES: {
  117.                     MessageBox(hwnd, L"Preferences selected", L"Info", MB_OK | MB_OK);
  118.                 }
  119.             break;
  120.                 case ID_FILE_NEW: {
  121.                     MessageBox(hwnd, L"New selected", L"Info", MB_OK | MB_OK);
  122.                 }
  123.             break;
  124.                 case ID_FILE_OPEN: {
  125.                     OPENFILENAME ofn;
  126.                     WCHAR szFileName[MAX_PATH] = L"";
  127.                     ZeroMemory(&ofn, sizeof(ofn));
  128.                     ofn.lStructSize = sizeof(ofn);
  129.                     ofn.hwndOwner = hwnd;
  130.                     ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
  131.                     ofn.lpstrFile = szFileName;
  132.                     ofn.nMaxFile = MAX_PATH;
  133.                     ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  134.                     ofn.lpstrDefExt = L"txt";
  135.                     if(GetOpenFileName(&ofn)) {
  136.                         MessageBox(hwnd, szFileName, L"Info", MB_OK | MB_OK);
  137.                     } else {
  138.                         MessageBox(hwnd, L"Cancelled", L"Info", MB_OK | MB_OK);
  139.                     }
  140.                 }
  141.             break;
  142.                 case ID_FILE_SAVE: {
  143.                     OPENFILENAME ofn;
  144.                     WCHAR szFileName[MAX_PATH] = L"";
  145.                     ZeroMemory(&ofn, sizeof(ofn));
  146.                     ofn.lStructSize = sizeof(ofn);
  147.                     ofn.hwndOwner = hwnd;
  148.                     ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
  149.                     ofn.lpstrFile = szFileName;
  150.                     ofn.nMaxFile = MAX_PATH;
  151.                     ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  152.                     ofn.lpstrDefExt = "txt";
  153.                     if(GetSaveFileName(&ofn)) {
  154.                         MessageBox(hwnd, szFileName, L"Info", MB_OK | MB_OK);
  155.                     } else {
  156.                         MessageBox(hwnd, L"Cancelled", L"Info", MB_OK | MB_OK);
  157.                     }
  158.                 }
  159.             break;
  160.             }
  161.         break;
  162.         case WM_SIZE: {
  163.             //------------------ Resize Toolbar ------------------
  164.             HWND hTool = GetDlgItem(hwnd, IDC_MAIN_TOOL);
  165.             SendMessage(hTool, TB_AUTOSIZE, 0, 0);
  166.            
  167.             //------------------ Resize Window ------------------
  168.             RECT rcTool, rcClient;
  169.             GetWindowRect(hTool, &rcTool);
  170.             int iToolHeight = rcTool.bottom - rcTool.top;
  171.             GetClientRect(hwnd, &rcClient);
  172.             int iEditHeight = rcClient.bottom - iToolHeight;
  173.             HWND hEdit = GetDlgItem(hwnd, IDC_LIST);
  174.             SetWindowPos(hEdit, NULL, 0, iToolHeight, rcClient.right, iEditHeight, SWP_NOZORDER);
  175.         }
  176.         break;
  177.         case WM_CLOSE:
  178.             DestroyWindow(hwnd);
  179.         break;
  180.         case WM_DESTROY:
  181.             PostQuitMessage(0);
  182.         break;
  183.         default:
  184.             return DefWindowProc(hwnd, Message, wParam, lParam);
  185.     }
  186.     return 0;
  187. }
  188.  
  189. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
  190.     g_hInst = hInstance;
  191.     WNDCLASSEX wcex;
  192.     static TCHAR szWindowClass[] = L"win32app";
  193.     static TCHAR szTitle[] = L"AES Encypt";
  194.     wcex.cbSize = sizeof(WNDCLASSEX);
  195.     wcex.style          = CS_HREDRAW | CS_VREDRAW;
  196.     wcex.lpfnWndProc    = WndProc;
  197.     wcex.cbClsExtra     = 0;
  198.     wcex.cbWndExtra     = 0;
  199.     wcex.hInstance      = hInstance;
  200.     wcex.hIcon          = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON));
  201.     wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
  202.     wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
  203.     wcex.lpszMenuName   = NULL;
  204.     wcex.lpszClassName  = szWindowClass;
  205.     wcex.hIconSm        = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_MYICON), IMAGE_ICON, 16, 16, 0);
  206.    
  207.     if (!RegisterClassEx(&wcex)) {
  208.         MessageBox(NULL, L"Call to RegisterClassEx failed!", L"AES Encrypt", MB_OK);
  209.         return 1;
  210.     }
  211.    
  212.     INITCOMMONCONTROLSEX icex;
  213.    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  214.    icex.dwICC = ICC_STANDARD_CLASSES;
  215.    InitCommonControlsEx(&icex);
  216.    
  217.     HWND hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 560, 360, NULL, NULL, hInstance, NULL);
  218.     ShowWindow(hWnd, nCmdShow);
  219.     UpdateWindow(hWnd);
  220.    
  221.     MSG msg;
  222.     while (GetMessage(&msg, NULL, 0, 0))
  223.     {
  224.         TranslateMessage(&msg);
  225.         DispatchMessage(&msg);
  226.     }
  227.  
  228.     return (int) msg.wParam;
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement