Skocz do zawartości

Nighthawk

Członkowie
  • Postów

    0
  • Dołączył

  • Ostatnio

    Nigdy

Nighthawk's Achievements

Newbie

Newbie (1/14)

0

Reputacja

  1. A mam jeszcze jeden problem co zrobic aby ta kontrolka nie miglaa od ciaglego przerysowywanie?? oto jej kod: #include "control.h" ATOM RegisterGolControl( HINSTANCE hInstance) { WNDCLASSEX wincl; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hInstance = hInstance; wincl.lpszClassName = "GOL"; wincl.lpfnWndProc = GOLControlProcedure; wincl.hCursor=LoadCursor(NULL,IDC_ARROW); wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); wincl.style = 0; wincl.hIcon = NULL; wincl.hIconSm = NULL; wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; return RegisterClassEx(&wincl); }; //X i Y to miejsce gdzie maja byc narysowane kwadraty :) inline void DrawRectangle( HWND hwnd, int X, int Y, HBRUSH hBrush) { RECT rect; SetRect( &rect, X + 1, Y + 1, X + CellSize.x - 1, Y + CellSize.y - 1 ); HDC hDc = GetDC( hwnd ); X += CellSize.x -15; Y += CellSize.y -15; Rectangle(hDc,X,Y,X+CellSize.x,Y+CellSize.y); FillRect( hDc, &rect, hBrush ); ReleaseDC( hwnd, hDc ); }; void CreateDrawStructure( void ) { DrawPoint.x = 0; DrawPoint.y = 0; CellSize.x = 15; CellSize.y = 15; HBRUSH hbrush; DrawTable.resize(40); for( int i = 0; i < 40; i++) { hbrush = CreateSolidBrush( RGB( 255, 255, 255) ); DrawTable.resize(40, hbrush); } }; inline void DrawGrid(HWND hwnd, int left, int top, int right, int bottom) { static RECT rect; bool TooWidth = true,//zmienna ktore maja informowac czy wszystkie TooHeight = true;//komorki zmieszcza sie na planczy // najpierw oblicze ile pol moze byc narysowane //sprawdzam czy wszystkie pola moga byc narysowane //najpierw szerokosc // if( CellSize.x * DrawTable.size() > right - left ) // TooWidth = false; //potem wysokosc // if( CellSize.y * DrawTable[0].size() > right - left ) // TooHeight = false; //teraz mozemy to narysowa SetWindowPos( hwnd, HWND_TOP, left, top, right-left-20, bottom-top-50, SWP_NOMOVE); for( int i = 0; i < DrawTable.size(); i++) for( int j = 0; j < DrawTable[0].size(); j++) { if( i*CellSize.x >= right - left -20) TooWidth = false; if( j+CellSize.y >= bottom - top -50) TooHeight = false; if( TooWidth && TooHeight) DrawRectangle( hwnd, i*14, j*14, DrawTable[j] ); } }; LRESULT CALLBACK GOLControlProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static RECT rect; switch (message) { case WM_CREATE: CreateDrawStructure(); break; case WM_PAINT: DrawGrid( hwnd, LOWORD(wParam), HIWORD(wParam), LOWORD(lParam), HIWORD(lParam) ); break; case WM_COMMAND: MessageBox( NULL, "Tekst", "Tyul", MB_OK); break; default: return DefWindowProc (hwnd, message, wParam, lParam) ; break; } return 0; }; #include "control.h" ATOM RegisterGolControl( HINSTANCE hInstance) { WNDCLASSEX wincl; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hInstance = hInstance; wincl.lpszClassName = "GOL"; wincl.lpfnWndProc = GOLControlProcedure; wincl.hCursor=LoadCursor(NULL,IDC_ARROW); wincl.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); wincl.style = 0; wincl.hIcon = NULL; wincl.hIconSm = NULL; wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; return RegisterClassEx(&wincl); }; //X i Y to miejsce gdzie maja byc narysowane kwadraty :) inline void DrawRectangle( HWND hwnd, int X, int Y, HBRUSH hBrush) { RECT rect; SetRect( &rect, X + 1, Y + 1, X + CellSize.x - 1, Y + CellSize.y - 1 ); HDC hDc = GetDC( hwnd ); X += CellSize.x -15; Y += CellSize.y -15; Rectangle(hDc,X,Y,X+CellSize.x,Y+CellSize.y); FillRect( hDc, &rect, hBrush ); ReleaseDC( hwnd, hDc ); }; void CreateDrawStructure( void ) { DrawPoint.x = 0; DrawPoint.y = 0; CellSize.x = 15; CellSize.y = 15; HBRUSH hbrush; DrawTable.resize(40); for( int i = 0; i < 40; i++) { hbrush = CreateSolidBrush( RGB( 255, 255, 255) ); DrawTable.resize(40, hbrush); } }; inline void DrawGrid(HWND hwnd, int left, int top, int right, int bottom) { static RECT rect; bool TooWidth = true,//zmienna ktore maja informowac czy wszystkie TooHeight = true;//komorki zmieszcza sie na planczy // najpierw oblicze ile pol moze byc narysowane //sprawdzam czy wszystkie pola moga byc narysowane //najpierw szerokosc // if( CellSize.x * DrawTable.size() > right - left ) // TooWidth = false; //potem wysokosc // if( CellSize.y * DrawTable[0].size() > right - left ) // TooHeight = false; //teraz mozemy to narysowa SetWindowPos( hwnd, HWND_TOP, left, top, right-left-20, bottom-top-50, SWP_NOMOVE); for( int i = 0; i < DrawTable.size(); i++) for( int j = 0; j < DrawTable[0].size(); j++) { if( i*CellSize.x >= right - left -20) TooWidth = false; if( j+CellSize.y >= bottom - top -50) TooHeight = false; if( TooWidth && TooHeight) DrawRectangle( hwnd, i*14, j*14, DrawTable[j] ); } }; LRESULT CALLBACK GOLControlProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static RECT rect; switch (message) { case WM_CREATE: CreateDrawStructure(); break; case WM_PAINT: DrawGrid( hwnd, LOWORD(wParam), HIWORD(wParam), LOWORD(lParam), HIWORD(lParam) ); break; case WM_COMMAND: MessageBox( NULL, "Tekst", "Tyul", MB_OK); break; default: return DefWindowProc (hwnd, message, wParam, lParam) ; break; } return 0; };
  2. ot jest kod okna glownego ale jak wciskam przycisk to nic sie nie robi poza tym ze okno glowne traci focus i slychac "klik" z glosnikow a nic sie nie pojawia i juz nei wiem czy ja cos popsulem w kodzie czy cos sie popsulo w moim systemie :( #include <windows.h> #include "control.h" #include "struct.h" #include <fstream> using namespace std; dane Dane; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM); BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam );// /* Make the class name into a global variable */ char szClassName[ ] = "WindowsApp"; HINSTANCE hInst; int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { /* This is the handle for our window */ HWND hwnd; MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ hInst = hThisInstance; 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; if( !RegisterGolControl( hThisInstance ) ) MBOK("kontolka nie dziala", "UWAGA!!"); /* 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 */ 500, /* The programs width */ 500, /* 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 */ ); CreateWindow("button", "przycisk", WS_CHILD | WS_VISIBLE, 10, 10, 100, 20, hwnd, (HMENU) 501, hThisInstance, NULL ); // CreateWindow("GOL", szClassName, WS_CHILD | WS_VISIBLE, 10, 40, 50, 50, hwnd, // (HMENU) 502, hThisInstance, NULL ); // CreateWindowEx( ); /* Make the window visible on the screen */ ShowWindow ( hwnd, SW_SHOW); // UpdateWindow (hwnd) ; // InitCommonControls(); /* Run the message lo op. 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); } return messages.wParam; } LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static RECT rect; switch (message) /* handle the messages */ { case WM_PAINT: GetClientRect( hwnd, &rect ); // SendMessage( GetDlgItem(hwnd, 502), WM_PAINT, MAKELONG( rect.left, rect.top ), // MAKELONG( rect.right, rect.bottom) ); SendMessage( GetDlgItem(hwnd, 501 ), WM_PAINT, 0, 0); break; case WM_COMMAND: static int wyn =DialogBox( hInst, TEXT("IDD_DLG1"), hwnd, DialogProc ); if( wyn == -1) MessageBox( NULL, "nie dziala", "zle",MB_OK); else MessageBox( NULL, "dziala", "zle",MB_OK); break; 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; }; BOOL CALLBACK DialogProc(HWND hwndDlg,UINT uMsg, WPARAM wParam,LPARAM lParam ) { };
  3. Witam mam pare pytan dotyczacych WINAPI, ale najpierw wyjasnie problem. Stworzylme program zlozony z jednego przycisku ( przynajmnije na razie) i mojej wlasne kontrolki( jest to pole do gry zlozonez malych "kwadracikow") zakde z pol mojej kontrolki moze miec wlasny kolor. I tutaj pojawia sie moje pytanie: Co zrobic aby to cholerstwo nie migalo. Zakladam ze jest to efekt ciaglego rysowania, ale wystepuje on nawet jak nic nei robie z programem. 2) Nie wiem dlaczego ale w tym samym programie nie moge uruchomic MessageBox'ow. Moze jakies pomysle? 3) jak w Devie odpalic DialogBox'a ?? Zrobilem plik zasobow i niby odpalam funkcje DialogBox() i nic. Assassin.
×
×
  • Utwórz nowe...