|
Jepp, I've read them...
"There is an empty room full of people who think you are creative"
|
|
|
|
|
Hello Gurus,
I wish to build an application that will be a map designer for old fashionned 2D games.
The workspace will contain:
- references to tiles which are bitmaps either opened from existing bmp files or created by the application. So I will provide a simple bitmap editor. These bitmaps will be stored in separate .bmp files at a given path. I intend to save the path of the bitmap files in the main document. The tiles will be 3 sizes: 8x8, 16x16 or 32x32. The tiles are in 4 gray scales.
- tables: Once tiles are done (at least one tile), we can create tables of tiles. The tables will contain references to the tiles. All tiles in a table are the same size: 8x8 or 16x16 or 32x32.
- sprites, once tables are built (at least one table), we can create sprites, which are composed of tiles. the sprites's size are a multiple of the tile's size in width and eight.
- frames: These sprites can contain several frames. Frames are a set of sprites (of course). The size of sprites are any size but a multiple of the tiles in width and in height. all frames must be the same size.
- maps, like sprites, once tables are created (at least one), we can create maps. The size of map are any size but a multiple of the size of tile in widht and eight.
The document will open or save all these information.
I want to build all in visual with drag'n drop stuffs for the tables, sprites and maps editors.
I hope you see the application I wish to build.
How can I handle such application in MFC?
Thanks for the suggestions and helps.
Best regards.
Fred.
There is no spoon.
|
|
|
|
|
I would make an MDI application and associate different views (CView derived classes) with your MAP file. The reason to be MDI is so you can open your MAP file and BMP files at the same time, or copy and paste between different MAP files.
You can have different 'windows' open on the same document. Map overview, map editor, sprite placer, etc.
|
|
|
|
|
So, I should make a CView derived class for each type of files it must handle? one for a map (heart document), one for the tile, one for the table etc.?
There is no spoon.
|
|
|
|
|
Typically, there is a CDocument-derived class for each file TYPE that you will want to manage and at least one CView-derived class associated with each document. If you want to 'look' at the data in a a particular document in different ways, then you can attach different CView-derived classes to the same document. For exmaple, I might have a doument with some histical stock prices in it. One CView might be a grid of the symbols in rows and their values in columns. Another CView on the same document might contain picotorial graphs.
In your case, the map data might be contained in one document, tables another document, sprite lists another document. The map data might have different views - one view might be a spreadheet of the map data another view might be a picture of the map, etc.
|
|
|
|
|
It's not quite what you're after, but this article[^] might help.
|
|
|
|
|
hi, all
I got the "First-chance exception in PrevCheck.exe: 0xC0000005: Access Violation" when the program try to access one of the library file, the application is linked to .lib file, it's accessable....
cfg.Step().Format( "Checking Day Bucket for %s", m_tmDay.Format( "%D-%b-%y" ));
if I do F11, It should go to the function of cdate.h in library
string_t CDate::Format( const char * szFormat ) const
it will go there, but the same time, Access Violation come up....
also,
"First-chance exception in Pre.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception"
could anyone tell me what to check?
Cheers,
|
|
|
|
|
valerie99 wrote:
cfg.Step().Format( "Checking Day Bucket for %s", m_tmDay.Format( "%D-%b-%y" ));
could anyone tell me what to check?
The first thing I would do is break this statement down into three separate statements so that you can concentrate on one of them instead of all three.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Thanks for your reply. I broke it down, the access violation happened when the m_tmDay.Format( "%D-%b-%y" ) calling cdate.h function
string_t CDate::Format( const char * szFormat ) const
it's definited as "CDate m_tmDay;" in header file.
Thank you!
|
|
|
|
|
My suspicion is this correction required:
cfg.Step().Format( "Checking Day Bucket for %s", (LPCTSTR)(m_tmDay.Format( "%D-%b-%y" )));
|
|
|
|
|
Thank you. I just tried it, but it still gave me the access violation....
I think the problem is in cdate.h
string_t CDate::Format( const char * szFormat ) const
the "string_t" is another string library file......
don't know what to do........thanks ....
|
|
|
|
|
you saved me from hell...............!!!!!
it works!!!!!!!!!
|
|
|
|
|
Hi everyone,
I have a question. Do anyone know how to detect calibration in ATM machines?
I have a autoscript .exe file. When I run the file, it opens a dialog box having CAlibration button on it. When I hit the calibration button, it does the calibration and ends without showing that when it is done.
So, what my problem is, I want to detect that calibration window and see when it closes.
Your help will be appreciated.
Thanks
Preeti
Preeti9
|
|
|
|
|
you calibrate an automatic teller machine ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Yes,
Please help
Thanks
Preeti
Preeti9
|
|
|
|
|
Assuming it's running Windows (is it?), then you can use the standard techniques for any displayed window. For example: Use FindWindow to locate the dialog box. Periodically check if the window still exists (IsWindow). There are other methods to detect the process and when it closes provided that the process doesn't keep running after calibration is complete.
|
|
|
|
|
Hi,
Yes, its running on windows. I wrote a code that opens up the window , I mean completes calibration. Same as you said, use FindWindow to locate the dialog box. Its working properly but I don't know when does it completes the calibration. I am not able to detect when that window closes.
I don't know how to use IsWindow. Can you give me more detail on that?
Also, what other methods can you use to detect a process ?
Thanks for your help.
Waiting for more details.
Thanks
Preeti
Preeti9
|
|
|
|
|
IsWindow simply returns TRUE or FALSE if the specified window handle is a valid window or not. So, if it suddenly returned FALSE, obviously the window is no longer around.
Example:
HWND hWnd = FindWindow(....);
while( true )
{
if( ! IsWindow(hWnd) )
break;
Sleep(1000);
};
This is the quick and crude method. Find the window handle and periodically poll to see if the window still exists.
You can also do the same thing without polling by using a window hook. Lookup SetWindowsHook and CBTProc for more information.
To wait for the process to complete rather than the window. You need to get a process handle that's associated with that window and wait for it to close. This method, of course, will only work if the process doesn't live on after the window is destroyed.
Pseudo Example (error checking removed for brevity):
HWND hWnd = FindWindow(...);
DWORD ProcID;
DWORD ThrdID = 0;
HANDLE hProcess;
ThrdID = GetWindowThreadProcessId( hWnd, &ProcID );
hProcess = OpenProcess( SYNCRONIZE, FALSE, ProcID );
WaitForSingleObject( hProcess, INFINITE );
CloseHandle(hProcess);
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Thanks for your help...
I don't know but if I use here IsWindow, I am getting the same result as I was getting it earlier.
I am sending you my code ....have a look and let me know is this correct to detect the calibration , I mean when that window closes.
Here's the code:
{
CTouchScreenAPI* pTouch;
HWND hCalWin;
DWORD procId;
HANDLE hProcess;
DWORD dwWaitResult;
pTouch = CTouchScreenAPI::Create();
if (pTouch)
{
if (pTouch->Init())
pTouch->Recalibrate(FALSE);
else
MessageBox(NULL, "Created touchscreen interface OK, but Init() failed", "Info", MB_OK);
HWND hCalWin = ::FindWindow(pszABSPOINT_WND_CLASS_NAME, NULL);
while( true )
{
if( ! IsWindow(hCalWin) )
break; // window is gone;
Sleep(1000); // wait a second for window to close
};
GetWindowThreadProcessId(hCalWin, &procId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procId);
while (1)
{
dwWaitResult = MsgWaitForMultipleObjects(1, &hProcess, FALSE, 30*1000, QS_PAINT);
if (dwWaitResult == WAIT_OBJECT_0 + 1)
{
MSG xMsg;
while (PeekMessage(&xMsg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&xMsg);
DispatchMessage(&xMsg);
}
}
else if (dwWaitResult == WAIT_TIMEOUT)
{
SendMessage(hCalWin, WM_CLOSE, 0, 0);
TerminateProcess(hProcess, 0);
break;
}
else dwWaitResult == WAIT_OBJECT_0;
{
//Calibration process completed;
break;
}
}
Thanks
Preeti
Preeti9
|
|
|
|
|
A couple of things:
1. Does the pTouch->Recalibrate and/or CTouchScreenAPI::Create spawn another process? Or is the recalibrate function contained within your own process (separate thread maybe?) Does recalibrate return immediately?
2. You don't necessarily need to do both the IsWindow loop and the process loop. In any case you need to call GetWindowThreadProcessId before the IsWindow loop. Otherwise, what's the point? The window is gone so the call will always fail.
3. Don't use PROCESS_ALL_ACCESS unless you absolutely have to. Use the minimum security setting to get the job done. Depending on the circumstances and user's security level the call may fail trying for all access. SYNCHRONIZE is all you need for waiting on the handle. If you need to call TerminateProcess then add PROCESS_TERMINATE as well.
4. You might want to use QS_ALLINPUT rather than QS_PAINT so that all messages get processed. See "Waiting in a message_loop"" for an example.
5. Since you're apparently doing all this in a window oriented thread (probably you're main thread), you don't want to use Sleep(1000). This will just freeze up your window while you're waiting in the loop. It'd better doing only the process wait loop, peek message loop, or using a window hook to wait for close notification of the window.
6. It's kind of pointless to call TerminateProcess immediately after SendMessage. You're not exactly giving the process much time to clean up and exit normally. Don't call TerminateProcess except as last resort.
|
|
|
|
|
Hi there, First of all ,thank you for your help...
Now, coming to the code:
1. Recalibrate function is contained within the process. yes, recalibrate function return immediately.
2. Ok, I am gonna use IsWindow loop and calling GetWindowThreadProcessID before the loop.
3.Ok, I used Synchronize rather than Process_all_access.
4. is also Ok.
5. is also Ok.
6. Should I wait for some time and then call Terminate Process?
Thanks
Waiting for reply
Preeti
Preeti9
|
|
|
|
|
If the Recalibrate function is contained within your own process, then waiting for the process to complete won't work. You'll be waiting for yourself to exit. However, if recalibrate spawns off another thread (sounds possible since it returns immediately) then you can wait on the thread handle instead.
Use these tests to verify that another thread was launched.
Add code similar to:
pTouch->Recalibrate();
HWND hWnd = FindWindow(...);
DWORD RecalProcID;
DWORD RecalThreadID = GetWindowThreadProcessId( hWnd, &ProcID );
DWORD MyProcID = GetCurrentProcessId();
DWORD MyThreadID = GetCurrentThreadId();
HANDLE hRecalThread = OpenThread( SYNCHRONIZE, FALSE, RecalThreadID );
Put a breakpoint before the recalibrate call.
When breakpoint is hit, open the threads window (menu: Debug/Windows/Threads)
Monitor this window to see if another thread is created when recalibrate is executed.
If in the same process, then RecalProcID will match MyProcID.
If different thread, then RecalThreadID will be different than MyThreadID.
What you're looking for is that RecalThreadID is created fresh when Recalibrate is called (or when TouchScreen object is created) and that the thread goes away when the calibration is done.
If, on the other hand, RecalThreadID is the same as MyThreadID then you cannot use MsgWaitForMultipleObjects to wait on anything as you will be waiting on yourself. Then about the only you can do is check IsWindow periodically inside a PeekMessage loop. Undoubtedly you will need to process messages as the recalibrate itself will be depending on it.
What does the Recalibrate function return? Are there any other functions for checking for status?
Ultimately if the recalibrate spawns another thread and then the thread goes away when recalibration is complete, then you don't even need the IsWindow loop - just the MsgWaitForMultipleObjects.
|
|
|
|
|
![Go to Parent](https://www.codeproject.com/App_Themes/CodeProject/Img/arrow-up24.png) Hi,
Yes, I am doubtful if I can use here Msgwaitformultipleobjects or not....
I wasn't able to implement this:
pTouch->Recalibrate();
HWND hWnd = FindWindow(...);
DWORD RecalProcID;
DWORD RecalThreadID = GetWindowThreadProcessId( hWnd, &ProcID );
DWORD MyProcID = GetCurrentProcessId();
DWORD MyThreadID = GetCurrentThreadId();
HANDLE hRecalThread = OpenThread( SYNCHRONIZE, FALSE, RecalThreadID );
This is giving me errors for OpenThread.
I am sending you my code again and please let me know how to proceed further to detect that calibration window.
Here's the code:
// TSCalibrate.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "CWin32AbsPointAPI.h"
void main ()
{
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
CTouchScreenAPI* pTouch;
HWND hCalWin;
DWORD SYNCRONIZE;
DWORD procId;
HANDLE hProcess;
DWORD dwWaitResult;
pTouch = CTouchScreenAPI::Create();
if (pTouch)
{
if (pTouch->Init())
pTouch->Recalibrate(FALSE);
else
MessageBox(NULL, "Created touchscreen interface OK, but Init() failed", "Info", MB_OK);
HWND hCalWin = ::FindWindow(pszABSPOINT_WND_CLASS_NAME, NULL);
GetWindowThreadProcessId(hCalWin, &procId); // retrieves the identifier of the thread that created this window.
hProcess = OpenProcess(SYNCHRONIZE, FALSE, procId);//returns a handle to an existing process object
while( true )
{
if( ! IsWindow(hCalWin) )
break; // window is gone;
// Sleep( 1000); // wait a second for window to close
};
while (1)
{
dwWaitResult = MsgWaitForMultipleObjects(1, &hProcess, FALSE, 30*1000, QS_ALLINPUT);
if (dwWaitResult == WAIT_OBJECT_0 + 1)
{
MSG xMsg;
while (PeekMessage(&xMsg, NULL, 0, 0, PM_REMOVE))
{
if (xMsg.message == WM_QUIT)
return 1;
TranslateMessage(&xMsg);
DispatchMessage(&xMsg);
}// end of PeekMessage while loop.
}
else if (dwWaitResult == WAIT_TIMEOUT)
{
SendMessage(hCalWin, WM_CLOSE, 0, 0);
//TerminateProcess(hProcess, 0);
break;
}
else dwWaitResult == WAIT_OBJECT_0;
{
//Calibration process completed;
break;
}
}
}
else
{
MessageBox(NULL, "Unable to get pointer to Touchscreen interface", "Info", MB_OK);
}
return 0;
}
Thanks
Wating for reply
Thanks Once again
I don't know if I can attach files to this email...otherwise I would have send you all the files to check....I am confused. PLease help.
Preeti9
|
|
|
|
|
I was forgetting that OpenThread is available only for Windows 2000 and up. What operating system is this running on? If this is on 2000 and up, then you can enable those functions by adding:
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
before including the Windows header files.
In any case you don't need the OpenThread call and its wait loop just to be able to step through the first few lines in order to determine what threads are created.
What does Recalibrate return? TRUE/FALSE or something else?
|
|
|
|
|
I have windows XP.....But its still giving me errors with OpenProcess.
Recalibrate function is returning False....
Thanks
Preeti
Preeti9
|
|
|
|
|