Hello,
I am in the process of learning to code for windows and I am following examples out of a book (Beginning Game Programming Second Edition by Jonathan S. Harbour), but unfortunately one of these examples uses SetPixel function. So when I create a window and try to draw a line, lets say across the window. It seems that on computer it only draws half of the line and other side is blank. Does anyone know what might cause this?
I am using Visual Studio 2008, Direct X 11.0
Link to screen shot of what I see:
[
My Screen]
Update: Code Listed below
#include<windows.h>
#include<stdlib.h>
#include<time.h>
#define APPTITLE "Hello World"
BOOL InitInstance(HINSTANCE, int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WinProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char *szHello = "Hello World!";
RECT rt;
int x, y, n;
COLORREF c;
switch (message)
{
case WM_PAINT:
GetClientRect(hWnd, &rt);
hdc = BeginPaint (hWnd, &ps);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
c = RGB(0, 0, 0);
y = 300;
for(x=0; x <= 1280; x++)
{
SetPixel(hdc, x, y, c);
}
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIconSm = NULL;
return RegisterClassEx(&wc);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hWnd = CreateWindow(
APPTITLE, APPTITLE, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1280, 720, NULL, NULL, hInstance, NULL);
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
MyRegisterClass(hInstance);
if(!InitInstance (hInstance, nCmdShow))
return FALSE;
srand(time(NULL));
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}