If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
I make a mini screen-shot code. But put the rectangles not at start and end of mouse.
What i am wrong?
An some times background of all panel is altered. How to improve that? There is some wxwidget program to study?
screenShotFrame::screenShotFrame(wxFrame *frame)
: screenShot(frame)
{
this->GetSize(&w,&h);
wxCoord screenWidth, screenHeight;
screenDC.GetSize(&screenWidth, &screenHeight);
//this->SetSize(screenWidth,screenHeight);
screenshot=wxBitmap(screenWidth, screenHeight,-1);
memDC.SelectObject(screenshot);
//Blit (in this case copy) the actual screen on the memory DC and thus the Bitmap
memDC.Blit( 0, //Copy to this X coordinate
0, //Copy to this Y coordinate
screenWidth, //Copy this width
screenHeight, //Copy this height
&screenDC, //From where do we copy?
0, //What's the X offset in the original DC?
0 //What's the Y offset in the original DC?
);
//Select the Bitmap out of the memory DC by selecting a new
//uninitialized Bitmap
memDC.SelectObject(wxNullBitmap);
image=screenshot.ConvertToImage();
screenShotBitmap->SetBitmap(screenshot);
}
void screenShotFrame::screenCapturePart1( wxMouseEvent& event )
{
x1=x2=y1=y2=0;
wxPoint pt = wxGetMousePosition();
x1= pt.x - this->GetScreenPosition().x;
y1 = pt.y - this->GetScreenPosition().y;
}
void screenShotFrame::screenCapturePart2( wxMouseEvent& event )
{
wxPoint pt = wxGetMousePosition();
x2= pt.x - this->GetScreenPosition().x;
y2 = pt.y - this->GetScreenPosition().y;
DoPaint(this,*wxRED_PEN);
}
void screenShotFrame::DoPaint(wxWindow* wnd, const wxPen& linePen)
{
wxSize s(wnd->GetClientSize());
wxBufferedPaintDC dc(wnd);
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(x1, y1, x2, y2);
}
Works just fine. A question please.
Why with old code the background is altered? With new code is just fine, without any modification. I don’t understand this behaviour.
Thanks.
Jim
I didn't run the code, so i don't really know what you meant with "altered background". Maybe there were some artifacts when the old code was trying to draw outside the window area?
Sorry, wrong .., sometimes make problem with background. Maybe because i have two screens...
I am trying to figure out..
As i see when press mouse and release in same point make this every time. An some other times, i don’t know why. Code is very simple.
--------------
This happens every time that mouse leaves on vertical line that distinguishes the two screens.
Last edited by dkaip on Thu Oct 19, 2017 8:47 am, edited 2 times in total.
I must send a picture before(1.png) and after (2.png) ...
This happens every time that mouse leaves on vertical line that distinguishes the two screens.
You're passing in a window pointer. Are you sure it's the correct one? How does the "real" paint event handler look like? In a paint event you should only draw onto the window that generated the event.
In the drawing code you're only drawing the lines, you're not erasing the background. Is that intended?
As there was a similar question a while ago, i decided to write a small class for grabbing a screen area. For simplicity it only uses the "fake" method that just grabs the whole screen and displays the bitmap full screen. I.e. if there are any "moving" parts on the "real" screen, you won't see that during the selection process. You'll just see a static bitmap. A proper solution is more effort, maybe i'll write that at a later time.
void MyFrame::OnStartCapture(wxCommandEvent& WXUNUSED(event))
{
ScreenSelectionDialog dlg(this);
if( dlg.ShowModal() == wxID_OK )
{
// if you just want the selection rectangle and process the area yourself
wxRect r = dlg.GetSelectionRect();
// if you want the selected screen area as a bitmap
::wxInitAllImageHandlers();
wxBitmap captured = dlg.GetCapturedArea();
captured.SaveFile( "d:\\_captured.png", wxBITMAP_TYPE_PNG );
}
}
That's not a compiler error, it's an assert at runtime. I work under Windows only, so i'm not sure why the code doesn't work under GTK. I can only assume that the CaptureMouse() in the dialog ctor is too early under GTK.
I am truing to new version, but after click on screen stops at appbase.cpp line 1163 at wxTrap();
Have i something wrong?
---------------------------------------------