Skip to main content
GameDev.net gamedev.net
🔒 Locked

Winapi ...

Started by TIMPAN Jan 23, 2006 at 1:06 PM 11 replies 2.5k views
Original Post
TIMPAN
TIMPAN
Okay, there is no error or nothing but the window dosent got away when I quit it // SRC #include LRESULT CALLBACK WndProc (HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lparam); HWND GmaWindow (int SizeX, int SizeY,LPCSTR WindowName,HINSTANCE wndH); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE pInstance,PSTR cmdc,int cmdshow) { MSG Messages; HWND hWnd = GmaWindow(300,300,"Slugther",hInstance); while(1) { if(GetMessage(&Messages,0,0,0)) { TranslateMessage(&Messages); DispatchMessage(&Messages); } else { } } UnregisterClass("NEXT",hInstance); return Messages.wParam; } LRESULT CALLBACK WndProc (HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lparam) { switch(Msg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CLOSE: PostQuitMessage(0); break; } return DefWindowProc(hwnd,Msg,wParam,lparam); } HWND GmaWindow (int SizeX, int SizeY,LPCSTR WindowName,HINSTANCE wndH) { HWND WindowSly; WNDCLASSEX wndClassEx = {0}; wndClassEx.cbSize = sizeof(wndClassEx); wndClassEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wndClassEx.hInstance = wndH; wndClassEx.lpfnWndProc = WndProc; wndClassEx.style = CS_VREDRAW | CS_HREDRAW; wndClassEx.lpszClassName = "NEXT"; RegisterClassEx(&wndClassEx); WindowSly = CreateWindowEx(NULL,"NEXT",WindowName,WS_OVERLAPPED, 350, 200 , SizeX, SizeY, 0, 0, wndH, 0); if(!WindowSly) MessageBox(NULL,"Error in registering part of the window","ERROR",MB_OK); UpdateWindow(WindowSly); ShowWindow(WindowSly,1); return WindowSly; } yes it's kinda bad done, but that is cuz I redidit a million times and this is the product. Anyways, the window quits or so it seems, its still active. So when I press Ctrl+Alt+Del and choose process I can see it but not in running processes ? crazy, wacky hack :-) no but please help !
TIMPAN
TIMPAN
how do I do code tags ?
TIMPAN
TIMPAN
#include <windows.h>LRESULT CALLBACK WndProc (HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lparam);HWND GmaWindow (int SizeX, int SizeY,LPCSTR WindowName,HINSTANCE wndH);int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE pInstance,PSTR cmdc,int cmdshow){MSG Messages;HWND hWnd = GmaWindow(300,300,"Slugther",hInstance);while(1){if(GetMessage(&Messages,0,0,0)){TranslateMessage(&Messages);DispatchMessage(&Messages);}else{}}UnregisterClass("NEXT",hInstance);return Messages.wParam;}LRESULT CALLBACK WndProc (HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lparam){switch(Msg){case WM_DESTROY: PostQuitMessage(0); break;case WM_CLOSE: PostQuitMessage(0); break;}return DefWindowProc(hwnd,Msg,wParam,lparam);}HWND GmaWindow (int SizeX, int SizeY,LPCSTR WindowName,HINSTANCE wndH){HWND WindowSly;WNDCLASSEX wndClassEx = {0};wndClassEx.cbSize = sizeof(wndClassEx);wndClassEx.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);wndClassEx.hInstance = wndH;wndClassEx.lpfnWndProc = WndProc;wndClassEx.style = CS_VREDRAW | CS_HREDRAW;wndClassEx.lpszClassName = "NEXT";RegisterClassEx(&wndClassEx);WindowSly = CreateWindowEx(NULL,"NEXT",WindowName,WS_OVERLAPPED,350, 200 , SizeX, SizeY, 0, 0, wndH, 0);if(!WindowSly) MessageBox(NULL,"Error in registering part of the window","ERROR",MB_OK);UpdateWindow(WindowSly);ShowWindow(WindowSly,1);return WindowSly;}
TIMPAN
TIMPAN
this must really be a hard one !
TIMPAN
TIMPAN
Tried both: it does not work, it still shows up after being closed down in the process list.
glat
glat
The problem is that you are not quitting your program when GetMessage returns 0. Try changing your message loop to:
while(GetMessage(&Messages,0,0,0) > 0){    TranslateMessage(&Messages);    DispatchMessage(&Messages);}
Brian Jones
Brian Jones
Also there appears to be no way out of your event loop. Try adding a break command in your else block.
I don't have a signature
TIMPAN
TIMPAN
Ohh glat & Brian Jones thanks ! now I can finally go to bed ... :-) thanks ! wont forget this
Peter Conn
Peter Conn
Hiya, just a little note:

Quote:

while(GetMessage(&Messages,0,0,0) > 0)
{
TranslateMessage(&Messages);
DispatchMessage(&Messages);
}


You can just use:

while(GetMessage(&Messages,0,0,0))
{
TranslateMessage(&Messages);
DispatchMessage(&Messages);
}

I know it isn't anything major, just saves an ever so little bit of typing.
Whether you think you can or think you can’t, you’re probably right – Henry Ford
Colin Jeanne
Colin Jeanne
But it's not correct since GetMessage() will return -1 on an error.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.