I am writing an application using MFC and was wanting to include a function similar to the select function available in Paint.
I want to allow the user to grab the screen and drag it where they want to, can anyone give me some pointers as to how I would go about this?
Any help would be greatly appreciated.
6 3811 Banfa 9,065
Recognized Expert Moderator Expert
What you will need to do is this, when the set the first point (a rectangle is defined by 2 points) just record it, when they select the second point you have the rectangle to copy. At this point you will probably need to create 2 bitmaps, 1 cotaining the contents of the screen (with the selction removed and 1 containing the selection. These can be created with CreateCompatabl eBitmap, then you will also need a compatable device context (with the screen) for each bitmap and you will need to select the created bitmaps into the created device contexts. You can then fill in the bitmaps by using BitBlt to copy what is currently on the screen. Then as they are draging the selection around you can use BitBlt to fill in the Window client area from the 2 bitmaps until they have finished. Once finished you can Blt everything back onto the screen and delete the created device contexts and bitmaps.
What you will need to do is this, when the set the first point (a rectangle is defined by 2 points) just record it, when they select the second point you have the rectangle to copy. At this point you will probably need to create 2 bitmaps, 1 cotaining the contents of the screen (with the selction removed and 1 containing the selection. These can be created with CreateCompatabl eBitmap, then you will also need a compatable device context (with the screen) for each bitmap and you will need to select the created bitmaps into the created device contexts. You can then fill in the bitmaps by using BitBlt to copy what is currently on the screen. Then as they are draging the selection around you can use BitBlt to fill in the Window client area from the 2 bitmaps until they have finished. Once finished you can Blt everything back onto the screen and delete the created device contexts and bitmaps.
Hey Banfa,
This is what I have at the moment (which isn't much);
OnMouseMove(... ){
...
CRect rect(0,0,wWidth ,wHeight);
CreateCompatibl eBitmap(m_hDC, wWidth, wHeight);
CDC compDevice; // device compatible to the screen
?
}
where wWidth & wHeight are the width and height of the screen in pixels.
HDC m_hDC =GetDC(m_hWnd); where m_Wnd is a handle to the window.
I am wanting the whole screen to be dragged which is why there is only a single rectangle - is this correct?
Also I am unsure as to how you select the bitmaps into the device context and use BitBlt?
Cheers
Banfa 9,065
Recognized Expert Moderator Expert
Looks about right but don't mix WIN32 and MFC if possible, it will just get confusing, look up the methods
Get a Device Context for the Window
CDC* CWnd::GetDC( );
Create a bitmap compatable with the device context
BOOL CBitmap::Create CompatibleBitma p( CDC* pDC, int nWidth, int nHeight );
Create a device contaxt compatable with another device context
virtual BOOL CDC::CreateComp atibleDC( CDC* pDC );
Select a bitmap object into a device context, having done this you can use the device context to draw to the bitmap
CBitmap* CDC::SelectObje ct( CBitmap* pBitmap );
Copy bits of a bitmap between different (or the same) device contexts
BOOL CDC::BitBlt( int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop );
If you are not using MFC then don't use CDC compDevice, use HDC compDevice and all the above functions have WIN32 API equivilents with the same name.
Banfa,
I have tried to add the code as you instructed however I am not getting it right, the code I have is below;
CRect rect(0,0,wWidth ,wHeight);
CreateCompatibl eBitmap(m_hDC, wWidth, wHeight);
CDC *compDevice = GetDC();
CreateCompatibl eBitmap(*compDe vice, wWidth, wHeight);
CreateCompatibl eDC(*compDevice );
CBitmap *bitmap;
compDevice->SelectObject(* bitmap);
compDevice->BitBlt(0,0,wWi dth,wHeight,com pDevice,0,0,SRC COPY);
While the code compiles the SelectObject line throws an exception when it is executed (because it has no value, I assume) however I am unsure as to what should be there. Also I don't think that the compDevice (5th arg in BitBlt) that I have put in is correct?
Again any help would be greatly appreciated.
Sorry should also mention that it is MFC that I am using.
Banfa 9,065
Recognized Expert Moderator Expert
OK, you are using MFC so I assume you are calling this from a class sub-classed from CWnd
Creation Code -
CClientDC wndDC; //CClientDC autoatically calls GetDC and ReleaseDC
-
-
CBitmap bitmap;
-
bitmap.CreateCompatibleBitmap(&wndDC, wWidth, wHeight);
-
-
CDC bitmapDC;
-
bitmapDC.CreateCompatibleDC(&wndDC);
-
-
CBitmap *pOldBitmap = bitmapDC.SelectObject(&bitmap);
-
-
bitmapDC.BitBlt(0,0,wWidth,wHeight,wndDC,0,0,SRCCOPY);
-
however these variables
CBitmap bitmap;
CDC bitmapDC;
CBitmap *pOldBitmap;
need to be persistent so that you can call the deletion code -
bitmapDC.SelectObject(pOldBitmap);
-
-
bitmap.DeleteObject();
-
-
bitmapDC.DeleteDC();
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Attila |
last post by:
Hello,
I have seen the select function used on forms fields, and it
usually takes place immediately after a setfocus call is made.
However, after adding the code to a test page, I don't see what it
does. Can anyone tell me what exactly it does?
Thanks,
Attila
|
by: Dennis |
last post by:
In my program I have defined a global vector with
//=======prototypes section ====================
float select(const int k, std::vector<float> &myArr, int iStart, int iEnd);
.....
//====Global Vectors ==================================
std::vector<float> gTmpArr(8000,0);
In Main, I would like to pass this vector to a function such as:
|
by: supline |
last post by:
I have a function that creates a select list:
function make_select_ns($name,$array,$persist){
$string = "<select name=\"$name\">";
$string .="<option selected>" . ucfirst($name) . "</option>\n";
if ($name == $array){array_shift($array);} //removes duplicate when
table name equals 1st item in array
foreach ($array AS $value) {
if (($value == $persist) && is_string($persist)){$selected =
"selected";}
|
by: Bari |
last post by:
Hi all,
My problem is: I'm waiting with select() on a socket array, when data
is written in one of the sockets the select awakes. The problem is that
untill it finishes I can't listen to the other sockets (I'm using only
one task).
I've heard that there is an option for a non blocking select, is it
true?
If not does anyone have any idea?
|
by: ravip |
last post by:
I am trying to select some text in a texbox , on keyDown event.
but when i write such simple code its not selecting the text in that textbox ,
instead its only focusing that textbox.
It selects the same when called on keyUp event.
But its my application need that it should get called on keyDown event.
Please provide help , if possible
Thnks,
| |
by: radders |
last post by:
Hi everyone, I've written a simple programme using Visual C++ that assigns the values of the mouse's coordinates to a set of variables each time the mouse is moved to a new position with a button pressed. It then draws a line between the new cursor position and the position stored in the variables, allowing you to sketch with the mouse. What I would like to do is assign a function to repaint the dialogue box to its initial setting (i.e. only...
|
by: Sonbol |
last post by:
Hi,
I am new to linux programming. I am using c to develop a program that aims to create many children in order to communicate with their parents through pipes
I need the parent to wait for all the children to finish processing and write to their parent using the appropriate pipe for each children. I know that I may use the select function for this purpose and I have read a lot about it but I don't know how to use it in my program
code...
|
by: printline |
last post by:
Hi all
I have a problem with a form script.
The form script should do the following:
When a user selects a value from a drop down list and hits the "next" button it should take him to a specific site. Also he has the option to check a checkbox "Remeber this choice" so that when he returns to the site it remembers what he has choosen from the drop down list and automatically takes him to a specific site.
Here is my code:
|
by: SteveGod |
last post by:
Hi,
I'm trying to create a report that will produce automated sets of Committee Minutes for School Appeals, where there are a set range of different outcomes.
The field involved are all from the same table, and called:
, , , and
In the query where the result of the outcome in needed, it has the following in a field:
Minute: MINUTEOUTCOME(,,,,)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |