banner



How To Get In A Window

Thread: How get the width and height of a Window

  1. #1

    How get the width and pinnacle of a Window

    I demand to know how to get the width and meridian of a Window in Vista
    I've tried GetWindowRect(); but information technology wont work right and I don't know why.
    And also i have tried to go the HBITMAP from a window and save it only it wont relieve some parts of the window, and it shows a solid colour or some thing that don't have annihilation to do with the window.

    Please help me!

    David

    Last edited by poqdavid; November 10th, 2010 at 03:22 PM.

    "Writing in C or C++ is like running a chain saw with all the condom guards removed!"


  2. #ii

    Re: How get the width and pinnacle of a Window

    I've tried GetWindowRect(); just it wont work right and I don't know why.

    Okay, how practise you find out it works incorrect?

    Best regards,
    Igor


  3. #three

    Re: How get the width and meridian of a Window

    Quote Originally Posted by Igor Vartanov View Post

    Okay, how do you find out it works wrong?

    when i move the window the size of the bitmap it changes.
    Last edited by poqdavid; November 10th, 2010 at 03:22 PM.

    "Writing in C or C++ is like running a chain saw with all the safety guards removed!"


  4. #four

    Re: How become the width and height of a Window

    Quote Originally Posted past poqdavid View Post

    when i motility the window the size of the bitmap it changes.

    What bitmap? What does that accept to do with GetWindowRect?

  5. #5

    Smile Re: How get the width and height of a Window

    A window is identified by a HWND handle.

    A bitmap is identified past a HBITMAP handle.

    Those objects nothing have in mutual beside that you tin can display (paint) a bitmap in a window. Or brand a screenshot of a window and store the result in a bitmap.

    Just all that requires much more than calling GetWindowRect.


  6. #6

    Re: How go the width and summit of a Window

    Quote Originally Posted by GCDEF View Post

    What bitmap? What does that have to practise with GetWindowRect?

    Code:

    HBITMAP CaptureWindow(void) {  	//Capture desktop into bitmap 	HBITMAP hBitmap = Zip; 	RECT rcDt; 	HWND hDtWnd = ::GetForegroundWindow(); 	  	HDC hDtDC = GetDC(hDtWnd); 	  	if(hDtDC && GetWindowRect(hDtWnd, &rcDt)) 	{ 		//Create mem DC & bitmap         int due west = rcDt.right - rcDt.left; 		int h = rcDt.bottom - rcDt.top; 		HDC hMemDC = CreateCompatibleDC(hDtDC); 		hBitmap = CreateCompatibleBitmap(hDtDC, west, h); 			  		if(hMemDC && hBitmap) 		{ 			//Select our bitmap 			HGDIOBJ hOldBmp = SelectObject(hMemDC, hBitmap);  			//Copy desktop to mem DC 			BitBlt(hMemDC, 0,0, w, h, hDtDC, 0, 0, SRCCOPY);  			//Select former bmp 			SelectObject(hMemDC, hOldBmp); 		}  		//Release DCs 		DeleteDC(hMemDC); 		ReleaseDC(hDtWnd, hDtDC); 	}  	return hBitmap; }
    this is the problem you can see it in the image
    Concluding edited by poqdavid; November tenth, 2010 at 03:23 PM.

    "Writing in C or C++ is similar running a chain saw with all the safety guards removed!"


  7. #7

    Re: How go the width and meridian of a Window

    After calling GetWindowRect, call ScreenToClient.

  8. #viii

    Re: How get the width and height of a Window


  9. #nine

    Smile Re: How go the width and height of a Window

    Quote Originally Posted by Skizmo View Post

    The ScreenToClient converts screen coordinates (of a point) to client coordinates. While the screen coordinates are absolute to the screen the client coordinates are relative to the peak-left corner of the window. In your example the ScreenToClient doesn't help crusade it doesn't change width and height and if not using MFC you would need to telephone call ScreenToClient for each corner beside of the elevation-left corner which turns to (0, 0) in client coordinates.

    In the function you posted you lot didn't utilise the rectangle rcDt, and so the bug for the wrong display probably are in one of the next functions.


  10. #ten

    Re: How become the width and height of a Window

    Quote Originally Posted by itsmeandnobodyelse View Post

    The ScreenToClient converts screen coordinates (of a point) to client coordinates. While the screen coordinates are absolute to the screen the client coordinates are relative to the top-left corner of the window. In your instance the ScreenToClient doesn't aid crusade it doesn't modify width and height and if non using MFC you would need to call ScreenToClient for each corner abreast of the elevation-left corner which turns to (0, 0) in client coordinates.

    In the function y'all posted you didn't use the rectangle rcDt, so the issues for the incorrect brandish probably are in i of the side by side functions.

    can you show me a sample how i put that in to my code.
    y'all know i trying to learn C++ past my self alone and also i started this C++ alone no i helped me.

  11. #11

    Smile Re: How get the width and height of a Window

    Quote Originally Posted past poqdavid View Post

    can you show me a sample how i put that in to my code.
    yous know i trying to learn C++ by my cocky alone and as well i started this C++ solitary no ane helped me.

    I would, but you need to post the part where the bitmap was outputted or where you move the window. Unfortunately, GetWindowRect returns accented coordinates but if you draw into a window the relative coordinates (relative to the height-left coordinates) were used. If the window has a frame you lot also would need to subtract the frames. The sizes yous can get by a telephone call to GetSystemMetrics with arguments SM_CXFIXEDFRAME respectively SM_CYFIXEDFRAME.

    BTW, for getting a screenshot in windows you would find a lot of working source code both with and without MFC.


  12. #12

    Re: How get the width and height of a Window

    Quote Originally Posted by itsmeandnobodyelse View Post

    I would, just you lot demand to post the function where the bitmap was outputted or where you motion the window. Unfortunately, GetWindowRect returns accented coordinates simply if you draw into a window the relative coordinates (relative to the meridian-left coordinates) were used. If the window has a frame you besides would need to subtract the frames. The sizes you can get by a call to GetSystemMetrics with arguments SM_CXFIXEDFRAME respectively SM_CYFIXEDFRAME.

    BTW, for getting a screenshot in windows you would detect a lot of working source code both with and without MFC.

    Code:

    void SaveIt(HBITMAP hbmp, HDC hdc,const WCHAR *filename)       { 		     // using namespace Gdiplus; 		  	 // Initialize GDI+.              Gdiplus::GdiplusStartupInput gdiplusStartupInput;              ULONG_PTR gdiplusToken;              Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); 			 CLSID   encoderClsid; 	         Gdiplus::Status stat;  	 	        // Get the CLSID of the PNG encoder.           GetEncoderClsid(L"paradigm/png", &encoderClsid);            // Get width and peak of source HBITMAP           BITMAP bm;           memset((void*)&bm, 0, sizeof(BITMAP));           GetObject(hbmp, sizeof(BITMAP), (void*)&bm);           int width = bm.bmWidth;           int height = bm.bmHeight;            // Create a GDI+ bitmap of the aforementioned dimensions, with alpha.           Gdiplus::Bitmap* copy = new Gdiplus::Bitmap(width, height, PixelFormat32bppRGB); 		  copy = new Gdiplus::Bitmap(hbmp, Nada); 		   		  //Gdiplus::Bitmap* re-create = new Gdiplus::Bitmap(hbmp, Naught); 	           //Go an HDC for this new Bitmap          Gdiplus::Graphics* yard =  Gdiplus::Graphics::FromImage(copy); 		  g->DrawImage(copy, 0, 0, 1280, 800); 		            HDC copyHdc = grand->GetHDC(); 		           HDC srcHdc = ::CreateCompatibleDC(hdc);           ::SelectObject(srcHdc, hbmp);            //This loses all alpha:          // BOOL bbrv = ::BitBlt(copyHdc, 0, 0, width, height, srcHdc, 0,0, SRCCOPY);            //This retains some blastoff (just where A == 0)          BLENDFUNCTION bf1;           bf1.BlendOp = AC_SRC_OVER;           bf1.BlendFlags = 0;           bf1.SourceConstantAlpha = 0xff;           bf1.AlphaFormat = AC_SRC_ALPHA; 		            BOOL abrv = ::AlphaBlend(copyHdc, 0, 0, width, superlative, srcHdc, 0, 0, width, height, bf1);  		  		  	 // 			            ::DeleteDC(srcHdc);            g->ReleaseHDC(copyHdc);  		  stat = copy->Save(filename, &encoderClsid , Zilch); 		 		   Gdiplus::GdiplusShutdown(gdiplusToken);        }
    Last edited past poqdavid; Nov 10th, 2010 at 02:06 PM.

  13. #13

    Smile Re: How go the width and top of a Window

    Quote Originally Posted by poqdavid View Post

    void SaveIt(HBITMAP hbmp, HDC hdc,const WCHAR *filename)
    {
    // using namespace Gdiplus;
    // Initialize GDI+.
    Gdiplus::GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR gdiplusToken;
    Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, Null);
    CLSID encoderClsid;
    Gdiplus::Status stat;

    // Go the CLSID of the PNG encoder.
    GetEncoderClsid(L"image/png", &encoderClsid);

    // Go width and superlative of source HBITMAP
    BITMAP bm;
    memset((void*)&bm, 0, sizeof(BITMAP));
    GetObject(hbmp, sizeof(BITMAP), (void*)&bm);
    int width = bm.bmWidth;
    int superlative = bm.bmHeight;

    // Create a GDI+ bitmap of the same dimensions, with alpha.
    Gdiplus::Bitmap* re-create = new Gdiplus::Bitmap(width, height, PixelFormat32bppRGB);
    copy = new Gdiplus::Bitmap(hbmp, Zippo);

    //Gdiplus::Bitmap* copy = new Gdiplus::Bitmap(hbmp, NULL);

    //Get an HDC for this new Bitmap
    Gdiplus::Graphics* k = Gdiplus::Graphics::FromImage(copy);
    chiliad->DrawImage(re-create, 0, 0, 1280, 800);

    HDC copyHdc = g->GetHDC();

    HDC srcHdc = ::CreateCompatibleDC(hdc);
    ::SelectObject(srcHdc, hbmp);

    //This loses all alpha:
    // BOOL bbrv = ::BitBlt(copyHdc, 0, 0, width, height, srcHdc, 0,0, SRCCOPY);

    //This retains some alpha (only where A == 0)
    BLENDFUNCTION bf1;
    bf1.BlendOp = AC_SRC_OVER;
    bf1.BlendFlags = 0;
    bf1.SourceConstantAlpha = 0xff;
    bf1.AlphaFormat = AC_SRC_ALPHA;

    BOOL abrv = ::AlphaBlend(copyHdc, 0, 0, width, elevation, srcHdc, 0, 0, width, elevation, bf1);

    //

    :eleteDC(srcHdc);

    chiliad->ReleaseHDC(copyHdc);

    stat = copy->Salve(filename, &encoderClsid , NULL);

    Gdiplus::GdiplusShutdown(gdiplusToken);

    }

    It is some time ago when I lastly fabricated bitmap output, but I call back your issues are in

    Lawmaking:

    BOOL abrv = ::AlphaBlend(copyHdc, 0, 0, width, superlative, srcHdc, 0, 0, width, superlative, bf1);
    where both points passed are (0, 0). I of those points probably should be the absolute top-left of the window you want to draw into. From the docs I would presume information technology is the first pair (0, 0) which you should endeavour to substitution past the summit-left coordinates you get by a telephone call to GetWindowRect.

  14. #14

    Re: How get the width and summit of a Window

    Quote Originally Posted by itsmeandnobodyelse View Post

    Information technology is some time ago when I lastly made bitmap output, but I think your problems are in

    Code:

    BOOL abrv = ::AlphaBlend(copyHdc, 0, 0, width, height, srcHdc, 0, 0, width, pinnacle, bf1);

    where both points passed are (0, 0). One of those points probably should be the absolute top-left of the window you want to draw into. From the docs I would assume information technology is the first pair (0, 0) which you should try to commutation past the height-left coordinates you get by a call to GetWindowRect.

    Well i tried it merely it didn't work
    Last edited by poqdavid; November 10th, 2010 at 03:24 PM.

    "Writing in C or C++ is like running a concatenation saw with all the safety guards removed!"


  15. #15

    Re: How get the width and height of a Window

    It'd be much easier if yous explained the logic backside your SaveIt. Why but not save the source bitmap?

    Well i tried it simply information technology didn't work

    And definitely yous should be a bit more than talkative near what you tried and what didn't piece of work...

    All-time regards,
    Igor


Posting Permissions

  • You may not postal service new threads
  • You may not mail replies
  • Yous may not mail service attachments
  • You may not edit your posts
  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Click Here to Expand Forum to Full Width



Source: https://forums.codeguru.com/showthread.php?505077-How-get-the-width-and-height-of-a-Window

Posted by: whitepaligar.blogspot.com

0 Response to "How To Get In A Window"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel