How to get handle of static edit control?

Discussion in 'Win32' started by haroonrulz, Jun 27, 2012.

  1. haroonrulz

    haroonrulz Banned

    Aug 30, 2012
    Likes Received:
    Trophy Points:
    Dear Friends, I am developing a testing tool, for that I need "to obtain the handle of static edit control". Since I assume that I cant obtain the handle directly, I first got the handle of label control.So my question is "Is there any function to obtain the handle of static edit control using label control handle or function to directly get the edit control handle". Please look at the attachment.Kindly help me.
  2. hobbyist

    hobbyist New Member

    Jan 7, 2012
    Likes Received:
    Trophy Points:
    You could enumerate through the children and then find edit controls by searching for their class names.

    I'm no programming guru or anything, but I played around with a program to tinker with WinSpy 1.7 where I set the text of each edit control. Maybe it can help.

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
    #include <commctrl.h>
    typedef struct { // parent info struct
        TCHAR caption[BUFSIZ];
        TCHAR search[BUFSIZ];
        HWND hwnd;
        BOOL found;
    } pinfo;
    BOOL CALLBACK myParentProc(HWND hwnd, LPARAM lparam) {
        // get a handle to the "parent" window
        TCHAR buffer[BUFSIZ] = { 0 };
        pinfo *tmp = (pinfo *)lparam;
        GetWindowText(hwnd, buffer, sizeof buffer);
        if(strstr(buffer, tmp->search)) {
            strcpy(tmp->caption, buffer);
            tmp->hwnd = hwnd;
            tmp->found = TRUE;
            return FALSE;
        return TRUE;
    BOOL CALLBACK myChildProc(HWND hwnd, LPARAM lparam) {
        static int count = 0;
        TCHAR clsName[BUFSIZ] = { 0 };
        GetClassName(hwnd, clsName, BUFSIZ);
        if(strcmp(clsName, "Edit") == 0) {
           sprintf(clsName, "handle %u", hwnd);
           printf("Set Text \"%s\" on control %u %s\n", clsName, hwnd,
                  SendMessage(hwnd, WM_SETTEXT, NULL, (LPARAM)clsName) == TRUE ? "Succeeded" : "Failed");
        return TRUE;
    int main() {
        pinfo nfo;
        ZeroMemory(&nfo, 0);
        strcpy(, "WinSpy++");
        EnumWindows(myParentProc, (LPARAM)&nfo);
        if(nfo.found == TRUE) {
           printf("caption: %s\nHWND: %u\n", nfo.caption, nfo.hwnd);
           EnumChildWindows(nfo.hwnd, myChildProc, 0);
        return 0;

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice