עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

בעיה מוזרה בC++

Featured Replies

פורסם

אני עשיתי חלון בC++ אבל משום מה הפעילות של החלון לא נגמר אחרי סוף התכנית אני ב Task Manager

ב Processes שהתוכניתרצה איך לתקן את זה?

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
//globals
LPDIRECT3DDEVICE9 p_Device;
bool AppRunning = true;
//end globals
//functions
HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h);
LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2);
LPDIRECT3DDEVICE9 InitDevice(HWND wnd);
void DrawScene();

//end Functions

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow)
{
MSG msg;
HWND wnd = NewWindow("stamchalon",100,100,500,500,hInstance);
ShowWindow(wnd,SW_SHOW);
UpdateWindow(wnd);
p_Device = InitDevice(wnd);
while(AppRunning)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{

DrawScene();
}
}
p_Device->Release();
DestroyWindow(wnd);
return 0;
}
HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h)
{
WNDCLASSEX wnd_Structure;

wnd_Structure.cbSize = sizeof(WNDCLASSEX);
wnd_Structure.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wnd_Structure.lpfnWndProc = OurWindowProcedure;
wnd_Structure.cbClsExtra = 0;
wnd_Structure.cbWndExtra = 0;
wnd_Structure.hInstance = h;
wnd_Structure.hIcon = NULL;
wnd_Structure.hCursor = NULL;
wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wnd_Structure.lpszMenuName = NULL;
wnd_Structure.lpszClassName = "DragonFighters";
wnd_Structure.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
RegisterClassEx(&wnd_Structure);
return CreateWindow(str_Title,str_Title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,500,500,0,0,h,0);

}
LRESULT CALLBACK OurWindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
switch(uint_Message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}

case WM_PAINT:
{
ValidateRect(han_Wind,0);
return 0;
}
break;
}
return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);
}
LPDIRECT3DDEVICE9 InitDevice(HWND wnd)
{
LPDIRECT3D9 p_dx_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(p_dx_Object == NULL)
{
MessageBoxA(wnd,"DirectX is not installed","Error",MB_OK);
AppRunning = false;
}
D3DPRESENT_PARAMETERS dx_PresParams;

ZeroMemory( &dx_PresParams, sizeof(dx_PresParams) );
dx_PresParams.Windowed = TRUE;
dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN;
LPDIRECT3DDEVICE9 p_dx_Device;

p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device);
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
MessageBox(wnd,"Failed to create even the reference device!","Error",MB_OK);
}
}
return p_dx_Device;
}
void DrawScene()
{
p_Device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);
p_Device->BeginScene();
//here we draw our scene
p_Device->EndScene();
p_Device->Present(NULL,NULL,NULL,NULL);
}

פורסם

למה פשוט לא לעבור ל XNA או managed directx..

בכל מקרה, נראה לי שהבעיה אולי קשורה לזה שאתה בודק אם יש WM_QUIT שזה קורה כששולחים למשל PostQuitMessage שאתה קורא לו ב WM_DESTROY שהוא קורה כששולחים DestroyWindow אבל את זה אתה עושה אחרי ה WM_QUIT.

איך אתה יוצא מהתוכנה ? ע"י לחיצה על כפתור ה X בחלון ?

פורסם
  • מחבר

כן בלחיצה על כפתור ה X בחלון

פורסם

נסה להוריד את הבדיקה של WM_QUIT בלולאה הראשית. בפונקציית טיפול ההודעות, תוסיף טיפול ב WM_CLOSE שם תעשה את ה Release ו DestroyWindow (במקום איפה שהם עכשיו). וב WM_DESTROY תעשה PostQuitMessage(0);

פורסם

אני לא מבין אנשים שכותבים עוד UI ב- C++

פורסם

מה רע ב C++ ? יש את MFC ו WTL שדי מקלים על הנושא...

האמת מעניין באמת לכמה אנשים במחשב (בלי כרטיס מסך של ATI) מותקן ה .NET framework על המחשב.

פורסם

אפשר ב- .net 2 לפתח UI עשיר , מודרני וידידותי מאוד למשתמש בכמעט אפס שורות קוד

וכך זה מותיר לך זמן כמפתח לעסוק בנושאים יותר מתקדמים

אין שום סיבה שכמתכנת אני אכתוב למשל קוד שאם אני מגדיל חלון אז יתר הרכיבים בתוך החלון גדלים ו\או נצמדים לשוליים בהתאמה לגודל החלון

לעשות משימה כזו ב- C++ יכול לקחת מאות שורות קוד, ב- .net אין צורך לדאוג לזה בכלל

צריך לדעת לבחור נכון את שפת התכנות לכל מטרה, הדבר אחרון שהיתי עושה עם C++ זה UI

פורסם

כל אחד ומה שהוא רגיל אליו :)

ד"א מה שהוא עושה פה זה לא UI, הוא לומד מ tutorial ל directx רגיל, אומנם יש גם managed DX אבל פה הוא לא בונה ממשק..

יש גם ספריות שעוזרות לבנות ממשק שמאפשר דברים כאלו גם ב MFC, ועדיין מרבית התוכנות בעולם לא כתובות ב .NET (גם כאלו שיוצאות היום).

פורסם
  • מחבר

לא עבד

פורסם

תראה את הקוד החדש.

פורסם
  • מחבר

הנה

אבל אם אני דיבוג ואז רליס אז התוכנית נגמרת ולהפך


#include "resource.h"
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Terrain.h"
#define Radians (D3DX_PI/180)
#define Degrees (180/D3DX_PI)
#define ToRadians(n) n * Radians
#define ToDegrees(n) n * Degrees
//globals
HWND wnd;
LPDIRECT3DDEVICE9 p_Device;
D3DXMATRIXA16 m_world;
D3DXMATRIXA16 m_view;
D3DXMATRIXA16 m_projection;
LPDIRECT3DTEXTURE9 texture=NULL;
Terrain *te;
bool AppRunning = true;
float angle = 0;
struct CUSTOMVERTEX
{
float x,y,z;
float u,v;
};
#define CVFVF D3DFVF_XYZ | D3DFVF_TEX1
//end globals
//functions
HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h);
LRESULT CALLBACK WindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2);
LPDIRECT3DDEVICE9 InitDevice(HWND wnd);
void SetUpVertices(HWND wnd);
void SetUpCamera();
void DrawScene();

//end Functions

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow)
{
MSG msg;
wnd = NewWindow("DragonFighters",100,100,700,700,hInstance);
ShowWindow(wnd,SW_SHOW);
UpdateWindow(wnd);
p_Device = InitDevice(wnd);
SetUpCamera();
te = new Terrain(wnd,p_Device);
te->LoadHugeTerrain("test.raw");
p_Device->SetRenderState(D3DRS_LIGHTING,false);
if(D3DXCreateTextureFromFile(p_Device, "C://test.dds",&texture)!=D3D_OK)
{
MessageBox(wnd,"Cannot load texture","Error",MB_OK);
PostQuitMessage(0);
}
while(AppRunning)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
//if(msg.message == WM_QUIT)
// break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else{

DrawScene();
}
}
delete te;

PostQuitMessage(0);
DestroyWindow(wnd);
return 0;
}
HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h)
{
WNDCLASSEX wnd_Structure;

wnd_Structure.cbSize = sizeof(WNDCLASSEX);
wnd_Structure.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wnd_Structure.lpfnWndProc = WindowProcedure;
wnd_Structure.cbClsExtra = 0;
wnd_Structure.cbWndExtra = 0;
wnd_Structure.hInstance = h;
wnd_Structure.hIcon = LoadIcon(h,MAKEINTRESOURCE(IDI_DRAGONFIGHTERSICON));
wnd_Structure.hCursor = NULL;
wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wnd_Structure.lpszMenuName = NULL;
wnd_Structure.lpszClassName = "DragonFighters";
wnd_Structure.hIconSm = LoadIcon(h,MAKEINTRESOURCE(IDI_DRAGONFIGHTERSICON));
RegisterClassEx(&wnd_Structure);
return CreateWindow(str_Title,str_Title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,int_Width,int_Height,0,0,h,0);

}
LRESULT CALLBACK WindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
switch(uint_Message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_CLOSE:
{
p_Device->Release();
if(texture!=NULL)
texture->Release();
}
case WM_PAINT:
{
ValidateRect(han_Wind,0);
return 0;
}
break;
}
return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);
}
LPDIRECT3DDEVICE9 InitDevice(HWND wnd)
{
LPDIRECT3D9 p_dx_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(p_dx_Object == NULL)
{
MessageBoxA(wnd,"DirectX is not installed","Error",MB_OK);
AppRunning = false;
}
D3DPRESENT_PARAMETERS dx_PresParams;

ZeroMemory( &dx_PresParams, sizeof(dx_PresParams) );
dx_PresParams.Windowed = TRUE;
dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN;
LPDIRECT3DDEVICE9 p_dx_Device;

p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device);
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
MessageBox(wnd,"Failed to create even the reference device!","Error",MB_OK);
}
}
return p_dx_Device;
}

}
void SetUpCamera()
{
D3DXVECTOR3 pos(0,0,15.0f);
D3DXVECTOR3 target(0,0,0);
D3DXVECTOR3 up(0,1,0);
D3DXMatrixLookAtLH(&m_view,&pos,&target,&up);
p_Device->SetTransform(D3DTS_VIEW,&m_view);
RECT rect;
GetWindowRect(wnd,&rect);
D3DXMatrixPerspectiveFovLH(&m_projection,D3DX_PI/4,(rect.right-rect.left)/(rect.bottom-rect.top),1,50);
p_Device->SetTransform(D3DTS_PROJECTION,&m_projection);
}
void DrawScene()
{
p_Device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(72,61,139),1.0f,0);
p_Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
//D3DXMATRIXA16 rotation;
//D3DXMatrixRotationYawPitchRoll(&rotation,angle,angle/2,angle/3);
//D3DXMATRIXA16 transaltion;
//D3DXMatrixTranslation(&transaltion,-5,-5,-5);
//D3DXMatrixMultiply(&m_world,&transaltion,&rotation);
//p_Device->SetTransform(D3DTS_WORLD,&m_world);

p_Device->BeginScene();
//here we draw our scene
//p_Device->SetTexture(0,texture);
// p_Device->SetStreamSource(0, p_buffer, 0, sizeof(CUSTOMVERTEX));
// p_Device->SetFVF(CVFVF);
// p_Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 4);
te->Render();
p_Device->EndScene();
p_Device->Present(NULL,NULL,NULL,NULL);
angle+=ToRadians(2);
}

פורסם

אין לי את ה DX SDK מותקן, אבל נסה:

#include "resource.h"
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Terrain.h"
#define Radians (D3DX_PI/180)
#define Degrees (180/D3DX_PI)
#define ToRadians(n) n * Radians
#define ToDegrees(n) n * Degrees
//globals
HWND wnd;
LPDIRECT3DDEVICE9 p_Device;
D3DXMATRIXA16 m_world;
D3DXMATRIXA16 m_view;
D3DXMATRIXA16 m_projection;
LPDIRECT3DTEXTURE9 texture=NULL;
Terrain *te;
bool AppRunning = true;
float angle = 0;
struct CUSTOMVERTEX
{
float x,y,z;
float u,v;
};
#define CVFVF D3DFVF_XYZ | D3DFVF_TEX1
//end globals
//functions
HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h);
LRESULT CALLBACK WindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2);
LPDIRECT3DDEVICE9 InitDevice(HWND wnd);
void SetUpVertices(HWND wnd);
void SetUpCamera();
void DrawScene();

//end Functions

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow)
{
MSG msg;
wnd = NewWindow("DragonFighters",100,100,700,700,hInstance);
ShowWindow(wnd,SW_SHOW);
UpdateWindow(wnd);
p_Device = InitDevice(wnd);
SetUpCamera();
te = new Terrain(wnd,p_Device);
te->LoadHugeTerrain("test.raw");
p_Device->SetRenderState(D3DRS_LIGHTING,false);
if(D3DXCreateTextureFromFile(p_Device, "C://test.dds",&texture)!=D3D_OK)
{
MessageBox(wnd,"Cannot load texture","Error",MB_OK);
PostQuitMessage(0);
}
while(AppRunning)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
DrawScene();
}
}
delete te;
return 0;
}

HWND NewWindow(LPCTSTR str_Title,int int_XPos, int int_YPos, int int_Width, int int_Height,HINSTANCE h)
{
WNDCLASSEX wnd_Structure;

wnd_Structure.cbSize = sizeof(WNDCLASSEX);
wnd_Structure.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wnd_Structure.lpfnWndProc = WindowProcedure;
wnd_Structure.cbClsExtra = 0;
wnd_Structure.cbWndExtra = 0;
wnd_Structure.hInstance = h;
wnd_Structure.hIcon = LoadIcon(h,MAKEINTRESOURCE(IDI_DRAGONFIGHTERSICON));
wnd_Structure.hCursor = NULL;
wnd_Structure.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
wnd_Structure.lpszMenuName = NULL;
wnd_Structure.lpszClassName = "DragonFighters";
wnd_Structure.hIconSm = LoadIcon(h,MAKEINTRESOURCE(IDI_DRAGONFIGHTERSICON));
RegisterClassEx(&wnd_Structure);
return CreateWindow(str_Title,str_Title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,int_Width,int_Height,0,0,h,0);
}

LRESULT CALLBACK WindowProcedure(HWND han_Wind,UINT uint_Message,WPARAM parameter1,LPARAM parameter2)
{
switch(uint_Message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
AppRunning = false;
return 0;
}
case WM_CLOSE:
{
p_Device->Release();
if(texture!=NULL)
texture->Release();
DestroyWindow(han_wind);
break;
}
case WM_PAINT:
{
ValidateRect(han_Wind,0);
return 0;
}
break;
}
return DefWindowProc(han_Wind,uint_Message,parameter1,parameter2);
}
LPDIRECT3DDEVICE9 InitDevice(HWND wnd)
{
LPDIRECT3D9 p_dx_Object = Direct3DCreate9(D3D_SDK_VERSION);
if(p_dx_Object == NULL)
{
MessageBoxA(wnd,"DirectX is not installed","Error",MB_OK);
AppRunning = false;
}
D3DPRESENT_PARAMETERS dx_PresParams;

ZeroMemory( &dx_PresParams, sizeof(dx_PresParams) );
dx_PresParams.Windowed = TRUE;
dx_PresParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
dx_PresParams.BackBufferFormat = D3DFMT_UNKNOWN;
LPDIRECT3DDEVICE9 p_dx_Device;

p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device);
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
if (FAILED(p_dx_Object->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &dx_PresParams, &p_dx_Device)))
{
MessageBox(wnd,"Failed to create even the reference device!","Error",MB_OK);
}
}
return p_dx_Device;
}

}
void SetUpCamera()
{
D3DXVECTOR3 pos(0,0,15.0f);
D3DXVECTOR3 target(0,0,0);
D3DXVECTOR3 up(0,1,0);
D3DXMatrixLookAtLH(&m_view,&pos,&target,&up);
p_Device->SetTransform(D3DTS_VIEW,&m_view);
RECT rect;
GetWindowRect(wnd,&rect);
D3DXMatrixPerspectiveFovLH(&m_projection,D3DX_PI/4,(rect.right-rect.left)/(rect.bottom-rect.top),1,50);
p_Device->SetTransform(D3DTS_PROJECTION,&m_projection);
}
void DrawScene()
{
p_Device->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(72,61,139),1.0f,0);
p_Device->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);
//D3DXMATRIXA16 rotation;
//D3DXMatrixRotationYawPitchRoll(&rotation,angle,angle/2,angle/3);
//D3DXMATRIXA16 transaltion;
//D3DXMatrixTranslation(&transaltion,-5,-5,-5);
//D3DXMatrixMultiply(&m_world,&transaltion,&rotation);
//p_Device->SetTransform(D3DTS_WORLD,&m_world);

p_Device->BeginScene();
//here we draw our scene
//p_Device->SetTexture(0,texture);
// p_Device->SetStreamSource(0, p_buffer, 0, sizeof(CUSTOMVERTEX));
// p_Device->SetFVF(CVFVF);
// p_Device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 4);
te->Render();
p_Device->EndScene();
p_Device->Present(NULL,NULL,NULL,NULL);
angle+=ToRadians(2);
}

פורסם
  • מחבר

לא עובד

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.