browse button and stuff

This is a discussion on browse button and stuff within the Windows Programming forums, part of the Platform Specific Boards category; i'm looking into win32 programming and it seems quite hard really. there are a lot of tutorials on how to ...

  1. #1
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246

    browse button and stuff

    i'm looking into win32 programming and it seems quite hard really. there are a lot of tutorials on how to create a window and it's clear more or less. but what if i want to put a browse button on my window and next to it an edit box. When the user clicks browse he can choose a directory, then that path is shown in the edit box. in my program i want to use that path to list all the files in the directory. How can i do it? what code should i put for the browse button and an edit box and where?
    :wq

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,854
    What have you got so far?

    Looked at CreateWindow() to make the button/edit or are you going to use the resource editor?

    What IDE are you using?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    i'm using dev c++.
    all i have is what dev c++ generated as a new win32 project, that is a registered window class, a message loop and a WndProc function.

    So are you saying there are two ways to put buttons? How to do this with resource files?

    Also i looked at some other win32 code and found that there are only InitCommonControls() and DialogBox() functions, that is the class is not registered and there is no message loop. Is this better to use? What's the difference?
    :wq

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Quote Originally Posted by viaxd
    When the user clicks browse he can choose a directory, then that path is shown in the edit box. in my program i want to use that path to list all the files in the directory. How can i do it? what code should i put for the browse button and an edit box and where?
    See this thread. What you want is the SHBrowseForFolder function, which displays a dialog box that allows the user to select a folder.

    Quote Originally Posted by viaxd
    Also i looked at some other win32 code and found that there are only InitCommonControls() and DialogBox() functions, that is the class is not registered and there is no message loop. Is this better to use? What's the difference?
    It uses a dialog box resource. A dialog box resource is usually designed visually, which makes it less tedious than specifying all the (x,y,width,height) values yourself in CreateWindow. DialogBox() calls CreateWindow() internally. If you need some more information about resources, you can see the links in this thread.
    Last edited by Dante Shamest; 12-17-2005 at 03:04 PM.

  5. #5
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Dante Shamest, thank you for a very helpful reply.
    First of all, i downloaded that resource editor and made an .rc file, but now i don't know what to do with it. I've included it in my project, but it seems i also need a .h file to use this resource. How do i create a header file for my resource?

    this is the generated resource:
    Code:
    #define IDD_DLG1 1000
    #define IDC_BTN1 1001
    #define IDC_EDT1 1002
    #define IDC_EDT2 1003
    #define IDC_HDR1 1004
    #define IDC_STC1 1005
    IDD_DLG1 DIALOGEX 6,6,177,86
    CAPTION "Renamer"
    FONT 8,"MS Sans Serif",0,0
    STYLE 0x10CF0000
    BEGIN
      CONTROL "Browse",IDC_BTN1,"Button",0x50010000,124,11,42,20
      CONTROL "",IDC_EDT1,"Edit",0x50010000,8,12,96,13,0x00000200
      CONTROL "",IDC_EDT2,"Edit",0x50010000,82,44,84,13,0x00000200
      CONTROL "",IDC_HDR1,"SysHeader32",0x50000002,44,-8,54,12
      CONTROL "Find:",IDC_STC1,"Static",0x50000000,4,46,70,11
    END
    Last edited by viaxd; 12-18-2005 at 07:22 AM.
    :wq

  6. #6
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    You need the following identifiers in any source file (.c, .cpp) that uses the dialog box resource:

    Code:
    #define IDD_DLG1 1000
    #define IDC_BTN1 1001
    #define IDC_EDT1 1002
    #define IDC_EDT2 1003
    #define IDC_HDR1 1004
    #define IDC_STC1 1005
    Usually they are placed in a header file resource.h and #included into source files that use them.

    Code:
    #include "resource.h"
    You don't actually need the header though. You can just copy and paste the #defines into source files that need them.

    IDD_DLG1 is the identifier for the dialog box resource. The other #defines are identifiers for buttons, edit controls, etc.

  7. #7
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Thanks again Dante, it works now. Doesn't do much, but works
    Now i need to figure out how to make Browse do what i want (using SHBrowseForFolder).
    Also, do you know functions that i can use to get a list of file names in a directory and a function to rename files?
    :wq

  8. #8
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Quote Originally Posted by viaxd
    do you know functions that i can use to get a list of file names in a directory
    FindFirstFile
    FindNextFile

    If you need examples for the above functions, search this forum or on Google.

    Quote Originally Posted by viaxd
    and a function to rename files?
    rename

  9. #9
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Big thanks, you've really helped me a lot!
    :wq

  10. #10
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    well, everything is ok, and it's all nearly finished, but there's a problem.
    rename doesnt' work. MoveFile doesn't work either. I'm assuming it's because the file is opened, don't know. There's got to be a way to rename a file...
    :wq

  11. #11
    ~viaxd() viaxd's Avatar
    Join Date
    Aug 2003
    Posts
    246
    Well, it actually works. After spending a day trying to figure out the problem, i finally solved it. MoveFile, of course, expects full paths as arguments. Silly mistake
    :wq

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shifting from C to C++: help with conceptual stuff
    By officedog in forum C++ Programming
    Replies: 6
    Last Post: 12-02-2008, 07:30 AM
  2. Get Button State
    By willc0de4food in forum Windows Programming
    Replies: 5
    Last Post: 10-09-2005, 07:44 PM
  3. button in function
    By algi in forum Windows Programming
    Replies: 1
    Last Post: 03-21-2005, 10:12 PM
  4. exit while loop when button clicked
    By shav in forum Windows Programming
    Replies: 18
    Last Post: 02-02-2005, 04:46 AM
  5. Need some help in BorlandC++ 3.1 (just basic stuff)
    By Fila in forum C++ Programming
    Replies: 6
    Last Post: 01-26-2005, 08:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21