Re: Basic question regarding checkboxes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




<stewb85@xxxxxxxxx> wrote in message news:25882ada-6759-4716-99e8-8de7cfb54c79@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Are you using MFC or the straight Win32 APIs? This is an MFC newsgroup.


I'll be honest with you. I don't actually know. I assume MFC, but as
I say, I've not done Windows before, and this Checkbox control is the
only thing I actually need to do. But its wasting valuable time I
could be spending on the actual algorithm I'm writing.

In the actual Dialog code, if I do
CheckDlgButton(IDC_CHECK1,BE_CHECKED) it works, but unfortunately this
isnt of much practical use to me.

How do I get the HWND that was returned when the dialog was created?
This is a program that has been passed to me, and unfortunately, the
person who gave it me isn't around to ask them.

I appreciate that this is basic, and all your help is very much
appreciated.

The fact that it works in the actual dialog code is a pretty good hint that you are using MFC. It appears that your real problem is not understanding that the above call is to a C++ member function. Your error message shows you are not calling the MFC version of CheckDlgButton but attempting to call the API version. The MFC version is a member function of the dialog and it "knows" the HWND of the dialog.

The solution is to call it this way:

pDialog->CheckDlgButton(IDC_CHECK1,BE_CHECKED);

No HWND required, but you have to have a pointer to the dialog object like pDialog. If you are making this call in some code module that is not part of the dialog then first you have to call that module, passing it the 'this' pointer from the dialog object. Your module would save this pointer for later use so it can call dialog functions. Do you understand this C++ idiom?

--
Scott McPhillips [VC++ MVP]

.



Relevant Pages

  • Re: Basic question regarding checkboxes
    ... But its wasting valuable time I ... you are using MFC. ... The MFC version is a member function of the dialog and it ... but you have to have a pointer to the dialog object like ...
    (microsoft.public.vc.mfc)
  • Re: Basic question regarding checkboxes
    ... when I put this in the hWND field I get the error ... Conversion from integral type to pointer type requires ... C-style cast or function-style cast ... Are you using MFC or the straight Win32 APIs? ...
    (microsoft.public.vc.mfc)
  • Re: Getting HWND of dialog
    ... Using MFC your HWND is a member variable of the CDialog derived class. ... can get it with the member function GetSafeHwnd(). ...
    (microsoft.public.vc.mfc)
  • Re: Mem leak when implement Singleton pattern on CWinApp derived class
    ... see is a misguided attempt to follow mindlessly some abstract idea about design patterns, ... violating any number of assumptions MFC makes about its environment. ... MFC will there EVER be an attempt to create more than one object instance for the CWinApp ... The destructor on a pointer ...
    (microsoft.public.vc.mfc)
  • Re: trouble with CDC
    ... The pointer can be used immediately unless there is some race condition ... time) with a 1 msec delay than with a 50 msec delay. ... only the MFC documentation concerning things that are documented by the SDK ... but only the MFC object might not have a stable connection to it (meaning I ...
    (microsoft.public.vc.mfc)