Thread: how to display jpeg image using borland C++ 5.02

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    19

    how to display jpeg image using borland C++ 5.02

    hi ,

    could any one tellme how could i display image (jpeg,Giff)

    in borland C++ 5.02 do uhave a code for that.

    Regards
    Gaurav

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I think you can use a list-view control as a image control (down the bottom).

    Here is a demo program:
    Code:
    #include <windows.h>
    #include <objbase.h>
    #include <commctrl.h>
    
    #if defined(_MSC_VER)
    #pragma comment(lib, "comctl32.lib")
    #pragma comment(lib, "ole32.lib")
    #endif
    
    #define MAIN_APP_WINDOW_CLASS TEXT("ScratchProgramWindowClass")
    #define WC_IMAGEBOX WC_LISTVIEW
    
    
    BOOL ImageBox_SetImage(HWND hwndImageBox, LPCTSTR szImagePath)
    {
    	LVBKIMAGE lv = { 0 };
    
    	lv.ulFlags =  LVBKIF_STYLE_NORMAL | LVBKIF_SOURCE_URL;
    	lv.pszImage = (LPTSTR) szImagePath; // full path required
    
    	return ListView_SetBkImage(hwndImageBox, &lv); 
    }
    
    //+-----------------------------------------------------------------------------
    LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
    {
    	switch(uMsg)
    	{
    		case WM_CREATE:
    		{
    			HWND hwndImage = CreateWindowEx(0, WC_IMAGEBOX, TEXT(""), WS_CHILD | WS_VISIBLE,
    	                         0, 0, 200, 200,
    	                         hwnd, NULL, (HMODULE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
    
    			ImageBox_SetImage(hwndImage, TEXT("C:\\MyImage.jpg"));
    			return 0;
    		}
    
    
    		case WM_DESTROY:
    		{
    			PostQuitMessage(0);
    			return 0;
    		}
    	}
    
    	return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    
    
    //+-----------------------------------------------------------------------------
    BOOL SetupWindowClass( void )
    {
    	WNDCLASSEX           wc  = { 0 };
    	INITCOMMONCONTROLSEX ice = { 0 };
    
    	wc.cbSize        = sizeof(WNDCLASSEX);
    	wc.style         = 0;
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = GetModuleHandle(NULL);
    	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	wc.hIconSm       = NULL;
    	wc.lpfnWndProc   = WndProc;
    	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE + 1);
    	wc.lpszMenuName  = NULL;
    	wc.lpszClassName = MAIN_APP_WINDOW_CLASS;
    
    	ice.dwSize = sizeof(ice);
    	ice.dwICC  = ICC_LISTVIEW_CLASSES;
    	InitCommonControlsEx(&ice);
    
    	return (BOOL) RegisterClassEx(&wc);
    }
    
    
    
    //+-----------------------------------------------------------------------------
    BOOL CALLBACK CreateAppWindow( int nCmdShow )
    {
    	HWND  hwnd;
    
    	hwnd = CreateWindowEx(0, MAIN_APP_WINDOW_CLASS, TEXT("Main Window"), WS_OVERLAPPEDWINDOW,
    	                      CW_USEDEFAULT, CW_USEDEFAULT, 500, 500,
    	                      NULL, NULL, GetModuleHandle(NULL), NULL);
    	if ( !hwnd )
    		return FALSE;
    
    	ShowWindow(hwnd, nCmdShow);
    	return TRUE;
    }
    
    
    //+-----------------------------------------------------------------------------
    INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE reserved, LPSTR lpCommand, INT nCmdShow )
    {
    	MSG  msg;
    	BOOL bRet;
    
    	CoInitialize(NULL);
    
    	if( !SetupWindowClass() )
    		return -1;
    
    	if ( !CreateAppWindow( nCmdShow ) )
    		return -1;
    
    	while ( bRet = GetMessage(&msg, NULL, 0, 0) )
    	{
    		if (bRet != -1)
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
    	}
    
    	CoUninitialize();
    	return (int) msg.wParam;
    }
    This method does not stretch the image so the image box should be the same size as the original image. Another solution is to use IPicture which is detailed on the web.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    19

    re: too urgent & IMP

    hi,

    This code which ugave me is not working well.

    can u tell and give the code that uses OLELoadpath and
    IPicture that I can embedded it with my borland C++ 5.02
    program. with out using MFC


    As i don't want MFC .

    Regards
    Gaurav

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Char [] to Image File (JPEG)
    By TranT in forum C Programming
    Replies: 33
    Last Post: 07-06-2009, 11:38 AM
  3. display image name
    By shamee_banu in forum Windows Programming
    Replies: 1
    Last Post: 06-29-2007, 12:13 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. how do i display a grayscale image ?
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 02-13-2002, 01:11 AM