Thread: Problem trying to retrieve data from combo box! (strange issue)

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Post Problem trying to retrieve data from combo box! (strange issue)

    Hi there,

    This is a strange one and has me totally stumped. I may need to post quite a bit of code which I usually don't do but I think I'll need to for this one. A brief description of what I'm trying to do follows.

    I'm pulling data off the graphics adapter (card) and storing it in a vector that belongs to a class. Then I'm using that vector to load strings into a combo box and then backing it with the relevant data. The data is a width, a height, and a refresh rate all stored as unsigned integers.

    Here's a snippet from the class definition:

    Code:
    Microsoft::WRL::ComPtr<IDXGIFactory4>	mdxgiFactory;
    Microsoft::WRL::ComPtr<ID3D12Device>	md3dDevice;
    DXGI_FORMAT mBackBufferFormat = DXGI_FORMAT_R8G8B8A8_UNORM;
    std::vector<UINT> mResolutionPair;
    struct resData { UINT w = 0; UINT h = 0; UINT Hz = 0; };
    std::vector<resData> comboResData;
    mResolutionPair is where all the data goes. It takes 4 values at a time. Width, height, numerator, denominator. The numerator and denominator are divided to produce a refresh rate.

    This is a part of the function that fills out the mResolutionPair vector:

    Code:
    // Call with nullptr to get list count.
    output->GetDisplayModeList(mBackBufferFormat, flags, &count, nullptr);
    
    std::vector<DXGI_MODE_DESC> modeList(count);
    output->GetDisplayModeList(mBackBufferFormat, flags, &count, &modeList[0]);
    
    for (int i = 0; i < count; i++)
    {
    	UINT n = modeList[i].RefreshRate.Numerator;
    	UINT d = modeList[i].RefreshRate.Denominator;
    
    	if ( mSetRefresh && ((n / d) == 60) )
    	{
    		mResolutionPair.push_back(modeList[i].Width);
    		mResolutionPair.push_back(modeList[i].Height);
    		mResolutionPair.push_back(n);
    		mResolutionPair.push_back(d);
    	}
    	else if (!mSetRefresh)
    	{
    		mResolutionPair.push_back(modeList[i].Width);
    		mResolutionPair.push_back(modeList[i].Height);
    		mResolutionPair.push_back(n);
    		mResolutionPair.push_back(d);
    	}
    }
    It uses DirectX stuff to load the data into the vector and it works fine. I've tested it in Debug mode and written the data out into strings and it's all there and in correct order. Then follows the function that puts the strings and backing data into the combo box:

    Code:
    void setResolution(HWND hDlg)
    {   
        D3DObj.comboResData.clear();
        D3DClass::resData _resdata;
        int j = 0;
    
        for (int i = 0; i < D3DObj.mResolutionPair.size(); i += 4)
        {
            _resdata.w = D3DObj.mResolutionPair[i];
            _resdata.h = D3DObj.mResolutionPair[i + 1];
            _resdata.Hz = D3DObj.mResolutionPair[i + 2] / D3DObj.mResolutionPair[i + 3];
    
            std::wstring _resolution = std::to_wstring(_resdata.w) +
                L" x " + std::to_wstring(_resdata.h);
    
            const WCHAR* resolution = _resolution.c_str();
            WPARAM nI = SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_ADDSTRING, (WPARAM)0, (LPARAM)resolution);
    
            D3DObj.comboResData.push_back(_resdata);
            SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_SETITEMDATA, (WPARAM)nI, (LPARAM) & (D3DObj.comboResData[j]));
            j++;
    
            #ifdef _SKIP
    
            D3DClass::resData* _temp = reinterpret_cast<D3DClass::resData*>(SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_GETITEMDATA, (WPARAM)nI, 0));
    
            std::wstring _string = std::to_wstring(_temp->w) + L" " + std::to_wstring(_temp->h) +
                L"\n" + std::to_wstring(_temp->Hz) + L"\n\n";
            OutputDebugString(_string.c_str());
    
            #endif
        }
    
        return;
    }
    Again works fine, no problems. If I change the #def from _SKIP to _DEBUG it prints all the data into the debug output with no issues.

    And finally the function that puts the refresh rate into the text box:

    Code:
    void setRefresh(HWND hDlg)
    {
        WPARAM nI = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBO1));
        D3DClass::resData* _resData = reinterpret_cast<D3DClass::resData*>(SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_GETITEMDATA, (WPARAM)nI, 0));
        D3DObj.mRefreshRate = _resData->Hz;
        SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT3), std::to_wstring(_resData->Hz).c_str());
    
        #ifdef _SKIP
    
        WPARAM nI = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBO1));
        D3DClass::resData* _temp = reinterpret_cast<D3DClass::resData*>(SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_GETITEMDATA, nI, (LPARAM)0));
    
        std::wstring _string = std::to_wstring(_temp->w) + L" " + std::to_wstring(_temp->h) +
            L"\n" + std::to_wstring(_temp->Hz) + L"\n\n";
        OutputDebugString(_string.c_str());
    
        #endif
    
        return;
    }
    I'll show a picture of the dialog box now for clarity:

    Problem trying to retrieve data from combo box! (strange issue)-db_1-jpg

    And the last piece of code to display is the dialog box message handling function. I've added spaces in parts for clarity:

    Code:
    INT_PTR CALLBACK ChooseRender(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
        WCHAR* text = nullptr;
        LRESULT checkBox = Button_GetCheck(GetDlgItem(hDlg, IDC_CHECK1));
    
        switch (message)
        {
    
        case WM_INITDIALOG:
        {
            setAdapterBufferField(text, hDlg); // this works - fills out text fields for adapter
    
            D3DObj.LogResolution(D3DObj.mdxgiFactory); // this works - fills class vector with display data
    
            setResolution(hDlg); // this works - loads class data into combo box fields and strings for selection
    
            ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_COMBO1), 0); // this works - sets starting selection in combo box
    
            setRefresh(hDlg); // this causes garbage value to appear - supposed to fill out refresh rate field (works in later call)
    
            return (INT_PTR)TRUE; // setting true or false makes no difference (seemingly)
        }
    
        case WM_COMMAND:
            if (LOWORD(wParam) == IDC_BUTTON1 || LOWORD(wParam) == IDCANCEL)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return (INT_PTR)TRUE;
            }
    
            if (LOWORD(wParam) == IDC_CHECK1)
            {
                if (checkBox == BST_CHECKED)
                {
                    D3DObj.mSetRefresh = true;
                    D3DObj.LogResolution(D3DObj.mdxgiFactory);
                    SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
                    setResolution(hDlg);
                    return (INT_PTR)TRUE;
                }
                else
                {
                    D3DObj.mSetRefresh = false;
                    D3DObj.LogResolution(D3DObj.mdxgiFactory);
                    SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
                    setResolution(hDlg);
                    return (INT_PTR)TRUE;
                }
            }
    
            if ((LOWORD(wParam) == IDC_COMBO1) && HIWORD(wParam) == CBN_SELCHANGE)
            {
                setRefresh(hDlg);
                return (INT_PTR)TRUE;
            }        
        }
    
        return (INT_PTR)FALSE;
    }
    I don't really expect anyone to read all that code, I just wanted to provide it for clarity in case anyone needs to refer to it to find a problem.

    Anyways the problem is....it works. Sometimes. When the dialog box initiates there is only ever a garbage value in the refresh rate field. The only way I can stop this is to check the check box in the top right. If I then re-select an item in the combo box the refresh rate show correctly.

    So the issue seems to be on startup. This is where things get really confusing. The #def block I wrote in the setResolution(hDlg) outputs all the data correctly even on startup. Note that it is using the CB_ADDSTRING message to get an index (nI) for the box entry for both the function stuff and the debug output string. Seems to work fine even inside the WM_INITDIALOG block.

    It's closely related setRefresh(hDlg) function however (which uses the exact same code) only ever produces a garbage value inside the WM_INITDIALOG block. To get it to work I have to check the check box and then select an entry in the combo box.

    I've tried absolutely everything to get this to show a valid refresh rate on startup. I've tried SetFocus and returning FALSE as the MSDN says to. I've tried calling setRefresh with a WPARAM returned from a call to ComboBox_GetCurSel. I even re-wrote the .rc file in notepad to put the combo box entry at the top of the list so it's highlighted on startup.

    None of it has worked. I even tried changing code in the #def block to print the index being used to check it was a valid integer. And it is.

    The only thing I can think of, is that when inside the WM_INITDIALOG block a call to setResolution works because the OS seems happy using a CB_ADDSTRING message to get an index. It does not however seem to appreciate the manual forced setting of an index in any way whatsoever, which is what happens in the setRefresh function.

    Once into the WM_COMMAND block though it runs fine once the check box has been checked or unchecked, and the setRefresh function doesn't seem to have an issue with the index when it has been retrieved from a user selection in the combo box.

    So...where am I going wrong? I assume there's something wrong with the way I'm trying to retrieve an index in the setRefresh function on startup (inside the WM_INITDIALOG block). I really can't think what it is though.

    Sorry that's an awfully long post but the problem has got me so stumped I really felt I needed to go all in on this one.

    Thanks

  2. #2
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    Just a small update. I removed the setRefresh call from the initiation and left only the call to it inside the if ((LOWORD(wParam) == IDC_COMBO1) && HIWORD(wParam) == CBN_SELCHANGE) active. If I run the program once it produces garbage value. If I run it again in the same window it all works. I even tried delegating the dialog box procedure call to another function and that still doesn't help.

    In other words, I have to run the dialog box twice in the same window to get it to work. I'm wondering if I've done something wrong in the WndProc window message handling function that calls the dialog box.

    I'll add any more info as I find it. Thanks.
    Last edited by shrink_tubing; 11-28-2023 at 03:59 AM.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Arrow

    I've done some further testing and kept on finding things that simply suggest it should be working. There's no issues with the size of the vectors, there's no issues with the integer values of the indexes being used to access the combo box entries.

    I've printed them all to the debug output and they're all correct.

    Interestingly when I force the index to 0 when writing to the combo box entries and select the first entry on startup it works, albeit only for the first entry because the others don't get filled.

    I've researched the bit sizes of the windows variables being used and tried every variable type I can WPARAM, LPARAM, LRESULT even longs to ensure there's no issue with a type or bit mis-match.

    So on and so on.

    In conclusion at this time it looks like a message handling issue. But for the moment that's out of my scope. Anyways I'm about to enter that dreadful place where knowledge runs out and reasonable trial and error has failed. After that point you're just going around in circles guessing and it runs the risk of sucking a person's soul out of them.

    I've decided to shelve this for a while and return to my windows programming book (I still have 900 pages to go) and I'll come back to it when my knowledge base has improved.

    Thanks

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    I don't see how this could be causing your issue, but the only thing I can see that you are definitely doing wrong is how you calculate the refresh rate. A refresh rate can be fractional, hence Numerator and Denominator, so when dividing those values you need to convert them to floating point first, and store the result as floating point, something like:
    Code:
    double Hz = double(Numerator) / Denominator; // if either operand is floating point then the other is also converted to fp
    So loading the data would go something like:
    Code:
    for (int i = 0; i < count; i++)
    {
        UINT n = modeList[i].RefreshRate.Numerator;
        UINT d = modeList[i].RefreshRate.Denominator;
        if (!mSetRefresh || double(n) / d == 60.0)
        {
            mResolutionPair.push_back(modeList[i].Width);
            mResolutionPair.push_back(modeList[i].Height);
            mResolutionPair.push_back(n);
            mResolutionPair.push_back(d);
        }
    }
    I've removed some code duplication also.
    Some more duplication removal:
    Code:
            if (LOWORD(wParam) == IDC_CHECK1)
            {
                D3DObj.mSetRefresh = (checkBox == BST_CHECKED);
                D3DObj.LogResolution(D3DObj.mdxgiFactory);
                SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
                setResolution(hDlg);
                return (INT_PTR)TRUE;
            }
    Another thing is that your identifier _SKIP is technically not allowed. Identifiers starting with an underscore are reserved for the implementation in the global scope (but they can be used in local scopes). Identifiers starting with an underscore followed by an uppercase letter, or identifiers containing a double underscore anywhere(!), are reserved for the implementation in all scopes. So you should either just say SKIP or perhaps use something like SHOW_DEBUG_INFO. Also, you probably shouldn't make a second call to SendMessage for the debug part since that means you've sent two messages for debugging while only sending one for the regular code, which could make a difference in the result (considering your problem).
    Code:
    //#define SHOW_DEBUG_INFO // uncomment to show info
     
    void setRefresh(HWND hDlg)
    {
        WPARAM nI = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBO1));
        D3DClass::resData* _resData = reinterpret_cast<D3DClass::resData*>(
            SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_GETITEMDATA, (WPARAM)nI, 0));
     
    #ifdef SHOW_DEBUG_INFO
        std::wstring _string = std::to_wstring(_resData->w) + L" "
            + std::to_wstring(_resData->h)
            + L"\n" + std::to_wstring(_resData->Hz) + L"\n\n";
        OutputDebugString(_string.c_str());
    #endif
     
        D3DObj.mRefreshRate = _resData->Hz;
        SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT3), std::to_wstring(_resData->Hz).c_str());
    }
    BTW, on x86_64, LPARAM is a signed 64-bit integer while WPARAM is an unsigned 64-bit integer. "long" on windows is only 32-bit, while "long long" is 64-bit, both of them signed, of course, unless you also say "unsigned".
    A little inaccuracy saves tons of explanation. - H.H. Munro

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    I was very much hoping you'd turn up sooner or later John. I'll go make those changes later today, exactly as you described them. I think will take a lot of research to discover exactly what's wrong but to me that's great advice you've given me again, and will be implemented promptly. Thanks very much

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Once you've done that, upload the entire thing as a zip file somewhere and post a link here. Also describe exactly what the problem seems to be with the current version.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  7. #7
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Post Link

    Hi there,

    Here's the link to onedrive where I've uploaded it. Rather a big file i don't know if that's because of all the directX stuff in the includes. I may have included stuff I didn't need to but I'm not sure how to avoid that.

    https://1drv.ms/u/s!AmIumtq4Ent9hjWP...VRgM1?e=zufoW3

    The current version has the same bug as it first had. One point of interest is that if you open and then close and then re-open the dialog box it works first time. That means as far as I know the code has only run the following message blocks:

    Code:
    switch (message)
    {
        case WM_INITDIALOG:
        {
            setAdapterBufferField(text, hDlg); // this works - fills out text fields for adapter
            D3DObj.LogResolution(D3DObj.mdxgiFactory); // this works - fills class vector with display data
            setResolution(hDlg); // this works - loads class data into combo box fields and strings for selection
            SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0); // this works - sets starting selection in combo box
            setRefresh(hDlg); // produces garbage value on first run
            return TRUE; // setting true or false makes no difference (seemingly)
        }
    
        case WM_COMMAND:
        {
            if (LOWORD(wParam) == IDC_BUTTON1)
            {
                EndDialog(hDlg, LOWORD(wParam));
                return TRUE;
            }
    .... switch block continues....
    So it's only run the WM_INITDIALOG block and the WM_COMMAND part up to the quit button that ends the dialog box. But re-opening it after this it works perfectly.

    Please note this is compiled in Visual Studio and includes a substantial amount of directX stuff to compile. I don't remember exactly how I set it up but I assume one must ensure VS is configured to be able to access all that, otherwise it may not compile. You can still see the program anyway if you navigate to the Debug folder and run the .exe. I'm not which version the Release folder has in it so probably best to ignore that one.

    If you have any issues accessing the file please let me know thanks

    *p.s. I let someone else look at the code before uploading and they think it might be a message issue as well
    Last edited by shrink_tubing; 11-30-2023 at 08:31 AM.

  8. #8
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    Quite a big file? 560MB, expanding to almost 3 gigs, is utter madness!
    99.9% of the size comes from the pre-compiled headers (the ".vs" dir) which are only there to speed up your compilation process.
    People trying to help do not need that.
    Neither do they need the compiled program ("x64" dir containing Debug and Release).
    There's some other stuff that's not necessary, but it's small enough that it doesn't matter.
    So at most you should have included everything except the ".vs" and "x64" directories.
    Here's a 43.6KB zip (< 0.01% of your original upload) that just contains that stuff:
    Filebin | 52qpepn3jyrj1wfg
    This will only be available for 6 days so you might want to upload it to OneDrive.

    BTW, I do not use Windows so I will not be trying to run it.
    I'm also not a Windows expert (I hardly remember anything about it since I last used it about 20 years ago).
    Hopefully someone who knows more about Windows will take a look, too.

    At any rate...

    It looks like if I was able to run your program it would show a blank window with a menu.
    Choosing "Options" from the menu will start the dialog box.
    When the dialog box inits for the first time, it will show garbage as the "Refresh Rate".
    If you either choose another resolution from the combo box or exit and reopen the dialog box, the refresh rate will display correctly.
    Also, you have the comment "change nI variable to 0 and it works (for first entry)", so it would seem that if you set nI to 0 in the code (instead of trying to retrieve it with ComboBox_GetCurSel) then it works if you just start the program and select "Options" from the main menu.
    I also assume that it acts like this in both Debug and Release mode.

    Is that right?

    Also, my idea with your debug code in setRefresh was to not call SendMessageW (or ComboBox_GetCurSel) twice since that's not what your non-debug code does. So try this and let me know the result:
    Code:
    void setRefresh(HWND hDlg)
    {
        WPARAM nI = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_COMBO1));
        auto _resData = (D3DClass::resData*)SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_GETITEMDATA, nI, 0);
     
        #ifdef SKIP  // change to _DEBUG to display
        std::wstring _string = std::to_wstring(_resData->w)  + L" "
                             + std::to_wstring(_resData->h)  + L"\n"
                             + std::to_wstring(_resData->Hz) + L"\n"
                             + std::to_wstring(nI)           + L"\n\n"; // may as well print nI, too
        OutputDebugString(_string.c_str());
        #endif
     
        D3DObj.mRefreshRate = _resData->Hz;
        SetWindowTextW(GetDlgItem(hDlg, IDC_EDIT3), std::to_wstring(_resData->Hz).c_str());
    }
    Last edited by john.c; 11-30-2023 at 01:20 PM. Reason: added printing of nI
    A little inaccuracy saves tons of explanation. - H.H. Munro

  9. #9
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Post New Link

    Hi there,

    I've removed the original and uploaded a small version based on your advice John. Now I know what to do (and what not to do) in the future

    https://1drv.ms/u/s!AmIumtq4Ent9hje6..._aaso?e=4PGKPF

    Your diagnosis is correct, with the only exception being that user made selection changes in the combo box on the first run make no difference to the bug.

    If you check the check box and re-select an entry in the combo box, or if you simply close the dialog box and re-open it, it works.

    I've made the code changes you prescribe in the new upload also (although the bug persists).

    Thanks for the advice John.

    *p.s. also you are correct about forcing the index to zero instead of using the WPARAM variable nI. It will successfully fill out just the first entry correctly with no garbage value in the Refresh Rate field.
    Last edited by shrink_tubing; 11-30-2023 at 01:51 PM.

  10. #10
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    I've made the code changes you prescribe in the new upload also
    Note that I made a small change in the setRefresh debug code to print nI as well.
    What does that debug code print on the first opening of the dialog box?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    Hi there,

    Thanks John I noticed that, the auto keyword and extra printing code. It gives 3 garbage values for the values retrieved from the combo box and a plain 0 for the index (nI). The index nI is always valid. For example if I change the initial combo box selection to number 5 in the WM_INITDIALOG block then that's what setRefresh shows. Seems to be valid to me. The other entries for width, height and Hz are still garbage values though.

    Thanks

  12. #12
    Registered User
    Join Date
    Jan 2010
    Posts
    206

    Thumbs up Seems fixed (I hope)

    Hi there,

    Okay it's working. But I don't really know exactly what I did. I wrote a small bit of code to display the messages the dlgproc was receiving and I found a list online that tells you which messages the numbers correspond to.

    It seems the dlgproc receives a WM_SETFONT message and then after that an WM_INITDIALOG message, then shortly after that it receives a WM_ACTIVATE message.

    Here's the code to retrieve them right at the start of the dlgproc:

    Code:
    #ifdef _DEBUG  // change to _DEBUG to display
        std::wstring _string = L"Message: " + std::to_wstring(message) + L"\n\n";
        OutputDebugString(_string.c_str());
    #endif
    And the debug outputs (at the top):

    Problem trying to retrieve data from combo box! (strange issue)-db_2-jpg

    and further down:

    Problem trying to retrieve data from combo box! (strange issue)-db_3-jpg

    So I decided to try just setting the adapter and format text fields in WM_INITDIALOG and leave the rest to the WM_ACTIVATE block. I felt maybe the activate message was a bit more "lively" for some reason.

    When I removed the return from the WM_INITDIALOG block it looks like this:

    Code:
    LRESULT CALLBACK ChooseRender(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
        WCHAR* text = nullptr;
        LRESULT checkBox = Button_GetCheck(GetDlgItem(hDlg, IDC_CHECK1));
    
        #ifdef _DEBUG  // change to _DEBUG to display
            std::wstring _string = L"Message: " + std::to_wstring(message) + L"\n\n";
            OutputDebugString(_string.c_str());
        #endif
    
        switch (message)
        {       
            case WM_INITDIALOG:
            {
                setAdapterBufferField(text, hDlg); // this works - fills out text fields for adapter
            }
    
            case WM_ACTIVATE:
            {
                D3DObj.LogResolution(D3DObj.mdxgiFactory); // this works - fills class vector with display data
                SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0); // clear combo box
                setResolution(hDlg); // this works - loads class data into combo box fields and strings for selection
                SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0); // this works - sets starting selection in combo box
                setRefresh(hDlg); // this now also works
                return TRUE;
            }
    
    .... dlgproc continues
    And that works fine. Beyond a hunch that was successful......I have absolutely no idea why this is working, but now I've found a solution perhaps it will be easier for others to tell me why.

    I don't want to just leave it at that I feel I really need to understand why this is happening. Anyways I'm pleased it's working though.

    Thanks very much for the help John and anyone else who may post future replies
    Last edited by shrink_tubing; 12-01-2023 at 08:39 AM.

  13. #13
    Registered User
    Join Date
    Dec 2017
    Posts
    1,633
    The code above does the following for WM_INITDIALOG:
    Code:
    setAdapterBufferField(text, hDlg);
    D3DObj.LogResolution(D3DObj.mdxgiFactory);
    SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
    setResolution(hDlg);
    SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
    setRefresh(hDlg);
    return TRUE;
    And then the following (repeating most of the above) for WM_ACTIVATE:
    Code:
    D3DObj.LogResolution(D3DObj.mdxgiFactory);
    SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
    setResolution(hDlg);
    SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
    setRefresh(hDlg);
    return TRUE;
    How do you know it's not just repeating the code that is making it work?
    To test it, get rid of the WM_ACTIVATE handler and try:
    Code:
    case WM_INITDIALOG:
      setAdapterBufferField(text, hDlg);
      D3DObj.LogResolution(D3DObj.mdxgiFactory);
      SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
      setResolution(hDlg);
      SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
      setRefresh(hDlg);
      D3DObj.LogResolution(D3DObj.mdxgiFactory);
      SendMessageW(GetDlgItem(hDlg, IDC_COMBO1), CB_RESETCONTENT, 0, 0);
      setResolution(hDlg);
      SendMessage(GetDlgItem(hDlg, IDC_COMBO1), CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
      setRefresh(hDlg);
      return TRUE;
    I'm not saying that's reasonable, but if it also works then it is because of some of the repetition and has nothing to do with WM_ACTIVATE.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  14. #14
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    Interesting possibility John! I'll go have a look thanks!

  15. #15
    Registered User
    Join Date
    Jan 2010
    Posts
    206
    You were spot on John. I removed WM_ACTIVATE block and duplicated the code in WM_INITDIALOG block. It worked again. So it means it has to run twice to work. Bizarre! I've left it as it is though because it looks a bit nicer than writing the code twice. But yep, that's it. Has to run twice for some reason!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to store and retrieve data with a Query function in C
    By JiaWei Lee in forum C Programming
    Replies: 0
    Last Post: 10-22-2016, 02:17 AM
  2. How to parse the data and retrieve the data.
    By kane_a in forum C Programming
    Replies: 11
    Last Post: 12-08-2005, 09:11 AM
  3. using class to retrieve and store data
    By FoodDude in forum C++ Programming
    Replies: 9
    Last Post: 08-19-2005, 07:50 AM
  4. Combo Box in MFC, how to randomize data of it...please help!
    By Unregistered in forum Windows Programming
    Replies: 3
    Last Post: 06-24-2002, 02:26 AM
  5. Retrieve specific data from text for edit
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 01-22-2002, 09:02 AM

Tags for this Thread