Thread: How to open files from list?

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    How to open files from list?

    Code:
    #include <windows.h>
     
    #define ID_EDIT 1
     
     
     
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
     
      static HWND hwndEdit;
      static int len;
      static TCHAR text[30];
     
     
      switch(msg)
      {
        case WM_CREATE:
            hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER,
                                    65, 10, 150, 20, hwnd, (HMENU) ID_EDIT,
                                    NULL, NULL);
     
            CreateWindow(
                    TEXT("button"), TEXT("Show file"),       
                    WS_VISIBLE | WS_CHILD,  
                    65, 50, 150, 25,        
                    hwnd, (HMENU) 1, NULL, NULL);      
                    
        CreateWindow(
                    TEXT("button"), TEXT("HELP"),       
                    WS_VISIBLE | WS_CHILD,  
                    65, 85, 150, 25,        
                    hwnd, (HMENU) 2, NULL, NULL);  
                    
        CreateWindow(
                    TEXT("button"), TEXT("QUIT"),       
                    WS_VISIBLE | WS_CHILD,
                    65, 120, 150, 25,        
                    hwnd, (HMENU) 3, NULL, NULL);  
        CreateWindow(TEXT("STATIC"), "ŠK", 
                        WS_CHILD | WS_VISIBLE | SS_LEFT,
                        40, 10, 20, 15,
                        hwnd, (HMENU) 4, NULL, NULL);
        CreateWindow(TEXT("STATIC"), "ŠK", 
                        WS_CHILD | WS_VISIBLE | SS_LEFT,
                        40, 11, 20, 22,
                        hwnd, (HMENU) 4, NULL, NULL);
        CreateWindow(TEXT("STATIC"), "(Įrašykite kamerą)", 
                        WS_CHILD | WS_VISIBLE | SS_LEFT,
                        80, 30, 200, 20,
                        hwnd, (HMENU) 4, NULL, NULL);
                return 0;
     
     
            break;
     
            case WM_COMMAND:        
               if (HIWORD(wParam) == BN_CLICKED) {
                   len = GetWindowTextLength(hwndEdit) + 1;
                   GetWindowText(hwndEdit, text, len);
                   SetWindowText(hwnd, text);
                   }
               if (LOWORD(wParam) == 2) {
                  PostQuitMessage(0);
                  }
               if (LOWORD(wParam) == 3) {
                  PostQuitMessage(0);
               
               }
            break;
     
            case WM_DESTROY:
                    PostQuitMessage(0);
            break;
      }
      return DefWindowProc(hwnd, msg, wParam, lParam);
    }
     
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                            LPSTR lpCmdLine, int nCmdShow )
    {
      MSG  msg ;    
      WNDCLASS wc = {0};
      wc.lpszClassName = TEXT( "Edit Control" );
      wc.hInstance     = hInstance ;
      wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
      wc.lpfnWndProc   = WndProc ;
      wc.hCursor       = LoadCursor(0,IDC_ARROW);
     
      
      RegisterClass(&wc);
      CreateWindow( wc.lpszClassName, TEXT("Edit control"),
                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                    220, 220, 280, 180, 0, 0, hInstance, 0);  
     
      while( GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      return (int) msg.wParam;
    }
    How can i do that

    07106 = O:\BREZ\MSKAM\MSKWMF\M156.WMF
    08124 = O:\BREZ\MSKAM\MSKWMF\M825.WMF
    09210 = O:\BREZ\MSKAM\MSKWMF\M1480.WMF
    92446 = O:\BREZ\MSKAM\MSKWMF\M793.WMF

    And after i type 07106 in the text box and press buton it opens this file O:\BREZ\MSKAM\MSKWMF\M156.WMF or if i type value wich is not in that list it shows me ERROR ?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    struct filenumandname
    {
        int num;
        string name;
    };
    
    ...
    
    struct filenumandname fnn[] =
    {
        { 7106, "..." },
        ...
    };
    Run through the list looking at each number to see if it matches. If so, open name.

    Edit: Since you're using 0 prefixed numbers some time, you may just want to use a pair of strings. If you do that, you can skip the structure and use a 2d array of strings:
    Code:
    string [][2] =
    {
        { "num", "name" },
        ...
    };
    Quzah.
    Last edited by quzah; 10-01-2009 at 02:30 AM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    2
    Can you add this to my code ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. circularly linked list
    By BlackOps in forum C Programming
    Replies: 0
    Last Post: 07-18-2009, 08:12 AM
  2. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  3. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  4. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 08:02 PM
  5. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM