Gosh and now I am stuck again.

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
148
149
150
151
152
153
154
155
156
#include <windows.h>
#include <tchar.h>
#include "drawing.h"

//adds windows styling
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

//constant control identifiers
#define EXITBUTTON 101


//globals
RECT rc;
HWND hWndButton;
HWND hWnd;
int posX = 0;
int posY = 0;

//This is where it all happens
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	

	switch (message)
	{
	case WM_CREATE:
	{
		//add controls on window creation message
		hWndButton = CreateWindowEx(
			NULL,
			_T("BUTTON"),
			_T("Exit"),
			WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
			posX,
			posY,
			80,
			26,
			hWnd,
			(HMENU) 101,
			GetModuleHandle(NULL),
			NULL);
		//end of Exit button

		//enter drawing class passing window handle
		drawing draw = drawing(&hWnd);
	}
		break;
	//control message processing
	case WM_COMMAND:
	{
		//switch process depending on control ID
		switch (LOWORD(wParam))
		{
		case EXITBUTTON:
			PostQuitMessage(0);
			break;
		}
	}
		break;
	// Position stuff when window size changes
	case WM_SIZE:
		GetClientRect(hWnd, &rc);
		posX = rc.right - 90;
		posY = rc.bottom - 36;
		MoveWindow(hWndButton, posX, posY, 80, 26, true);
		break;
	//client exit control on window
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	//if nothing happens pass it on to the default windows procedure
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}


//
// Application entry point
//
int WINAPI WinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR lpCmdLine,
	int nCmdShow) {
	
	
	//
	// create window class structure
	//
	WNDCLASSEX wcex;
	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = _T("mainWindowClass");
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	//register window
	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,
			_T("Call to RegisterClassEx failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	//
	//actually create the window
	//
	hWnd = CreateWindow(
		_T("mainWindowClass"),
		_T("Steve's Window!"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT,
		500, 400,
		NULL,
		NULL,
		hInstance,
		NULL
		);
	if (!hWnd)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);
		return 1;
	}
	//show and update the created window
	ShowWindow(hWnd,nCmdShow);
	UpdateWindow(hWnd);

	//
	//Enter the message loop
	//
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int)msg.wParam;
}

1
2
3
4
5
6
7
8
#pragma once
class drawing
{
public:
	HWND* mainHandle;
	drawing(HWND *handle);
};

1
2
3
4
5
6
7
8
9
#include "drawing.h"
#include <d2d1.h>
#include <windows.h>


drawing::drawing(HWND *handle)
{
	mainHandle = handle;
}


this seems to kick out a bundle of errors and I though it was really simple.

All I am trying to do is pass a handle to my main window so that my drawing class can go to work on it?

This must be a real newbie issue?
this seems to kick out a bundle of errors
If you want help with them, you should post the actual errors.

Also, please list the compiler that you're using.
oh yeah errors might be of use..

Error 1 error C2143: syntax error : missing ';' before '*'
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 3 error C2061: syntax error : identifier 'HWND'
Error 4 error C2511: 'drawing::drawing(HWND *)' : overloaded member function not found in 'drawing'
Error 5 error C2065: 'mainHandle' : undeclared identifier

using Visual Studio Express 2013 for Windows Desktop
Last edited on
I think all of your errors are tied to line 8 on the very last box you posted:

1
2
3
4
5
6
7
8
9
#include "drawing.h"
#include <d2d1.h>
#include <windows.h>


drawing::drawing(HWND *handle)
{
	mainHandle = handle;
}


wouldn't it have to be

drawing::mainHandle=handle;?

I'm confused by the need for the drawing function if all it does is set the value to mainHandle. Maybe if mainHandle was a private variable it'd make sense.

It's been a while since I've read up on this but I'm fairly sure that your problem is with the way you are declaring mainHandle.
What I am trying to do is pass the handle for the window to the drawing class so the functions I am going to write in that class can add items to the main window.

I thought passing the Handle as a pointer and storing it in a variable within the drawing class would allow me to use it for multiple things?
You can, but mainHandle isn't declared in the drawing function. It doesn't automatically read/recognize mainHandle from the drawing class.

That's why you need scope operators.

I haven't tried to compile it and I know little of drawing but I think your problem is the mainHandle.. figured I'd take a shot in the dark and see if it helped.
1
2
3
4
5
6
7
8
9
#include "drawing.h"
#include <d2d1.h>
#include <windows.h>


drawing::drawing(HWND *handle)
{
	drawing::mainHandle = handle;
}


That didn't work...
maybe line 47 should be

 
		drawing.drawing(&hWnd);


I think my first suggestion was wrong now that I think on it.
Last edited on
AHHHHHHHHHHHHHHHH!

Simple fix forgot to include <windows.h> in the header file so it didn't know what it was reserving space for....
Now it has compiled and I now have a handle to my window that I can now give to directx to mess around with yipee!

Thank You!
You should just pass handles by value, as handles themselves are references to larger data structures.
Topic archived. No new replies allowed.