mIRC Homepage
Posted By: Soul_Eater C++(not mirc related) help needed!!! - 23/01/05 11:02 PM
ok. This part of my program is supposed to retrieve the file location from an editbox in the dialog, then load it as a bitmap, then resize it, then display it.

It's not displaying anything.

Code:
 HWND hEditBox = GetDlgItem(hWndDlg,IDC_EDIT1);
    	char image[999];
	  GetWindowText(hEditBox,image,999);
//	 if (image != NULL) {
	   HBITMAP hBitmap = (HBITMAP)LoadAnImage(image);
       HBITMAP hBitmap2 = (HBITMAP)ScaleBitmapInt(hBitmap,220,176);
	   HWND hStatic = GetDlgItem(hWndDlg,ID_STATIC_1);
     	HDC hDC, MemDCExercising;
       PAINTSTRUCT Ps;
       hDC = BeginPaint(hStatic, &Ps);
    	MemDCExercising = CreateCompatibleDC(hDC);
       SelectObject(MemDCExercising, hBitmap2);
    	BitBlt(hDC, 10, 10, 450, 400, MemDCExercising, 0, 0, SRCCOPY);
    	DeleteDC(MemDCExercising);
    	DeleteObject(hBitmap);
		DeleteObject(hBitmap2);
    	EndPaint(hStatic, &Ps);


If someone thinks they need the LoadAnImage() and ScaleBitmapInt() code, let me know, I'll include it too.
well the obvious question is when are you calling it? You should NEVER use BeginPaint outside of the WM_PAINT case statement. You can use GetDC or GetDCEx for this.

Just curious but why scale the bitmap creating another object to delete? Just use select the original image into your memory dc and use StretchBlt. (make sure to call SetStretchBltMode otherwise the quality might suffer).

And you may want to check the returned value from your function. I cant really tell if the returned bitmap handles are valid or did the load fail etc..

also if your using LoadImage internally (or another win api) try using GetLastError to see if an error occured in those calls.

Also make sure the path is a fully qualified path. If the image is not within the same directory as the executable then you cant use "image.bmp" alone.

one last thing. it would probably be easier to just register a window class and use it instead of a static. this way you can do your paint directly in its WM_PAINT msg w/o the need to subclass. You dont add any overhead since your already using a child control it would just be a different one.
Posted By: Soul_Eater Re: C++(not mirc related) help needed!!! - 24/01/05 04:48 AM
I'm getting the biggest headache over here. All I want is for my hbitmap to be resized and draw, so then I can move on to the next issue.

Well here's what I tried, still no dice:

Code:
	   HBITMAP hBitmap = (HBITMAP)LoadAnImage(image);
      // HBITMAP hBitmap2 = (HBITMAP)ScaleBitmapInt(hBitmap,220,176);
       HWND hStatic = GetDlgItem(hWndDlg,ID_STATIC_1);
	   HDC hdcscreen = GetDC(hStatic);
	   HDC hdc = CreateCompatibleDC(hdcscreen);
	   SetStretchBltMode(hdc,COLORONCOLOR);
	   BITMAP bm;
	   GetObject(hBitmap,sizeof(bm),&bm);
	   StretchBlt(hdc, 
                     0, 0, 
                     220, 176, 
                     hdc, 
                     0, 0, 
                     bm.bmWidth, bm.bmHeight, 
                     SRCCOPY); 
	   BitBlt(hdcscreen, 
                    0,0, 
                    bm.bmWidth, bm.bmHeight, 
                    hdc, 
                    0,0, 
                    SRCCOPY); 
                 ReleaseDC(hStatic, hdcscreen); 
Posted By: LostServ Re: C++(not mirc related) help needed!!! - 25/01/05 03:37 AM
Since when did this become "C++ Message Board"?
If you need mIRC help, post on these boards.
If you need C++ help, find somewhere else to post.
Posted By: tidy_trax Re: C++(not mirc related) help needed!!! - 25/01/05 02:36 PM
Developer Forum description:

Quote:
This forum is for scripters, and for developers of applications that work with mIRC. Feel free to post your ideas, ask questions, and discuss scripting issues here.


Even though Soul_Eater didn't mention anything about his app being for mIRC, this board does help with languages other than mIRC.
Posted By: Sat Re: C++(not mirc related) help needed!!! - 25/01/05 05:21 PM
looks like you forgot to SelectObject the bitmap into the compatible DC this time..
Posted By: Soul_Eater Re: C++(not mirc related) help needed!!! - 25/01/05 09:45 PM
Actually, I fixed this problem. I have another now if anyone's interested grin
Posted By: vcv Re: C++(not mirc related) help needed!!! - 10/02/05 11:35 PM
What was it? I imagine it was something to do with the LoadAnImage code?
Posted By: Soul_Eater Re: C++(not mirc related) help needed!!! - 18/02/05 12:57 AM
No I was painting the wrong way.
© mIRC Discussion Forums