Click here to Skip to main content
15,913,758 members
Home / Discussions / C#
   

C#

 
GeneralPostMessage Pin
kobybr8-Jul-04 11:38
kobybr8-Jul-04 11:38 
GeneralRe: PostMessage Pin
Serge Lobko-Lobanovsky9-Jul-04 3:44
Serge Lobko-Lobanovsky9-Jul-04 3:44 
GeneralRe: PostMessage Pin
kobybr9-Jul-04 8:56
kobybr9-Jul-04 8:56 
Questiondsoframer disables plugins?? Pin
Asad Hussain8-Jul-04 11:00
Asad Hussain8-Jul-04 11:00 
GeneralCopy from Excel and paste on DataGrid Pin
Ruchi Gupta8-Jul-04 10:54
Ruchi Gupta8-Jul-04 10:54 
GeneralRe: Copy from Excel and paste on DataGrid Pin
Nick Parker8-Jul-04 11:30
protectorNick Parker8-Jul-04 11:30 
GeneralRe: Copy from Excel and paste on DataGrid Pin
Heath Stewart8-Jul-04 12:10
protectorHeath Stewart8-Jul-04 12:10 
GeneralRepainting window. Pin
Nick Z.8-Jul-04 9:59
Nick Z.8-Jul-04 9:59 
Im trying to repaint a window from handle.

I get its handle and call and API function
RedrawWindow, but it works half of the time.

The way its set up in my program. I have a global hook to mouse, on mouse move, my program gets the window handle to the window under mouse, from that handle i get device context, from dc I get the Graphics object and then paint a red rectangle over the window. Which works but in order to erase the rectangle when mouse is moved to a different window I have to cause the repaint event I presume.
I set that up, and the red rectangle gets "erased" about 30% of the time. I noticed only when I move the mouse to the lower edge of the screen and move it around then all rectangles get deleted. This is probably confusing so here is the code that needs help.

private void MovingMonitor(object sender, MouseEventArgs e)
{
//draws rectangle over point
//get handle of mouse over window
Point mousePoint = new Point(e.X,e.Y);
//get the window
IntPtr handle = USER32.GetAncestor(USER32.WindowFromPoint(mousePoint),2);
//get dc
IntPtr currentDC = USER32.GetWindowDC(handle);

if(stillWorking)
{
}
}
else
{
stillWorking = true;

if(lastHandle.Equals(handle))
{

testDraw = Graphics.FromHdc(currentDC);
//draw box around that window
USER32.Rect dcRect= new USER32.Rect();
USER32.Rect regionRect = new USER32.Rect();
USER32.GetWindowRect(handle,ref dcRect);
USER32.GetWindowRgnBox(handle,ref regionRect);
int width,height;
switch(USER32.GetWindowRgn(handle,GDI32.CreateRectRgn(0,0,0,0)))
{
case 0:
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
case 2:
width = (dcRect.x2 - dcRect.x1)-(regionRect.x1+(dcRect.x2 - dcRect.x1)-regionRect.x2);
height = (dcRect.y2 - dcRect.y1)-(regionRect.y1+(dcRect.y2 - dcRect.y1)-regionRect.y2);
break;
case 3:
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
default:
MessageBox.Show("Unexpected window style. Screencap may fail. Please e-mail pacemkr@optonline.net with details.",
"Warning!",MessageBoxButtons.OK,MessageBoxIcon.Warning);
width = dcRect.x2 - dcRect.x1;
height = dcRect.y2 - dcRect.y1;
break;
}

testDraw.DrawRectangle(new Pen(Color.Red,4),regionRect.x1,regionRect.y1,width,height);

}
else if(!(lastHandle.Equals(handle)))
{
//IntPtr lastDC = USER32.GetWindowDC(lastHandle);
//testDraw = Graphics.FromHdc(lastDC);
if(last!=0)
{
USER32.Rect dcRect= new USER32.Rect();
USER32.GetWindowRect(lastHandle,ref dcRect);
USER32.InvalidateRect(lastHandle, ref dcRect,false);
USER32.UpdateWindow(lastHandle);
message.UpdateMessage(i.ToString());
i++;
}
last++;
}

lastHandle = handle;
stillWorking = false;
}
}


All I want to do is draw a box around the window that my mouse is over.
Any ideas, questions, clues, are very much welcome.
Thanks.
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 11:24
protectorHeath Stewart8-Jul-04 11:24 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 15:24
Nick Z.8-Jul-04 15:24 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 16:34
protectorHeath Stewart8-Jul-04 16:34 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 15:43
Nick Z.8-Jul-04 15:43 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 16:21
Nick Z.8-Jul-04 16:21 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 16:38
protectorHeath Stewart8-Jul-04 16:38 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 17:00
Nick Z.8-Jul-04 17:00 
GeneralRe: Repainting window. Pin
Heath Stewart8-Jul-04 17:08
protectorHeath Stewart8-Jul-04 17:08 
GeneralRe: Repainting window. Pin
Nick Z.8-Jul-04 17:51
Nick Z.8-Jul-04 17:51 
GeneralA far more superior solution. Pin
Nick Z.8-Jul-04 18:54
Nick Z.8-Jul-04 18:54 
General"contexMenu" in "TreeView" for specific "Node". Pin
novitzky8-Jul-04 9:50
novitzky8-Jul-04 9:50 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
Judah Gabriel Himango8-Jul-04 9:59
sponsorJudah Gabriel Himango8-Jul-04 9:59 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
novitzky8-Jul-04 22:01
novitzky8-Jul-04 22:01 
GeneralRe: "contexMenu" in "TreeView" for specific "Node". Pin
saud_a_k9-Jul-04 1:37
saud_a_k9-Jul-04 1:37 
GeneralReturning a String from Managed to Unmanaged Code Pin
SanShou8-Jul-04 6:25
SanShou8-Jul-04 6:25 
GeneralRe: Returning a String from Managed to Unmanaged Code Pin
Heath Stewart8-Jul-04 8:49
protectorHeath Stewart8-Jul-04 8:49 
GeneralRe: Returning a String from Managed to Unmanaged Code Pin
SanShou8-Jul-04 8:57
SanShou8-Jul-04 8:57 

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.