CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2008
    Posts
    138

    Help in CxImage..

    Hi all...

    I'm using CxImage to load and draw PNG. Either in dialog box or preferably on desktop screen.. Need help how to draw the PNG... Which function do i need to use..

    Code:
    CxImage* newImage = new CxImage();
    newImage->LoadResource(FindResource(NULL,MAKEINTRESOURCE(IDR_PNG1),"PNG"),CXIMAGE_FORMAT_PNG);


    Thanks.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help in CxImage..

    How to use CxImage?
    What is CXImage? Is it from CP ( http://www.codeproject.com/KB/graphics/cximage.aspx )? Then have a look at the section "... Display a File in a Picture Box"
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2008
    Posts
    138

    Re: Help in CxImage..

    Yes it's from the same link..
    But That part of the link which say "Display a File in a Picture Box".. I'm finding hard to change in Non-MFC. . Could you please elaborate that... I load PNG and need to draw it.

    Thanks..

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help in CxImage..

    Picture box is just a static control with the style SS_BITMAP. Read MSDN to know what message and with which parameters you have to send to this control to display your image.
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2008
    Posts
    138

    Re: Help in CxImage..

    Hey Victor..

    I did something like this..Tell me it's right approach..

    Code:
    case WM_INITDIALOG:
    		{ 
    			HBITMAP m_bitmap = NULL;
    			CxImage image("E:\\My_Prog\\FINAL_PNG\\Res\\eScan.png", CXIMAGE_FORMAT_PNG);
    			
    			RECT rect;
    			HWND hImage = GetDlgItem(hWnd, IDC_DRAW_IMAGE);
    			GetClientRect(hImage, &rect);
    			int rectHeight = rect.bottom - rect.top;
    			int rectWidth = rect.right - rect.left;
    
    			int height = image.GetHeight();
    			int width = image.GetWidth();
    
    			//if height or width larger than image's size, resample it
    			//else show image in original size.
    
    			int xpos = 0;
    			int ypos = 0;
    			if(height > rectHeight || width > rectWidth)
    			{
    				//
    				double ratiox = (double)rectWidth /(double)width;
    				double ratioy = (double)rectHeight/(double)height;
    				double ratio = ratiox > ratioy? ratioy: ratiox;
    				width = width * ratio;
    				height = height * ratio;
    				image.Resample(width, height);
    				image.Save("E:\\My_Prog\\FINAL_PNG\\Res\\eScan.bmp", CXIMAGE_FORMAT_BMP);
    			}
    
    			xpos = (rectWidth - width)/2;
    			ypos = (rectHeight - height)/2;
    
    			//GetDlgItem(IDC_IMAGE)->GetDC()->FillSolidRect(0, 0, rectWidth, rectHeight, 0x000000);
    			HDC hdc = GetDC(hImage);
    			image.Draw(hdc, xpos, ypos);
    
    			//if(m_posFile == NULL)
    			//	m_posFile = m_pFileList->GetHeadPosition();
    			
    			break;
    		}

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help in CxImage..

    Why are you drawing it in WM_INITDIALOG case?
    Why not in WM_PAINT?
    Victor Nijegorodov

  7. #7
    Join Date
    Feb 2008
    Posts
    138

    Re: Help in CxImage..

    Yeah WM_PAINT worked.. I thought it should work on WM_INITDIALOG.. Thanks a ton..

    Well i've one other prob. I want to make my dialog transparent. I can do that if i make my Dialog box with the help of CreateWindowEx. Like that..

    Code:
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
     {
         hGlobalInst = hInstance;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         //wndclass.hbrBackground = (HBRUSH) GetStockObject (HOLLOW_BRUSH) ;
    	 wndclass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(255,255,255));
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = "HELLO" ;
         
         if (!RegisterClass (&wndclass))
         {
              //MessageBox (NULL, TEXT ("This program requires Windows NT!"),
                //          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
         /*hwnd = CreateWindow ("HELLO", TEXT ("LoadBitmap Demo"), 
                              WS_OVERLAPPEDWINDOW, 
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              CW_USEDEFAULT, CW_USEDEFAULT,
                              NULL, NULL, hInstance, NULL) ;*/
    
    	 hwnd = CreateWindowEx(WS_EX_TOOLWINDOW |WS_EX_LAYERED|WS_EX_APPWINDOW,
    						  "HELLO",  						// window class name
    						  NULL,								// window caption
    						  WS_POPUP,							// window style
    						  10,								// initial x position
    						  10,								// initial y position
    						  100,								// initial x size
    						  100,								// initial y size
    						  NULL,								// parent window handle
    						  NULL,								// window menu handle
    						  hInstance,						// program instance handle
    						  NULL) ;							// creation parameters
    
         ShowWindow (hwnd, iCmdShow) ;
         //UpdateWindow (hwnd) ;
    	 SetLayeredWindowAttributes(hwnd, RGB(255,255,255), 255, LWA_COLORKEY|LWA_ALPHA);
    
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    But here i'm creating dialog from resource. How do i make this transparent?

    Thanks again.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help in CxImage..

    If what you want is setting some window extended styles then SetWindowLong with GWL_EXSTYLE parameter will help you.
    Victor Nijegorodov

  9. #9
    Join Date
    Feb 2008
    Posts
    138

    Re: Help in CxImage..

    Hey Victor... I'm doing this to make my dialog transparent.. And it works... But i've one problem. I'm showing my PNG on picture box and it also get transparent.. How to i only show picture box PNG so that it seems that PNG is showed on desktop screen only..

    Code:
    SetWindowLong(hWnd,GWL_EXSTYLE,GetWindowLong(hWnd,GWL_EXSTYLE)^WS_EX_LAYERED);
     SetLayeredWindowAttributes(hWnd,RGB(0,0,0),0,LWA_ALPHA);

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Help in CxImage..

    Sorry, I don't know.
    Victor Nijegorodov

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