I noticed that when I close my window it is still in the active process's list when I hit ctrl-alt-del on my XP box. This happens no matter what except when i try to debug. Anyone know why it happens? Well ill post the code here:
Main.cpp
CBWin.HCode:int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { CBWin cWin = CBWin(hInstance, "My Window", 300,300, 300, 200); if(!cWin.Create(WS_OVERLAPPED | WS_SYSMENU, WS_EX_APPWINDOW)) { return(0); } cWin.Show(SW_SHOW); //::UpdateWindow(cWin.GetHandle()); MSG msg; HWND hWnd = cWin.GetHandle(); while(::GetMessage(&msg,hWnd,0,0)) { if(!IsDialogMessage(hWnd,&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return(msg.wParam); }
and CBWin.cppCode:#ifndef __CBWIN_H__ #define __CBWIN_H__ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include<Windows.h> #include<string> using std::string; #define CNAME "CBWIN" class CBWin{ public: CBWin(); //Pre: None //Post: CBWin(const HINSTANCE& hInstance, const string& strWindowName, const UINT& uiXPos, const UINT& uiYPos, const UINT& uiXSize, const UINT& uiYSize); ~CBWin(); //Pre: //Post: BOOL Create(const DWORD& dwStyle, const DWORD& dwExStyle); //Pre: //Post: BOOL Show(int nShow); //Pre: //Post: const HWND& GetHandle() const; private: //typedef unsigned int UINT; HWND hCBWin; HINSTANCE hInst; string strWName; UINT uiWidth; UINT uiHeight; UINT uiX; UINT uiY; BOOL bInitFail; // True indicates creation faiure BOOL RegisterWindow(); //Pre: Takes a UINT parameter representing styles to add to the WNDCLASSEX struct //Post: Registers a default window w/ styles of CS_OWNDC, CS_VREDRAW, CS_HREDRAW, // CS_DBLCLKS, returns TRUE if reigstration was successful BOOL BuildWindow(const DWORD& dwStyle,const DWORD& dwExStyle); //Pre: Recieves two DWORDS, the window style and the extended window style //Post: Returns TRUE if the Creation was succesful, FALSE if not static LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); protected: virtual LRESULT CALLBACK WindowProc(const HWND& hWnd, const UINT& Msg, const WPARAM& wParam, const LPARAM& lParam); //Pre: //Post: }; #endif
Thanks in advance if you see why this doesnt work how it should.Code:#include"CBWin.h" CBWin::CBWin() : hCBWin(NULL), hInst(NULL), uiX(100), uiY(100), uiWidth(300), uiHeight(200), strWName("Window"), bInitFail(TRUE) { } CBWin::CBWin(const HINSTANCE& hInstance, const string& strWindowName, const UINT& uiXPos, const UINT& uiYPos, const UINT& uiXSize, const UINT& uiYSize) : hCBWin(NULL), hInst(hInstance), strWName(strWindowName), uiX(uiXPos), uiY(uiYPos), uiWidth(uiXSize), uiHeight(uiYSize), bInitFail(FALSE) { } CBWin::~CBWin() { ::UnregisterClass(CNAME,hInst); hCBWin = NULL; hInst = NULL; } BOOL CBWin::Create(const DWORD& dwStyle, const DWORD& dwExStyle) { if(!bInitFail && !RegisterWindow()) { bInitFail = TRUE; } if(!bInitFail && !BuildWindow(dwStyle,dwExStyle)) { bInitFail = TRUE; } return(!bInitFail); } BOOL CBWin::Show(int nShow) { BOOL bShow = TRUE; if(!::ShowWindow(hCBWin,nShow)) bShow = FALSE; return(bShow); } const HWND& CBWin::GetHandle() const { return hCBWin; } BOOL CBWin::RegisterWindow() { ::WNDCLASSEX wndClass; ZeroMemory(&wndClass,sizeof(WNDCLASSEX)); wndClass.cbSize = sizeof(WNDCLASSEX); wndClass.hInstance = hInst; wndClass.lpszClassName = CNAME; // Defined in CBWin.h wndClass.lpszMenuName = NULL; wndClass.hIcon = ::LoadIcon(NULL,IDI_APPLICATION); wndClass.hIconSm = ::LoadIcon(NULL,IDI_APPLICATION); wndClass.hbrBackground = (HBRUSH)COLOR_WINDOW; wndClass.hCursor = ::LoadCursor(NULL,IDC_ARROW); wndClass.lpfnWndProc = WndProc; wndClass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClassEx(&wndClass)) { ::MessageBox(NULL,"ERROR REGISTERING WNDCLASSEX","CRITICAL ERROR", MB_ICONERROR | MB_OK); return(FALSE); } return(TRUE); } BOOL CBWin::BuildWindow(const DWORD& dwStyle, const DWORD& dwExStyle) { if(!bInitFail) // if there was no problem registering the window { hCBWin = CreateWindowEx(dwExStyle, CNAME, // Class Name strWName.c_str(), // Window Name dwStyle, uiX, // X Pos uiY, // Y Pos uiWidth, // Width uiHeight, // Height NULL, // Handle to parent window NULL, // Handle to MENU hInst, // Application Instance (LPVOID)this); if(!hCBWin) { ::MessageBox(NULL,"ERROR CREATING WINDOW","CRITICAL ERROR", MB_ICONERROR | MB_OK); return(FALSE); } return(TRUE); } return(FALSE); } LRESULT CALLBACK CBWin::WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { static CBWin* pCWin; switch(Msg) { case WM_NCCREATE: { LPCREATESTRUCT lpCS = (LPCREATESTRUCT)lParam; pCWin = (CBWin*)lpCS->lpCreateParams; ::SetWindowText(hWnd,lpCS->lpszName); return(::DefWindowProc(hWnd,Msg,wParam,lParam)); } case WM_CLOSE: { ::DestroyWindow(hWnd); return(0); } default: { if(pCWin) { return(pCWin->WindowProc(hWnd,Msg,wParam,lParam)); } else return(::DefWindowProc(hWnd,Msg,wParam,lParam)); } } } LRESULT CALLBACK CBWin::WindowProc(const HWND& hWnd, const UINT& Msg, const WPARAM& wParam, const LPARAM& lParam) { switch(Msg) { case WM_DESTROY: { ::PostQuitMessage(0); return(0); } default: return(::DefWindowProc(hWnd,Msg,wParam,lParam)); } }



LinkBack URL
About LinkBacks



) and can be quite irritating. Anyway in your WinMain msg loop if you replace: