Ir ao conteúdo
  • Cadastre-se

Cambalinho

Membro Pleno
  • Posts

    942
  • Cadastrado em

  • Última visita

Tudo que Cambalinho postou

  1. no windows 10, temos alguma configuração para mostrar a 1ª página de algum documento(doc, pdf, imagens), mas sem alterar o 'abrir'?
  2. como desenhar 1 linha usando o método BresenhamLine, angulo e comprimento maximo e o mapa para 3D(RayCasting)? Public Sub BresenhamLine(X1 As Long, Y1 As Long, X2 As Long, Y2 As Long, ByRef Map() As Long, ObjectSize As Long) Dim dx As Long Dim dy As Long Dim stepX As Long Dim stepY As Long Dim p As Long Dim MapX As Long Dim MapY As Long Dim x As Long Dim y As Long dx = Abs(X2 - X1) dy = Abs(Y2 - Y1) If X1 < X2 Then stepX = 1 Else stepX = -1 End If If Y1 < Y2 Then stepY = 1 Else stepY = -1 End If x = X1 y = Y1 'If (Map(Fix(x / ObjectSize), Fix(y / ObjectSize)) = 1) Then End Sub If dx > dy Then p = 2 * dy - dx Do While x <> X2 If p >= 0 Then y = y + stepY p = p - 2 * dx End If x = x + stepX p = p + 2 * dy If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If Loop Else p = 2 * dx - dy Do While y <> Y2 If p >= 0 Then x = x + stepX p = p - 2 * dy End If y = y + stepY p = p + 2 * dx If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If Loop End If DrawLine X1, Y1, X2, Y2 End Sub Public Sub DrawLineWithAngleAndLength(X1 As Long, Y1 As Long, angle_deg As Double, Length As Long, ByRef Map() As Long, ObjectSize As Long) ' Converter o ângulo para radianos Dim angle_rad As Double angle_rad = angle_deg '* 3.14159 / 180... sim já uso Radianos ' Calcular as coordenadas finais da linha Dim X2 As Long Dim Y2 As Long X2 = X1 + Length * Cos(angle_rad) Y2 = Y1 + Length * Sin(angle_rad) ' Chame a função BresenhamLine com as coordenadas finais BresenhamLine X1, Y1, X2, Y2, Map, ObjectSize End Sub estou a obter resultados inesperados no if: If (Map(Int(x / ObjectSize), Int(y / ObjectSize)) = 1) Then ForeColor vbBlack DrawLine X1, Y1, X2, Y2 Exit Sub End If até posso obter '-1'... mas não faz sentido... porque o Zero do array Map() é 1... por isso não me deveria dar esse erro
  3. muito obrigado pela correção. me corrija mais um pouco: - mesmo que a classe esteja numa libraria tenho de usar sempre o 'new'? - com o 'new' é possível chamar 1 função\método? sim, chama o initializate()... mas posso usar parametros?
  4. dim s as newclasse set s = new newclasse sempre que crio 1 instancia da classe tenho de fazer essa segunda linha.... é possível evitar essa segunda linha? é possível 'meter' essa linha na classe?
  5. e consegui: Public ptr As Long Public Sub GetPointer(ByRef valor As Variant) 'Debug.Print TypeName(valor) If (TypeName(valor) = "Long") Then ptr = VarPtr(valor) ElseIf (TypeName(valor) = "String") Then ptr = StrPtr(valor) End If End Sub Public Sub SetValue(value As Variant) If (ptr = 0) Then Exit Sub If (TypeName(value) = "Long") Then Call CopyMemory(ByVal ptr, value, Len(value)) ElseIf (TypeName(value) = "String") Then CopyMemory ByVal (ptr), ByVal StrPtr(value), LenB(value) End If End Sub mas ainda me falta corrigir este código: Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Any) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Function GetValueAddressed() As Long If (ptr = 0) Then Exit Function GetValueAddressed = DeRef(ptr) End Function ainda não percebi como posso alterar estas funções para usar String
  6. agora o string funciona: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public ptr As Long 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Sub GetPointer(ByRef valor As Long) ptr = VarPtr(valor) End Sub Public Sub GetPointerString(ByRef valor As String) ptr = StrPtr(valor) End Sub Public Function GetValueAddressed() As Long If (ptr = 0) Then Exit Function GetValueAddressed = DeRef(ptr) End Function Public Sub SetValue(value As Long) If (ptr = 0) Then Exit Sub Call CopyMemory(ByVal ptr, value, Len(value)) End Sub Public Sub SetStringValue(value As String) If (ptr = 0) Then Exit Sub CopyMemory ByVal (ptr), ByVal StrPtr(value), LenB(value) End Sub Public Function GetAddressed() As Long If (ptr = 0) Then GetAddressed = 0 GetAddressed = Hex(ptr) 'hex for get the hexadecimal values: memory addresses End Function com uso(sempre me esqueço do 'set nomevaraivel = new tipo' kkkk) Private Sub Form_Load() Dim MyVar As String Dim ptr As Pointer Set ptr = New Pointer MyVar = "joaquim Miguel Cambarinho de Jesus" ptr.GetPointerString MyVar ptr.SetStringValue "hello world" Debug.Print MyVar End Sub resultado: "hello worlduel Cambarinho de Jesus" o que não sei: 1 - é possível juntar a função GetPointer() e GetPointerString() numa? e será que posso usar double e float? 2 - ainda não sei usar os arrays... se tiver algumas dicas, por favor diga
  7. muito obrigado pela correção. agora preciso de atualizar: posso usar o tipo 'variant' ou isso? estou a testar isto: Private Sub Form_Load() Dim MyVar As Long Dim name As String Dim s As String name = "joaquim" MyVar = VarPtr(name) s = "joao" CopyMemory ByVal (MyVar), s, LenB(s) Debug.Print name End Sub o resultado é: '??' e nem sei o motivo
  8. até testei, mas a linha fica vermelha.... e isso é erro.. testei agora mesmo... é sério: devido a ser assim que funciona.. .digo eu.. posso usar o tipo 'variant' ou 'object' para aceitar qualquer tipo de dados?
  9. resolvido: Private Sub Form_Load() Dim MyVar As Long, MyPtr As Long MyVar = 12345 ' Set a variable value MyPtr = VarPtr(MyVar) ' Get a pointer to variable Debug.Print DeRef(MyPtr) ' De-reference - Prints "12345": prints the address variable value Dim MyVar2 As Long MyVar2 = 2000 'copy the '24' value to address variable: Call CopyMemory(ByVal MyPtr, MyVar2, Len(MyVar2)) Debug.Print MyVar End Sub 1 - VarPtr() obtém o endereço da variável; 2 - DefRef() obtém o valor da variável endereçada; 3 - CopyMemory(ByVal PonteiroDestino, ValorOrigem, TamanhoOrigem)... ... sim 'ByVal' fez a diferença... declaração: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) o meu código usa Long, como posso fazer para aceitar outros tipos? acabei de atualizar a class: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private ptr As Long 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Public Sub GetPointer(ByRef valor As Long) 'permite aceitar o sinal de igual ptr = VarPtr(valor) End Sub Public Function GetValueAddressed() As Long GetValueAddressed = DeRef(ptr) End Function Public Sub SetValue(value As Long) Call CopyMemory(ByVal ptr, value, Len(value)) End Sub Public Function GetAddressed() As Variant GetAddressed = Hex(ptr) 'hex for get the hexadecimal values: memory addresses End Function 'como a uso: Private Sub Form_Load() Dim MyVar As Long Dim ptr As Pointer Set ptr = New Pointer MyVar = 30 ptr.GetPointer MyVar ptr.SetValue 2000 Debug.Print MyVar End Sub 'imprimido: '2000' e está correto.... o problema é que só aceita long
  10. o varptr() é para obter o endereço da variavel o MyPtr recebe o ponteiro.. agora como posso usar o 'MyPtr ' na CopyMemory() para alterar o valor na 'MyVar'? Call CopyMemory(MyPtr, 12, Len(MyPtr)) o 'MyPtr' tem o endereço da variável... como faço para CopyMemory() usar isso?
  11. o problema é que o 'MyPtr' é 1 ponteiro... e este é que altera o valor de 'MyVar'... e sim usei 1 valor literal para testar... então se o 'MyPtr' já tem endereço de memória do 'MyVar', como posso alterar o valor do 'MyVar' usando o 'MyPtr'?
  12. eis a declaração do CopyMemory() no VB6: Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) a minha questão é: como se usa o CopyMemory() corretamente? eu já tentei usar, mas sem sorte: Option Explicit Private Declare Sub GetDWord Lib "MSVBVM60.dll" Alias _ "GetMem4" (ByRef inSrc As Any, ByRef inDst As Long) Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) 'Gets the address variable value: Private Function DeRef(ByVal inPtr As Long) As Long If (inPtr) Then Call GetDWord(ByVal inPtr, DeRef) End Function Private Sub Form_Load() Dim MyVar As Long, MyPtr As Long MyVar = 12345 ' Set a variable value MyPtr = VarPtr(MyVar) ' Get a pointer to variable Debug.Print DeRef(MyPtr) ' De-reference - Prints "12345": prints the address variable value 'copy the '24' value to address variable: Call CopyMemory(DeRef(MyPtr), 24, Len(MyVar)) Debug.Print DeRef(MyPtr) End Sub o 'DeRef() é para obter o valor da variável endereçada; o VarPtr() é para obter o endereço da variável. o meu objetivo, agora, é criar 1 classe Ponteiros para usar em VB6. assim posso obter, por exemplo, 1 array de pixels do CreateBitmap() ou CreateDIBSection(). o CopyMemory() ajuda muito, mas ainda estou confuso a usar com variáveis, quanto mais com ponteiros e arrays.
  13. parece que resolvi: 1 - usei 1 leitor de cartões em vez do adaptador; 2 - usei 1 programa para o formatar; 3 - usei o DiskPart para limpar os atributos e vi que estavam corretos; 4 - mesmo com o adaptador posso apagar os ficheiros e pastas... 5 - porque o Windows não deixa formatar?
  14. essa trava está para cima, para baixo fica 'lock'.. testei 1 pen USB, Leitora de Cartões, e formatei com 1 programa... o Windows 10 não consegue formatar na mesma. tenho 1 erro no próprio cartão e talvez no adaptador, mas não sei resolver
  15. no adaptador do microsd, tenho 1 botão que está para cima... e isso permite fazer leitura e escrita... mas tenho 1 erro no cartão de memória: não posso apagar ou formatar, porque dá-me 1 erro de erro 'read-only'... eu já tentei usar o DiskPart do CMD sem sucesso
  16. eu sei que é 1 linguagem antiga... mesmo assim vamos falar sobre desempenho nos ciclos: Public Function SetTransparentColor(color As Long) Dim X As Integer Dim Y As Integer Dim c As Long Dim h As Long Dim w As Long Dim temp As BGRAQUAD ' substitua BGRColor pelo tipo de dado correto usado em bDibBGRA h = Height - 1 w = Width - 1 For c = 0 To h * w ' movendo as operações fora do loop for X = c Mod (w + 1) Y = Int(c / (w + 1)) temp = bDibBGRA(c) ' modificando apenas a propriedade necessária If (RGB(temp.B, temp.G, temp.R) = color) Then temp.B = 255 bDibBGRA(c) = temp End If Next c End Function esta função, mesmo sem nada dentro do 'for', consome imenso desempenho... porque isso acontece? deveria usar 'while' ou tem haver com outras coisas?
  17. eu percebi mal alguma coisa.. desculpe: #include <iostream> using namespace std; class test2 { public: void (*Hello)(); void hey() { if (this->Hello != NULL) this->Hello(); } }; void test2::Hello() { cout << "hello"; } int main() { test2::Hello(); cin.get(); return 0; } tenho 1 erro na linha: void test2::Hello() "error: cannot declare pointer to 'void' member"
  18. muito obrigado a todos... então fico com a questão: sei que posso usar variáveis de funções... mas é(é o meu objetivo principal) possível testar se a função foi definida ou não?
  19. consegui melhores resultados: double GetRadians(int Degrees) { return (Degrees*M_PI/180); } void DrawRayLine(double X0, double Y0, double Radians, int Width,int Walls[10][10], int WallWidth, int WallHeight) { double adjustedRadians = fmod(Radians, 2 * M_PI); double X1 = X0 + cos(adjustedRadians) * Width; double Y1 = Y0 + sin(adjustedRadians) * Width; if (X1 < X0) { double temp = X0; X0 = X1; X1 = temp; } double dx = abs(X1 - X0); double dy = abs(Y1 - Y0); double Steps; double x = X0; double y = Y0; if (dx >dy) Steps = dx; else Steps = dy; // Calcular incrementos double INCREMENTO = 5.0; double Xincrement = (dx / Steps) * INCREMENTO; double Yincrement = (dy / Steps) * INCREMENTO; // Restante do código para desenhar o raio // Verificar se toca em uma parede bool hitsWall = false; int S=0; while (x < X1 || y < Y1) { int currentX = static_cast<int>(x /32); int currentY = static_cast<int>(y /32); //cout << x << "\t" << y <<"\n"; if (currentX >= 0 && currentX < WallWidth && currentY >= 0 && currentY < WallHeight) { if (Walls[currentY][currentX] != 0) { hitsWall = true; break; } } x += Xincrement; y += Yincrement; S++; } MessageBox (NULL,to_string(S).c_str(), "hello",MB_OK); HDC HDCConsole = GetWindowDC(GetConsoleWindow()); HPEN LineColor = CreatePen(0,1,RGB(255,0,0)); HPEN OldPen =(HPEN)SelectObject(HDCConsole,LineColor); MoveToEx(HDCConsole,X0,Y0,nullptr); LineTo(HDCConsole,x,y); SelectObject(HDCConsole,OldPen); DeleteObject(LineColor); } HDC HDCConsole = GetWindowDC(GetConsoleWindow()); int main() { int LevelMap[10][10]= { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,1,0,0,1}, {1,0,0,0,0,1,0,0,0,1}, {1,0,0,0,0,0,1,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }; HBRUSH WhiteSquare=CreateSolidBrush(RGB(255,255,255)); HBRUSH BlueSquare=CreateSolidBrush(RGB(0,0,255)); HBRUSH OldBrush; for(int X=0, Y=0;Y<10;) { if(LevelMap[Y][X]==1) OldBrush=(HBRUSH)SelectObject(HDCConsole,BlueSquare); if(LevelMap[Y][X]!=1) OldBrush=(HBRUSH)SelectObject(HDCConsole,WhiteSquare); Rectangle(HDCConsole,X*32,Y*32,X*32+35,Y*32+35); X++; if(X>=10) { X=0; Y++; } SelectObject(HDCConsole,OldBrush); } DeleteObject(WhiteSquare); DeleteObject(BlueSquare); DrawRayLine(3.5*32,3.5*32,GetRadians(45),10000,LevelMap,10,10); cin.get(); return 0; } noto 1 problema: se 45º é anti-horario porquê este resultado da linha vermelha?
  20. sim... estou a tentar: void DrawRayLine(int X0, int Y0, float Radians, int Width,int Walls[10][10], int WallWidth, int WallHeight) { int X1 = X0 + static_cast<int>(cos(Radians) * Width); int Y1 = Y0 + static_cast<int>(sin(Radians) * Width); int dx = abs(X1 - X0); int dy = abs(Y1 - Y0); double Steps; double x = X0; double y = Y0; // Calcular incrementos double INCREMENTO = 32.0; double Xincrement = INCREMENTO * cos(Radians); double Yincrement = INCREMENTO * sin(Radians); // Restante do código para desenhar o raio // Verificar se toca em uma parede bool hitsWall = false; while (x < X1 || y < Y1) { int currentX = static_cast<int>(x /32); int currentY = static_cast<int>(y /32); //cout << x << "\t" << y <<"\n"; if (currentX >= 0 && currentX < WallWidth && currentY >= 0 && currentY < WallHeight) { if (Walls[currentX][currentY] != 0) { hitsWall = true; break; } } x += Xincrement; y += Yincrement; } HDC HDCConsole = GetWindowDC(GetConsoleWindow()); HPEN LineColor = CreatePen(0,1,RGB(255,0,0)); HPEN OldPen =(HPEN)SelectObject(HDCConsole,LineColor); MoveToEx(HDCConsole,X0,Y0,nullptr); LineTo(HDCConsole,x,y); SelectObject(HDCConsole,OldPen); DeleteObject(LineColor); } int main() { int LevelMap[10][10]= { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }; for(int X=0, Y=0;Y<10;) { HDC HDCConsole = GetWindowDC(GetConsoleWindow()); Rectangle(HDCConsole,X*32,Y*32,X*32+31,Y*32+31);// ainda não comparo os valores para mudar a cor X++; if(X>=10) { X=0; Y++; } } DrawRayLine(3*32,3*32,25*3.14/180,200,LevelMap,10,10); cin.get(); return 0; } este exemplo desenha a linha desejada, mas a linha termina no interior do quadrado e não no inicio do quadrado.... por usar o 32. e isso pode variar com o angulo.
  21. tem razão amigo... por isso alterei o código: void DrawLineAngle(int X0, int Y0, float Radians, int Width) { int X1 = X0 + cos(Radians)*Width; int Y1 = Y0 + sin(Radians)*Width; int dx = abs(X1-X0); int dy = abs(Y1-Y0); double Steps; double x=X0; double y=Y0; HDC HDCConsole = GetWindowDC(GetConsoleWindow()); HPEN LineColor = CreatePen(0,1,RGB(255,0,0)); HPEN OldPen =(HPEN)SelectObject(HDCConsole,LineColor); const double INCREMENTO = 32.0; if (dx >dy) Steps = dx; else Steps = dy; double Xincrement = (dx / Steps) * INCREMENTO; double Yincrement = (dy / Steps) * INCREMENTO; int v=0; while(x<=X1 and y<=Y1) { x = x + Xincrement; y = y + Yincrement; v++; }; if(x>X1) x=X1; if(y>Y1) y=Y1; cout << "Steps: " << v << "\n"; MoveToEx(HDCConsole,X0,Y0,nullptr); LineTo(HDCConsole,x,y); SelectObject(HDCConsole,OldPen); DeleteObject(LineColor); } agora funciona muito obrigado. esta função pode ser usada ou atualizada para usar numa grelha com quadrados de 32 por 32?(mesmo que só passe 3 ou 4 pixels no mesmo quadrado)
  22. eis a minha função atual para desenhar 1 linha com 1 comprimento e Radianos: void DrawLineAngle(int X0, int Y0, float Radians, int Width)//Width é 100 { int X1 = X0 + cos(Radians)*Width;//200 int Y1 = Y0 + sin(Radians)*Width; cout << "X1: " << X1<< "\n"; int dx = abs(X1-X0); int dy = abs(Y1-Y0); double Steps; double x=X0; double y=Y0; HDC HDCConsole = GetWindowDC(GetConsoleWindow()); HPEN LineColor = CreatePen(0,1,RGB(255,0,0)); HPEN OldPen =(HPEN)SelectObject(HDCConsole,LineColor); const double INCREMENTO = 32.0; if (dx >dy) Steps = dx; else Steps = dy; double Xincrement = (dx / Steps) * INCREMENTO; double Yincrement = (dy / Steps) * INCREMENTO; cout << "Xincrement: " << Xincrement<< "\n"; int v=0; for(v=0; v < Steps; v++) { x = x + Xincrement; y = y + Yincrement; cout << "X: " << x << " Y: " << y << "\n"; if(x>=X1 or y>=Y1) break;//porque tenho de usar esse 'if', senão dá-me mais comprimento } cout << v<< "\n"; MoveToEx(HDCConsole,X0,Y0,nullptr); LineTo(HDCConsole,X0+100,y); SelectObject(HDCConsole,OldPen); DeleteObject(LineColor); } e como a uso: DrawLineAngle(100,100,0,100); porque o ciclo 'for' é executado 1 única vez e o 'v' é zero? deveria somar '32' no 'x' e 1 vez seria '132', ou seja inferior ao comprimento.... o que estou a fazer errado no código?
  23. como usar '__attribute__((weak))'? #include <iostream> #define event __attribute__((weak)) using namespace std; class test2 { public: void Hello() event; void hey() { if(&Hello==NULL) Hello(); } }; /*void test2::Hello() { cout << "hello world!!!"; }*/ test2 a; int main() { a.hey(); return 0; } ao executar tenho 1 erro: "Process returned -1073741819 (0xC0000005) execution time : 0.680 s Press any key to continue." o erro está nesta linha que estou a tentar corrigir: if(&Hello==NULL) Hello(); como se usa o __attribute__((weak)) para testar se a função foi definida?

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!