简体   繁体   中英

i have a win32 windows application and want to capture full screen and remove the border of window displayed?

win32 windows application and want to capture full screen and remove the border of window displayed any one tell me how can i do so if this window capture the mouse keyboard controls then it will be ideal?

// MonitorScreen.cpp : Defines the entry point for the application. //

#include "stdafx.h" 
#include "MonitorScreen.h

#define MAX_LOADSTRING 100

// Global Variables: HINSTANCE hInst;                               // current instance TCHAR szTitle[MAX_LOADSTRING];                  // The title bar text TCHAR szWindowClass[MAX_LOADSTRING];          // the main window class name

// Forward declarations of functions included in this code module: ATOM             MyRegisterClass(HINSTANCE hInstance); BOOL              InitInstance(HINSTANCE, int); LRESULT CALLBACK  WndProc(HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK   About(HWND, UINT, WPARAM, LPARAM);

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {  UNREFERENCED_PARAMETER(hPrevInstance);  UNREFERENCED_PARAMETER(lpCmdLine);

    // TODO: Place code here.   MSG msg;    HACCEL hAccelTable;

    // Initialize global strings    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);  LoadString(hInstance, IDC_MONITORSCREEN, szWindowClass, MAX_LOADSTRING);    MyRegisterClass(hInstance);

    // Perform application initialization:  if (!InitInstance (hInstance, nCmdShow))    {       return FALSE;   }

    hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MONITORSCREEN));

    // Main message loop:   while (GetMessage(&msg, NULL, 0, 0))    {       if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))         {           TranslateMessage(&msg);             DispatchMessage(&msg);      }   }

    return (int) msg.wParam; }



// //  FUNCTION: MyRegisterClass() // //  PURPOSE: Registers the window class. // //  COMMENTS: // //    This function and its usage are only necessary if you want this code //    to be compatible with Win32 systems prior to the 'RegisterClassEx' //    function that was added to Windows 95. It is important to call this function //    so that the application will get 'well formed' small icons associated //    with it. // ATOM MyRegisterClass(HINSTANCE hInstance) {     WNDCLASSEX wcex;

    int s =sizeof(WNDCLASSEX);  wcex.cbSize =sizeof(WNDCLASSEX);

    wcex.style          = DESKTOP_HOOKCONTROL  ;//CS_HREDRAW | CS_VREDRAW;  wcex.lpfnWndProc    = WndProc;  wcex.cbClsExtra     = 0;    wcex.cbWndExtra     = 0;    wcex.hInstance      = NULL;//hInstance;     wcex.hIcon          = NULL;//LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MONITORSCREEN));   wcex.hCursor        = NULL;//LoadCursor(NULL, IDC_ARROW);   wcex.hbrBackground  = (HBRUSH)(9);  wcex.lpszMenuName   = NULL;//MAKEINTRESOURCE(IDC_MONITORSCREEN);    wcex.lpszClassName  = szWindowClass;    wcex.hIconSm        = NULL;//LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));

    return RegisterClassEx(&wcex); }

// //   FUNCTION: InitInstance(HINSTANCE, int) // //   PURPOSE: Saves instance handle and creates main window // //   COMMENTS: // //        In this function, we save the instance handle in a global variable and //        create and display the main program window. // BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {    HWND hWnd;

   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

   if (!hWnd)    {
      return FALSE;    }

   ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);

   return TRUE; }

// //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // //  PURPOSE:  Processes messages for the main window. // //  WM_COMMAND - process the application menu //  WM_PAINT - Paint the main window //  WM_DESTROY  - post a quit message and return // // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {    int wmId, wmEvent;  PAINTSTRUCT ps;     HDC hdc;

    switch (message)    {   case WM_COMMAND:        wmId    = LOWORD(wParam);       wmEvent
= HIWORD(wParam);       // Parse the menu selections:       switch (wmId)       {       case IDM_ABOUT:             DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);           break;      case IDM_EXIT:          DestroyWindow(hWnd);            break;      default:            return DefWindowProc(hWnd, message, wParam, lParam);        }       break;  case WM_PAINT:      hdc = BeginPaint(hWnd, &ps);        // TODO: Add any drawing code here...       EndPaint(hWnd, &ps);        break;  case WM_DESTROY:        PostQuitMessage(0);         break;  default:        return DefWindowProc(hWnd, message, wParam, lParam);    }   return 0; }

// Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {   UNREFERENCED_PARAMETER(lParam);     switch (message)    {   case WM_INITDIALOG:         return (INT_PTR)TRUE;

    case WM_COMMAND:        if (LOWORD(wParam)
== IDOK || LOWORD(wParam) == IDCANCEL)      {           EndDialog(hDlg, LOWORD(wParam));            return (INT_PTR)TRUE;       }       break;  }   return (INT_PTR)FALSE; }

Found this on google: Difficulties with Screen Capture, C/C++... Try to understand the code and adjust it to you needs.

void CaptureScreen(LPCTSTR lpszFilePathName)
{
      BITMAPFILEHEADER      bmfHeader;
      BITMAPINFO                  *pbminfo;
      HBITMAP                        hBMP;
      CFile                        oFile;

      CDC            *pDC            = GetWindowDC();
      INT            nSizeImage      = 1024 * 768 * 3;
      CHAR      *pBuff            = new CHAR[sizeof(BITMAPINFOHEADER) + nSizeImage];
      pbminfo                        = (BITMAPINFO *)pBuff;
      hBMP                        = (HBITMAP)pDC->GetCurrentBitmap()->m_hObject;

      ZeroMemory(pbminfo, sizeof(BITMAPINFO));

      pbminfo->bmiHeader.biSize            = sizeof(BITMAPINFOHEADER);

      GetDIBits(pDC->m_hDC,
                    hBMP,
                    0,
                    1,
                    NULL,
                    pbminfo,
                    DIB_RGB_COLORS);

      GetDIBits(pDC->m_hDC,
                    hBMP,
                    0,
                    pbminfo->bmiHeader.biHeight,
                    pBuff + sizeof(BITMAPINFOHEADER),
                    pbminfo,
                    DIB_RGB_COLORS);

      ReleaseDC(pDC);

      bmfHeader.bfType            = 0x4d42; /*"BM"*/
      bmfHeader.bfSize            = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + nSizeImage;
      bmfHeader.bfReserved1      = 0;
      bmfHeader.bfReserved2      = 0;
      bmfHeader.bfOffBits            = (DWORD) sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

      oFile.Open(lpszFilePathName, CFile::modeWrite | CFile::modeCreate);

      oFile.Write(&bmfHeader, sizeof(BITMAPFILEHEADER));
      oFile.Write(pBuff, sizeof(BITMAPINFOHEADER) + pbminfo->bmiHeader.biSizeImage);
      delete []pBuff;
      oFile.Close();
}

I'm going to assume you don't actually want to capture the screen, your question cannot make sense. I'm guessing you simply want to make your window maximized to occupy the full screen. Put the template generated code back the way it was, simply change the ShowWindow call:

 ShowWindow(hWnd, SW_MAXIMIZE);

I think you want to use OpenGL or DirectX and invoke full-screen mode for your application. There will of course be a few keystrokes you can't intercept, such as the Secure Attention Sequence (usually CTRL+ALT+DEL) but most interaction with the computer will be directed to your program.

first to get the full screen you should type this in: ShowWindow(hWnd, SW_SHOWMAXIMIZED) Second to remove the border or witch is called thick frame in the window styles you should type in your CreateWindow function(the place where you put your styles (WS_)): CreateWindow(your class, window name, WS_POPUP | WS_BORDER, The rest of your params for the create window func.);

Ps:WS_BORDER IS JUST A 1 PX BLACK BORDER so you can know where is the window if it was not minimized and on top of a window woth the same bg color AND YOU CAN REMOVE IT WHENEVER YOU WANT Also you wont be able to minimize,maximize,close the window with the built in buttons because they wont be there so if you want to close the app just make a button that sends a PostQuitMessage when pressed.

good luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM