   Problem with if condition
  Why should if condition not work as expected?m_pSWindow->pSButton is a pointer to struct with data which isn't NULL.FOLLOWING DOESN'T WORK:1. if (m_pSWindow->pSButton != NULL)BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);2. if (m_pSWindow->pSButton == NULL)BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);3. if (m_pSWindow->pSButton != NULL)BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);else{}AND THIS WORKS:1. BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);2. if (m_pSWindow->pSButton != NULL)BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);elseBitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);I tried to combine messagebox with if statement, but it just freezes the window.Any idea why this is happening?Have a good day!Martin   
  Your second if statement uses == but it should be !=.   ;  woah, code can get pretty messy O.o All those m's and W's make me dizzy. Anyway, let me understand what you are trying to do here.m_pSWindow->pSButton is a pointer that is not NULL. Let's say then that it points to address 0x0001 (for the sake of the example).Statement 1:if (m_pSWindow->pSButton != NULL) should in this case be true (assuming the memory space at 0x0001 is not empty). You basically have this going on : if (value at 0x0001 does not equal "zero"). If either the value at 0x0001 is NULL or the pointer itself is a NULL pointer (points to 0x0000), the if statement will be false.I'm going to assume that the pieces of code after "AND THIS WORKS:" are "corrections" to their respective failed code (1 to 1 and 2 to 2, etc.). This probably means that the pointer you are trying to process is in fact NULL or it points to memory that is empty. Why that is I leave to you to figure out :d.I hope I got it XD I'm pretty noobish at programming myself   ;  The problem is, that pointer is not NULL, but even if I write == NULL, or != NULL it still doesn't get executed. Examples in AND THIS WORKS are random, just like in FOLLOWING DOESN'T WORK.Here I wanted to show, that both conditions aren't executed:1. if (m_pSWindow->pSButton != NULL)2. if (m_pSWindow->pSButton == NULL)That's the main problem, if it isn't NULL and it isn't not NULL, then wtf is it???   ;  I can almost garuntee you that the compiler isn't broken. And if the compiler isn't broken, it must be your code. Why don't you copy + paste the function (without editting it, or 'cleaning it up') that has this problem in it? Post it surrounded by [ source] and [ /source] tags.A suggestion: Use brackets after an 'if' statement, like this:if(...){    //My code...}Especially when you are encountering errors like this, use brackets. Even if it's just one line; sometimes it's easy to make a mistake that can be hard to spot.Also, double check that the variable is actually initialized to NULL. Remember it doesn't start off NULL, just as ints don't start off at 0.   ;Quote:Original post by MarusuThe problem is, that pointer is not NULLWhich pointer?  m_pSWindow, m_pSWindow->pSButton, or this?   ;  EDIT: Nvm, I'm an idiot >.>[Edited by - boogyman19946 on May 16, 2010 7:34:03 PM];  No, boogyman19946, you're not an idiot ;)"Which pointer? m_pSWindow, m_pSWindow->pSButton, or this?"m_pSWindow->pSButtonHere's the code. Only WinProc function from my win32 wrapper.I can post more if you want.LRESULT CALLBACK Win32::WinProc(HWND hWindow, UINT iMessage, WPARAM wParam, LPARAM lParam){WindowChangeFocus(hWindow);switch (iMessage){case WM_CREATE:{//MessageBox (hWindow, TEXT("Window has been successfully created"), TEXT("Succes"), MB_OK);return 0;}case WM_ACTIVATE:{return 0;}case WM_CAPTURECHANGED:{return 0;}case WM_SIZE:{m_pSWindow->iWidth = LOWORD(lParam);m_pSWindow->iHeight = HIWORD(lParam);InvalidateRect(m_pSWindow->hWindow, NULL, NULL);return 0;}case WM_MOUSEMOVE:{m_iCursorX = LOWORD(lParam);m_iCursorY = HIWORD(lParam);if (m_pSWindow->pSButton != NULL && m_iCursorX > m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50 && m_iCursorX < m_pSWindow->iWidth - 50 && m_iCursorY > m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50 && m_iCursorY < m_pSWindow->iHeight - 50)SetCursor(LoadCursor(NULL, IDC_HAND));return 0;}case WM_LBUTTONDOWN:if (m_pSWindow->pSButton != NULL && m_iCursorX > m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50 && m_iCursorX < m_pSWindow->iWidth - 50 && m_iCursorY > m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50 && m_iCursorY < m_pSWindow->iHeight - 50)PostQuitMessage(0);return 0;case WM_PAINT:{// Begin paintm_pSWindow->hdcWindow = BeginPaint(m_pSWindow->hWindow, &m_pSWindow->psWindow);FillRect(m_pSWindow->hdcWindow, &m_pSWindow->psWindow.rcPaint, (HBRUSH)CreateSolidBrush(RGB(255, 255, 255))); // Fill screen with white color, helps to remove trails of button, while resizeing windowm_pSWindow->psWindow.fErase = FALSE;if (m_pSWindow->bPaint)DrawText(m_pSWindow->hdcWindow, m_pSWindow->wssText.str().c_str(), m_pSWindow->wssText.str().length(), &m_pSWindow->rcText, DT_WORDBREAK | DT_VCENTER);if (m_pSWindow->pSButton != NULL && m_pSWindow->bPaint){BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);}//else//BitBlt(m_pSWindow->hdcWindow, m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50, m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50, m_pSWindow->pSButton->iWidth, m_pSWindow->pSButton->iHeight, m_pSWindow->pSButton->hdcButton, 0, 0, SRCCOPY);// End PaintEndPaint(m_pSWindow->hWindow, &m_pSWindow->psWindow);return 0;}case WM_CLOSE:{if (MessageBox(hWindow, L"Are you sure you want to close the window?", L"Close Window", MB_YESNO) == IDYES){DestroyWindow(hWindow);}return 0;}case WM_DESTROY:{PostQuitMessage(0);return 0;}default:return DefWindowProc (hWindow, iMessage, wParam, lParam);}};  does it need to be likeif ( (m_pSWindow->pSButton != NULL) && m_pSWindow->bPaint)?   ;  You are not making this easy on yourself.When your code look like this ... you are doing something wrong, and it's not just that not everyone uses 24 inch widescreen monitors with an 8 point font size:case WM_MOUSEMOVE:{m_iCursorX = LOWORD(lParam);m_iCursorY = HIWORD(lParam);if (m_pSWindow->pSButton != NULL && m_iCursorX > m_pSWindow->iWidth - m_pSWindow->pSButton->iWidth - 50 && m_iCursorX < m_pSWindow->iWidth - 50 && m_iCursorY > m_pSWindow->iHeight - m_pSWindow->pSButton->iHeight - 50 && m_iCursorY < m_pSWindow->iHeight - 50)SetCursor(LoadCursor(NULL, IDC_HAND));return 0;}Assuming C rather than C++, here is an improvement:case WM_MOUSEMOVE:{SomeTypeHere *button = m_pSWindow->pSButton;int x, y;m_iCursorX = LOWORD(lParam);m_iCursorY = HIWORD(lParam);x = m_pSWindow->iWidth  - m_iCursorX - 50;y = m_pSWindow->iHeight - m_iCursorY - 50;if (button != NULL && x > 0 && x < button->iWidth    && y > 0 && y < button->iHeight)SetCursor(LoadCursor(NULL, IDC_HAND));return 0;}Doesn't that look much nicer?!When you code looks like this, you're far more likely to spot your own bugs.Note that I'm still not comfortable with the repetition of the 50 there. It is clearly a magic number and should be declared as such with an appropriate name.The boundary tests likely also aren't quite right. The greater-than's should probably be greater-than-or-equal-to, not that it tends to matter much when it's only used for mouse coordinates.Repeat after me: "Repetition is a bad thing... Repetition is a bad thing..."   