473,466 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PLEASE HELP!! Transparent blitting not working!

The following code is used to draw a bitmap on a form with a color key
(i.e. a color that's not drawn). For speed purposes, I'm trying to
call the Win32 API function: TransparentBlt.

But the call is failing (and the image is not drawn), with an error
code of 126: "The specified module could not be found"
(ERROR_MOD_NOT_FOUND).

(The bitmap is loaded from a separate file called "bmp.bmp", any
bitmap renamed to that will do. I'm using Win XP Pro SP2 and
VStudio.NET 2003.)

Thanks a lot for your help!
<<
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyForm : Form
{
Bitmap m_bmp;

public static void Main() { Application.Run(new MyForm()); }
public MyForm()
{
m_bmp = (Bitmap)Bitmap.FromFile("bmp.bmp");
}

[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr
hObject);
[DllImport("gdi32.dll")]
public static extern int DeleteObject(IntPtr hObject);
[DllImport("msimg32.dll")]
public static extern int TransparentBlt(IntPtr hdcDest, int
nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc,
int nYSrc, uint clr);

protected override void OnPaint(PaintEventArgs pea)
{
Graphics gfx = pea.Graphics;

IntPtr hBmp = m_bmp.GetHbitmap();
IntPtr hdcPanel = GetDC(this.Handle);
IntPtr hdcBmp = CreateCompatibleDC((IntPtr)null);
IntPtr hdcOld = SelectObject(hdcBmp, hBmp);

TransparentBlt(hdcPanel, 0, 0, 200, 200, hdcBmp, 0, 0, 0);

SelectObject(hdcBmp, hdcOld);
DeleteObject(hBmp);
DeleteDC(hdcBmp);
ReleaseDC(this.Handle, hdcPanel);
}
}


--Nick
Nov 16 '05 #1
2 3501
why would u want to use win32 api?

"Nick Jacobson" <ni***********@yahoo.com> wrote in message
news:f8*************************@posting.google.co m...
The following code is used to draw a bitmap on a form with a color key
(i.e. a color that's not drawn). For speed purposes, I'm trying to
call the Win32 API function: TransparentBlt.

But the call is failing (and the image is not drawn), with an error
code of 126: "The specified module could not be found"
(ERROR_MOD_NOT_FOUND).

(The bitmap is loaded from a separate file called "bmp.bmp", any
bitmap renamed to that will do. I'm using Win XP Pro SP2 and
VStudio.NET 2003.)

Thanks a lot for your help!
<<
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyForm : Form
{
Bitmap m_bmp;

public static void Main() { Application.Run(new MyForm()); }
public MyForm()
{
m_bmp = (Bitmap)Bitmap.FromFile("bmp.bmp");
}

[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr
hObject);
[DllImport("gdi32.dll")]
public static extern int DeleteObject(IntPtr hObject);
[DllImport("msimg32.dll")]
public static extern int TransparentBlt(IntPtr hdcDest, int
nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc,
int nYSrc, uint clr);

protected override void OnPaint(PaintEventArgs pea)
{
Graphics gfx = pea.Graphics;

IntPtr hBmp = m_bmp.GetHbitmap();
IntPtr hdcPanel = GetDC(this.Handle);
IntPtr hdcBmp = CreateCompatibleDC((IntPtr)null);
IntPtr hdcOld = SelectObject(hdcBmp, hBmp);

TransparentBlt(hdcPanel, 0, 0, 200, 200, hdcBmp, 0, 0, 0);

SelectObject(hdcBmp, hdcOld);
DeleteObject(hBmp);
DeleteDC(hdcBmp);
ReleaseDC(this.Handle, hdcPanel);
}
}


--Nick

Nov 16 '05 #2
Calling the .NET function is too slow. The Win32 API is way faster.
" Bern" <x@x.com> wrote in message news:<41********@news.starhub.net.sg>...
why would u want to use win32 api?

"Nick Jacobson" <ni***********@yahoo.com> wrote in message
news:f8*************************@posting.google.co m...
The following code is used to draw a bitmap on a form with a color key
(i.e. a color that's not drawn). For speed purposes, I'm trying to
call the Win32 API function: TransparentBlt.

But the call is failing (and the image is not drawn), with an error
code of 126: "The specified module could not be found"
(ERROR_MOD_NOT_FOUND).

(The bitmap is loaded from a separate file called "bmp.bmp", any
bitmap renamed to that will do. I'm using Win XP Pro SP2 and
VStudio.NET 2003.)

Thanks a lot for your help!
<<
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyForm : Form
{
Bitmap m_bmp;

public static void Main() { Application.Run(new MyForm()); }
public MyForm()
{
m_bmp = (Bitmap)Bitmap.FromFile("bmp.bmp");
}

[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern int DeleteDC(IntPtr hObject);
[DllImport("gdi32.dll")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr
hObject);
[DllImport("gdi32.dll")]
public static extern int DeleteObject(IntPtr hObject);
[DllImport("msimg32.dll")]
public static extern int TransparentBlt(IntPtr hdcDest, int
nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc,
int nYSrc, uint clr);

protected override void OnPaint(PaintEventArgs pea)
{
Graphics gfx = pea.Graphics;

IntPtr hBmp = m_bmp.GetHbitmap();
IntPtr hdcPanel = GetDC(this.Handle);
IntPtr hdcBmp = CreateCompatibleDC((IntPtr)null);
IntPtr hdcOld = SelectObject(hdcBmp, hBmp);

TransparentBlt(hdcPanel, 0, 0, 200, 200, hdcBmp, 0, 0, 0);

SelectObject(hdcBmp, hdcOld);
DeleteObject(hBmp);
DeleteDC(hdcBmp);
ReleaseDC(this.Handle, hdcPanel);
}
}
>


--Nick

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mike Brown | last post by:
Please look at this section of my code. I am tryong to call the checkMonth function if the year selected is the current year. I tested the value being passed to the checkYear function and that is...
6
by: James Walker | last post by:
Can some one help I get an error of 'checkIndate' is null or not an object can someone please help. I can't work out why Thanks in advance James <form> <td height="24" colspan="7"...
5
by: PaulThomas | last post by:
Working with XP-Pro and VS.Net I have set my Start Page to "Home.aspx" but the application always starts the "Login" page - - - How can I change the start page to the Home.aspx??? On the login...
87
by: expertware | last post by:
Dear friends, My name is Pamela, I know little about CSS, but I would like to ask a question I have an image on a web page within a css layer: <DIV ID=MyLayer STYLE = "position:...
0
by: Nick Jacobson | last post by:
Please help! The following code is used to draw a bitmap on a form with a color key (i.e. a color that's not drawn). For speed purposes, I'm trying to call the Win32 API function:...
3
by: Minh | last post by:
I create a C# Project using Windows Application template, I add an imagelist to Form, and add icon to imagelist1. After that, I run Project, but an Exception has occured. I can fix it even...
2
by: juvi | last post by:
Dim myGraphics As System.Drawing.Graphics Dim buffer As Bitmap Dim fr_bm As Bitmap Dim to_bm As Bitmap Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)...
3
by: doc | last post by:
What will a flash xml client socket connect to? I have a working php TCP/IP server socket bound to a port >1023 and the flash client will not even connect to it. I can connect to it with non-xml...
29
by: FreshRob | last post by:
I have been trying to fix this issue the whole of today and have gotten no where. I am developing a new website, and wanted it to display a webpage in lightbox and have an external page added to the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.