SetDlgItemText() Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xzyx987X

    SetDlgItemText() Error

    Sorry if this is off topic for this group, but I couln't find any place
    better for directing question on Windows API programming. Here's the
    problem, I am calling the SetDlgItemText( ) function to set the text of an
    edit box for an about window for my program. For some weird reason though it
    won't work, and the GetLastError function gives a Control ID not found
    error. I am sure that the parameters are correct so I'm at a loss as to the
    cause. The only reason I can think of that this would happen is that the
    about window is set as a child window of the main one, but I don't see why
    that would be a problem. To be honest I would rather just send the edit box
    a set text message but the object is being genorated by a recource script
    and I'm not sure how to get it's hWnd. If you know how then please tell me.
    Another question I wanted to ask, just in case anyone knows, when using the
    CreateWindowEx( ) function one of the parameters is a handle to the
    application instance. The way I have the application set up though, it is a
    command line program that makes use of windows.h (the command line is really
    handy for debbuging) so I can't get this from the winmain function. Having
    this parameter NULL causes no problems in WinXP, but according to MSDN it
    may break compatiblility with Win98 and below. Then again they are probobly
    assuming the application has a winmain, which it doesn't. Does anyone know
    if this would actually be a problem, and if so how would I get the handle to
    the application instance without having a winmain?

    Here's the source (stripped of any sort of practical functionallity) :

    #include <windows.h>
    #include <stdio.h>
    #include <commctrl.h>
    #include "resource.h "

    //Function declarations

    BOOL MainDialogProc( HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam);

    BOOL AboutDialogProc (HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam);

    void initialize_proc (HWND hWnd);

    //Global variable declarations

    HWND hWstatusbar;

    //Main function. Serves as entry point for MainDialogProc

    bool main(void)
    {
    DialogBoxParam( GetModuleHandle (NULL),
    MAKEINTRESOURCE (IDD_DLG_MAIN),
    NULL,
    (DLGPROC)MainDi alogProc,
    0);

    return FALSE;
    }

    BOOL MainDialogProc( HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
    {

    switch(uMsg)
    {

    case 48: //Didn't feel like looking up the constant for this :P
    initialize_proc (hWnd);
    return TRUE;
    break;

    case WM_CLOSE:
    EndDialog(hWnd, 0);
    return TRUE;
    break;

    case WM_COMMAND:
    switch(LOWORD(w Param))
    {

    case ID_HELP_ABOUT:
    DialogBoxParam( GetModuleHandle (NULL),
    MAKEINTRESOURCE (IDD_DLG_ABOUT) ,
    hWnd,
    (DLGPROC)AboutD ialogProc,
    0);
    break;
    case ID_FILE_EXIT:
    EndDialog(hWnd, 0);
    return TRUE;

    }

    }

    return FALSE;

    }

    BOOL AboutDialogProc (HWND hWnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
    {

    switch (uMsg)
    {
    case 48:
    SetDlgItemText( hWnd, IDC_DISCLAIMER, "About Box.");
    printf("Last Error: %d \n", GetLastError()) ;
    break;
    case WM_COMMAND:
    switch (LOWORD(wParam) )
    {

    case IDOK:
    EndDialog(hWnd, 0);
    return TRUE;

    }

    }

    return FALSE;

    }

    void initialize_proc (HWND hWnd)
    {

    //This code is a bit messy and inflexible but the GUI coding isn't really
    the point here :)

    //Variables for creating the status bar

    INITCOMMONCONTR OLSEX ControlSet;

    RECT rcClient;

    ControlSet.dwSi ze = sizeof (ControlSet);
    ControlSet.dwIC C = ICC_BAR_CLASSES ;

    InitCommonContr olsEx(&ControlS et);

    GetClientRect(h Wnd, &rcClient);

    int parts[2] = {rcClient.right / 2, rcClient.right} ;

    //Create the status bar

    hWstatusbar = CreateWindowEx(
    0,
    STATUSCLASSNAME ,
    (LPCTSTR) NULL,
    WS_CHILD | WS_VISIBLE,
    0,
    0,
    0,
    0,
    hWnd,
    (HMENU) NULL,
    (HINSTANCE) NULL, //This statement may break compatibility with Win9x (at
    least according to MSDN)
    NULL);

    //Make sure status bar create was successful and if so, divide the status
    window into 2 parts and set the message

    if (!hWstatusbar){ printf("Status bar create error: %d \n",
    GetLastError()) ;}

    else
    {

    SendMessage(hWs tatusbar,
    SB_SETPARTS,
    (WPARAM) 2,
    (LPARAM) parts);
    SendMessage(hWs tatusbar,
    WM_SETTEXT,
    (WPARAM) 1,
    (LPARAM) "Ready!");

    }

    //Set the icon for the main diolog.

    SendMessage(hWn d,
    WM_SETICON,
    ICON_SMALL,
    (LPARAM) LoadImage(NULL,
    "C:\\Docume nts and Settings\\zyx98 7.ZYX987S-COMP\\My
    Documents\\icon .ico",
    IMAGE_ICON,
    16,
    16,
    LR_LOADFROMFILE )
    );

    return;

    }


  • Victor Bazarov

    #2
    Re: SetDlgItemText( ) Error

    "Xzyx987X" <Xzyx987X@mn.rr .com> wrote...[color=blue]
    > Sorry if this is off topic for this group, but I couln't find any place
    > better for directing question on Windows API programming. [...][/color]

    How about comp.os.ms-windows.program mer?


    Comment

    • Xzyx987X

      #3
      Re: SetDlgItemText( ) Error

      Ok thanks for your help. I'll repost this there.
      "Victor Bazarov" <v.Abazarov@att Abi.com> wrote in message
      news:IGGTa.1326 39$H17.44552@sc crnsc02...[color=blue]
      > "Xzyx987X" <Xzyx987X@mn.rr .com> wrote...[color=green]
      > > Sorry if this is off topic for this group, but I couln't find any place
      > > better for directing question on Windows API programming. [...][/color]
      >
      > How about comp.os.ms-windows.program mer?
      >
      >[/color]


      Comment

      Working...