Resources

This is a discussion on Resources within the C++ Programming forums, part of the General Programming Boards category; I just started Win32 API with my Borland C++ compiler. I just want to load a dialog box... I don't ...

  1. #1
    drdroid
    Guest

    Question Resources

    I just started Win32 API with my Borland C++ compiler. I just want to load a dialog box... I don't want to include any function to the buttons what so ever. I just want to see the dialog box... I tried to compile the code from sunlights windows tutorial and it doesn't bring up the dialog box... heres the code:

    Code:
    #include <windows.h>
    #include <tchar.h>
    #include "char.h"
    
    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	return FALSE;
    }
    
    int _tmain(void)
    {
    	DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(DIALOG2), 
    		NULL, (DLGPROC)MainDialogProc, 0);
    	return 0;
    }

  2. #2
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    You forgot to include your resource.h file!

  3. #3
    drdroid
    Guest

    resource file

    char.h is my resource file

  4. #4
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    sunlight's using resource.h...is char.h the exact same thing? if not, the problem might lie in char.h

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571

    Re: Resources

    Originally posted by drdroid

    Code:
    #include <windows.h>
    #include <tchar.h>
    #include "char.h"
    
    BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	return FALSE;
    }
    
    int _tmain(void)
    {
    	DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(DIALOG2), 
    		NULL, (DLGPROC)MainDialogProc, 0);
    	return 0;
    }
    Try using DialogBox( ) function instead of DialogBoxParam( )..
    DialogBoxParam is for Windows CE. DialogBox is the Win32 equivalent. If that does not work, try handling the WM_INITDIALOG case in your message proc, and using ShowWindow( ). I think it should work without that though.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  6. #6
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789

    Re: Re: Resources

    Originally posted by MrWizard


    Try using DialogBox( ) function instead of DialogBoxParam( )..
    DialogBoxParam is for Windows CE. DialogBox is the Win32 equivalent. If that does not work, try handling the WM_INITDIALOG case in your message proc, and using ShowWindow( ). I think it should work without that though.
    DialogBoxParam is fine...and can be used as you wish

    <secret>
    In fact if out look at your include's the real truth might show that DialogBox is an imposter and uses DialogBoxParam to do the work
    Code:
    #define DialogBoxA(hInstance, lpTemplate, hWndParent, lpDialogFunc) \
    DialogBoxParamA(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0L)
    #define DialogBoxW(hInstance, lpTemplate, hWndParent, lpDialogFunc) \
    DialogBoxParamW(hInstance, lpTemplate, hWndParent, lpDialogFunc, 0L)
    #ifdef UNICODE
    #define DialogBox  DialogBoxW
    #else
    #define DialogBox  DialogBoxA
    #endif // !UNICODE
    </secret>

    The code worked ok for me.....most probable that you havent included the resource in the project, or you are using the wrong ID (could DIALOG2 be DIALOG1???)

    Also....add this to your dialog proc

    Code:
    switch(uMsg){
    	case WM_CLOSE:
    		EndDialog(hWnd,0);
    		return TRUE;
    	}
    Cuz when you get that dialog working finally, you may find you cant get rid of it without the above code

  7. #7
    drdroid
    Guest

    Exclamation Errors

    I don't get any errors... the window just doesn't come up.

  8. #8
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Are you linking your resource.rc file to the project?

  9. #9
    drdroid
    Guest

    Post yes

    yes

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Resources in Dev C++
    By JJFMJR in forum Windows Programming
    Replies: 7
    Last Post: 08-27-2007, 06:14 AM
  2. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  3. Getting resources from another program.
    By Queatrix in forum C++ Programming
    Replies: 3
    Last Post: 02-11-2006, 09:00 PM
  4. Storing resources into a single file
    By LuckY in forum Game Programming
    Replies: 20
    Last Post: 08-15-2004, 12:28 AM
  5. Adding resources
    By nima_ranjbar in forum Windows Programming
    Replies: 0
    Last Post: 04-15-2002, 12:36 AM

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