|
Cédric gave you the solution: after mouse action, store the (new) rectangle coordinates into an 'array of rectangle coordinates' (as suggested you may better use a STL container as the std::vector ) and call in sequence InvalidateRect , UpdateWindow (to make re-paint happen), Inside the OnPaint message handler draw all the rectangles of the array.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thankx Cédric & CPallini, i hope this will help me
|
|
|
|
|
Hi,
I am inserting a OLE object yellow arrow to the left of some text
It seem like whenever I insert the object it effects the starting pos of the text
if (curr_start_cur == 0)
{
curr_start_cur = start;
curr_end_cur = end;
SetSel(curr_start_cur,((curr_start_cur+pos)-5));
oleptr->InsertObject(&reobject);
}
SetSel(Begin,Begin+pos+1);
setfontsize(11);
setbold();
SetColour(RGB(255,0,0));
setfontsize(11);
}
The following is my text
======> _ 000000 90EC D00C 0000 C STM R14,R12,12(R13) line 1
_ 000000 18CF LR R12,R15 line 2
The "======>" represent the OLE arrow object
from line 2 and downward all "_' are in red the rest of the text remains the normal color
however at line 1 the "_" is in red and also the following text is in read "000000 90EC"
was wondering if the insert object effects where the stating character of the SetSel starts
|
|
|
|
|
Hi all :
I wrote a simple dialog based program to control a specific machine. And there is a button on the program.
When I pressed the button, some functions (from the API of the machine) would be called to do something.
Because the document said that the function is asynchronous, it used PostThreadMessage() to send some API-defined messages.
And the function might be time out. So I used CreateThread() and SetTimer() to check the success message is received or not within the thread.
But I met a strange problem.
If I ran it with debug mode and set the breakpoint on function A (function A wasn't still be called), it runs normally.
If I ran it with debug mode and didn't set the breakpoint on function A or ran it with release mode, the function A would timeout.
But if I ran the sample program (vendor provide, but only binary file, don't have source code), it runs normally...
I checked the debug mode and release mode settings of the project.
The included folders, linked folders, library dependencies...etc are the same.
So I don't know how to solve this question...
Does anyone can give a hint or pointed what's wrong with the code ?
Below is my code :
WaitPostThreadMessage(), MyFunc1() are global functions
SUCCESS_MSG, ERROR_MSG are two messages sent by the machine
TIMEOUT_MSG is the message which I defined to represent the timeout.
The parameter dwThreadId would be sent to the machine to indicate which thread is the post target of the machine
When a user click the button. MachineProc::ClickBtn() will be called.
And I put the workflow code in CreatedThread().
The problem which I mentioned above occured at calling APIFuncB()
UINT_PTR uTimer;
int timerCount;
int timerThreshold;
bool bTimeOut;
void CALLBACK TimerFunc(HWND hwnd, UINT message, UINT idTimer, DWORD dwTime) {
timerCount++;
if(timerCount >= timerThreshold) {
bTimeOut = true;
}
}
int WaitPostThreadMessage() {
MSG msg;
while(!bTimeOut) {
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) {
switch(msg.message) {
case SUCCESS_MSG:
if(KillTimer(NULL, uTimer) == 0) {
}
return SUCCESS_MSG;
case ERROR_MSG:
if(KillTimer(NULL, uTimer) == 0) {
}
return ERROR_MSG;
default:
break;
};
TranslateMessage(&msg);
DispatchMessage(&msg);
}
if(bTimeOut) {
if(KillTimer(NULL, uTimer) == 0) {
}
break;
}
}
return TIMEOUT_MSG;
}
DWORD WINAPI CreatedThread(LPVOID) {
MSG msg;
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
int iResult;
DWORD dwThreadId = GetCurrentThreadId();
iResult = APIFuncA(argu1, dwThreadId);
iResult = MyFunc1();
}
int MyFunc1() {
int iResult;
bTimeOut = false;
timerCount = 0;
timerThreshold = 2;
APIFuncB();
uTimer = SetTimer(NULL, WM_APP_TIMER, 1000, (TIMERPROC)TimerFunc);
iResult = WaitPostThreadMessage();
if(iResult != SUCCESS_MSG) {
}
}
void MachineProc::ClickBtn() {
HANDLE hThread;
DWORD nThreadID;
hThread = CreateThread(0, 0, CreatedThread, 0, 0, &nThreadID);
}
The running ide is visual stuido 2005 (don't install windows sdk)
Thanks a lot.
|
|
|
|
|
It could be a timing problem, when you place a breakpoint and break into the debugger when it is hit, you change the timings of the program which might be just enough to make it succeed. (I'm talking from experience, synchronization issues are tricky)
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Thanks for the reply.
But I tried to change the time threshold. (I changed the threshold from 2 to 60)
The result is the same. Timeout still be happened.
So I think that the main problem is not about timing.
According to the experiment, it looks like there is another problem...
|
|
|
|
|
That is not what i meant...but if you are on to something then forget it
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Get a stopwatch and time how long it takes for APIFuncA() to run. From your symptoms it looks like the thread's exiting before APIFuncA() has run to completion.
I'd try simplifying your code - all that mucking about with Windows messages and threads is enough to give anyone a headache. How do you know that APIFuncA() has completed? There must be some indication somewhere.
Cheers,
Ash
modified on Wednesday, June 23, 2010 2:06 PM
|
|
|
|
|
Thanks for the reply.
The problem which I occurred is about APIFuncB(), not APIFuncA()
Accroding to the document, APIFuncA() returns an int value.
And does't need any waiting mechanism on APIFuncA().
But about APIFuncB(), the document only mentioned two points.
1 : APIFuncB() is asynchronous. When I call APIFuncB(), I must wait for PostThreadMessage of API.
And the message which API sent is SUCCESS_MSG and ERROR_MSG .
When I received the SUCCESS_MSG, I can call the subsequent API functions to do next steps.
2 : The timeout value of APIFuncB() is 1 second, so it suggest the timeout value in my program is 2 seconds.
And the document doesn't describe how to implement the waiting mechanism. I must implement by myself.
That's why I use SetTimer()、WaitPostThreadMessage()、TimerFunc() to implement the waiting mechanism.
Based on my code which posted in this article thread, I think that when I call APIFuncB(),
the created thread is still running, not ended.
Is my thought wrong ?
|
|
|
|
|
Hi
I'm creating a 3D app which the main purpose for it is to be a game engine renderer. The file format that I will use for geometry is the RAW Triangle, since it is very simple to understand. I've created a function able to read the entire 3d file and parse it to a IDirect3DVertexBuffer9. Things are going fine here, but the problem is when it becomes rendered. I'm not getting the full object rendered, it seems that file is corrupted.
|
|
|
|
|
ant-damage wrote: Things are going fine here, but the problem is when it becomes rendered. I'm not getting the full object rendered, it seems that file is corrupted.
Without seeing the code it is hard to know, but when you issue the call from your VertexBuffer are you setting the size and stride values correctly?
Tutorial on IDirect3DVertexBuffer9()[^]
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Yes. I used that tutorial from "drunkenhyena.com" to understand more about the direct 3d
The code I'm working is huge.
Here is the whole code.
main.cpp
#include "common.h"
#pragma comment(lib, "d3d9")
#pragma comment(lib, "user32")
#pragma comment(lib, "gdi32")
extern IDirect3D9 *g_d3d9;
extern IDirect3DDevice9 *g_device;
extern D3DPRESENT_PARAMETERS g_pparams;
extern const unsigned Width;
extern const unsigned Height;
extern HRESULT Init_d3d9(IDirect3D9 **d3d9);
extern void Init_pparams(HWND hwnd, D3DFORMAT format, D3DFORMAT depth, D3DPRESENT_PARAMETERS *pparams);
extern HRESULT Init_device(IDirect3D9 *d3d9, HWND hwnd, D3DPRESENT_PARAMETERS *pparams, IDirect3DDevice9 **device);
extern void Kill_d3d9(IDirect3D9 **d3d9, IDirect3DDevice9 **device);
HRESULT load_RAW(const char *fname, IDirect3DVertexBuffer9 **buffer, int *count)
{
HRESULT hr = E_FAIL;
FILE *f = fopen(fname, "r");
if(f)
{
(*count) = 0;
float tmp[3] = {0};
while(fscanf(f, "%g %g %g", &tmp[0], &tmp[1], &tmp[2]) == 3)(*count)++;
rewind(f);
HUD_VERTEX vert[(*count)];
memset(vert, 0, sizeof(vert));
for(int i = 0; i < (*count); i++)
{
fscanf(f, "%g %g %g", &(vert[i].x), &(vert[i].y), &(vert[i].z));
if(ferror(f))
{
fclose(f);
return hr;
}
}
fclose(f);
int byteLen = sizeof(vert);
hr = g_device->CreateVertexBuffer(byteLen, D3DUSAGE_WRITEONLY, HUD_VERTEX_fvf, D3DPOOL_MANAGED, buffer, NULL);
if(FAILED(hr))return hr;
void *ptr = NULL;
hr = (*buffer)->Lock(0, 0, &ptr, 0);
if(FAILED(hr))return hr;
memcpy(ptr, vert, byteLen);
hr = (*buffer)->Unlock();
if(FAILED(hr))return hr;
}
fclose(f);
return hr;
}
void Resources_Init()
{
}
void Resources_Free()
{
}
HRESULT Device_Render(IDirect3DVertexBuffer9 *buffer, int count)
{
HRESULT hr = D3D_OK;
hr = g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(1.0, 1.0, 1.0, 1.0), 0.0, 0);
if(FAILED(hr))return hr;
hr = g_device->BeginScene();
if(FAILED(hr))return hr;
g_device->SetFVF(HUD_VERTEX_fvf);
g_device->SetStreamSource(0, buffer, 0, sizeof(HUD_VERTEX));
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
g_device->EndScene();
g_device->Present(NULL, NULL, NULL, NULL);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_KEYDOWN:
case WM_CLOSE:
case WM_LBUTTONDOWN:
PostQuitMessage(0);
return 0;
default: return DefWindowProc(hwnd, message, wParam, lParam);
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "Render";
RegisterClass(&wc);
HWND hwnd = CreateWindow("Render", "Test window", WS_POPUP | WS_VISIBLE, 0, 0, Width, Height, NULL, NULL, hInstance, NULL);
HRESULT hr = D3D_OK;
hr = Init_d3d9(&g_d3d9);
if(FAILED(hr))
{
LOG("Init_d3d9() failed!", hr);
DestroyWindow(hwnd);
return 0;
}
Init_pparams(hwnd, D3DFMT_A8R8G8B8, D3DFMT_D24S8, &g_pparams);
hr = Init_device(g_d3d9, hwnd, &g_pparams, &g_device);
if(FAILED(hr))
{
LOG("Init_device() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
int circleTriangles = 0;
IDirect3DVertexBuffer9 *circle = NULL;
hr = load_RAW("circle.raw", &circle, &circleTriangles);
if(FAILED(hr))
{
LOG("load_RAW() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
MSG msg;
while(GetMessage(&msg, NULL, 0, 0))
{
hr = Device_Render(circle, circleTriangles + 1);
if(FAILED(hr))
{
LOG("Device_Render() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
hr = g_device->TestCooperativeLevel();
if(FAILED(hr))
{
LOG("TestCooperativeLevel() failed!", hr);
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return 0;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Kill_d3d9(&g_d3d9, &g_device);
DestroyWindow(hwnd);
return msg.wParam;
}
d3d9_api.cpp
#include "common.h"
IDirect3D9 *g_d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
IDirect3DDevice9 *g_device = NULL;
D3DPRESENT_PARAMETERS g_pparams = {0};
extern const unsigned Width = GetSystemMetrics(SM_CXSCREEN);
extern const unsigned Height = GetSystemMetrics(SM_CYSCREEN);
HRESULT Init_d3d9(IDirect3D9 **d3d9)
{
LOG(__FUNCTION__);
(*d3d9) = Direct3DCreate9(D3D_SDK_VERSION);
if(!(*d3d9))return E_FAIL;
else return D3D_OK;
}
void Init_pparams(HWND hwnd, D3DFORMAT format, D3DFORMAT depth, D3DPRESENT_PARAMETERS *pparams)
{
LOG(__FUNCTION__);
memset(pparams, 0, sizeof(D3DPRESENT_PARAMETERS));
pparams->BackBufferCount = 1;
pparams->MultiSampleType = D3DMULTISAMPLE_NONE;
pparams->MultiSampleQuality = 0;
pparams->SwapEffect = D3DSWAPEFFECT_DISCARD;
pparams->hDeviceWindow = hwnd;
pparams->Flags = 0;
pparams->FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
pparams->PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
pparams->BackBufferFormat = format;
if(depth == D3DFMT_UNKNOWN)pparams->EnableAutoDepthStencil = false;
else pparams->EnableAutoDepthStencil = true;
pparams->AutoDepthStencilFormat = depth;
pparams->Windowed = false;
pparams->BackBufferWidth = Width;
pparams->BackBufferHeight = Height;
}
HRESULT Init_device(IDirect3D9 *d3d9, HWND hwnd, D3DPRESENT_PARAMETERS *pparams, IDirect3DDevice9 **device)
{
LOG(__FUNCTION__);
HRESULT hr = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, pparams, device);
return hr;
}
void Kill_d3d9(IDirect3D9 **d3d9, IDirect3DDevice9 **device)
{
LOG(__FUNCTION__);
if((*device))
{
(*device)->Release();
(*device) = NULL;
}
if((*d3d9))
{
(*d3d9)->Release();
(*d3d9) = NULL;
}
}
extern void Resources_Init();
extern void Resources_Free();
HRESULT Reset_device(IDirect3DDevice9 *device, D3DPRESENT_PARAMETERS *pparams, HRESULT hr)
{
if(hr == D3DERR_DEVICELOST)
{
Resources_Free();
Sleep(500);
}
else if(hr == D3DERR_DEVICENOTRESET)
{
hr = device->Reset(pparams);
if(SUCCEEDED(hr))Resources_Init();
}
return hr;
}
common.h
#include <d3d9.h>
#include <stdio.h>
class gameLog
{
public:
gameLog(const char *file = "log.log")
{
FILE *f = fopen(file, "w");
fclose(f);
}
void operator()(const char *str, HRESULT hr = D3D_OK, const char *file = "log.log")
{
FILE *f = fopen(file, "a");
if(hr != D3D_OK) fprintf(f, "%s\tHRESULT: %#x\n", str, hr);
else fprintf(f, "%s\n", str);
fclose(f);
}
};
static gameLog LOG;
struct HUD_VERTEX
{
float x, y, z, rhw;
unsigned color;
};
const unsigned HUD_VERTEX_fvf = D3DFVF_XYZRHW | D3DFVF_DIFFUSE;
typedef HRESULT (WINAPI *D3DXCreateTextureFromFile_ENTRY)(IDirect3DDevice9 *pDevice, LPCTSTR pSrcFile, IDirect3DTexture9 **ppTexture);
inline HRESULT WINAPI D3DXCreateTextureFromFile(IDirect3DDevice9 *pDevice, LPCTSTR pSrcFile, IDirect3DTexture9 **ppTexture)
{
HINSTANCE hlib = LoadLibrary("d3dx9.dll");
if(hlib)
{
#ifdef UNICODE
D3DXCreateTextureFromFile_ENTRY func = (D3DXCreateTextureFromFile_ENTRY)GetProcAddress(hlib, "D3DXCreateTextureFromFileW");
#else
D3DXCreateTextureFromFile_ENTRY func = (D3DXCreateTextureFromFile_ENTRY)GetProcAddress(hlib, "D3DXCreateTextureFromFileA");
#endif
if(func)return func(pDevice, pSrcFile, ppTexture);
else return E_FAIL;
}
else return E_FAIL;
}
|
|
|
|
|
I did kind-of ask for that didn't I?? Okay... That's gonna take me a bit to look through....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
By the way I'm using Blender 2.49a for exporting the geometry files
Here
HRESULT load_RAW(const char *fname, IDirect3DVertexBuffer9 **buffer, int *count)
{
HRESULT hr = E_FAIL;
FILE *f = fopen(fname, "r");
if(f)
{
(*count) = 0;
float tmp[3] = {0};
while(fscanf(f, "%g %g %g", &tmp[0], &tmp[1], &tmp[2]) == 3)(*count)++;
rewind(f);
HUD_VERTEX vert[(*count)];
memset(vert, 0, sizeof(vert));
for(int i = 0; i < (*count); i++)
{
fscanf(f, "%g %g %g", &(vert[i].x), &(vert[i].y), &(vert[i].z));
if(ferror(f))
{
fclose(f);
return hr;
}
}
fclose(f);
int byteLen = sizeof(vert);
hr = g_device->CreateVertexBuffer(byteLen, D3DUSAGE_WRITEONLY, HUD_VERTEX_fvf, D3DPOOL_MANAGED, buffer, NULL);
if(FAILED(hr))return hr;
void *ptr = NULL;
hr = (*buffer)->Lock(0, 0, &ptr, 0);
if(FAILED(hr))return hr;
memcpy(ptr, vert, byteLen);
hr = (*buffer)->Unlock();
if(FAILED(hr))return hr;
}
fclose(f);
return hr;
}
And here
HRESULT Device_Render(IDirect3DVertexBuffer9 *buffer, int count)
{
HRESULT hr = D3D_OK;
hr = g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(1.0, 1.0, 1.0, 1.0), 0.0, 0);
if(FAILED(hr))return hr;
hr = g_device->BeginScene();
if(FAILED(hr))return hr;
g_device->SetFVF(HUD_VERTEX_fvf);
g_device->SetStreamSource(0, buffer, 0, sizeof(HUD_VERTEX));
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
g_device->EndScene();
g_device->Present(NULL, NULL, NULL, NULL);
}
|
|
|
|
|
I have never looked at the RAW output from Blender, and without compiling this only one thing "jumps" out at me....
g_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, count);
Are you sure that Blender is outputting a Triangle Strip or a list of triangles?
http://en.wikipedia.org/wiki/File:Triangle_Strip_Small.png[^]
In this example a Triangle strip would be vertexes A, B, C, D, E, F.
But a list of triangles would be:
A,B,C, C,B,D, E,C,D, F,E,D
You can see how incorrectly sending the right destination from one to the other could render with bizarre results....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Blender is outputting a strange kind of list of triangles. For instance, a circle, it seems that Blender is outputting a triangle fan.
|
|
|
|
|
ant-damage wrote: it seems that Blender is outputting a triangle fan.
Then you will need to define this as a triangle fan for display....
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
I think that I've found the solution for my problem here.
|
|
|
|
|
The RAW Triangle Format is parsed by reading lines, not individual values. That was what I didn't know.
|
|
|
|
|
congrats on finding it! I never worked with raw, we use other model formats.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
By the way, which formats do you use?
|
|
|
|
|
3dStudio, OpenFlight... Mostly
basically everything supported by open scene graph.
I haven't written my own loader for years.
_________________________
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
|
|
|
|
|
Hey, i just wanted to ask if theres a way i can read the data of a file so i can paste it to another file?
Like i read the data of cmd.exe and paste it to whatever.exe?
|
|
|
|
|
Please be clear what you are asking.
ALLERSLIT wrote: i can read the data of a file so i can paste it to another file?
cmd.exe is not a file to be read from, it's an executable.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Executables are files though
|
|
|
|
|