Issues on code (radio buttons)

Ask your support questions in here

Moderator: Moderator Team

Post Reply
Fraizeraust
Posts: 223
Joined: Thu Jan 05, 2017 11:46 am
Location: Italy
Contact:

Issues on code (radio buttons)

Post by Fraizeraust » Wed Jul 25, 2018 5:25 pm

Hi,

I posted this topic on Support section since this is related to Win32 API, foremost ReactOS. I am trying to implement a small feature which is a dialog with radio buttons that you can either enable or disable AUTOCHK on startup. For the moment I have only implemented the visuals part and not the functionality itself yet.

Even though the visuals are rather a playground for most, I'm struggling a lot to get things done. To begin with, here's the code:

Code: Select all

#include "autochkpage.h"
#include "resource.h"
#include "precomp.h"

HWND h1RadioButton;
HWND h2RadioButton;
BOOL bIsEnabled = TRUE;
HWND hAutoChkPage = NULL;

INT_PTR CALLBACK 
AutoChkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
  UNREFERENCED_PARAMETER(lParam);
  UNREFERENCED_PARAMETER(wParam);

  h1RadioButton = GetDlgItem(hDlg, IDC_AUTOCHK_ENABLE);
  h2RadioButton = GetDlgItem(hDlg, IDC_AUTOCHK_DISABLE);

  switch (message)
  {
    case WM_INITDIALOG:
    {
      hAutoChkPage = hDlg;
      return TRUE;
    }

    case WM_COMMAND:
    {
      switch ( LOWORD(lParam) )
      {
        case IDC_AUTOCHK_ENABLE:
        {
          SendMessage(h1RadioButton, BM_SETCHECK, 1,0);
          SendMessage(h2RadioButton, BM_SETCHECK, 0,0);

          bIsEnabled = TRUE;
          break;
        }
        case IDC_AUTOCHK_DISABLE:
        {
          SendMessage(h1RadioButton, BM_SETCHECK, 0,0);
          SendMessage(h2RadioButton, BM_SETCHECK, 1,0);

          bIsEnabled = FALSE;
          break;
        }
      }
    break;
    }

    case WM_NOTIFY:
    {
      switch ( ((LPNMHDR)lParam)->code )
      {
        case PSN_APPLY:
        {
          SetWindowLongPtr(hAutoChkPage, DWLP_MSGRESULT, PSNRET_NOERROR);
          PropSheet_UnChanged(GetParent(hAutoChkPage), hAutoChkPage);
          return TRUE;
        }

        case PSN_HELP:
        {
          MessageBoxW(hAutoChkPage, L"Help not implemented yet!", L"Help", MB_ICONINFORMATION | MB_OK);
          return TRUE;
        }

        case PSN_KILLACTIVE: // Is going to lose activation.
        {
          // Changes are always valid of course.
          SetWindowLongPtr(hAutoChkPage, DWLP_MSGRESULT, FALSE);
          return TRUE;
        }

        case PSN_QUERYCANCEL:
        {
          // Allows cancellation.
          SetWindowLongPtr(hAutoChkPage, DWLP_MSGRESULT, FALSE);
          return TRUE;
        }
        /*
        * DO NOT TOUCH THESE NEXT MESSAGES, THEY ARE OK LIKE THIS...
        */
        case PSN_RESET: // Perform final cleaning, called before WM_DESTROY.
          return TRUE;

        case PSN_SETACTIVE: // Is going to gain activation.
        {
          SetWindowLongPtr(hAutoChkPage, DWLP_MSGRESULT, 0);
          return TRUE;
        }
      }

    return FALSE;
    }

    default:
      return FALSE;
  }

  return FALSE;
}
I have two problems with it. First, the visual work however the General dialog sheet is overridden by the Auto Check dialog and I have no idea whatsoever why it does do this. Here's an image link below if you do not know what I mean.

URL Image: https://imgur.com/a/5dkjgen

As you can see, it gets created a new dialog on the right after Tools dialog (which is good) but it just overrides the first dialog which is supposed to be the General dialog. And the second problem is whenever I compile the code it complains about an error like below:

Code: Select all

/home/fraizeraust/ReactOS/Fork/reactos/base/applications/msconfig_new/autochkpage.h:11:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'AutoChkPageWndProc'
The file above is the C header for autochkpage.c main code. I did a double check on the header and again, I couldn't find anything wrong so I have no idea what's happening. In fact, I had to comment #include "autochkpage.h" in order to compile the code successfully.

Here's the code both of the header and the dialog sheet:

Header

Code: Select all

#ifndef _AUTOCHKPAGE_H_
#define _AUTOCHKPAGE_H_

INT_PTR CALLBACK AutoChkPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

#endif /* _AUTOCHKPAGE_H_ */
Dialog Sheet

Code: Select all

/* Auto Check page */
    psp[nPages].dwSize      = sizeof(PROPSHEETPAGEW);
    psp[nPages].dwFlags     = PSP_HASHELP;
    psp[nPages].hInstance   = hInstance;
    psp[nPages].pszTemplate = MAKEINTRESOURCEW(IDD_GENERAL_PAGE);
    psp[nPages].pfnDlgProc  = AutoChkPageWndProc;
    ++nPages;
Before you may ask, all the code you see I implemented it on msconfig_new. Hopefully someone can help me.

EDIT: If someone is looking for the whole code instead, here's the link.

https://github.com/Fraizeraust/reactos/ ... chk-dialog

Thank you

ThFabba
Developer
Posts: 236
Joined: Sun Jul 11, 2010 11:39 am

Re: Issues on code (radio buttons)

Post by ThFabba » Wed Jul 25, 2018 8:32 pm

You're defining a second dialog template with the same id, IDD_GENERAL_PAGE. That's why the general page gets overwritten. You need a different id.

Your compiler error comes from the fact that you include autochkpage.h first, before anything else:

Code: Select all

#include "autochkpage.h"
#include "resource.h"
#include "precomp.h"
#include "comctl32supp.h"
The first thing in your header file, however, is "INT_PTR", which is not a built-in type. It is defined by Windows's header files, so such a header must be included first. You should move the autochkpage.h include to below the other includes instead.
Also, precompiled header files should always be included first (because depending on compiler settings they will be auto-included, so by not including precomp.h first you're creating an inconsistency between PCH and non-PCH build).

So this order should fix the problem:

Code: Select all

#include "precomp.h"
#include "resource.h"
#include "comctl32supp.h"
#include "autochkpage.h"

Fraizeraust
Posts: 223
Joined: Thu Jan 05, 2017 11:46 am
Location: Italy
Contact:

Re: Issues on code (radio buttons)

Post by Fraizeraust » Wed Jul 25, 2018 8:49 pm

Thank you so much Thomas Faber (as well as Mark Jansen since he did say that too on IRC). Now I can continue implementing the rest.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest