|
Hi All,
I have a doubt.
PostMessage() will post the message and returns immediately won't wait for Message to complete.
where as SendMessage() will post the message and will not return till the message is completed.
My doubt is why we have to wait in SendMessage() till the message is completed.
Can any body can clarify my doubt?
|
|
|
|
|
Sometimes we need to know the retult of the message and using the return value or wparam or lparam of the message.
Take WM_GETTEXT as an example.
Only after the destination window processed this messasge and filled the lparam with it's text,can our program do something accordingly.
In such case we must use SendMessage.
|
|
|
|
|
|
SendMessage() is a synchronous call, meaning it waits for the code and result of the operation (framework equivalent of making a blocking function call), whereas PostMessage() is asynchronous, meaning there's no waiting for result.
Where is either useful?
-SendMessage() : Your continuation of execution depends on the result of the operation and/or the CWnd's lie in the same thread (blocking calls are a non-issue).
-PostMessage() : Non-blocking is essential, such is the case for threaded programming.
|
|
|
|
|
how to mdichildframe in pane of splitter aplication in vc++
|
|
|
|
|
Your question is not clear, please add some more detail about what you are trying to achieve.
The best things in life are not things.
|
|
|
|
|
Can you please re-phrase your query? Is not clear on what you are asking. make it a little elaborate.
|
|
|
|
|
|
From MSDN page for WM_ACTIVATETOPLEVEL
http://msdn.microsoft.com/en-us/library/xkd95027(VS.80).aspx
I got the below description:
This message is similar in use to WM_ACTIVATEAPP, but works in situations where windows belonging to different processes are mixed in a single window hierarchy (common in OLE applications).
Does anybody know where is a example/demo/document available that illustrate "windows belonging to different processes are mixed in a single window hierarchy"?
I googled but found almost nothing.
Thanks!
|
|
|
|
|
Since they mention OLE, you could start there perhaps...
Compound Documents[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks!
I think I got the basic idea.
Just like embeded MS Word into your_app, the embeded MSWord view window is a chid window of your_app.exe but it's essentially relaies on a external process WinWord.exe
|
|
|
|
|
i registed my message on DlgMain WM_PK_MESSAGE by RegisterWindowMessage
and i have a DLL..have InjectDLL Function callback to a wndproc
i want my DLL get WM_PK_MESSAGE..
can you have some ideas for me
tk so much
|
|
|
|
|
Hi,
In each process you using the registered message, you should first call
WM_PK_MESSAGE = RegisterWindowMessage
and then you can use the WM_PK_MESSAGE.
|
|
|
|
|
You also need to use the ON_REGISTERED_MESSAGE macro instead of the normal ON_MESSAGE e.g.
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
ON_REGISTERED_MESSAGE(m_nRegMsg, OnRegisteredMessage)
END_MESSAGE_MAP()
|
|
|
|
|
Hi,
I got a ball hitting a paddle and I want it's X velocity to increase/decrease depending on where it hits the paddle. The code below works with whole numbers but not for numbers like "0.67" or "2.45". I'm looking for a way to animate objects moving at smaller increments for better precision. Thanks.
int speed=Ball_List[b]->speed;
int paddle_center = Player->Location.X + Player->Width / 2;
int ball_center = Ball_List[b]->gameBall->Location.X + Ball_List[b]->gameBall->Width / 2;
int paddle_location = ball_center - paddle_center;
double a=(90-paddle_location);
double angle = (Math::PI / 180) * a;
Ball_List[b]->xVel = speed*Math::Cos(angle);
Ball_List[b]->yVel = -speed*Math::Sin(angle);
Ball_List[b]->gameBall->Location = Point(Ball_List[b]->gameBall->Location.X + Ball_List[b]->xVel, Ball_List[b]->gameBall->Location.Y + Ball_List[b]->yVel);
[/code]
|
|
|
|
|
Can you tell us what doesn't work when you use non-integers. And non-integers for what?
|
|
|
|
|
I tried using doubles but for a value like 0.6 the ball doesn't move at all. The box control takes doubles but will round them down to the nearest integer. Is there a way to do this over the course of X number of frames?
I'm using non-integers for the box control's position. Right now there's only about 6 different directions the ball takes when hitting the paddle. I need finer control over the speed of the ball.
This problem happens with any sort of animation I try to do. What if I wanted smooth acceleration of a game object? This wouldn't be possible with the problem I'm encountering.
|
|
|
|
|
Ah, okay gotcha.
Well, in that case you can use floats or doubles for the position and the velocity. It's just a matter of rounding the position to an int before using it to display the ball.
Or of course, you could keep an integer position of last impact, along with an integer number of frames since it occured and a double velocity, or position increment per frame. Each time you display, just show the ball at [impact.x + frames*velocity.x, impact.y + frames*velocity.y]
But the easier is to just keep the position and velocity as doubles, converting to an int when using for display purposes. (You might also have to add code that will check if the ball is within a threshold distance, since non-integers will mean your ball wont hit the walls or paddle 'exactly' - well not at the exact moment of a frame, anyway.
|
|
|
|
|
I'm not sure I understand. Do you understand what I'm trying to do? after the ball hits the paddle it should move left/right depending on how far from the center it is. Just need finer precision on the angle(xvel) of the ball. Thanks.
I tried something like this. I took a number like 1.65 and did
1.65 - Math::Floor(1.65) to get just the decimal part of the number 0.65.Then every frame I added 0.65 to 0.65 and checked if it was >= 1. If it was I added 1.0 to the left/right property of the box. I then repeated that.
The problem with it was I wasn't encounting for the speed of the ball. If the speed of the ball is 6 it moves 6 frames every timer tick. The code I was trying only moved 1 pixel at a time.
I'm just not sure on the math to incorporate the speed into it.
|
|
|
|
|
 Sorry about that. Um, I think I understand your intention.
It sounds to me much like a game of pong or similar. Lord knows what I've done with my old code. I can't be bothered even think about the physics right now, but I've thrown together some code that will throw a red dot into a parabolic arc.
In such a path, we'll have to both be able to have small increments of movement, and be able to vary them. You just have to assign the ball's velocity and position in an appropriate way for your application.
Enjoy.
#include <windows.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Click to release a ball",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
float ballPosX, ballPosY, ballVelocityX, ballVelocityY;
const int myTimerId = 1;
const int intervalMs = 50;
VOID CALLBACK myTimerProc(HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
ballPosX += ballVelocityX;
ballPosY += ballVelocityY;
ballVelocityY -= 0.1;
InvalidateRect(hwnd, NULL, true);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_DESTROY:
KillTimer(hwnd, myTimerId);
PostQuitMessage (0);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
SetPixel(hdc, ballPosX, ballPosY, RGB(250,0,0));
SetPixel(hdc, ballPosX, ballPosY+1, RGB(250,0,0));
SetPixel(hdc, ballPosX+1, ballPosY, RGB(250,0,0));
SetPixel(hdc, ballPosX+1, ballPosY+1, RGB(250,0,0));
EndPaint(hwnd, &ps);
break;
case WM_LBUTTONUP:
ballPosX=0;
ballPosY=0;
ballVelocityX=3.2;
ballVelocityY=8.1;
KillTimer(hwnd, myTimerId);
SetTimer(hwnd, myTimerId, intervalMs, myTimerProc);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
|
|
|
|
 I got bored. Here try if this if you like - it's two balls, a red one and a white one. If you hit the red one with the white one it will move in a direction away from the white one before being slowed to a halt by friction. Of course your collision handling stuff will be different(hopefully pixel-accurate, unlike mine) for the paddle and the ball, but it's the same concepts at work.
#include <math.h>
#include <windows.h>
#include <windowsx.h>
#include <wingdi.h>
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
void handleCollisions();
char szClassName[ ] = "CodeBlocksWindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor =LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
if (!RegisterClassEx (&wincl))
return 0;
hwnd = CreateWindowEx (
0,
szClassName,
"Click to release a ball",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
544,
375,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);
ShowWindow (hwnd, nCmdShow);
while (GetMessage (&messages, NULL, 0, 0))
{
TranslateMessage(&messages);
DispatchMessage(&messages);
}
return messages.wParam;
}
float ballPosX, ballPosY, ballVelocityX, ballVelocityY;
float curMouseX, lastMouseX, curMouseY, lastMouseY;
int clientWidth, clientHeight;
const int myTimerId = 1;
const int intervalMs = 50;
const int ballRadius = 10;
const int cursorRadius = 15;
void handleCollisions()
{
float dx, dy, dist;
dx = ballPosX - curMouseX;
dy = ballPosY - curMouseY;
dist = sqrt( dx*dx + dy*dy);
if (dist<ballRadius+cursorRadius)
{
ballVelocityX = 0.5 * dx;
ballVelocityY = 0.5 * dy;
}
if (ballPosX < ballRadius)
ballVelocityX = abs(ballVelocityX);
if (ballPosY < ballRadius)
ballVelocityY = abs(ballVelocityY);
if (ballPosX > clientWidth-ballRadius)
ballVelocityX = -1 * abs(ballVelocityX);
if (ballPosY > clientHeight-ballRadius)
ballVelocityY = -1 * abs(ballVelocityY);
}
VOID CALLBACK myTimerProc(HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
ballPosX += ballVelocityX;
ballPosY += ballVelocityY;
ballVelocityX *= 0.9;
ballVelocityY *= 0.9;
handleCollisions();
InvalidateRect(hwnd, NULL, true);
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
RECT clientRect;
HBRUSH newBr, oldBr;
switch (message)
{
case WM_CREATE:
ballPosX = 100;
ballPosY = 100;
SetTimer(hwnd, myTimerId, intervalMs, myTimerProc);
GetClientRect(hwnd, &clientRect);
clientWidth = clientRect.right;
clientHeight = clientRect.bottom;
return true;
case WM_DESTROY:
KillTimer(hwnd, myTimerId);
PostQuitMessage (0);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
newBr = CreateSolidBrush(RGB(250,0,0));
oldBr = (HBRUSH)SelectObject(hdc, newBr);
Ellipse(hdc, ballPosX-ballRadius,ballPosY-ballRadius,ballPosX+ballRadius,ballPosY+ballRadius);
SelectObject(hdc, oldBr);
DeleteObject(newBr);
Ellipse(hdc, curMouseX-cursorRadius, curMouseY-cursorRadius, curMouseX+cursorRadius, curMouseY+cursorRadius);
EndPaint(hwnd, &ps);
break;
case WM_MOUSEMOVE:
lastMouseX = curMouseX;
lastMouseY = curMouseY;
curMouseX = GET_X_LPARAM(lParam);
curMouseY = GET_Y_LPARAM(lParam);
InvalidateRect(hwnd,NULL,true);
break;
case WM_LBUTTONUP:
ballPosX=11;
ballPosY=11;
ballVelocityX=6.2;
ballVelocityY=18.1;
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
}
|
|
|
|
|
Thanks for the examples. The first one has smooth transitions in motion. Exactly what I need. However I'm using .net(managed code) not winAPI. It seems .net rounds the floats down to a whole number?
Would you be able to help me with the formula for moving an object using my previous post idea?
Thanks.
|
|
|
|
|
That's okay. I had fun playing around with it.
Cyclone_S wrote: However I'm using .net(managed code) not winAPI. It seems .net rounds the floats down to a whole number?
I'd be very surprised.
You're not giving it the impression that this is your intention, by (I don't know, say) multiplying floats with ints - I've no idea what the result is - real or integer..
I don't understand, you have the formula for moving the ball. - BallPos += Velocity - You also have a way of applying gravity or friction - just alter the velocity.
Perhaps you'd be better off in the right forum?
Perhaps
http://www.codeproject.com/Forums/3785/Managed-Cplusplus-CLI.aspx[^]
or
http://www.codeproject.com/Forums/1649/Csharp.aspx[^]
All the best. 
|
|
|
|
|
Hi. I got the following situation,
void FunctionA(some params)
{
SOCKET sock = create new socket();
WSAEVENT hEvent = new event();
wsaeventselect(sock, event, some flags);
FunctionB(sock);
delete event();
}
void FunctionB(sock)
{
}
The thing is, i dont have access to FunctionA() but it calls
FunctionB() , where i am the master and can do anything. In function B i am receiving a socket which has an event associated with it but nothing else. I got no handle to an event - nothing, just a socket. Is there any way to get this event handle having only socket descriptor? If there is no such API, windows system should store these events somewhere, right? Is there any way to dig into this place and grab events from there?
Thanks
011011010110000101100011011010000110100101101110
0110010101110011
|
|
|
|
|
I don't know anything at all about WSA sockets, save for the few crumbs I just picked up reading the winsock function reference at msdn.
However, I can see nothing to indicate this to be the case - nor can I think of a reason why this would necessarily be included - i.e if it's a socket you've created, then surely it is also you thas already attached said event to it - in which case you'd already have it's handle.. At least that's the way I guess it.
With that in mind, and the preparedness to go poking about in windows' memory space, I'd suggest that there is likely to be a far simpler way - unless of course FunctionA is in the kernel.
When FunctionB ends, it has to be able to return control to FunctionA, right? With this address available, you can look at the (machine) code for FunctionA, so with a little fancy footwork you can easily get the location in memory of the variable that is used to store the newly created event, and snatch the handle from there..
You know how I'd go about it? I'd write a dummy FunctionB, and put a statement something like
printf("here is my marker");
I'd then fire-up the program in OllyDbg, and search for refferences to "here is my marker". When I'd found the place that the memory containing this string was referenced, I'd know that I'd found my FunctionB. From there I would simply place a break-point inside my function, start the program running and wait for it to hit the break-point. Single-stepping would then allow me to return to FunctionA, where I could grab the required handle from the memory it was originally stored into.
Might take 30 mins to come up with working code for a real FunctionB to grab the event handle, so long as there's no bumps along the way like protected memory. I forget how to go about reading a process's memory but I've got code some where to do it.
You sure have got me curious about your project.. 
|
|
|
|
|