Setting Focus code wise.

I'm making a calc. I have a clear button and when i click it i want to set focus back to the edit box. How do I do this. Anyone have the book Windows 98 programming from the ground up? I have this book, it's ok but like the menu thing, it didn't have anything about the MAKEINTRESOURCE() func or macro whatever it is. It said you could do it with the name of the menu, but that doesn't work. Anyway I got the menu going but how to you set focus to a control with code??

Comments

  • : I'm making a calc. I have a clear button and when i click it i want to set focus back to the edit box. How do I do this. Anyone have the book Windows 98 programming from the ground up? I have this book, it's ok but like the menu thing, it didn't have anything about the MAKEINTRESOURCE() func or macro whatever it is. It said you could do it with the name of the menu, but that doesn't work. Anyway I got the menu going but how to you set focus to a control with code??
    :
    If you in your RC file will call your resource using " and " it will be considered a textual name, so you can pass it as a parameter to 'LoadMenu()' etc. - like this:
    [code]
    "MyFirstMenu" MENU
    POPUP
    MENUITEM ... etc.
    END
    END
    [/code]
    if the menu name without these: "," then it is an ID and you need the MAKEINTRESOURCE(id) macro.

    On your question: you set a focus to a window - with:
    [code]
    SetFocus (hWnd);
    [/code]
    when in dialog you find the HWND of a control with GetDlgItem():
    [code]
    SetFocus (GetDlgItem (hDlg, IDC_EDIT1));
    [/code]
  • Ok that makes more sense. The book doesn't have the " " around the menu name in the .rc file. So if you wanted to use this way you would have to either write your own .rc file or use the editor then open it with notepad and change it, cause MSCV++ makes it a integer by default right?

    : [code]
    : "MyFirstMenu" MENU
    : POPUP
    : MENUITEM ... etc.
    : END
    : END
    : [/code]


    book example is like this
    [code]
    [blue]
    MyFirstMenu MENU
    POPUP
    MENUITEM... etc.
    END
    END
    [/blue]
    [/code]

    There is nothing like a book that is wrong to just mess you up, cause you don't assume a book as being wrong. That's why I bought the damn thing, so I wouldn't follow wrong tutorials :)

  • No, you can give resources a string identifier in the editor by enclosing it with "". But why do you want to make it a string?
  • I just looked up my Petzold's book - there is nothing better than this! Here is what he says about resource identifiers: "...if there is no #define for a name of the resource it is still considered a string..." that means:

    In RES1.RC we have a string:
    [code]
    MyFirstMenu MENU ...
    ...
    END
    [/code]
    so we have to use 'LoadMenu (hInstance, "MyFirstMenu");'

    In RES2.RC we have an ID:
    [code]
    #define MyFirstMenu 101

    MyFirstMenu MENU ...
    ...
    END
    [/code]
    so we have to use
    'LoadMenu (hInstance, MAKEINTRESOURCE(MyFirstMenu));'
    ===========================================================
    Whoa! Learn something every day!

    P.S. By the way: get yourself a Petzold - no tutorial beats that one...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories