Strange Behavior While Doing Day 002

I am getting strange behavior while debugging my code during the stage 002 video. Here is a screen cap of exactly what is happening:

I am building my solution inside VS 2013 and i have checked to make sure the required libraries are referenced in the linker. Anyways here is my code:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/************************************************************
 $File: $
 $Date: $
 $Revision: $
 $Creator Bla $
 $Notice: (C) Copyright 2015 by Bla. All Rights Reserved
************************************************************/

#include <windows.h>

LRESULT CALLBACK WindowCallback(HWND window, UINT message, WPARAM wParameter, LPARAM lParameter){

	// holds result of message handling
	LRESULT result = 0;

	// perform an action based on the message
	switch (message)
	{
		// window resized
		case WM_SIZE:
		{
		}
		break;

		// window is destroyed
		case WM_DESTROY:
		{
		}
		break;

		// window is closed
		case WM_CLOSE:
		{
		}
		break;

		// window was clicked and has focus
		case WM_ACTIVATEAPP:
		{
		}
		break;

		// window is being drawn into
		case WM_PAINT:
		{
			// paint struct
			PAINTSTRUCT paint;

			// begin drawing
			HDC DeviceContext = BeginPaint(window, &paint);

			// get the x position of the first drawable position in the window 
			int x = paint.rcPaint.left;

			// get the y position of the first drawable position in the window
			int y = paint.rcPaint.bottom;

			// get the windows width
			int width = paint.rcPaint.right - paint.rcPaint.left;

			// get the windows height
			int height = paint.rcPaint.bottom - paint.rcPaint.top;

			// clear the window to white
			PatBlt(DeviceContext, x, y, width, height, WHITENESS);

			// end drawing
			EndPaint(window, &paint);
		}
		break;

		// if it's none of the above
		default:
		{
			result = DefWindowProc(window, message, wParameter, lParameter);
		}
		break;
	}

	//return the resault
	return result;
}

int CALLBACK WinMain(HINSTANCE instance, HINSTANCE previousInstance, LPSTR commandLine, int showCode) {

	// window class initiation
	WNDCLASS windowClass = {};

	// set window style (unique window context, redraw on resize)
	windowClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;

	windowClass.lpfnWndProc = WindowCallback;

	// set window instance
	windowClass.hInstance = instance;

	// set the window name
	windowClass.lpszClassName = "ScorpionSquadWindowClass";

	// initiate the window class
	if(RegisterClass(&windowClass))
	{
		// create the window handle
		HWND windowHandle = CreateWindowEx(0, windowClass.lpszClassName, "Scorpion Squad", WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, instance, 0);

		// if the window handle was created
		if (windowHandle)
		{
			// holds the current message in queue
			MSG message;

			// infinate message loop
			for (;;)
			{
				// start looking for messagws in the queue
				BOOL messageResult = GetMessage(&message, 0, 0, 0);

				// if the mesage result returns positive
				if (messageResult > 0)
				{
					// translate the message and prepare it for processing
					TranslateMessage(&message);

					// dispatch it to the window procedure
					DispatchMessage(&message);
				}
				// the message was negitave
				else
				{
					// so break out of the loop
					break;
				}
			}
		}
		// otherwise the window handle couldn't be created
		else
		{

		}
	}
	// otherwise the window clouldn't be registered
	else
	{

	}
	return 0;
}

Any assistance would be greatly appreciated.

Sincerely,

Scorpion Squad

Edited by Scorpion Squad on
Is your question about why windows looks "transparent" ?

Can you verify if WindowCalback is receiving WM_PAINT message? Step through with debugger and verify if DeviceContext, x, y, width and height variables have reasonable values.

EDIT: Oh, I see the problem - your value assigned to "y" is incorrect. For GDI coordinates start at top left corner. So y grows down. And your "y" value should be top coordinate, not bottom one:
1
int y = paint.rcPaint.top;

Edited by Mārtiņš Možeiko on

Is your question about why windows looks "transparent" ?

Can you verify if WindowCalback is receiving WM_PAINT message? Step through with debugger and verify if DeviceContext, x, y, width and height variables have reasonable values.

EDIT: Oh, I see the problem - your value assigned to "y" is incorrect. For GDI coordinates start at top left corner. So y grows down. And your "y" value should be top coordinate, not bottom one:
1
int y = paint.rcPaint.top;

Wow, i can't believe i missed that after watching the video over and over again trying to compare my code to his. :) Thanks for helping me out! B)

Sincerely,

Scorpion Squad