On windows operating system How can we make a window an active window (focussed window) using c/c++ programming.
I tried using SetForegroundWindow() but it is not working.
AllowSetForegroundWindow() will work on Windows XP?

Any how please give me an idea regaurding this.

Recommended Answers

before you call that you must satisfy the conditions of SetForegroundWindow. This is easiest if you use SystemParametersInfo() to change the value of SPI_SETFOREGROUNDLOCKTIMEOUT to 0. Then SetForegroundWindow will work.

Jump to Post

All 4 Replies

before you call that you must satisfy the conditions of SetForegroundWindow. This is easiest if you use SystemParametersInfo() to change the value of SPI_SETFOREGROUNDLOCKTIMEOUT to 0. Then SetForegroundWindow will work.

oh yeah dont forget to set it back to what it was after the call to SetForegroundWindow() so that the OS behaves as it should.

Your pm box is full ravin.
You may have an outdated sdk which is why this might not work for you. Try downloading latest platform sdk.

SPI_GETFOREGROUNDLOCKTIMEOUT is #defined as 0x2000
SPI_SETFOREGROUNDLOCKTIMEOUT is #defined as 0x2001

So you could try this...

DWORD timeout;
SystemParametersInfo(0x2000,0,&timeout,0);
SystemParametersInfo(0x2001,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
SetForegroundWindow(hwnd);
SystemParametersInfo(0x2001,0,&timeout,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.