View Full Version: Block form focus in VC++

C++ Learning Community > C++ Help > Block form focus in VC++


Title: Block form focus in VC++
Description: can you block focus of a form if clicked


raden101 - January 28, 2007 09:39 PM (GMT)
HI
i was wondering if there was a way to block focus of a form.. for instance if you have two windows(forms) open and one is active(has focus) and you click the other one, is there a way to make it not take focus or become the active window?

im working in V C++

Shonoby - January 28, 2007 10:16 PM (GMT)
I don't think that u can do that it comes made in your computers code. So i guess the only way to do that is to learn 'command prompt' or your computers code which could be messy if u don't know what ur doing. -_-

raden101 - January 28, 2007 10:53 PM (GMT)
well is there a way to make a pic or somthing display of other aplication?

so say i have a prgram running and i want to put a watermark on your screen.. is there a way to do that?

Shonoby - January 28, 2007 11:09 PM (GMT)
Srry, i don't know what u mean.

raden101 - January 28, 2007 11:16 PM (GMT)
basicly i want to put a watermark on my desktop....

Rmstn1580 - January 28, 2007 11:28 PM (GMT)
What's a watermark, ho.

Ravotus - January 28, 2007 11:33 PM (GMT)
You need to use the Windows API for that. If you don't know what it is, you're probably shouldn't be using it yet. :)

If you've used it before, read more about the EnableWindow function on the MSDN.

And disgregard Shonoby's first post, it has no factual information whatsoever.

adeyblue - January 28, 2007 11:53 PM (GMT)
Putting this in the window's WndProc works for me. It still allows you to activate the window by the keyboard (ALT+TAB), while blocking it with the mouse.

CODE

case WM_MOUSEACTIVATE:
{
   SetActiveWindow(GetActiveWindow());
   return MA_NOACTIVATEANDEAT;
}
break;

raden101 - January 29, 2007 07:08 PM (GMT)
thank you.

yeah i was pretty sure Shonoby did know what he was talking about..

ill try the EnableWindow too but how do you use the code adeyblue added in a WndProc?

adeyblue - January 31, 2007 04:18 PM (GMT)
In a skeleton window procedure, something like this

CODE

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch(msg)
   {
       case WM_MOUSEACTIVATE:
       {
           SetActiveWindow(GetActiveWindow());
           return MA_NOACTIVATEANDEAT;
       }
       break;
       case WM_COMMAND:
       {
       // Whatever code here
       }
       break;
       case WM_CREATE:
       {
       // Whatever code here
       }
       break;
       // Handle other cases, then
       default:
           return DefWindowProc(hwnd, msg, wParam, lParam);
   }
   return 0;
}




Hosted for free by InvisionFree