Warum wird Klick auf STATIC nicht abgefangen ?



  • Ich habe folgenden Code geschrieben, um den Klick auf ein Static zu erhalten, jedoch funktioniert es nicht, aber warum ? SS_NOTIFY ist beim STATIC in der Resource definiert !!!

    #include <windows.h>
    #include <stdio.h>
    #include "resource.h"
    
    char szposition[100]="";
    
    BOOL CALLBACK StaticProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
        return DialogBox(hInstance,MAKEINTRESOURCE(DIALOG1),NULL,StaticProc);
    }
    
    BOOL CALLBACK StaticProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
        case WM_INITDIALOG:
    
            return true;
    
        case WM_LBUTTONDBLCLK:
    
            return true;
    
        case WM_COMMAND:
    
            switch(HIWORD(wParam))
            {
            case BN_CLICKED:
    
                if(LOWORD(wParam)==IDOK)
                    SendMessage(hwnd,WM_CLOSE,0,0);
    
                return true;
    
            case STN_DBLCLK:
    
                if(LOWORD(wParam)==STATICFELD)
                    MessageBox(hwnd,"Staticfeld erfolgreich geklickt !","Hinweis",0);
    
                return true;
            }
    
            return true;
    
            case WM_MOUSEMOVE:
    
                szposition[0]='\0';
                sprintf(szposition,"Maus ist bei: %i,%i",LOWORD(lParam),HIWORD(lParam));
                SendDlgItemMessage(hwnd,MAUSPOSITION,WM_SETTEXT,0,(long)szposition);
    
                return true;
    
            case WM_CLOSE:
    
                EndDialog(hwnd,0);
                PostQuitMessage(0);
    
                return true;
        }
        return false;
    } :(
    


  • Schau mal auf www.winapi.net (unter Tipps & Tricks), die haben da ein Beispiel mit ner URL in einem Dialog, dürfte aber in einem normalen Fenster auch nicht anders sein.



  • Lass mal die Zeile

    if(LOWORD(wParam)==STATICFELD)
    

    weg.



  • danke fritzchen 🙂



  • Wer sich da auch immer bedankt hat: ich habe nur geraten. 😉



  • ich wars 🙄 :p

    aber ich habs noch ned ausprobiert. 😞



  • Klappt auch nicht mit weglassen, ausserdem sagt die MSDN das auch aus ! 🙄



  • I think you have to subclass the static control, but i'm not sure of course.



  • Es funzt einfach nicht auch nicht bei www.winapi.net



  • I couldn't believe that. winapi.net is very good page and if the code would not work they won't publish it. i think it's your mistake. :p



  • So, hab jetzt schnell mal gecodet, so funktionierts (musst nur noch auf dein Programm umschreiben ;)):

    #define UNICODE
    
    #include <windows.h>
    
    // ------------------------------------------------------------------------------------------- //
    
    #define STATIC_ID 5000
    
    // ------------------------------------------------------------------------------------------- //
    
    LRESULT CALLBACK MainProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
    
    // ------------------------------------------------------------------------------------------- //
    
    HINSTANCE hInst;
    
    // ------------------------------------------------------------------------------------------- //
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
    {
        hInst = hInstance;
    
        WNDCLASSEX main;
        main.cbSize         = sizeof(main);
        main.cbClsExtra     = 0;
        main.cbWndExtra     = 0;
        main.hbrBackground  = (HBRUSH) COLOR_APPWORKSPACE;
        main.hCursor        = LoadCursor(0,IDC_ARROW);
        main.hIcon          = LoadIcon(0,IDI_APPLICATION);
        main.hIconSm        = LoadIcon(0,IDI_APPLICATION);
        main.hInstance      = hInst;
        main.lpfnWndProc    = MainProc;
        main.lpszClassName  = TEXT("static_click");
        main.lpszMenuName   = 0;
        main.style          = CS_VREDRAW | CS_HREDRAW;
        RegisterClassEx(&main);
    
        HWND hMainWnd = CreateWindowEx(0,TEXT("static_click"),TEXT("static_click"),WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,100,60,0,0,hInst,0);
        ShowWindow(hMainWnd,SW_SHOW);
        UpdateWindow(hMainWnd);
    
        MSG msgMain;
        while(GetMessage(&msgMain,0,0,0))
        {
            TranslateMessage(&msgMain);
            DispatchMessage(&msgMain);
        }
    
        return msgMain.wParam;
    }
    
    // ------------------------------------------------------------------------------------------- //
    
    LRESULT CALLBACK MainProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
        static HWND hStatic;
    
        switch(uMsg)
        {
    
        case WM_COMMAND:
            {
                switch(HIWORD(wParam))
                {
    
                case STN_DBLCLK:
                    {
                        MessageBox(0,TEXT("Yeah!"),TEXT("..."),MB_OK);
                    } break;
    
                }
                return 0;
            } break;
    
        case WM_CREATE:
            {
                hStatic = CreateWindowEx(0,TEXT("static"),TEXT("Test"),WS_CHILD | WS_VISIBLE | SS_NOTIFY,5,5,90,16,hWnd,(HMENU) STATIC_ID,hInst,0);
                return 0;
            } break;
    
        case WM_DESTROY:
            {
                PostQuitMessage(0);
                return 0;
            } break;
    
        }
    
        return DefWindowProc(hWnd,uMsg,wParam,lParam);
    }
    

    Ich übernehme keine Haftung für Schaden aller Art :D. Aber bei mir funktioniert's so.

    cu

    EDIT: Und NEIN, mein normaler Code sieht _nicht_ so aus! 🙂

    [ Dieser Beitrag wurde am 14.12.2002 um 21:07 Uhr von MagiC Creator editiert. ]



  • mein pc ist von deinem kot kaputtgegangen



  • Glaub ich nicht, sonst hättest du ja gar nicht mehr hier antworten können :D.

    cu



  • @Magic

    Dein Code funzt prima, aber hast Du ne Erklärung dafür warum es so, über die Resource nicht funktioniert, müsste doch eigentlich genauso laufen, oder ?



  • Alarm zurück... auf einmal funzt der Code, frag mich nur warum ? Meiner sieht jetze so aus, aber noch ein Problem, wenn ich nur einen Klick abfangen will, also STN_CLICKED sagt er mir in meinem Code (wahrscheinlich BN_CLICKED) schon einmal existiert ! Liegt das an den selben wParam und lParam Werten die die Aufrufe zurückliefern ? Bestimmt, oder ?

    #include <windows.h>
    #include <stdio.h>
    #include "resource.h"
    
    char szposition[100]="";
    
    BOOL CALLBACK StaticProc (HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
        return DialogBox(hInstance,MAKEINTRESOURCE(DIALOG1),NULL,StaticProc);
    }
    
    BOOL CALLBACK StaticProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
        case WM_INITDIALOG:
    
            return true;
    
        case WM_LBUTTONDBLCLK:
    
            return true;
    
        case WM_COMMAND:
    
            switch(HIWORD(wParam))
            {
            case BN_CLICKED:
    
                if(LOWORD(wParam)==IDOK)
                    SendMessage(hwnd,WM_CLOSE,0,0);
    
                return true;
    
            case STN_DBLCLK:
    
                    MessageBox(hwnd,"Du hast auf das STATICFELD geklickt !","STATIC",0);
    
                return true;
            }
    
            return true;
    
            case WM_MOUSEMOVE:
    
                szposition[0]='\0';
                sprintf(szposition,"Maus ist bei: %i,%i",LOWORD(lParam),HIWORD(lParam));
                SendDlgItemMessage(hwnd,MAUSPOSITION,WM_SETTEXT,0,(long)szposition);
    
                return true;
    
            case WM_CLOSE:
    
                EndDialog(hwnd,0);
                PostQuitMessage(0);
    
                return true;
        }
        return false;
    }
    


  • STN_CLICKED == BN_CLICKED


Anmelden zum Antworten