|
The source is included with MFC.....
Steve
|
|
|
|
|
The majority of MFC class methods have equivalents in Win32; check the documentation on MSDN for any extra parameters needed. The CDC and CBitmap objects would be replaced by HDC and HBITMAP handles. It is simply a matter of reading the documentation and modifying the code according to the correct rules.
I must get a clever new signature for 2011.
|
|
|
|
|
|
goldenrose9 wrote: but this code doesn't work at all.
May I suggest you try using your debugger to find out why.
I must get a clever new signature for 2011.
|
|
|
|
|
In your Height and Width functions, the first argument to GetObject should be a HBITMAP, not a BITMAP*.
Judging from your original post, the HBITMAP to use would be pOldBitmapImage. In the second post, you assign NULL to this, which is inconsistent with what you do in your original post; you'd want to get the HBITMAP from dcImage and put that in pOldBitmapImage.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
|
|
google for it, you will find lots.
|
|
|
|
|
|
goldenrose9 wrote: nice joke.... Google. anyways thanx 4 d reply The only joke is that you consistently ask for answers you can find yourself, using google. If you expect people to take your questions seriously, then invest a little time to try to find the answer yourself, instead of expecting other people to do your work for you.
BTW, use of SMS speak is not acceptable on these forums.
|
|
|
|
|
|
Here's how it went:
- Hans suggested you could use the TransparentBlt function, and included a link to the MSDN documentation page to help you get started.
- You responded by asking for a sample, rather than trying to work it out for yourself.
- Hans suggested (quite rightly) that there were lots to be found if you use Google.
- You responded by saying you thought his answer was a joke, and thus not worth consideration.
- Hans explained that people are not going to help you unless you are prepared to at least try and do some of your own work.
- You responded by a childish show of petulance, just because people will not do what you are quite capable of doing for yourself.
I must get a clever new signature for 2011.
|
|
|
|
|
|
Hi,
I'm currently making a simple game. Pressing the down arrow places a box on the form. Pressing up shoots missiles(blue boxes) and creates multiple instances of m1 which is part of the missle class.
What I want to do is change the color of each missle as it collides with the red box. So far only the last missile changes color. The other instances of the missle class get ignored.
#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class object
{
public:
PictureBox^ Box3;
object( Form ^ form )
{
Box3 = gcnew PictureBox();
Box3->Left = 150;
Box3->Top = 50;
Box3->Width = 100;
Box3->Height = 100;
Box3->BackColor = System::Drawing::Color::Red;
form->Controls->Add(Box3);
}
};
public ref class missile
{
public:
PictureBox^ Box1;
Timer^ Timer1;
missile( Form ^ form )
{
Timer1 = gcnew Timer;
Timer1->Interval = 1;
Timer1->Start();
Box1 = gcnew PictureBox();
Box1->Left = 150;
Box1->Top = 240;
Box1->Width = 10;
Box1->Height = 10;
Box1->BackColor = System::Drawing::Color::Blue;
form->Controls->Add(Box1);
Timer1->Tick += gcnew System::EventHandler(this, &missile::timer1_Tick);
}
System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
Box1->Top -= 1;
}
};
public ref class Form1 : public Form
{
public:
PictureBox^ Box2;
missile^ m1;
object^ o1;
Timer^ Timer3;
bool x;
Form1()
{
x=false;
Timer3 = gcnew Timer();
Timer3->Interval = 1;
Timer3->Start();
Box2 = gcnew PictureBox();
Box2->BackColor = Color::Blue;
Box2->Top = 240;
Box2->Left = (this->Width / 2) - 40;
Box2->Width = 40;
Box2->Height = 10;
this->Controls->Add(Box2);
this->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::Form_KeyDown);
Timer3->Tick += gcnew System::EventHandler(this, &Form1::timer3_Tick);
}
System::Void Form_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
if(e->KeyCode == Keys::Up){x=true;m1 = gcnew missile(this);m1->Box1->Left = Box2->Left + (Box2->Width / 2) - 10;}
if(e->KeyCode == Keys::Left){Box2->Left -= 4;}
if(e->KeyCode == Keys::Right){Box2->Left += 4;}
if(e->KeyCode == Keys::Down) {o1 = gcnew object(this); }
}
System::Void timer3_Tick(System::Object^ sender, System::EventArgs^ e)
{
if(x==true)
{
if(m1->Box1->Top == o1->Box3->Bottom){m1->Box1->BackColor = Color::Green;}
}
}
bool isColliding(PictureBox^ box1, PictureBox^ box3)
{
Rectangle r1 = m1->Box1->Bounds;
Rectangle r2 = o1->Box3->Bounds;
return r1.IntersectsWith(r2);
}
};
[STAThread]
int main()
{
Application::Run(gcnew Form1());
}
I also am trying to figure out how to remove the instances from memory after a set amount of time as too many instances slows the program.
Thanks for the help.
modified on Saturday, March 19, 2011 9:48 PM
|
|
|
|
|
Hi,
welcome to CodeProject. I have several comments on your code:
1.
you did something wrong when posting the code as all > signs became double-HTML-encoded (see the >), making things pretty hard to read.
2.
I don't understand at all why this would be a C/C++ question, it looks like C++/CLI to me; that is .NET's version of C++, and it has its own forum on CodeProject. The current one is for native, unmanaged C or C++ code.
3.
a timer interval of 1 msec is not what you are going to get, you may want to read my article here: Timer surprises, and how to avoid them[^].
4.
You are using a PictureBox for each missile; I wouldn't do that. All the PB does for you is remember its Location and show an image somewhere on your form. You could as well paint the image yourself, by overriding the Form's OnPaint method (or, what I prefer: by adding a Panel and overriding its OnPaint). So in more detail I would:
- define a little Missile class with a Point and a Color member, and a PaintMe(Graphics g, Point at) method.
- instantiate Missiles and hold them in a generic List.
- in the Form/Panel's OnPaint enumerate those Missiles and have each of them paint itself.
Doing so would allow you to run hundreds of missiles without things getting slow.
5.
Collision detection could benefit from the same list of Missiles (that is assuming multiple missiles are moving at the same time, either controlled by your key stuff, or maybe just by a timer). You could again enumerate the Missile instances, and for each of them check for a collision and act accordingly (change color, explode, break in two, whatever).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Sorry about that. I fixed the post.
How would I get my code working using my current aproach. I will try to redo the code after I know whats wrong with it\fix it.
By enumerate do you mean to specify each missile individualy like
missile^ m1;
missile^ m2;
missile^ m3;
m1 = gcnew missile(this);
m2 = gcnew missile(this);
m3 = gcnew missile(this);
etc
|
|
|
|
|
Not really. This is how it would look in C#; C++/CLI allows similar stuff, I'm less fluent in it:
List<Missile> missiles=new List<Missile>();
for(int i=0; i<10; i++) {
Missile m=new Missile();
m.Location=new Point(100+33*i, 200*10*i);
m.SetColor(Color.Yellow);
missiles.Add(m);
}
foreach(Missile m in missiles) {
if (m.IsHit()) m.SetColor(Color.Green);
}
which illustrates you don't need individual variables for collectible items at all.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Thanks Luc.
|
|
|
|
|
a small brief of my program is as follows.
my program is in win32,
i had used BMP image on the Dialog,
the BMP image cover the entire dialog.
BMP image is in blue color.
And added a button on the dialog.
without using manifest the button is ok, but after enabling xp visual style a strange border is created around the button. As the Dialog has BMP image loaded, it creates a strange look, if some how the extra border of the button can be removed, then it will be ok. I am unable to remove the extra border.
i don't want to remove the button border, i want to remove only the extra border that is created around the button after enabling xp visual styles.
please help.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
The most direct way to accomplish what you want is to write an ownerdraw button control. There are articles about doing this here on CodeProject. All you have to do is select one that doesn't apply XP theming.
BTW, have you tried your app on Vista or Windows 7? They might display the button in a different way.
|
|
|
|
|
thanx, how to make a portion of BMP image transparent in WIN32 way.
Some Day I Will Prove MySelf :: GOLD
|
|
|
|
|
i use NtQuerySystemInformation
but i get a error
if(!NtQuerySystemInformation(16,&hInfo,sizeof(hInfo),NULL))
{
printf("Load NtQuery Unsucessfull");
Sleep(-1);
return 1;
}
CString szTam;
szTam.Format(L"%d",hInfo.HandleCount);
MessageBox(0,szTam,0,0);
for(int i=0;i < hInfo.HandleCount;i++)
{
SYSTEM_HANDLE hSystem=hInfo.Handles[i];
HANDLE hdupHandle=NULL;
......
}
can you help me?
or i must ReadProcessMemory?
|
|
|
|
|
so0_lanhlung2 wrote: if(!NtQuerySystemInformation(16,&hInfo,sizeof(hInfo),NULL))
What does the '16 ' stand for? On my winternl.h file the SYSTEM_INFORMATION_CLASS enumeration does not contain such a value.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
Would help if you'd tell us -so we don't have to try and look it up- which SystemInformationClass '16' is and what is hInfo.
I checked NtQuerySystemInformation[^] in MSDN, and i guess you might be using SYSTEM_PROCESS_INFORMATION. In the documentation it says:
The HandleCount member contains the total number of handles being used by the process in question; use GetProcessHandleCount to retrieve this information instead. Maybe you should use GetProcessHandleCount[^] instead? However, MSDN does not seem to list a Handles member there so i might be off track, altrough this GetProcessHandleCount thing might be applicable to your case too.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
modified on Saturday, March 19, 2011 6:07 AM
|
|
|
|
|