mIRC Home    About    Download    Register    News    Help

Print Thread
C++(not mirc related) help needed!!! #108924 23/01/05 11:02 PM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
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.

Re: C++(not mirc related) help needed!!! #108925 24/01/05 04:10 AM
Joined: Jun 2003
Posts: 195
N
Narusegawa_Naru Offline
Vogon poet
Offline
Vogon poet
N
Joined: Jun 2003
Posts: 195
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.

Last edited by Narusegawa_Naru; 24/01/05 04:18 AM.

Have Fun smile
Re: C++(not mirc related) help needed!!! #108926 24/01/05 04:48 AM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
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); 

Re: C++(not mirc related) help needed!!! #108927 25/01/05 03:37 AM
Joined: Mar 2004
Posts: 359
L
LostServ Offline
Fjord artisan
Offline
Fjord artisan
L
Joined: Mar 2004
Posts: 359
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.

Re: C++(not mirc related) help needed!!! #108928 25/01/05 02:36 PM
Joined: Nov 2003
Posts: 2,327
T
tidy_trax Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
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.


New username: hixxy
Re: C++(not mirc related) help needed!!! #108929 25/01/05 05:21 PM
Joined: Apr 2004
Posts: 847
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 847
looks like you forgot to SelectObject the bitmap into the compatible DC this time..


Saturn, QuakeNet staff
Re: C++(not mirc related) help needed!!! #108930 25/01/05 09:45 PM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
Actually, I fixed this problem. I have another now if anyone's interested grin

Re: C++(not mirc related) help needed!!! #108931 10/02/05 11:35 PM
Joined: Dec 2002
Posts: 87
V
vcv Offline
Babel fish
Offline
Babel fish
V
Joined: Dec 2002
Posts: 87
What was it? I imagine it was something to do with the LoadAnImage code?

Re: C++(not mirc related) help needed!!! #108932 18/02/05 12:57 AM
Joined: Mar 2003
Posts: 187
S
Soul_Eater Offline OP
Vogon poet
OP Offline
Vogon poet
S
Joined: Mar 2003
Posts: 187
No I was painting the wrong way.