|
-
Jun 22nd, 2001, 11:14 PM
#1
Thread Starter
PowerPoster
please look at this simple code!
Ok I quit programming for one month and now i started again so here i wrote my empty window program:
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT imsg, WPARAM wparam, LPARAM lparam)
{
switch(imsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, imsg, wparam, lparam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
MSG msg;
HWND winhwnd;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "mycalss";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Error in Class Registeration", "Error", MB_OK);
return 0;
}
winhwnd = CreateWindow("myclass", "the title", WS_OVERLAPPEDWINDOW,
0,0,34,34,NULL,NULL,hInstance,NULL);
if(winhwnd == NULL)
{
MessageBox(NULL, "Error Creating Hwnd", "Error", MB_OK);
return 0;
}
ShowWindow(winhwnd, nShowCmd);
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Can you please get the error in there because when i run the program, it give me the messagebox saying "Error Creating Hwnd".
Thanks!
-
Jun 22nd, 2001, 11:26 PM
#2
Hyperactive Member
Found it!
Here:
Code:
wc.lpszClassName = "mycalss";
That is what the classname is, and here:
Code:
winhwnd = CreateWindow("myclass", "the title", WS_OVERLAPPEDWINDOW,
0,0,34,34,NULL,NULL,hInstance,NULL);
the classnames are different. i changed them, and it worked
Amon Ra
The Power of Learning.
-
Jun 22nd, 2001, 11:27 PM
#3
Hyperactive Member
just make them the same
Amon Ra
The Power of Learning.
-
Jun 22nd, 2001, 11:37 PM
#4
Thread Starter
PowerPoster
I did not get that!
I did not get that. How come the class name "myclass" was different in the class and hwnd. I used the same name!
And here is a kind of new version of that. It gives the same error!
Code:
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT imsg, WPARAM wparam, LPARAM lparam)
{
switch(imsg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, imsg, wparam, lparam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wc;
MSG msg;
HWND winhwnd;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "mycalss";
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "Error in Class Registeration", "Error", MB_OK);
return 0;
}
winhwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
"myclass",
"the title",
WS_OVERLAPPEDWINDOW,
0,
0,
340,
304,
NULL,
NULL,
hInstance,
NULL);
if(winhwnd == NULL)
{
MessageBox(NULL, "Error in hwnd Registeration", "Error", MB_OK);
return 0;
}
ShowWindow(winhwnd, nShowCmd);
UpdateWindow(winhwnd);
while(GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
Please tell me the exact error!
-
Jun 22nd, 2001, 11:40 PM
#5
Hyperactive Member
no...
One of them is "mycalss" and the other is "myclass". Spelling mistake
Amon Ra
The Power of Learning.
-
Jun 22nd, 2001, 11:40 PM
#6
Thread Starter
PowerPoster
sorry!
Oh yes i got that the class names were like that
mycalss
myclass
May I was sleeping at that time!
THanks a lot buddy
-
Jun 22nd, 2001, 11:42 PM
#7
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|