Click here to Skip to main content
15,896,063 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: [Win32]Add context menu to edit control Pin
వేంకటనారాయణ(venkatmakam)20-Jun-11 2:23
వేంకటనారాయణ(venkatmakam)20-Jun-11 2:23 
GeneralRe: [Win32]Add context menu to edit control Pin
Member 296547120-Jun-11 3:07
Member 296547120-Jun-11 3:07 
GeneralRe: [Win32]Add context menu to edit control Pin
Mark Salsbery20-Jun-11 10:16
Mark Salsbery20-Jun-11 10:16 
AnswerRe: [Win32]Add context menu to edit control Pin
User 742933821-Jun-11 1:04
professionalUser 742933821-Jun-11 1:04 
QuestionSendMessage Pin
Sakhalean19-Jun-11 23:36
Sakhalean19-Jun-11 23:36 
AnswerRe: SendMessage Pin
xrg_soft@163.com19-Jun-11 23:49
xrg_soft@163.com19-Jun-11 23:49 
GeneralRe: SendMessage Pin
Sakhalean20-Jun-11 0:00
Sakhalean20-Jun-11 0:00 
AnswerRe: SendMessage Pin
Albert Holguin20-Jun-11 4:42
professionalAlbert Holguin20-Jun-11 4:42 
Questiondoubi in vc++ Pin
Remya.pv19-Jun-11 18:24
Remya.pv19-Jun-11 18:24 
AnswerRe: doubi in vc++ Pin
Richard MacCutchan19-Jun-11 21:49
mveRichard MacCutchan19-Jun-11 21:49 
AnswerRe: doubi in vc++ Pin
Chandrasekharan P19-Jun-11 21:55
Chandrasekharan P19-Jun-11 21:55 
AnswerRe: doubi in vc++ Pin
Mark Salsbery20-Jun-11 11:05
Mark Salsbery20-Jun-11 11:05 
Questionabout "windows belonging to different processes are mixed in a single window hierarchy" Pin
xrg_soft@163.com19-Jun-11 17:40
xrg_soft@163.com19-Jun-11 17:40 
AnswerRe: about "windows belonging to different processes are mixed in a single window hierarchy" Pin
Mark Salsbery19-Jun-11 18:11
Mark Salsbery19-Jun-11 18:11 
GeneralRe: about "windows belonging to different processes are mixed in a single window hierarchy" Pin
xrg_soft@163.com20-Jun-11 19:06
xrg_soft@163.com20-Jun-11 19:06 
Questionregister window message Pin
so0_lanhlung219-Jun-11 16:56
so0_lanhlung219-Jun-11 16:56 
AnswerRe: register window message Pin
xrg_soft@163.com19-Jun-11 17:44
xrg_soft@163.com19-Jun-11 17:44 
GeneralRe: register window message Pin
softwaremonkey19-Jun-11 19:41
softwaremonkey19-Jun-11 19:41 
QuestionMoving Objects in small increments Pin
Cyclone_S19-Jun-11 14:07
Cyclone_S19-Jun-11 14:07 
QuestionRe: Moving Objects in small increments Pin
enhzflep19-Jun-11 15:03
enhzflep19-Jun-11 15:03 
AnswerRe: Moving Objects in small increments Pin
Cyclone_S19-Jun-11 16:03
Cyclone_S19-Jun-11 16:03 
GeneralRe: Moving Objects in small increments Pin
enhzflep19-Jun-11 16:23
enhzflep19-Jun-11 16:23 
GeneralRe: Moving Objects in small increments Pin
Cyclone_S19-Jun-11 16:49
Cyclone_S19-Jun-11 16:49 
GeneralRe: Moving Objects in small increments Pin
enhzflep19-Jun-11 18:24
enhzflep19-Jun-11 18:24 
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. Smile | :)

#include <windows.h>

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "CodeBlocksWindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Click to release a ball",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
float ballPosX, ballPosY, ballVelocityX, ballVelocityY;
const int myTimerId = 1;
const int intervalMs = 50;

VOID CALLBACK myTimerProc(HWND hwnd,        // handle to window for timer messages
    UINT message,     // WM_TIMER message
    UINT idTimer,     // timer identifier
    DWORD dwTime)     // current system time
{
	ballPosX += ballVelocityX;
	ballPosY += ballVelocityY;
	ballVelocityY -= 0.1;
	InvalidateRect(hwnd, NULL, true);
}

/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

    switch (message)                  /* handle the messages */
    {
        case WM_DESTROY:
            KillTimer(hwnd, myTimerId);
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            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:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}

GeneralRe: Moving Objects in small increments Pin
enhzflep19-Jun-11 21:35
enhzflep19-Jun-11 21:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.