Skocz do zawartości

Poltergeist

Członkowie
  • Postów

    0
  • Dołączył

  • Ostatnio

    Nigdy

Posty napisane przez Poltergeist

  1. Mam taki problem - kod jest banalny - oprocz wyswietlenia okienka nie robi kompletnie nic. A jednak - zajętość procesora nie schodzi poniżej 97%. Dlaczego tak jest i co zrobic, zeby tak nie bylo?

    #include <windows.h>
    
    // Global event handle. This event is set when we the main window thread
    // wants to finish its existence
    HANDLE hGlobalEvent; 
    
    
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
            switch(Msg)
            {
                    
                    // message send when we want to close the window
                    case WM_DESTROY:
                    {
                            PostQuitMessage(0);
                            break;
                    }
                    
                    // default window procedure
                    default:
                            return DefWindowProc(hWnd, Msg, wParam, lParam);
            }
            
            return 0L;
    }
    
    
    
    
    DWORD WINAPI mainWindowThread(LPVOID lpParameter)
    {
            HINSTANCE hInstance = *((HINSTANCE*)(lpParameter));
            // define the new window class structure
            WNDCLASSEX wc;
            
            wc.cbSize                       = sizeof(WNDCLASSEX);
        wc.style                    = CS_VREDRAW | CS_HREDRAW;
        wc.lpfnWndProc              = WndProc;
        wc.cbClsExtra               = 0;
        wc.cbWndExtra               = 0;
        wc.hInstance                = hInstance;
        wc.hIcon                    = NULL;
        wc.hCursor                  = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground    = (HBRUSH)GetSysColorBrush(COLOR_3DFACE);
        wc.lpszMenuName             = NULL;
        wc.lpszClassName    = "MAIN_WINDOW";
        wc.hIconSm                  = NULL;
            
            // register new window class
            if(!RegisterClassEx(&wc))
                    return 1;
    
            // create main window program based on the previously registered window class
            HWND hWnd = CreateWindowEx( NULL, "MAIN_WINDOW", "main_window", WS_OVERLAPPEDWINDOW,
                                                                    50, 50, 800, 600, NULL, NULL, hInstance, NULL);
            // show the window                                                      
            ShowWindow(hWnd, SW_NORMAL);
            
            
            // message loop
            MSG message;
            while(true)
            {
                    if( PeekMessage(&message, NULL, 0, 0, PM_REMOVE) )
                    {
                            if(message.message == WM_QUIT)
                                    break;
                            
                            TranslateMessage(&message);
                            DispatchMessage(&message);
                    }
            }
            
            SetEvent(hGlobalEvent);
            
            return message.wParam;
    }
    
    
    
    
    
    int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
            // we have to synchronize the main window thread with the main program thread,
            // meaning that until the main window thread doesn't exit, the main program
            // thread doesn't exit as well...
            
            // create a synchronizing event with initial state set to false
            hGlobalEvent = CreateEvent(NULL, true, false, "MAIN_WINDOW_THREAD_EVENT");
            
            // create a thread for the main window
            DWORD ThreadID;
            HANDLE hThread = CreateThread(NULL, 0, mainWindowThread, &hInstance, 0, &ThreadID);
            
            // wait until the state of the synchronizing event is set to true
            if( WaitForMultipleObjects(1, &hGlobalEvent, true, INFINITE) != WAIT_OBJECT_0 )
                    MessageBox(NULL, "Synchronization error", "Error", MB_OK);
            
            // close the main window thread handle
            CloseHandle(hThread);
    
    }

    Z gory dzieki za pomoc

  2. Mam problem - stworzylem kontrolke EDIT, ale nie mam zielonego pojecia, jak obsluzyc dla niej zdarzenie wcisniecia klawisza?

    Probowalem juz WM_COMMAND, ale do niczego nie doszedlem - notification code, przekazywany jako HiWORD(wParam) zwraca kod WM_KEYDOWN (256) nawet przy kliknieciu mysza, a jak obczaic kod klawisza to juz kompletnie nie mam pojecia.

    Probowalem tez WM_NOTIFY, ale ten komunikat w ogole sie nie pojawia.

    Nie musze mowic, ze umieszczenie obslugi komunikatu WM_KEYDOWN zostaje wywolane tylko dla nacisniecia klawisza, gdy focus jest na oknie-rodzicu kontrolki (norma - w koncu to jego procedura obslugi komunikatu).

    Prosze - pomozcie

    dzieki wielkie

×
×
  • Utwórz nowe...