Author Topic: Weird WinAPI problem  (Read 8977 times)

Offline mandrav

  • Project Leader
  • Administrator
  • Lives here!
  • *****
  • Posts: 4291
    • Code::Blocks IDE
Re: Weird WinAPI problem
« Reply #15 on: March 06, 2006, 09:01:39 pm »
What exactly did that prove other than they are very similar calls? One has a few more arguments, so what?  :? (I'm not trying to do a win32 vs WX here, I was just curious). I wanted to see an example of actually getting something done.

I think you 're comparing oranges to apples here...

wxWidgets (like any other toolkit) takes away the need to manually manage memory resources. This fact alone should make this discussion stop right here.
There's not much to talk about. Use whatever you feel like it's better for the job. Really.

I 've seen all kinds of holly wars going on in various forums. But praising the Winapi? That's a first ;)!
Sorry, I couldn't resist :lol:
« Last Edit: March 06, 2006, 09:03:11 pm by mandrav »
Be patient!
This bug will be fixed soon...

sethjackson

  • Guest
Re: Weird WinAPI problem
« Reply #16 on: March 06, 2006, 09:05:54 pm »
Yeah use whatever you want to. Lets not start a war or something. :D I like wx because it is cross-platform. Code once run everywhere (mostly).
Like Yiannis said you are the first person to praise the Win32 API that I know of. :lol:

Offline Vampyre_Dark

  • Regular
  • ***
  • Posts: 255
  • Hello!
    • Somewhere Over The Rainbow...
Re: Weird WinAPI problem
« Reply #17 on: March 06, 2006, 10:19:13 pm »
No war whatsoever guys.

Here is some code where I ineract with some buttons on my game's config program to choose resolution. It uses the win32 api to interact with the various controls on the dialog. It's fairly straightforward and clean:
Code: [Select]
    //get the resolution selection
    LRESULT ResSel = SendMessage(hListRes,LB_GETCURSEL,0,0);
    if (ResSel == LB_ERR) nRes = 0;
    else nRes = ResSel;

    if (IsDlgButtonChecked(hMain,IDC_CHK_FULLSCREEN) == BST_CHECKED)
        bFullScreen = true;
            else bFullScreen = false;

    if (IsDlgButtonChecked(hMain,IDC_CHK_VSYNC) == BST_CHECKED)
        bVSync = true;
            else bVSync = false;

    if (IsDlgButtonChecked(hMain,IDC_CHK_SOUND) == BST_CHECKED)
        bSound = true;
            else bSound = false;


Here is quick code where I toggle back the default values, once again very clean.
Code: [Select]
void DefaultConfig(void)
{
    CheckDlgButton(hMain,IDC_CHK_FULLSCREEN,BST_CHECKED);
    CheckDlgButton(hMain,IDC_CHK_VSYNC,BST_CHECKED);
    CheckDlgButton(hMain,IDC_CHK_SOUND,BST_CHECKED);

    SendMessage(hListRes,LB_SETCURSEL,0,0);

    return;
}

The base of the program couldn't be simpler...

Code: [Select]
int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpszArg, int nStyle)
{

    //load the config dialog
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DLG1), NULL, (DLGPROC)DlgProc);

    return 0;
}


LRESULT CALLBACK DlgProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{

    HRESULT hRes;

    switch(Msg)
    {

        case WM_INITDIALOG:
        {
            //grab all the controls, and toggle
            //their default states
            hMain = hWnd;

            hListRes = GetDlgItem(hMain,IDC_RESLIST);
            hChkFullScreen = GetDlgItem(hMain,IDC_CHK_FULLSCREEN);
            hChkVSync = GetDlgItem(hMain,IDC_CHK_VSYNC);
            hChkSound = GetDlgItem(hMain,IDC_CHK_SOUND);

            BuildList();

            //if the config file cannot be loaded,
            //set the default options
            DefaultConfig();

            LoadConfig();

        }break;


        case WM_COMMAND:
        {
            switch( LOWORD(wParam) )
            {


                case IDC_BTN_SAVE:
                {
                    SaveConfig();
                    EndDialog(hMain,0);
                    break;
                }


                case IDC_BTN_CANCEL:
                {
                    EndDialog(hMain,0);
                    break;
                }


                case IDC_BTN_DEFAULT:
                {
                    DefaultConfig();
                    break;
                }


            }break;
        }

        //window being destroyed
        case WM_CLOSE:
        case WM_QUIT:
        case WM_DESTROY:
        {
            EndDialog(hMain,0);
            break;
        }

        default:
            return false; // Didn't handle message
    }

    return true;
}

I've written lots of little things over the past year since I got more comfortable with win32 api, and it's all simple and clean. I have something that is way more complicated archived around here somewhere with tabbed pages inside a dialog and all this other junk and it's still clean and straightforward.  :|
C::B Wishlist
~BOYCOTT THE EVIL YELLOW BOXES~

Offline TDragon

  • Lives here!
  • ****
  • Posts: 936
    • Twilight Dragon Media
Re: Weird WinAPI problem
« Reply #18 on: March 06, 2006, 10:33:36 pm »
Don't make me post my Win32 and wxWidgets versions of the level editor for my 2d side-scroller game. There is a marked difference between the two with respect to the amount of code, the simplicity of the code, and the functionality of the final product. The wxWidgets version wins hands down. Some places these really come into play are in properly arranging the toolbar and child editor windows (not more than 10 lines of code total, and everything adjusts itself when the parent window changes), and in scrolling the child editor windows (not more than 5 lines of code per child window). And I don't have to code all the hacks to make the scrolling work properly, because the creators of wxWidgets already did for me.
http://tdm-gcc.tdragon.net/ - TDM-GCC compiler suite for Windows (GCC 5.1.0 2015-06-28, 32/64-bit, no extra DLLs)

Offline kkez

  • Almost regular
  • **
  • Posts: 153
    • WinapiZone
Re: Weird WinAPI problem
« Reply #19 on: March 07, 2006, 01:01:16 pm »
I think it's only a mess when you are new to it.  :? You learn to do a cleaner job in time. My first win32 programs were messes all over the place, because I was new to it, and I didn't understand it as much. After you've been usng it awhile, you start to understand more how everything works together, and it becomes more clean and organised as a result.
*
I totally agree with you :)