odmalowanie okien winapi

0

witam mam problemik z wypisawaniem textu na oknie lub w kontrolce edit
sprawa wygląda tak wpisuje do kontrolki edit jakiś text a następnie wciskam klawisz. w obsłudze komunikatu tego klawisz wstawiam funkcje, która przepisuje text z edita do stringa a następnie wypisuje na polu okna lub w drugim edicie. niby wszystko działa ale po kazdym wpisaniu textu i wcisnięciu klawisz napis wyświetlany się nie zmienia dopiero po zminimalizowaniu okna i ponownym z maxymalizowaniu wyświetla nowy napis wstawiłem też wypisywanie textu w obsłudze komunikatu WM_PAINT ale nic nie dało

0

(chyba) trzeba przesłać nie komunikat WM_PAINT, tylko [nie pamiętam nazwy] który wskazuje że widok jest już nieaktualny (UPDATE? VALIDATE?)

0

Zamiast bezpośrednio wysyłać komunikaty do okna użyj funkcji RedrawWindow.

0

próbowałem wszystkiego UPDATE VALIDATE REDRAW i nic dalej ten sam efekt wstawiałem te funkcje w obsłudze komunikatu klawisza oraz w obsłudze WM_PAINT. wstawiłem nawet messageboxa żeby mi wyświetlał czy string przechowujący text się uaktualnia i tak właśnie sie dzieje więc wszystko niby ok a wyswietlić się nie chce HELP!

0

Rzuć jakimś kodem bo tak to tylko zgadywać można...

0

nie wiem gdzie popełniam błąd więc wkleiłem wszystko
jest troche pogmatwany ze względu na samodzielne próby
rozwiazania problemu

#include <windows.h>
#define ID_P1 501
#define ID_P2 502
#define ID_P3 503
#define ID_P4 504
#define ID_P5 505
#define ID_P6 506

HWND hwnd,hprzycisk, hprzycisk1,hprzycisk2,hpole, hpole1, hpole2;
LPSTR a,b,c;
DWORD d1, d2, d3;
CHAR* d,e;
CHAR f;
HDC hdc,hdc1;
PAINTSTRUCT ps;
RECT rc;
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
/* This is the handle for our window /
MSG messages; /
Here messages to the application are saved */
WNDCLASSEX wincl;

        /* Data structure for the windowclass */

/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);

/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;                 /* No menu */
wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
wincl.cbWndExtra = 0;                      /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
    return 0;

/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
       0,                   /* Extended possibilites for variation */
       szClassName,         /* Classname */
       "Windows App",       /* Title Text */
       WS_OVERLAPPEDWINDOW, /* default window */
       CW_USEDEFAULT,       /* Windows decides the position */
       CW_USEDEFAULT,       /* where the window ends up on the screen */
       544,                 /* The programs width */
       375,                 /* and height in pixels */
       HWND_DESKTOP,        /* The window is a child-window to desktop */
       NULL,                /* No menu */
       hThisInstance,       /* Program Instance handler */
       NULL                 /* No Window Creation data */
       );
       hprzycisk = CreateWindowEx(0,"BUTTON","start",WS_CHILD|WS_VISIBLE|WS_BORDER,50,50,150,30,hwnd,(HMENU)ID_P1,hThisInstance,NULL);
 hprzycisk1 = CreateWindowEx(0,"BUTTON","stop",WS_CHILD|WS_VISIBLE|WS_BORDER,50,100,150,30,hwnd,(HMENU)ID_P2,hThisInstance,NULL);
hprzycisk2 = CreateWindowEx(0,"BUTTON","koniec",WS_CHILD|WS_VISIBLE|WS_BORDER,50,150,150,30,hwnd,(HMENU)ID_P3,hThisInstance,NULL);
hpole = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,50,200,40,30,hwnd,(HMENU)ID_P4,hThisInstance,NULL);
hpole1 = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,100,200,40,30,hwnd,(HMENU)ID_P5,hThisInstance,NULL);
hpole2 = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,150,200,40,30,hwnd,(HMENU)ID_P6,hThisInstance,NULL);
SetWindowText(hpole,"a");
 SetWindowText(hpole1,"b");
  SetWindowText(hpole2,"c");
  
  SetRect(&rc,300,30,400,70);
d1 = GetWindowTextLength(hpole);
d2 = GetWindowTextLength(hpole1);
d3 = GetWindowTextLength(hpole2);

 a=(LPSTR)GlobalAlloc(GPTR,10);
 b=(LPSTR)GlobalAlloc(GPTR,2);
 c=(LPSTR)GlobalAlloc(GPTR,2);
 hdc = BeginPaint(hwnd,&ps);
//  TextOut(hdc,0,0,"fa",2);
                        
/* Make the window visible on the screen */
ShowWindow (hwnd, nFunsterStil);
UpdateWindow(hwnd);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
    /* Translate virtual-key messages into character messages */
    TranslateMessage(&messages);
    /* Send message to WindowProcedure */
    DispatchMessage(&messages);
}

/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;

}
CHAR* oblicz(){
// LPSTR a,b,c;
//HWND hpole, hpole1, hpole2;

GetWindowText(hpole,a,10);

GetWindowText(hpole1,b,2);
GetWindowText(hpole2,c,2);
return a;
}

/* This function is called by the Windows function DispatchMessage() */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages /
{
case WM_COMMAND:
switch(wParam)
{
case ID_P1:
d = oblicz();
int s;
// s=(int)a;
//s=2
s;
// a=(LPSTR)s;
// SetWindowText( hpole, "helo") ;
hdc1 = BeginPaint(hpole1,&ps);
SetRect(&rc,300,30,500,90);
GetWindowText(hpole,a,10);
//TextOut(hdc,200,100,"fa",2);
DrawText(hdc,a,-1,&rc,DT_CENTER);
ReleaseDC(hpole1,hdc1);
// GetUpdateRect(hwnd,&rc,true);
//InvalidateRect(hwnd,&rc,false);
UpdateWindow(hwnd);

                               MessageBox(hwnd,a,"test",MB_ICONINFORMATION);
                               break;
                          case ID_P2:
                               f='j';
                               d=&f;
                               MessageBox(hwnd,d,"test",MB_ICONINFORMATION);
                               break;
                          case ID_P3:
                               MessageBox(hwnd,"wcisnołeś koniec","test",MB_ICONINFORMATION);
                               break;
                          //default:
                            //      MessageBox(hwnd,"Zrobiłeś coś innego","test",MB_ICONINFORMATION);
                          
                                  }
                                  case WM_PAINT:
                                       GetWindowText(hpole,a,10);
                                       hdc1 = BeginPaint(hpole1,&ps);
                                       SetTextColor(hdc1,RGB(100,0,0));
                                       TextOut(hdc1,0,0,"    ",4);
                                        TextOut(hdc1,0,0,a,4);
                                        DrawText(hdc1,"              ",-1,&rc,DT_CENTER);
                                        DrawText(hdc1,a,-1,&rc,DT_CENTER);
                                        ReleaseDC(hpole1,hdc1);
                                            UpdateWindow(hwnd);
                                        //RedrawWindow(hwnd,&rc,ps,RDW_ERASE);
                                       // GetUpdateRect(hwnd,&rc,true);
  //  case WM_DESTROY:
    //    PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
     //   break;
    default:                      /* for messages that we don't deal with */
        return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;

}

0

Odmalowaniem powinna sie zajac DefWindowProc () o ile sie nie myle.
Niech procedura okna konczy sie tak:
return DefWindowProc (hwnd, message, wParam, lParam);
(wywal to z 'default:')

Na twoim miejscu nie konstruowal bym tak tego switch'a bo co jesli bedziesz obslugiwal komunikat WM_SIZE zeby pobrac rozmiar okna, a potem obsluzyc je w standardowy sposob?
Bedziesz musial recznie ustawic rozmiar okna... a tak to wystarczy w WM_SIZE pobrac rozmiar okna i break, a DefWindowProc() zrobi za Ciebie reszte.

0

Hmmm milo, ze tak blisko mnie mieszka jakis koder ;] (Sosnowiec)

0
int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)
{
  ...

 hdc = BeginPaint(hwnd,&ps); //<--- a to po co???

 ...
}

W dokumentacji mamy:

An application should not call BeginPaint except in response to a WM_PAINT message. Each call to BeginPaint must have a corresponding call to the EndPaint function.

Jeżeli chcesz pobrać kontekst okna użyj funkcji GetDC, a następnie zwalniaj go funkcją ReleaseDC

case WM_PAINT:
   GetWindowText(hpole,a,10);
   hdc1 = BeginPaint(hwnd,&ps);   
   SetTextColor(hdc1,RGB(100,0,0));
   TextOut(hdc1,0,0,"    ",4);
   TextOut(hdc1,0,0,a,4);
   DrawText(hdc1,"              ",-1,&rc,DT_CENTER);
   DrawText(hdc1,a,-1,&rc,DT_CENTER);
   ReleaseDC(hpole1,hdc1); //<--- zamiast tego użyj EndPaint
   UpdateWindow(hwnd);     //<--- to usuń
   return 0;   //<--- a to dodaj

W przypadku button'ów i editów, zamiast DrawText użyj SetWindowText.

To na razie tyle ;).

0

dzięki wielkie zaraz nad tym posiedze jak coś wyjdzie to dam znać
PS mi też jest miło że nie jestem sam w regionie ;)

0

ciekawe zjawisko jak użyłem GetDC zamiast BeginPaint to zaczeło jakoś rozsadnie działać jak uporządkuje kod to go wkleje dla zainteresowanych
dzięki wielkie za pomoc

0

case ID_P1:
d = oblicz();
hdc1 = GetDC(hwnd);
hdc2 = GetDC(hpole1);
SetRect(&rc,300,30,500,90);
GetWindowText(hpole,a,10);
TextOut(hdc2,0,0,a,4);
DrawText(hdc1," ",4,&rc,DT_CENTER);
DrawText(hdc1,a,-1,&rc,DT_CENTER);
ReleaseDC(hpole1,hdc1);

                         MessageBox(hwnd,a,"test",MB_ICONINFORMATION);
                               break;

i to już mniejwiecej działa

0
d = oblicz();
hdc1 = GetDC(hwnd);
SetRect(&rc,300,30,500,90);
GetWindowText(hpole,a,10);
SetWindowText(hpole,a);
DrawText(hdc1,"      ",4,&rc,DT_CENTER); //<--- a to po co?
DrawText(hdc1,a,-1,&rc,DT_CENTER);
ReleaseDC(hwnd,hdc1);
                                                                                       
MessageBox(hwnd,a,"test",MB_ICONINFORMATION);
break;

PS. a tak w ogóle to ten kod jest bez sensu :P

1 użytkowników online, w tym zalogowanych: 0, gości: 1