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

C#

 
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 
Finally fixed.
I dont know what the problem was, deffinitely related to the API functions mentioned previously. However, drawing on the desktop DC instead of the individual window DC and then updating the desktop, solved the problem. One other way to solve my problem I guess could be using PostMessage to post the WM_PAINT message to the window manualy.

Thank you very much for you help Heath. You gave me a lot of usefull information that lead me to the solution.

And here is the working code, in case someone could find it usefull. I will be working on another approach to what this handler does, something that wont cause so much flickering on the screen and as soon as I have it, I will post the code in this thread or if someone could suggest the best place to put something like this just for refference.

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(IntPtr.Zero);

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,2),dcRect.x1+regionRect.x1,dcRect.y1+regionRect.y1,width,height);
first=1;

}
else if(!(lastHandle.Equals(handle)))
{
//IntPtr lastDC = USER32.GetWindowDC(lastHandle);
//testDraw = Graphics.FromHdc(lastDC);
if(first!=0)
{
USER32.Rect dcRect= new USER32.Rect();
USER32.GetWindowRect(IntPtr.Zero,ref dcRect);

USER32.InvalidateRect(IntPtr.Zero, ref dcRect,false);
USER32.UpdateWindow(IntPtr.Zero);
}
}

lastHandle = handle;
stillWorking = false;
}
}
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 
Generalmicrosoft.office.interop Pin
dcronje8-Jul-04 5:49
dcronje8-Jul-04 5:49 
GeneralRe: microsoft.office.interop Pin
Heath Stewart8-Jul-04 8:28
protectorHeath Stewart8-Jul-04 8:28 
GeneralIDragSourceHelper problem Pin
TylerBrinks8-Jul-04 4:17
TylerBrinks8-Jul-04 4:17 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 5:28
protectorHeath Stewart8-Jul-04 5:28 
GeneralRe: IDragSourceHelper problem Pin
TylerBrinks8-Jul-04 5:52
TylerBrinks8-Jul-04 5:52 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 6:43
protectorHeath Stewart8-Jul-04 6:43 
GeneralRe: IDragSourceHelper problem Pin
Heath Stewart8-Jul-04 6:53
protectorHeath Stewart8-Jul-04 6:53 
GeneralForm display porblem Pin
wk_vigorous8-Jul-04 1:52
wk_vigorous8-Jul-04 1:52 
GeneralRe: Form display porblem Pin
Nick Parker8-Jul-04 3:43
protectorNick Parker8-Jul-04 3:43 

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.