Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:19:28+00:00 2026-05-29T20:19:28+00:00

Problem is like this: I have two winapi application’s. There is only one way

  • 0

Problem is like this:
I have two winapi application’s. There is only one way communication. App1 sends message to App2. App2 should receive WM_COPYDATA with structure which has coordinates of two shapes and then it should paint those shapes.
Message is received. Data from structure is ok. Code in WM_COPYDATA case is executed which should paint window but nothing happens ( window has just solid white background)

Sending message looks like this:

HWND secondApp = FindWindowEx(NULL, NULL, _T("lab2app2"), NULL ); 
int error = GetLastError();
if(secondApp != 0) // window found, send message
{
    // prepare data
    FiguresData figuresData;
    // Set Data About Location and dimensions of figures
    // TODO
    figuresData.square_origin_x = square_origin_x;
    figuresData.square_origin_y = square_origin_y;
    figuresData.circle_origin_x = circle_origin_x;
    figuresData.circle_origin_y = circle_origin_y;

    COPYDATASTRUCT data;

    data.dwData = FIGURESDATA;
    data.cbData = sizeof( figuresData );
    data.lpData = &figuresData;
    bool value =  SendMessage(secondApp, WM_COPYDATA, (WPARAM)(HWND)mainWindow, (LPARAM)(LPVOID)&data);
}

FiguresData structure is straightforward and has only 4 ints in it.

The App2 receives messages and code for that is:

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;

switch (message)
{
case WM_PAINT:

    RECT clientRectangle;
GetClientRect(hWnd, &clientRectangle);

hdc = BeginPaint(hWnd, &ps);

    // nothing really here

    EndPaint(hWnd, &ps);
    break;

case WM_COPYDATA:
    {
    PCOPYDATASTRUCT pData;
    pData = (PCOPYDATASTRUCT) lParam;

    int square_origin_x = ((FiguresData *) ( pData->lpData ))->square_origin_x;
    int square_origin_y = ((FiguresData *) ( pData->lpData ))->square_origin_y;
    int circle_origin_x = ((FiguresData *) ( pData->lpData ))->circle_origin_x;
    int circle_origin_y = ((FiguresData *) ( pData->lpData ))->circle_origin_y;
    hdc = BeginPaint(hWnd, &ps);
    HPEN oldPen = (HPEN)SelectObject(hdc, pen);
    HBRUSH oldBrush = (HBRUSH)SelectObject(hdc, backgroundBrush);
    COLORREF oldBackgroundColor = SetBkColor(hdc, backgroundColor);

    Rectangle(hdc, square_origin_x, square_origin_y, square_origin_x+ SQUARE_SIDE, square_origin_y + SQUARE_SIDE);
    Ellipse(hdc, circle_origin_x, circle_origin_y, circle_origin_x+ SQUARE_SIDE, circle_origin_y + SQUARE_SIDE);


    // Put everything back the way we found it
    SelectObject(hdc, oldPen);
    SetBkColor(hdc, oldBackgroundColor);

    EndPaint(hWnd, &ps);
    break;
    }
case WM_DESTROY:
    PostQuitMessage(0);
    break;
default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    break;
}

return 0;
}

On debugger I see that window handle is ok. Message is sent as well as received by App2 and code in the WM_COPYDATA case is executed but it has no effect.
No shapes are drawn on the App2’s window and I have no idea why. Any clue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:19:30+00:00Added an answer on May 29, 2026 at 8:19 pm

    You are calling BeginPaint outside of a WM_PAINT handler. BeginPaint returns a device context that allows drawing only on the invalid region of the window. Since you have not called InvalidateRect, the window is not yet invalid, so BeginPaint does not paint anything.

    As a general rule, you should restrict your painting to your WM_PAINT handler. Have your WM_COPYDATA handler remember what needs to be painted, then invalidate the window and have the WM_PAINT handler actually paint it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem where I have some html like this <p>There is the
The problem like this, I have a groupBox which contains two radio buttons, when
I have a mysql problem. I have two tables like this that I need
This is a simplified version of my problem. I have two buttons, and one
I have two tables one Employee and mailing Subscriptions Employee looks like this: Name
Here's my problem - I have some code like this: <mx:Canvas width=300 height=300> <mx:Button
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have a problem with IE. I have a fixed div like this: #fixed
i am having a strange problem, i have a static class like this public
I'm having a problem. I have a UIView, that looks like this : In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.