|
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
|
|
|
|
|
this is my function
void CShowHandlesOfProc::AddHandlesToList(CListCtrl *m_list,DWORD pid)
{
int nItem=0;
NTSTATUS status;
PSYSTEM_HANDLE_INFORMATION handleInfo;
ULONG handleInfoSize = 0x10000;
HANDLE processHandle;
ULONG i;
_NtQuerySystemInformation NtQuerySystemInformation =
(_NtQuerySystemInformation)GetLibraryProcAddress("ntdll.dll", "NtQuerySystemInformation");
_NtDuplicateObject NtDuplicateObject =
(_NtDuplicateObject)GetLibraryProcAddress("ntdll.dll", "NtDuplicateObject");
_NtQueryObject NtQueryObject =
(_NtQueryObject)GetLibraryProcAddress("ntdll.dll", "NtQueryObject");
if(!(processHandle = OpenProcess(PROCESS_DUP_HANDLE|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid))) return;
handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc(handleInfoSize);
while((status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,handleInfoSize,NULL)) == STATUS_INFO_LENGTH_MISMATCH)
handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2);
if(!NT_SUCCESS(status)) return;
for(i = 0; i < handleInfo->HandleCount; i++)
{
SYSTEM_HANDLE handle = handleInfo->Handles[i];
HANDLE dupHandle = NULL;
POBJECT_TYPE_INFORMATION objectTypeInfo;
PVOID objectNameInfo;
UNICODE_STRING objectName;
ULONG returnLength;
if(handle.ProcessId != pid) continue;
if(!NT_SUCCESS(NtDuplicateObject(processHandle,(HANDLE)handle.Handle,GetCurrentProcess(),&dupHandle,0,0,0))) continue;
objectTypeInfo = (POBJECT_TYPE_INFORMATION)malloc(0x1000);
if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectTypeInformation,objectTypeInfo,0x1000,NULL)))
{
CloseHandle(dupHandle);
continue;
}
if((handle.GrantedAccess != 0x0012019f)
&& (handle.GrantedAccess != 0x001a019f)
&& (handle.GrantedAccess != 0x00120189)
&& (handle.GrantedAccess != 0x00100000))
{
wprintf(L"%s - 0x%X - ",objectTypeInfo->Name.Buffer, handle.Handle);
CString szType,szHandle,szName;
szHandle.Format(L"0x%X",handle.Handle);
m_list->InsertItem(nItem,szHandle);
nItem++;
objectNameInfo = malloc(0x1000);
if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectNameInformation,objectNameInfo,0x1000,&returnLength)))
{
objectNameInfo = realloc(objectNameInfo, returnLength);
if(!NT_SUCCESS(NtQueryObject(dupHandle,ObjectNameInformation,objectNameInfo,returnLength,NULL)))
{
free(objectTypeInfo);
free(objectNameInfo);
CloseHandle(dupHandle);
continue;
}
}
objectName = *(PUNICODE_STRING)objectNameInfo;
if(objectName.Length) wprintf(L"%s",objectName.Buffer);
else wprintf(L"\0");
wprintf(L"\n");
}
free(objectTypeInfo);
free(objectNameInfo);
CloseHandle(dupHandle);
}
free(handleInfo);
CloseHandle(processHandle);
return;
}
this is my structs
#define SystemHandleInformation 16
#define ObjectBasicInformation 0
#define ObjectNameInformation 1
#define ObjectTypeInformation 2
typedef ULONG (NTAPI *_NtQuerySystemInformation)(
ULONG SystemInformationClass,
PVOID SystemInformation,
ULONG SystemInformationLength,
PULONG ReturnLength
);
typedef ULONG (NTAPI *_NtDuplicateObject)(
HANDLE SourceProcessHandle,
HANDLE SourceHandle,
HANDLE TargetProcessHandle,
PHANDLE TargetHandle,
ACCESS_MASK DesiredAccess,
ULONG Attributes,
ULONG Options
);
typedef ULONG (NTAPI *_NtQueryObject)(
HANDLE ObjectHandle,
ULONG ObjectInformationClass,
PVOID ObjectInformation,
ULONG ObjectInformationLength,
PULONG ReturnLength
);
typedef struct _UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING, *PUNICODE_STRING;
typedef struct _SYSTEM_HANDLE
{
ULONG ProcessId;
BYTE ObjectTypeNumber;
BYTE Flags;
USHORT Handle;
PVOID Object;
ACCESS_MASK GrantedAccess;
} SYSTEM_HANDLE, *PSYSTEM_HANDLE;
typedef struct _SYSTEM_HANDLE_INFORMATION
{
ULONG HandleCount;
SYSTEM_HANDLE Handles[1];
} SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION;
typedef enum _POOL_TYPE
{
NonPagedPool,
PagedPool,
NonPagedPoolMustSucceed,
DontUseThisType,
NonPagedPoolCacheAligned,
PagedPoolCacheAligned,
NonPagedPoolCacheAlignedMustS
} POOL_TYPE, *PPOOL_TYPE;
typedef struct _OBJECT_TYPE_INFORMATION
{
UNICODE_STRING Name;
ULONG TotalNumberOfObjects;
ULONG TotalNumberOfHandles;
ULONG TotalPagedPoolUsage;
ULONG TotalNonPagedPoolUsage;
ULONG TotalNamePoolUsage;
ULONG TotalHandleTableUsage;
ULONG HighWaterNumberOfObjects;
ULONG HighWaterNumberOfHandles;
ULONG HighWaterPagedPoolUsage;
ULONG HighWaterNonPagedPoolUsage;
ULONG HighWaterNamePoolUsage;
ULONG HighWaterHandleTableUsage;
ULONG InvalidAttributes;
GENERIC_MAPPING GenericMapping;
ULONG ValidAccess;
BOOLEAN SecurityRequired;
BOOLEAN MaintainHandleCount;
USHORT MaintainTypeList;
POOL_TYPE PoolType;
ULONG PagedPoolUsage;
ULONG NonPagedPoolUsage;
} OBJECT_TYPE_INFORMATION, *POBJECT_TYPE_INFORMATION;
this funciton run in Console project
but when i creat dialog MFC..and i try add handle to ListCtrl have Error
Access violation reading location 0xbaadf00d.
i don't know...
help me plz
|
|
|
|
|
so0_lanhlung2 wrote: Access violation reading location 0xbaadf00d. i
I think this value suggests that you are trying to use a pointer that has not been initialised. It's a pity you posted all this code above, but not the part that causes the error.
I must get a clever new signature for 2011.
|
|
|
|
|
From http://en.wikipedia.org/wiki/Hexspeak[^]:
# 0xBAADF00D ("bad food") is used by Microsoft's LocalAlloc(LMEM_FIXED) to indicate uninitialised allocated heap memory when the debug heap is used. [3[^]]
My guess would be that something goes wrong during memory allocation. Maybe you are trying to allocate too much (continous) memory. Check out Listing Used Files[^] here on CodeProject, it seems to be doing something similar than you are, there seems to be a way to query how much memory you need so you don't need to keep increasing the buffer with realloc until it is big enough. Can't say anything better at this point, am not much familiar with sysinternals.
> 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<
|
|
|
|
|
thanks for reply ...
i'll reseach
|
|
|
|
|
Just a silly attempt: could you try to comment out all the lines below the offending one, until for loop ends?
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]
|
|
|
|
|
I create a new project with AppWizard. I select single document and do not use document view architecture, and it works fine. But if I comment out the line CPaintDC dc(this);
in the OnPaint handler and run it what happens is when I minimize the window and then restore it the status bar and the toolbar don not display. Clicking on the window brings back the status bar and moving the window or opening a menu brings back the toolbar. I thought it was something in my code on another program but this is all created by AppWizard and I'm not smart enough to figure it out. Has anyone else seen this or is it my computer?
|
|
|
|
|
I think that is not you computer or your code problem. You should not comment CPaintDC dc(this); Line.If you don't want to handle wm_paint message you have to comment out on_wm_paint() message(you should not handle it);If you are going to hanel it the line CPaintDC dc(this); Must be present.try by commenting the line on_wm_paint in BEGIN_MESSAGE_MAP.For more information on wm_paint read the following article from msdn.
http://msdn.microsoft.com/en-us/library/dd145213%28v=vs.85%29.aspx[^]
|
|
|
|
|
Thanks for your reply. My point is this is a new app created by AppWizard and I haven't
added anything. The only code in OnPaint is the declaration of the CPaintDC. It never gets used. I stepped through the construction code for CPaiintDC and I don't see anything to do with the toolbar or the status bar. Its not a problem its just something I noticed and was trying to figure out what one thing had to do with another.
|
|
|
|
|
I have seen a similar issue in a pure Win32 program when not calling BeginPaint() in the handler for the WM_PAINT message. I believe it has something to do with the way messages are cascaded through the windows from the frame down. Bottom line is to leave the basic structure of the wizard generated code intact, especially since you do not know what is under the covers in MFC.
I must get a clever new signature for 2011.
|
|
|
|
|