Using MoveWindow for a control in a dialog

Posted on 2003-02-21
Medium Priority
Last Modified: 2010-10-05
I've tried to show a rectangle over the selected control in a dialog. But, when I try to move the rectangle using the movewindow() function, the rectangle just disappears. My guess is that I'm not getting the coordinates of the selected control with respect to the dialog containing that control. How can I do it? The rectangle is simply a static control, and I want to show it round the selected text control.
Question by:motorway
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

scerveza earned 400 total points
ID: 7997959
[QUOTE]The rectangle is simply a static control, and I want to show it round the selected text control.[/QUOTE]

A static control is a type of text control and showing
it around a selected text control will hide that text
control. Are you sure you want to do that?

Anyways, here's how you move controls around in a dialog
box (using standard windows programming).

LRESULT CALLCACK WndProc(HWND handle, UINT msg, WPARAM wparam, LPARAM lparam)

  // get rect of dialog's client area
  RECT clientRect;
  GetClientRect(handle, &clientRect);

  // get static control (will vary)
  // and get it's rect
  HWND static_control = GetDlgItem(handle, IDRES_STATIC);
  RECT staticRect;
  GetWindowRect(static_control, &staticRect);
  int dx = staticRect.right - staticRect.left;
  int dy = staticRect.bottom - staticRect.top;

  // move static control around
  MoveWindow(static_control, 15, 15, dx, dy, TRUE);

  return TRUE;

 // ...

Expert Comment

ID: 7997969
sorry that window procedure should be declared

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question