Why won't the window appear?

I made a class and a few functions to simplify winapi programming, but after I added it to the code, the window stopped appearing... So, does anyone know what's wrong?

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
#include <windows.h>

struct window;

LRESULT CALLBACK easywin_defproc(window&,UINT,WPARAM,LPARAM);

struct window{
	WNDCLASSEX wndclass;
	char* text;
	HWND hwnd;
	int x,y;
	int width,height;
	window():text(NULL),hwnd(0),x(-1),y(-1),width(0),height(0){
		wndclass.cbSize=sizeof(WNDCLASSEX);
		wndclass.style=CS_HREDRAW|CS_VREDRAW;
		wndclass.lpfnWndProc=NULL;
		wndclass.cbClsExtra=0;
		wndclass.cbWndExtra=0;
		wndclass.hInstance=GetModuleHandle(0);
		wndclass.hIcon=NULL;
		wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
		wndclass.hbrBackground=(HBRUSH)GetStockObject(LTGRAY_BRUSH);
		wndclass.lpszMenuName=NULL;
		wndclass.lpszClassName=NULL;
		wndclass.hIconSm=NULL;}
	window(WNDCLASSEX wc):text(NULL),hwnd(0),x(-1),y(-1),width(0),height(0){
		wndclass=wc;
		RegisterClassEx(&wndclass);}
	window(WNDCLASS wc):text(NULL),hwnd(0),x(-1),y(-1),width(0),height(0){
		wndclass=*(WNDCLASSEX*)(&wc+1);
		wndclass.cbSize=sizeof(WNDCLASSEX);
		wndclass.hIconSm=NULL;
		RegisterClassEx(&wndclass);}
	bool set_vars(char* class_name,LRESULT CALLBACK (*wndproc)(HWND,UINT,WPARAM,LPARAM),HBRUSH bground,HICON icon=NULL,HICON smicon=NULL){
		wndclass.lpszClassName=class_name;
		wndclass.lpfnWndProc=wndproc;
		wndclass.hbrBackground=bground;
		wndclass.hIcon=icon;
		wndclass.hIconSm=smicon;
		return RegisterClassEx(&wndclass);}
	bool create(int X,int Y,int W,int H,UINT style,char* title=NULL,HWND parent=NULL,HMENU menu=NULL){
		text=title;
		x=X;
		y=Y;
		width=W;
		height=H;
		hwnd=CreateWindowEx(0,wndclass.lpszClassName,title,style,X,Y,W,H,parent,menu,wndclass.hInstance,NULL);
		return hwnd!=NULL;}};

LRESULT CALLBACK DispatchMessage(window& win,MSG* msg){
	return easywin_defproc(win,msg->message,msg->wParam,msg->lParam);}

LRESULT CALLBACK easywin_defproc(window& win,UINT msg,WPARAM wparam,LPARAM lparam){
	switch(msg){
		case WM_MOVE:
			win.x=LOWORD(lparam);
			win.y=HIWORD(lparam);
			break;
		case WM_SIZE:
			if(wparam==SIZE_RESTORED){
				win.width=LOWORD(lparam);
				win.height=HIWORD(lparam);}
			break;
		case WM_SETTEXT:
			win.text=(char*)lparam;
			break;}
	return win.wndclass.lpfnWndProc(win.hwnd,msg,wparam,lparam);}

LRESULT CALLBACK bmpsproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
	switch(msg){
		case WM_CLOSE:
			ShowWindow(hwnd,SW_HIDE);
			break;
		default:
			return DefWindowProc(hwnd,msg,wparam,lparam);}
	return 0;}

LRESULT CALLBACK piproc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
	//prints to debug window all the messages received
	printf("msg: %i\n",msg);
	switch(msg){
		case WM_CREATE:
			statusbar=CreateWindowEx(0,STATUSCLASSNAME,"",WS_CHILD|WS_VISIBLE,-100,-100,
10,10,hwnd,(HMENU)IDSB_STATUSBAR,GetModuleHandle(0),NULL);
			//this freezes the program (?)
			//toolbar=CreateToolbarEx(hwnd,WS_VISIBLE,IDTB_TOOLBAR,sizeof(tbbuttons),
GetModuleHandle(0),IDB_FILE,tbbuttons,sizeof(tbbuttons),24,24,24,24,sizeof(TBBUTTON));
			break;
		case WM_CLOSE:
			DestroyWindow(hwnd);
			break;
		case WM_SIZE:
			if(wparam==SIZE_RESTORED){
				SendMessage(statusbar,WM_SIZE,0,0);
				SendMessage(toolbar,WM_SIZE,0,0);}
			break;
		case WM_MOUSEMOVE:
			sprintf(mouse_pos,"(%i,%i)",LOWORD(lparam),HIWORD(lparam));
			SendMessage(statusbar,SB_SETTEXT,1,(LPARAM)mouse_pos);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_PAINT:
			hdc=BeginPaint(hwnd,&ps);
			img.draw(0,0,hdc);
			EndPaint(hwnd,&ps);
			break;
		default:
			return DefWindowProc(hwnd,msg,wparam,lparam);}
	return 0;}

int WINAPI WinMain(HINSTANCE hinst,HINSTANCE hprev,LPSTR cmdline,int cmdshow){
	//variable declaration
	MSG msg;
	//register the class
	win.set_vars("PiPaint",piproc,(HBRUSH)GetStockObject(LTGRAY_BRUSH),
(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,48,48,0),
(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,16,16,0));
	win.create(CW_USEDEFAULT,CW_USEDEFAULT,640,480,WS_OVERLAPPEDWINDOW,"PiPaint");
	win.set_vars("BMPsettings",bmpsproc,(HBRUSH)GetStockObject(LTGRAY_BRUSH),
(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,48,48,0),
(HICON)LoadImage(hinst,MAKEINTRESOURCE(MAINICON),IMAGE_ICON,16,16,0));
	//main loop
	while(GetMessage(&msg,win.hwnd,0,0)){
		TranslateMessage(&msg);
		DispatchMessage(win,&msg);}
	return msg.wParam;}


I overloaded the DispatchMessage function to accept a window reference, and had it call easywin_defproc to update variables and from there call the function that the user gave. I really don't see why it isn't showing up...

I also had it print out all of the messages it was receiving (piproc), and it gave this:

WM_GETMINMAXINFO - 36
WM_NCCREATE - 129
WM_NCCALCSIZE - 131
WM_CREATE - 1
WM_NOTIFYFORMAT - 85
WM_QUERYUISTATE - 297
WM_PARENTNOTIFY - 528
Last edited on
You don't ShowWindow after creating it.
Oh, derr. Thanks!
Topic archived. No new replies allowed.