#include "stdafx.h"
#pragma comment (lib,"dxguid.lib")
#pragma comment (lib,"ddraw.lib")
#include <windows.h>
#include <ddraw.h>
const PHYSICAL_WIDTH = 800;
const PHYSICAL_HEIGHT = 600;
LPDIRECTDRAW lpDDraw;
LPDIRECTDRAWSURFACE lpPrimarySurface;
LRESULT CALLBACK DDrawWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL DDrawInit(HWND hWnd);
void DDrawDone();
void DrawScreen();
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS wndClass;
HWND hWnd;
MSG msg;
ZeroMemory(&wndClass, sizeof(wndClass));
wndClass.style = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc = DDrawWndProc;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.lpszClassName = "DDrawApp";
wndClass.lpszClassName = "test";
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
RegisterClass(&wndClass);
hWnd = CreateWindowEx(
WS_EX_RIGHT,
wndClass.lpszClassName,
"DirectDraw Application",
0,
250,
100,
500,
300,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK DDrawWndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
DDrawInit(hWnd);
SetTimer(hWnd, 1, 50, 0);
return 0;
case WM_TIMER:
DrawScreen();
return 0;
case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
SendMessage(hWnd, WM_CLOSE, 0, 0);
return 0;
case WM_DESTROY:
KillTimer(hWnd, 1);
DDrawDone();
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
BOOL DDrawInit(HWND hWnd)
{
DDSURFACEDESC ddsd;
DDSCAPS ddsc;
LPDIRECTDRAWCLIPPER clipper;
if (DirectDrawCreate(NULL, &lpDDraw, NULL) != DD_OK)
return FALSE;
if (lpDDraw->SetCooperativeLevel(hWnd, DDSCL_NORMAL ) != DD_OK)
return FALSE;
//DetectDisplayMode();
//if (lpDDraw->SetDisplayMode(500, 300, 8) != DD_OK) return FALSE;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
ddsd.dwFlags = DDSD_CAPS;
if (lpDDraw->CreateSurface(&ddsd, &lpPrimarySurface, NULL) != DD_OK) return FALSE;
HRESULT r;
/* r=lpDDraw->CreateClipper( 0, &clipper, 0 );
r=clipper->SetHWnd( 0,hWnd );
r=lpPrimarySurface->SetClipper( clipper );
*/
return TRUE;
}
void DDrawDone()
{
if (lpPrimarySurface != NULL)
lpPrimarySurface->Release();
if (lpDDraw != NULL)
lpDDraw->Release();
}
void DrawScreen()
{
DDSURFACEDESC ddsd;
static int pos;
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if (lpPrimarySurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) == DD_OK)
{
char* buffer = (char*)ddsd.lpSurface;
for (int i = 0; i < 300 / 2; i++)
{
//memset(buffer + (i * ddsd.lPitch), i + pos, 500);
memset(buffer + ((300 / 2 + i) * ddsd.lPitch), i - pos,
500);
}
pos++;
lpPrimarySurface->Unlock(ddsd.lpSurface);
}
}
direct draw в midi окне api
в midi окне рисует всякие линии и точки с помощью direct draw используя api(без mfc)
спасибо
вот нашел простенький пример в инете, только он работал на полный экран, я немного поисправлял его и теперь в окне...только проблема рисует он все еще на весь экран поверх всех окон...а как это исправить не знаю...