Thread: Using the SetDlgItemText function

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    12

    Using the SetDlgItemText function

    This is very basic but not for a beginner.

    While developing a win32 application:
    There is an edit box on a dialog box. Want the edit box to show a text when
    the dialog box is being created.

    case WM_INITDIALOG:
    SetDlgItemText(hdwnd,ID_ESCREEN,"Here is the text");

    There is no error while compiling. But when executing the app, I recieve a windows mwssage:
    MyCalculator has caused an error in imekernel32.sys.

    What am I missing here? Any hints?

    Thanx In Advance
    you never undersdand me, or worse, you never care to understand me!

  2. #2
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Strange, should work....
    Are you sure thats the handle to the dialog?
    And might there be something wrong with the way you make the editbox (unlikely)

    Anyone that knows what the imkernel32 thing is?

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    12
    Yes, is really strange.
    But the most confusing partis that I can initialize the edit box properly in another message such as WM_COMMAND.
    I use VC++ and this is not the first headache I have with the compiler.

    Nima
    you never undersdand me, or worse, you never care to understand me!

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Is the dialog modal or modeless...?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    I use VC and I dont have any problems.....load the following and say if it works

    TEST.cpp
    Code:
    #include <windows.h>
    #include "resource.h"
    
    int CALLBACK WindowProc(HWND hwnd, 
    UINT message,	WPARAM wParam, LPARAM lParam)
    {
        switch (message)                
        {
               case WM_INITDIALOG:            
    	SetDlgItemText(hwnd,IDC_EDIT1,"Here is the text");
               return 1;
               
    		   case WM_COMMAND:
    
    			   switch(wParam){
    			   case IDOK:
    				   EndDialog(hwnd,0);
    			   }
    			   return 1;         
        }
        return 0;
    }
    
    
    
    int WINAPI WinMain(HINSTANCE hThisInstance,
     HINSTANCE hPrevInstance,
     LPSTR lpszArgument, int nFunsterStil)
    
    {
       return DialogBox(hThisInstance,
    MAKEINTRESOURCE(IDD_DIALOG1),
    HWND_DESKTOP,(DLGPROC)WindowProc);
    }
    resource.h
    Code:
    //{{NO_DEPENDENCIES}}
    // Microsoft Developer Studio generated include file.
    // Used by Script1.rc
    //
    #define IDD_DIALOG1                     101
    #define IDC_EDIT1                       1000
    
    // Next default values for new objects
    // 
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE        102
    #define _APS_NEXT_COMMAND_VALUE         40001
    #define _APS_NEXT_CONTROL_VALUE         1001
    #define _APS_NEXT_SYMED_VALUE           101
    #endif
    #endif
    Script1.rc
    Code:
    //Microsoft Developer Studio generated resource script.
    //
    #include "resource.h"
    
    #define APSTUDIO_READONLY_SYMBOLS
    ////////////////////////////////////////////////////
    
    //
    // Generated from the TEXTINCLUDE 2 resource.
    //
    #include "afxres.h"
    
    /////////////////////////////////////////////////////
    
    #undef APSTUDIO_READONLY_SYMBOLS
    
    ////////////////////////////////////////////////////////
    // English (U.K.) resources
    
    #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
    #ifdef _WIN32
    LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
    #pragma code_page(1252)
    #endif //_WIN32
    
    //////////////////////////////////////////////////
    //
    // Dialog
    //
    
    IDD_DIALOG1 DIALOG DISCARDABLE  0, 0, 186, 95
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "OK",IDOK,129,7,50,14
        EDITTEXT        IDC_EDIT1,26,25,79,15,ES_AUTOHSCROLL
    END
    
    
    //////////////////////////////////////////////
    //
    // DESIGNINFO
    //
    
    #ifdef APSTUDIO_INVOKED
    GUIDELINES DESIGNINFO DISCARDABLE 
    BEGIN
        IDD_DIALOG1, DIALOG
        BEGIN
            LEFTMARGIN, 7
            RIGHTMARGIN, 179
            TOPMARGIN, 7
            BOTTOMMARGIN, 88
        END
    END
    #endif    // APSTUDIO_INVOKED
    
    
    #ifdef APSTUDIO_INVOKED
    ////////////////////////////////////////////////////////
    //
    // TEXTINCLUDE
    //
    
    1 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "resource.h\0"
    END
    
    2 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "#include ""afxres.h""\r\n"
        "\0"
    END
    
    3 TEXTINCLUDE DISCARDABLE 
    BEGIN
        "\r\n"
        "\0"
    END
    
    #endif    // APSTUDIO_INVOKED
    
    #endif    // English (U.K.) resources
    ////////////////////////////////////////////////////////
    
    
    
    #ifndef APSTUDIO_INVOKED
    ///////////////////////////////////////////////////////////////
    // Generated from the TEXTINCLUDE 3 resource.
    //
    
    
    /////////////////////////////////////////////////////////////
    #endif    // not APSTUDIO_INVOKED

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM