Click here to Skip to main content
16,006,065 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to move child window of CMyView to the middle of the client area... Pin
Raphael Kindt10-Sep-02 2:43
Raphael Kindt10-Sep-02 2:43 
AnswerRe: How to move child window of CMyView to the middle of the client area... Pin
Steen Krogsgaard10-Sep-02 3:02
Steen Krogsgaard10-Sep-02 3:02 
GeneralProblem with ListBox and ProgressBar Pin
chen9-Sep-02 16:25
chen9-Sep-02 16:25 
GeneralRe: Problem with ListBox and ProgressBar Pin
valikac9-Sep-02 16:56
valikac9-Sep-02 16:56 
GeneralRe: Problem with ListBox and ProgressBar Pin
Steen Krogsgaard10-Sep-02 3:42
Steen Krogsgaard10-Sep-02 3:42 
Questionis there ane api ? Pin
imran_rafique9-Sep-02 16:25
imran_rafique9-Sep-02 16:25 
AnswerRe: is there ane api ? Pin
valikac9-Sep-02 16:57
valikac9-Sep-02 16:57 
AnswerRe: is there ane api ? Pin
TyMatthews10-Sep-02 5:16
TyMatthews10-Sep-02 5:16 
I think this might work for you, although it doesn't feel very elegant. Try looking at the Win32 API EnumWindows(). You define a callback function and pass that into EnumWindows(). For every top-level window open on the desktop, you'll get one call into your function, which hands you the HWND of that window and a user-defined field.

With the HWND, you can then call GetWindowThreadProcessId() to try and match to your already-known Process ID. So you'd set it up so that your callback function will keep churning (by setting the return value to TRUE) until it finds the right Process ID. Use the lParam field in EnumWindows to pass along an information struct that holds your ProcessID and the output HWND.

There's probably a cleaner way to do this, but this should get you on the right track. Here's some pseudo-code:

typedef struct
{
  DWORD dwProcessID;
  HWND hWnd;
} ENUM_PARAM, *LPENUM_PARAM;

BOOL CALLBACK cbEnumWindows( HWND hwnd, LPARAM lParam )
{
  LPENUM_PARAM lpEnum = static_cast< LPENUM_PARAM >( lParam );
  if( lpEnum )
  {
    DWORD dwProcessID = 0;
    GetWindowThreadProcessId( hwnd, &dwProcessID );
    if( dwProcessID == lpEnum->dwProcessID )
    {
       lpEnum->hWnd = hwnd;
       return FALSE;
    }
  }

  return TRUE;
}

int main( int argc, char *argv[] )
{
   ENUM_PARAM EnumParam;

   EnumParam.dwProcessID = 1234;  // How you get your ProcessID
   EnumParam.hWnd = NULL;

   EnumWindows( cbEnumWindows, static_cast< LPARAM >( &EnumParam ) );

   if( EnumParam.hWnd )
   {
      // Hey, we've got it!
   }
}
</code>


Ty

QuestionGuess what output, and tell me why? Pin
cadinfo9-Sep-02 16:04
cadinfo9-Sep-02 16:04 
AnswerRe: Guess what output, and tell me why? Pin
Michael Dunn9-Sep-02 16:35
sitebuilderMichael Dunn9-Sep-02 16:35 
GeneralRe: Guess what output, and tell me why? Pin
cadinfo10-Sep-02 2:57
cadinfo10-Sep-02 2:57 
GeneralRe: Guess what output, and tell me why? Pin
jhwurmbach10-Sep-02 3:56
jhwurmbach10-Sep-02 3:56 
GeneralRe: Guess what output, and tell me why? Pin
cadinfo10-Sep-02 16:14
cadinfo10-Sep-02 16:14 
GeneralRe: Guess what output, and tell me why? Pin
jhwurmbach10-Sep-02 20:31
jhwurmbach10-Sep-02 20:31 
Questionhow to copy file from dir1 to dir2 in code Pin
ns9-Sep-02 12:20
ns9-Sep-02 12:20 
AnswerRe: how to copy file from dir1 to dir2 in code Pin
Anders Molin9-Sep-02 12:27
professionalAnders Molin9-Sep-02 12:27 
GeneralRe: how to copy file from dir1 to dir2 in code Pin
Anonymous9-Sep-02 14:07
Anonymous9-Sep-02 14:07 
GeneralLocation of entry in database -help!ADO Pin
ns9-Sep-02 12:05
ns9-Sep-02 12:05 
GeneralRe: Location of entry in database -help!ADO Pin
Pavel Klocek10-Sep-02 3:20
Pavel Klocek10-Sep-02 3:20 
GeneralQuestion About Classes Pin
Nick Parker9-Sep-02 12:02
protectorNick Parker9-Sep-02 12:02 
GeneralRe: Question About Classes Pin
Christian Graus9-Sep-02 12:27
protectorChristian Graus9-Sep-02 12:27 
GeneralRe: Question About Classes Pin
Nick Parker10-Sep-02 2:58
protectorNick Parker10-Sep-02 2:58 
GeneralRe: Question About Classes Pin
jparsons10-Sep-02 3:05
jparsons10-Sep-02 3:05 
GeneralRe: Question About Classes Pin
Pavel Klocek10-Sep-02 3:23
Pavel Klocek10-Sep-02 3:23 
GeneralRe: Question About Classes Pin
Nick Parker10-Sep-02 7:42
protectorNick Parker10-Sep-02 7:42 

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.