CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    george7378 Guest

    Images and dialog boxes

    Hi everyone,

    I have the following code which displays an image in a picture frame on a dialog box:

    Code:
    #include "windows.h"
    #include <cstdio>
    #include "resource.h" 
    #include <tchar.h>
    #include <urlmon.h>
    #include <iostream>
    #include "stdlib.h"
    
    #pragma comment(lib, "urlmon.lib")
    
    BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case IDC_SUN:
    					DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_SUNPAGE), hwnd, ToolDlgProc);
    				break;
    							
    				case IDC_CLOSEASTRO:
    					EndDialog(hwnd, 0);
    				break;
    				
    				case IDC_MOON:
    					break;
    
    				case IDC_ABOUT:
                        DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, ToolDlgProc);
    			    break;
    
    				case IDC_ABOUTOK:
    					EndDialog(hwnd, 0);
    				break;
    
    				case IDC_STARTLOAD:
    					EndDialog(hwnd, 0);
    					DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAIN), hwnd, ToolDlgProc);
    				break;
    
    			}
    		break;
    
    		case WM_CLOSE:
    			EndDialog(hwnd, 0);
    		    break;
    
    		default:
    			return FALSE;
    	}
    	return TRUE;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    	LPSTR lpCmdLine, int nCmdShow)
    {
    	return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, ToolDlgProc);
    }
    Here is the resource file:

    Code:
    LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
    IDB_SUNPIC        BITMAP DISCARDABLE         "C:\\Documents and Settings\\XP\\My Documents\\latest.bmp"
    
    IDD_SUNPAGE DIALOG 0, 0, 490, 352
    STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_FIXEDSYS | WS_VISIBLE | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU
    CAPTION "Latest Sun"
    FONT 8, "Ms Shell Dlg 2"
    {
        CONTROL         IDB_SUNPIC, IDC_SUNFRAME, WC_STATIC, SS_BITMAP, 30, 12, 341, 236
    }
    I have created the bitmap and picture frame resources in the RC file, and assigned the bitmap to the frame in the above line. When I run the program, the image displays, but if I change the image and restart the program, it stays the same when the program displays it. How do I make it refresh the image?

    Thanks.
    Last edited by george7378; June 24th, 2010 at 10:10 AM.

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Images and dialog boxes

    Please use code tags.

    I didn't look at your code, but what do you mean by "change the image"? Do you change it in the resource editor, or with some external program? If with an external program, do you recompile after changing the image? The image that resides in the res folder is linked into the program resources at compile time. Once compiled, the image is ignored by the program until you recompile.

  3. #3
    george7378 Guest

    Re: Images and dialog boxes

    I tried to find the button for code tags, but I couldn't. Do I have to put them in manually?

    Anyway, yes - that's what I mean, and that explains why it doesn't change when I use paint to modify it. Are there any commands I can use to make it read from the image instead of keeping the image it integrated while compiling?

    Thanks.

  4. #4
    Join Date
    Jun 2010
    Posts
    4

    Re: Images and dialog boxes

    I think size of your static IDC_SUNFRAME remains unchanged in rc-file.
    You change latest.bmp file, but VC resource editor does not know it.
    Possible solutions:
    1. [simple] Update rc-file after any bmp-file modification.
    2. [complex] Update size of IDC_SUNFRAME dynamically at runtime. Inside WM_INITDIALOG for example.

  5. #5
    george7378 Guest

    Re: Images and dialog boxes

    Thanks for the advice - the idea of the program is that it downloads a picture of the Sun from a set URL (http://sohowww.nascom.nasa.gov/data/...024/latest.jpg) and displays it when the window is opened. I have got it to downlod, and, now I know that I need to recompile every time I want to view the new image.

    Can you offer any help on the WM_INITDIALOG option?

    Thanks.

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Images and dialog boxes

    Loading an image has its own complications due to the fact that files are stored as device independent bitmaps (DIBs) and windows drawing uses DDBs internally. This article should give you a place to start:

    http://support.microsoft.com/kb/158898

  7. #7
    Join Date
    Jun 2010
    Posts
    4

    Re: Images and dialog boxes

    Here is WM_INITDIALOG implementation plan:
    1. Handle WM_INITDAILOG message in your dialog procedure.
    2. Inside WM_INITDIALOG handler detect your bitmap size.
    3. Use GetDlgItem to detect IDC_SUNFRAME HWND.
    4. Call SetWindowPos or MoveWindow to set its size.
    I hope it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured