Новый участник
Сообщения: 24
Благодарности: 0
|
Профиль
|
Отправить PM
| Цитировать
Уважаемые знатоки ресурса, прошу помочь доделать программу.
Исходный код прилагаю.
При компиляции приложения возникают 3 ошибки:
- error C4700: uninitialized local variable 'hdcCompatible' used
- error C4700: uninitialized local variable 'hdcScreen' used
- error C4700: uninitialized local variable 'hOldBitmap' used
Прошу ткнуть носом, или помочь довести код до рабочего состояния. Буду благодарен за любую помощь.
Цитата:
#include "stdafx.h"
#include "resource.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst;
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
//LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WIN32PROJECT1, szWindowClass, MAX_LOADSTRING);
//LoadString(hInstance, IDC_PRINTSCREEN, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32PROJECT1));
//hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PRINTSCREEN);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
//wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_PRINTSCREEN);
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WIN32PROJECT1));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
//wcex.lpszMenuName = (LPCSTR)IDC_PRINTSCREEN;
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_WIN32PROJECT1);
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
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;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
TCHAR szHello[MAX_LOADSTRING];
HDC hDC,hCompatibleDC,hDC1,hdcScreen,hdcCompatible;
PAINTSTRUCT PaintStruct;
HANDLE hBitmap,hOldBitmap,hbmScreen,hwnd;
RECT Rect;
BITMAP Bitmap;
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
/////////////////////////////////////////////////////////////////////
hdcScreen = GetDC(NULL);
hdcCompatible = CreateCompatibleDC(hdcScreen);
hbmScreen = CreateCompatibleBitmap(hdcScreen,GetDeviceCaps(hdcScreen, HORZRES),GetDeviceCaps(hdcScreen, VERTRES));
// Выбираем совместимый точеный рисунок в DC.
hOldBitmap=SelectObject(hdcCompatible,hbmScreen);
// копируем цветовые данные для всего дисплея в точечный рисунок,
// который выбирается в совместимый DC.
BitBlt(hdcCompatible,0,0,GetDeviceCaps(hdcScreen,HORZRES),GetDeviceCaps(hdcScreen,VERTRES),hdcScreen ,0,0,SRCCOPY);
//
break;
case WM_PAINT:
/////////////////////////////////////////////////////////////////////
hDC1=BeginPaint(hWnd,&PaintStruct);
BitBlt(hDC1,0,0,GetDeviceCaps(hdcScreen, HORZRES),GetDeviceCaps(hdcScreen, VERTRES),hdcCompatible,0,0,SRCCOPY);
EndPaint(hWnd,&PaintStruct);
//
return 0;
case WM_DESTROY:
///////////////////////////////////////////////////////////////////////
SelectObject(hdcCompatible,hOldBitmap);
DeleteDC(hdcCompatible);
DeleteObject(hOldBitmap);
ReleaseDC(NULL, hdcScreen);
//
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
|
|