Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch statement use

Should i use this form of switch statement:

  switch(msg)
  {
    case WM_LBUTTONDOWN:
    {
           char szFileName[MAX_PATH];
           HINSTANCE hInstance = GetModuleHandle(NULL);
           GetModuleFileName(hInstance, (LPWCH)szFileName, MAX_PATH);
           MessageBox(hwnd, (LPCWSTR)szFileName, L"This program is:", MB_OK | MB_ICONINFORMATION);
    }
    break;

    case WM_CLOSE:
        DestroyWindow(hwnd);
    break;
    case WM_DESTROY:
        PostQuitMessage(0);
    break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
  }
  return 0;

or make a function for the first case constant ?

like image 657
RaouL Avatar asked Jun 30 '26 23:06

RaouL


2 Answers

There's nothing wrong with how you have it, but it's probably cleaner code to call a function so you can keep your functions a reasonable size.

like image 170
Brian R. Bondy Avatar answered Jul 03 '26 12:07

Brian R. Bondy


Also, take a look at message crackers

like image 23
Nemanja Trifunovic Avatar answered Jul 03 '26 14:07

Nemanja Trifunovic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!