Pushok

File browser (WINAPI)

Mar 28th, 2011
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include <windows.h>
  2. #include "resource.h"
  3. #include <tchar.h>
  4.  
  5. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  6.  
  7. int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  8.     LPSTR lpCmdLine, int nCmdShow )
  9. {
  10.     MSG  msg ;    
  11.     HWND hwnd;
  12.     WNDCLASS wc;
  13.  
  14.     wc.style         = CS_HREDRAW | CS_VREDRAW;
  15.     wc.cbClsExtra    = 0;
  16.     wc.cbWndExtra    = 0;
  17.     wc.lpszClassName = TEXT( "Window" );
  18.     wc.hInstance     = hInstance ;
  19.     wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  20.     wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
  21.     wc.lpfnWndProc   = WndProc;
  22.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  23.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  24.  
  25.     RegisterClass(&wc);
  26.     hwnd = CreateWindow( wc.lpszClassName, TEXT("Window"),
  27.         WS_SYSMENU | WS_VISIBLE,
  28.         100, 100, 250, 250, NULL, NULL, hInstance, NULL);  
  29.  
  30.     ShowWindow(hwnd, nCmdShow);
  31.     UpdateWindow(hwnd);
  32.  
  33.     while( GetMessage(&msg, NULL, 0, 0)) {
  34.         TranslateMessage(&msg);
  35.         DispatchMessage(&msg);
  36.     }
  37.     return (int) msg.wParam;
  38. }
  39.  
  40. LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
  41. {
  42.     static HWND listbox;
  43.     static HWND button;
  44.     static HWND button_del;
  45.     static HWND edit;
  46.  
  47.     PAINTSTRUCT ps;
  48.     HDC hd;
  49.  
  50.     switch(msg)  
  51.     {
  52.     case WM_DESTROY:
  53.         {
  54.             PostQuitMessage(0);
  55.             return 0;
  56.         }
  57.     case WM_CREATE:
  58.         {
  59.             listbox = CreateWindow(TEXT("listbox") , NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY,
  60.                 10, 10, 210, 120, hwnd,(HMENU) 1, NULL, NULL);
  61.             button = CreateWindow(TEXT("button") , TEXT("Find"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  62.                 120, 140, 100, 25, hwnd,(HMENU) 2, NULL, NULL);
  63.             button_del = CreateWindow(TEXT("button") , TEXT("Clr"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  64.                 10, 140, 100, 25, hwnd,(HMENU) 4, NULL, NULL);
  65.             break;
  66.         }
  67.     case WM_COMMAND:
  68.         {
  69.             if(HIWORD(wParam) == BN_CLICKED)
  70.             {
  71.                 if(LOWORD(wParam) == 2)
  72.                 {
  73.                     TCHAR buff[2048];
  74.                     WIN32_FIND_DATA fData = {0};
  75.                     GetCurrentDirectory(sizeof(buff), buff);
  76.                     wcscat(buff, L"\\*");
  77.  
  78.                     HANDLE hFile = FindFirstFile(buff, &fData);
  79.                     if(hFile != INVALID_HANDLE_VALUE){
  80.                         do {
  81.                             if(_tccmp(fData.cFileName, L".") && _tccmp(fData.cFileName, L".."))
  82.                                 SendMessage(listbox, LB_ADDSTRING, NULL, (LPARAM)fData.cFileName);
  83.                         } while (FindNextFile(hFile, &fData));
  84.                     }
  85.                     FindClose(hFile);
  86.  
  87.                 } else if(LOWORD(wParam) == 4)
  88.                 {
  89.                     SendMessage(listbox, LB_RESETCONTENT, 0, 0);
  90.                 }
  91.             }
  92.             if(LOWORD(wParam) == ID_FILE_INFO)
  93.             {
  94.                 MessageBox(0, L"Programm by Push", L"Thanks", 0);
  95.             }
  96.             if(HIWORD(wParam) == LBN_SELCHANGE)
  97.             {
  98.                 if(LOWORD(wParam) == 1)
  99.                 {
  100.                     TCHAR* buff = new TCHAR[1024];
  101.                     SendMessage(listbox, LB_GETTEXT, SendMessage(listbox, LB_GETCURSEL, NULL, NULL), (LPARAM)buff);
  102.                     MessageBox(NULL, buff, NULL, NULL);
  103.                 }
  104.             }
  105.             break;
  106.         }
  107.     }
  108.     return DefWindowProc(hwnd, msg, wParam, lParam);
  109. }
Advertisement
Add Comment
Please, Sign In to add comment