Thread: Dialog

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    18

    Dialog

    Hi,

    I need help in writing a simple Windows application. I'm just starting out with Win32 so I'm having a lot of problems with this.

    I want an application that would only have one dialog box - no window. I already know how to write an application with a window, but I don't what to do with the dialog box - how to create it.

    I don't want to post my code just yet, becuase it's a complete mess, but I also don't expect anyone to write me the whole code. I think I can figure most of it out if you give me some pointers. I don't even know how to show the dialog - with the CreateWindow/ShowWindow function? Do I need the wndclass when dealing with only a dialog?

    As I said, I'm just starting but I can write a simple window so I'd just need some guides where to go.


    btw, while trying to figure out this myself I was able to create a windows application that compiled but didn't run. There wasn't anything odd in the code, yet whenever I ran it, it didn't show up (couldn't see it in task manager either).

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Have you read the Forger's tutorial on www.winprog.org ? You should. Also, I would definitely advise you to wait until you know how to make GDI programs run correctly before moving to Dialog-only programs. As for your question about WndProc(), yes you always need it because it defines the behaviour of your application.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    18
    Thanks about that, but I'm having a problem.

    I did exactly like written in that tutorial and it worked OK. Then I opened the resource file to edit some code and renamed IDD_DIALOG1 to IDD_DLG etc... And now when I build it, I can't run the exe. This has happened before (as I wrote in my first post) and I don't know what's happening. The project compiles without errors etc... basically the program exists and should be working but for some reason I can't run it :|

    I even tried this app at a friend and the same happens. As I said, this happened a couple of times already to me. I think manually editing the .rc files causes this?

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    It sounds like you renamed your dialogs resource, but the program itself is still looking for it under the old name. Make sure you change _all_ of the IDD_DIALOG1s to IDD_DLG. They must match up. DialogBox() is probaly saying "What? This resource isn't here!" and returning an error code. (One you're probably not checking for...)
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  6. #6
    Registered User
    Join Date
    Dec 2005
    Posts
    18
    Yes I did that, but the problem was still there. After some fiddling around I found out the problem was with the text editor control. I don't know why or what but whenever I add a control to the dialog I can't run the executable (but it compiles).

    Can anyone please download this project and test themselvec why this is happening? Maybe I'm missing something.

    http://www.bestsharing.com/files/ms0...ialog.rar.html
    (tell me if the link isn't working)

  7. #7
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    In the download you provided, I can't find any EDIT controls anywhere.

  8. #8
    Registered User
    Join Date
    Dec 2005
    Posts
    18
    Yeah, sorry about that. I forgot to write that you should try compiling it the way it is and run it. Then try adding an edit control, recompile it and see if it runs.

  9. #9
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    After adding an edit control, I had to change
    Code:
    	case WM_COMMAND:
    		switch(wParam)
    		{
    		case IDCLOSE:
    			EndDialog(hWndDlg, 0);
    			return TRUE;
    		}
    to this

    Code:
      case WM_COMMAND: {
        switch(wParam) {
          case IDCLOSE: {
            EndDialog(hWndDlg, 0);
            return TRUE;
          }
        }
        return TRUE ;
      }
    Then the edit control displays.

  10. #10
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    maybe i is a stupidhead but methinks you should be tryin visual c++
    p.s. its free!
    Keyboard Not Found! Press any key to continue. . .

  11. #11
    Registered User
    Join Date
    Dec 2005
    Posts
    18
    Thanks everyone. I'm still learning and I need to get this done fast for school
    Althought, Dante, your solution did work, I think the problem was that I used a common control, so I had to include commctrl.h, ComCtl32.lib and call InitCommonControls().

    I have another question.

    So I made an edit control but I want it to only accept numbers from 0 to 50 - I used ES_NUMBER flag for only numbers - but I don't know how to either prevent typing in any larger number or attach a spin control to the edit box and then set the spin range to 0-50.

    The major problem I'm having is how to attach the spin control to the edit control. I tried grouping, buddying,... Also I would like to keep it as win32 as possible (AFAIK spin control is MFC) so if anyone can tell me how to do this with the Win32 up-down control?

    Thanks again.

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. Edit controls of a dialog from another dialog...
    By Snake in forum Windows Programming
    Replies: 9
    Last Post: 07-01-2005, 02:18 PM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 02:59 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM