|
Derive a new class from the CEdit and handle the ON_WM_CONTEXTMENU() message.Check this article for referance,
<href="http: www.codeproject.com="" kb="" edit="" cmenuedit.aspx"="">How to modify a CEdit context menu[^]
http://www.mono-project.com/Main_Page
|
|
|
|
|
I'm not using MFC.
So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?
|
|
|
|
|
Member 2965471 wrote: So i've to call SetWindowSubclass function and set my own EditProc in which handle WM_CONTEXTMENU?
Yes.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
As an alternative to the mentioned subclassing, it is also possible to handle WM_RBUTTONDOWN directly in your dialogs message loop:
HWND hwndDlg = CreateDialog(...);
MSG msg;
while(GetMessage(&msg,0,0,0)){
if(msg.hwnd == GetDlgItem(hwndDlg,ID_MYEDITCONTROL) && msg.message == WM_RBUTTONDOWN)
;
else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
modified 13-Sep-18 21:01pm.
|
|
|
|
|
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;
}
}
|
|
|
|
|