Click here to Skip to main content
15,922,325 members
Home / Discussions / C#
   

C#

 
GeneralRe: custom ListView header ctrl and XP theme Pin
Heath Stewart7-Jul-04 5:39
protectorHeath Stewart7-Jul-04 5:39 
QuestionHow do I do double-click file opening with my C# app? Pin
spazzman7-Jul-04 0:18
spazzman7-Jul-04 0:18 
AnswerRe: How do I do double-click file opening with my C# app? Pin
Dave Kreskowiak7-Jul-04 5:04
mveDave Kreskowiak7-Jul-04 5:04 
GeneralRe: How do I do double-click file opening with my C# app? Pin
spazzman7-Jul-04 12:01
spazzman7-Jul-04 12:01 
GeneralRe: How do I do double-click file opening with my C# app? Pin
MilesAhead7-Jul-04 12:27
MilesAhead7-Jul-04 12:27 
GeneralRe: How do I do double-click file opening with my C# app? Pin
Dave Kreskowiak7-Jul-04 12:39
mveDave Kreskowiak7-Jul-04 12:39 
GeneralRe: How do I do double-click file opening with my C# app? Pin
spazzman8-Jul-04 2:12
spazzman8-Jul-04 2:12 
GeneralWrong dimensions. Pin
6-Jul-04 21:26
suss6-Jul-04 21:26 
I am trying to take a screenshot of a window from its handle.

This is the code that takes the handle and get the image from it.

public Image gdiShot(IntPtr handle)
{
//get dc from handle
IntPtr sourceDC = USER32.GetWindowDC(handle);
//create the copy destination dc
IntPtr destDC = GDI32.CreateCompatibleDC(sourceDC);
//get dimensions of dc
USER32.Rect rect = new USER32.Rect();
USER32.GetWindowRect(handle,ref rect);
int width = rect.x2 - rect.x1;
int height = rect.y2 - rect.y1;
//create bitmap
IntPtr h_myImage = GDI32.CreateCompatibleBitmap(sourceDC,width,height);
//select bitmap object into destination device context
GDI32.SelectObject(destDC,h_myImage);
//time to blit
GDI32.BitBlt(destDC,0,0,width,height,sourceDC,0,0,0x00CC0020);

//cleanup
GDI32.DeleteDC(destDC);
USER32.ReleaseDC(handle,sourceDC);
Image myImage = Image.FromHbitmap(h_myImage);
return myImage;
}

Now this works, IF my windows style is set to the default blue,silver,or olive etc. However, I use a custom skin and I am not the only one. And when I run this code with the custom skin, I always end up having 3 extra lines of pixels on top of the image. In reality the window IS 3 pixels lower on the desktop then reported by GetWindowRect API call. At this point I was about to blame the skin, but I open SnagIt take the shot of the same window with custom skin and what do you know, no extra lines on top. In other words I know it is possible.

I am open to ANY suggestions. For ex: alternative API calls to use, a way to try and get the REAL visible coordinates of a window.

Also worth mentioning:
This only applies to windows with title bars. The device context sees the window as 500x500. In reality pasted into Photoshop its 500x497.

I get the window handle passed on to this functino from a mouse click, then GetWindowFromPoint, and then GetAncestor to get to the handle of the root window.

Any suggestions please, I'm desperate.
I've seen SnagIt do it Eek! | :eek: now I have to find a way to do it too, because I know its possible.

Anybody know a way to get titlebar height? D'Oh! | :doh:
GeneralRe: Wrong dimensions. Pin
Hesham Amin6-Jul-04 22:55
Hesham Amin6-Jul-04 22:55 
GeneralRe: Wrong dimensions. Pin
Nick Z.6-Jul-04 23:28
Nick Z.6-Jul-04 23:28 
GeneralRe: Wrong dimensions. Pin
Heath Stewart7-Jul-04 5:27
protectorHeath Stewart7-Jul-04 5:27 
GeneralRe: Wrong dimensions. Pin
Nick Z.6-Jul-04 23:44
Nick Z.6-Jul-04 23:44 
GeneralMicrosoft wrote : filters property pages Pin
hpAng6-Jul-04 20:48
hpAng6-Jul-04 20:48 
GeneralRe: Microsoft wrote : filters property pages Pin
hpAng6-Jul-04 21:13
hpAng6-Jul-04 21:13 
GeneralRe: Microsoft wrote : filters property pages Pin
Heath Stewart7-Jul-04 5:23
protectorHeath Stewart7-Jul-04 5:23 
QuestionHow to Prevent decompile or dis-assembly c# project (.NET)? Pin
Anonymous6-Jul-04 20:07
Anonymous6-Jul-04 20:07 
AnswerRe: How to Prevent decompile or dis-assembly c# project (.NET)? Pin
Colin Angus Mackay7-Jul-04 0:24
Colin Angus Mackay7-Jul-04 0:24 
GeneralRe: How to Prevent decompile or dis-assembly c# project (.NET)? Pin
Heath Stewart7-Jul-04 5:17
protectorHeath Stewart7-Jul-04 5:17 
Answernot only you that face this problem :) Pin
Hesham Amin7-Jul-04 4:18
Hesham Amin7-Jul-04 4:18 
GeneralMemory usage of 1 form Pin
dev1t6-Jul-04 17:25
dev1t6-Jul-04 17:25 
GeneralRe: Memory usage of 1 form Pin
insurgentpyro6-Jul-04 18:57
insurgentpyro6-Jul-04 18:57 
GeneralRe: Memory usage of 1 form Pin
dev1t7-Jul-04 3:01
dev1t7-Jul-04 3:01 
GeneralRe: Memory usage of 1 form Pin
Peter Vertes7-Jul-04 3:48
Peter Vertes7-Jul-04 3:48 
GeneralRe: Memory usage of 1 form Pin
Dave Kreskowiak7-Jul-04 4:53
mveDave Kreskowiak7-Jul-04 4:53 
GeneralRe: Memory usage of 1 form Pin
Heath Stewart7-Jul-04 5:09
protectorHeath Stewart7-Jul-04 5:09 

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.