Hi,
How would you simulate the printscreen buton being pressed in C++ Code?
Thank you in advance,
L99
How Would You Simulate PrintScreen In Code
Page 1 of 17 Replies - 1157 Views - Last Post: 10 May 2012 - 05:11 AM
Replies To: How Would You Simulate PrintScreen In Code
#2
Re: How Would You Simulate PrintScreen In Code
Posted 03 May 2012 - 10:50 AM
Let's start with what are you expectations and actions you envision for a printscreen in c++ (presumably in a console program)?
#3
Re: How Would You Simulate PrintScreen In Code
Posted 03 May 2012 - 11:14 AM
modi123_1, on 03 May 2012 - 10:50 AM, said:
Let's start with what are you expectations and actions you envision for a printscreen in c++ (presumably in a console program)?
Well its a Win32 Gui, but It actually exacutes in the side-by-side cmd prompt. Also, does it help by me saying its in codeblocks?
Thanks,
L99
#4
Re: How Would You Simulate PrintScreen In Code
Posted 04 May 2012 - 04:21 PM
Hi lukeme99,
No it doesn't matter which IDE you are using.
Do you mean you wish to use a console to run the program but copy and print a
regular Window ?
I am not sure what you mean but have a look at my tutorial on bitmap printing
BitMap Printing
then all you have to do is copy the window onto the clipboard then from the
clipboard print it out.
Best Wishes
Snoopy.
No it doesn't matter which IDE you are using.
Do you mean you wish to use a console to run the program but copy and print a
regular Window ?
I am not sure what you mean but have a look at my tutorial on bitmap printing
BitMap Printing
then all you have to do is copy the window onto the clipboard then from the
clipboard print it out.
Best Wishes
Snoopy.
#5
Re: How Would You Simulate PrintScreen In Code
Posted 05 May 2012 - 07:36 AM
snoopy11, on 04 May 2012 - 04:21 PM, said:
Hi lukeme99,
No it doesn't matter which IDE you are using.
Do you mean you wish to use a console to run the program but copy and print a
regular Window ?
I am not sure what you mean but have a look at my tutorial on bitmap printing
BitMap Printing
then all you have to do is copy the window onto the clipboard then from the
clipboard print it out.
Best Wishes
Snoopy.
No it doesn't matter which IDE you are using.
Do you mean you wish to use a console to run the program but copy and print a
regular Window ?
I am not sure what you mean but have a look at my tutorial on bitmap printing
BitMap Printing
then all you have to do is copy the window onto the clipboard then from the
clipboard print it out.
Best Wishes
Snoopy.
The tutorial will be helpful, because I don't mean print, as in ink on paper, I mean a snapshot of the screen that I can paste into paint or word etc,
Thank you so much,
L99
#6
Re: How Would You Simulate PrintScreen In Code
Posted 05 May 2012 - 10:28 AM
Ah cutting and pasting
sorry you weren't that clear in your post...
Try this small example then...
I know its for text and not a picture but if you do some research
on how SetClipboardData works on msdn you will find its easy to modify to your situation.
Best Wishes Snoopy.
sorry you weren't that clear in your post...
Try this small example then...
#include <windows.h>
char EditText[256];
int EditTextLength;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Clipboard Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton;
static HWND hwndEdit;
HGLOBAL hGlobal;
PSTR pGlobal;
switch (message) /* handle the messages */
{
case WM_CREATE:
hwndButton = CreateWindow ( TEXT ("button"),"Cut Text",WS_CHILD|WS_VISIBLE|1,55,100,100,25,hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
hwndEdit = CreateWindow (TEXT ("edit"),NULL,WS_CHILD| ES_LEFT|WS_BORDER| WS_VISIBLE,55, 50, 100, 25, hwnd,
(HMENU) 1,((LPCREATESTRUCT) lParam) -> hInstance ,NULL);
return 0;
case WM_COMMAND:
switch (wParam)
{
case 1:
EditTextLength = GetWindowTextLength(hwndEdit) +1;
GetWindowText(hwndEdit, EditText, EditTextLength);
hGlobal = GlobalAlloc(GHND|GMEM_SHARE,
EditTextLength*sizeof (char));
pGlobal = (char*)GlobalLock (hGlobal);
strcpy (pGlobal, EditText);
GlobalUnlock(hGlobal);
OpenClipboard(hwnd);
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
I know its for text and not a picture but if you do some research
on how SetClipboardData works on msdn you will find its easy to modify to your situation.
Best Wishes Snoopy.
#7
Re: How Would You Simulate PrintScreen In Code
Posted 09 May 2012 - 11:45 AM
snoopy11, on 05 May 2012 - 10:28 AM, said:
Ah cutting and pasting
sorry you weren't that clear in your post...
Try this small example then...
I know its for text and not a picture but if you do some research
on how SetClipboardData works on msdn you will find its easy to modify to your situation.
Best Wishes Snoopy.
sorry you weren't that clear in your post...
Try this small example then...
#include <windows.h>
char EditText[256];
int EditTextLength;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Clipboard Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndButton;
static HWND hwndEdit;
HGLOBAL hGlobal;
PSTR pGlobal;
switch (message) /* handle the messages */
{
case WM_CREATE:
hwndButton = CreateWindow ( TEXT ("button"),"Cut Text",WS_CHILD|WS_VISIBLE|1,55,100,100,25,hwnd,(HMENU) 1,((LPCREATESTRUCT) lParam) -> hInstance,NULL);
hwndEdit = CreateWindow (TEXT ("edit"),NULL,WS_CHILD| ES_LEFT|WS_BORDER| WS_VISIBLE,55, 50, 100, 25, hwnd,
(HMENU) 1,((LPCREATESTRUCT) lParam) -> hInstance ,NULL);
return 0;
case WM_COMMAND:
switch (wParam)
{
case 1:
EditTextLength = GetWindowTextLength(hwndEdit) +1;
GetWindowText(hwndEdit, EditText, EditTextLength);
hGlobal = GlobalAlloc(GHND|GMEM_SHARE,
EditTextLength*sizeof (char));
pGlobal = (char*)GlobalLock (hGlobal);
strcpy (pGlobal, EditText);
GlobalUnlock(hGlobal);
OpenClipboard(hwnd);
EmptyClipboard();
SetClipboardData(CF_TEXT, hGlobal);
CloseClipboard();
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
I know its for text and not a picture but if you do some research
on how SetClipboardData works on msdn you will find its easy to modify to your situation.
Best Wishes Snoopy.
Thanks allot!
L99
#8
Re: How Would You Simulate PrintScreen In Code
Posted 10 May 2012 - 05:11 AM
Well don't thank me just yet,
There is a lot of work to be done in
Getting a Bitmap of the screen
onto the clipboard.
As you will no doubt find out.
Come back with code next time
give it your very best effort ok ?
Best Wishes.
Snoopy.
There is a lot of work to be done in
Getting a Bitmap of the screen
onto the clipboard.
As you will no doubt find out.
Come back with code next time
give it your very best effort ok ?
Best Wishes.
Snoopy.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote







|