GetDlgItem liefert Null handle



  • hi,

    beim aufruf von GetDlgItem bekomm ich ein null handle zurück und ich verstehe nicht so ganz wieso.

    ich erstelle mir einen button und geben dem auch eine ID

    #define BUTTO 3245
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT uiMessage, WPARAM wParam, LPARAM lParam)
    {
    	static HWND hDia;
    	static HWND hBut=NULL;
    
        switch(uiMessage)
        {
    	case WM_CREATE:
    			{
    				hBut = CreateWindow(TEXT("button"), TEXT("Neues"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON |WS_TABSTOP,
    									0, 0, 0, 0, hWnd, (HMENU) BUTTO, hInst, NULL);
    				if (hBut != NULL)
    					CreateToolTip(BUTTO, hBut, L"ich bin der doofe tooltiptext");
    
    				MoveWindow(hBut, 30, 49, 200,200, true);
    
    				break;
    			}
    
    ................................................
    
    BOOL CreateToolTip(int toolID, HWND hDlg, WCHAR* pText)
    {
    
        if (!toolID || !hDlg || !pText)
        {
            return FALSE;
        }
        // Get the window of the tool.
        HWND hwndTool = GetDlgItem(hDlg, toolID); <--- null handle
    
    ..........................
    }
    

    was mach ich falsch, hDlg ist gültig, die id passt auch und trotzdem null handle, woran kann das liegen?



  • Als Fehlermeldung liefert mir der GetLastError()
    "An attempt has been to operate on an impersonation token by a thread that is not currently impersonating a client"

    was heist das den jetzt?



  • osbi schrieb:

    hi,

    if (hBut != NULL)
    	CreateToolTip(BUTTO, hBut, L"ich bin der doofe tooltiptext");
    ................................................
    
    BOOL CreateToolTip(int toolID, HWND hDlg, WCHAR* pText)
    {
    
        if (!toolID || !hDlg || !pText)
        {
            return FALSE;
        }
        // Get the window of the tool.
        HWND hwndTool = GetDlgItem(hDlg, toolID); <--- null handle
    
    ..........................
    }
    

    Hi,
    was willst du mit diesem aufruf von GetDlgItem erreichen? Den Handel von dem Button übergibste ja schon 😕
    und 2tens ist die Funktion doch nur für Dialoge gedacht wie der Name schon verrät oder nicht?

    The GetDlgItem function retrieves the handle of a control in the specified dialog box.

    Return Values

    If the function succeeds, the return value is the window handle of the given control.
    If the function fails, the return value is NULL, indicating an invalid dialog box handle or a nonexistent control.

    MFG PinguGroup



  • PinguGroup schrieb:

    und 2tens ist die Funktion doch nur für Dialoge gedacht wie der Name schon verrät oder nicht?

    Oder nicht. Warum sollte man sie nicht auch in Fensteranwendungen benutzen? Hat den Vorteil, dass man keine globalen Varaiblen für die Fensterhandles benötigt. Die IDs sind ja sowieso Konstanten.


Anmelden zum Antworten