Results 1 to 25 of 25

Thread: Very Simple Question!!!

  1. #1
    needaname16
    Guest

    Talking Very Simple Question!!!

    Hi

    I am relatively new to normal Windows Applicaitons in C++, I have gained a basic understanding of the interaction between forms and member varaibles and message maps. I have been able to set text to an text box control ok, but I am having trouble disabling a text box. Here is an exert of the code:

    // m_TextEdit is a member variable of Class CEdit

    // In the Menu Item in the OnClicked Event

    // CInfoDlg is the Class for the Dialog

    CInfoDlg Dlg;

    Dlg.m_TextEdit.EnableWindow(FALSE):

    if (Dlg.DoModal() == IDOK)
    {
    // Some Code follows here
    }

    When I do this the text box is still enabled. Any suggestions

    Needaname16

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    While the dialog box is not shown, the edit control doesn't exist in reality, there is only the MFC container (CEditControl). A call to EnableWindow will therefore have no effect. Call this function in your dialog's OnInitDialog function (you may have to overwrite it). If the dialog box should always or initially be disabled, you can also specify it as a property in the dialog editor.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I already wrote that, parksie, but I deleted it again. He did not say normal windows programming. He said normal "Windows Applicaitons" (whatever that is ), so he is right. Without using Spy++, you'll probably not be able to distinguish an API app from a MFC app. (Except some...)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Normal windows applications then, more or less the same thing.

    Either way, MFC isn't the way the core Windows developers do things.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But it is for example the VC++ developers do things
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It seems that way

    The Win32 developers are all hardcore C addicts

    As far as MFC goes, I have no quibble with it when it's used in its place, which is pretty much DB access and anything that fits exactly into the Document/View paradigm (which I don't like, and I'm not the only one ).

    However, I stick to my argument that you should learn the real way first, and then choose MFC if you want. Otherwise you have slightly less chances than the snowball's of working out how to use it effectively.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The Win32 developers are nice people (uuhh... ) who care for relics from C and don't want to exclude them from the "benefits of windows"

    If the Win API was a class library, it would a) look like MFC so you'd since long been programming only for linux and b) hinder anyone that uses a function style language (pascal, C) from programming windows. And compatibility would be another problem. The COM is way younger than the WinAPI.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yep. C is still an insanely compatible language

    Actually, it wouldn't look like MFC - the reason that is so ugly in places is because it's an adaptor over a non-OO methodology.

    Admittedly, a nice OOP C++ interface would be bloody nice and dead easy to program for, but it would remove compatibility not only with non-C++ users, but also with anyone that didn't use MSVC++ (name mangling).

    I'm excluding COM because it's not fast enough to use for event handling.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    needaname16
    Guest

    Thumbs up

    hmmmmmm......

    That was an interesting discussion above, I started with straight fortran, basic, c and pascal (doing firmware based development). Just recently I have been learning the Visual tools by Microsoft and working with windows. Can someone enlighten me on how to get information and use API to develop Windows applications. I agree with the discussion above and would like to improve the method I use to do Windows programming.

    Thanks

    Needaname16

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Needaname16: Go to MSDN (msdn.microsoft.com) and download the Platform SDK. That gives you EVERYTHING you need

    CB: Name mangling is only a small part of the problem.

    Look up ABI (Application Binary Interface) to find the sorts of problems you get. As a quick few off the top of my head:

    Name mangling
    Structure alignment
    Virtual function pointer tables
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Structure alignement is not a problem, you can set that for every compiler I know.
    vtables are used for COM too, so that can't be a problem.

    But I still agree, it's just not standardized enough to make it possible. (Import libraries...)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Does COM use the actual C++ vtables? I'm sure that's an implementation-definable detail (i.e. you can put it wherever you want as long as the code works).

    Eventually things like this will all get sorted out (c.f. .NET )
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, I think it does.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    So how would you use it with something like Borland then? Surely they'd have a different in-memory layout.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Not necessarily, vtables are rather simple. You can emulate them using C (look in some COM headers, maybe DirectX, to see what they do exactly). To do this, you define a struct that has the additional member pVTable of type SOMESTRUCT*. Then you define SOMESTRUCT as collection of function pointers. Since interfaces never have data members, the vtable is always at the same location.

    It might be more complicated for real classes, but with the pure virtual COM interfaces it seems to work.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I know you can do it in C because that's what compilers used to do, convert C++ to C and then use a C compiler on it

    Just because they're simple doesn't mean they're compatible.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But this is what a COM call is converted to:
    Code:
    mov eax, _IMyInterfaceOffset$[ebp] ; local var or function parameter
    push ecx   ; parameters
    push 4    ; more parameters
    push eax ; this pointer
    mov ecx, [eax]  ; first data member of IMyInterface to ecx
             ; this is the vtable
    call [ecx + <function offset>]  ; do the call
    e.g. Blt is the 5th function of the interface IDirectDrawSurface4 and has the offset 20 (= 5*4)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    As you just proved to me, that's dependent on internal layout.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  19. #19
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    But this is what a COM call is converted to:
    Code:
    mov eax, _IMyInterfaceOffset$[ebp] ; local var or function parameter
    push ecx   ; parameters
    push 4    ; more parameters
    push eax ; this pointer
    mov ecx, [eax]  ; first data member of IMyInterface to ecx
             ; this is the vtable
    call [ecx + <function offset>]  ; do the call
    e.g. Blt is the 5th function of the interface IDirectDrawSurface4 and has the offset 20 (= 5*4).

    Such code is created by VC++6, and it can't be different for Borland cpp builder or else the code wouldn't work.
    Also, the compiler doesn't know if it is compiling a COM object, so they just can't get a special treating.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  20. #20
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by CornedBee
    Such code is created by VC++6, and it can't be different for Borland cpp builder or else the code wouldn't work.
    Also, the compiler doesn't know if it is compiling a COM object, so they just can't get a special treating.
    Somehow I get the feeling that we're talking two different things here.

    I'm pointing out that just because MSVC has the vtable first doesn't mean you have to. I suppose it just means that any compiler that professes to create COM DLLs does it that way for everything.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  21. #21
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I mean that every compiler that is able to create COM objects without some special option needs to do it this way.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  22. #22
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Yeah, but not every compiler professes to be able to create COM DLLs (GCC for one).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  23. #23
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, but gcc was developed for unix-like systems, not for windows. A linker that is able to create dlls may enable gcc to create COM objects.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  24. #24
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    The linker has nothing to do with C++ class layouts - that's up to the compiler.

    But the core point of what I'm saying is, you cannot guarantee it will work with COM unless the compiler says it can.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  25. #25
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yeah, exactly.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width