|
One thing you may have to consider is that you will have to heavily customize certain parts of tyour app if you want the help to be fully integrated, such as having a "Help" button on a dialog, context sensitive help etc.
You will need to override
virtual void CWinApp::WinHelp( DWORD dwData, UINT nCmd = HELP_CONTEXT );
as well as some of the other help messages
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
Hi, I am writing a modal dialog app without any MFC. I am painting the window
myself by handling the WM_PAINT messages (using a dc in mem to draw to and then using BitBlt).
The problem is when the dialog is moved very rapidly around the screen it
sometimes stops being drawn correctly. The dialog is then drawn as garbage like parts of the desktop, or is drawn only partially correctly.
Am I allowed to draw to areas of the dc in mem that will later be "covered" by edit boxes or static bitmaps (defined in the dialog resource)? Is this
the problem?
Here's the relevant code in the dialog proc:
case WM_PAINT:<br />
{<br />
BeginPaint(hWnd, &ps);<br />
Paint(hWnd, &ps);<br />
EndPaint(hWnd, &ps);<br />
break;<br />
<br />
<br />
}<br />
<br />
case WM_ERASEBKGND:<br />
return (LRESULT)1;
<br />
<br />
case WM_CTLCOLOREDIT:<br />
{<br />
SetBkMode((HDC)wParam,TRANSPARENT);<br />
SetBkColor((HDC)wParam,RGB(192,192,192));<br />
SetTextColor((HDC)wParam,RGB(0,0,0));<br />
return (BOOL)Back; <br />
}
Code for painting:
static void Paint(HWND hWnd, LPPAINTSTRUCT lpPS)<br />
{<br />
RECT rc;<br />
HDC hdcMem;<br />
HBITMAP hbmMem, hbmOld;<br />
HBRUSH hbrBkGnd;<br />
<br />
<br />
GetClientRect(hWnd, &rc);<br />
<br />
<br />
hdcMem = CreateCompatibleDC(lpPS->hdc);<br />
<br />
<br />
hbmMem = CreateCompatibleBitmap(lpPS->hdc,<br />
rc.right-rc.left,<br />
rc.bottom-rc.top);<br />
<br />
<br />
hbmOld =(HBITMAP)SelectObject(hdcMem, hbmMem);<br />
<br />
<br />
hbrBkGnd = CreateSolidBrush(GetSysColor(COLOR_WINDOW));<br />
FillRect(hdcMem, &rc, hbrBkGnd);<br />
DeleteObject(hbrBkGnd);<br />
<br />
<br />
<br />
<br />
<br />
SetBkMode(hdcMem, TRANSPARENT);<br />
<br />
<br />
HPEN MyPen;<br />
HBRUSH MyBrush;<br />
<br />
MyPen=CreatePen(PS_SOLID,1,RGB(96,96,96));
MyBrush = CreateSolidBrush(RGB(96,96,96));<br />
SelectObject(hdcMem,MyPen);<br />
SelectObject(hdcMem,MyBrush);<br />
<br />
Rectangle(hdcMem,0,0,600,600);<br />
<br />
MyPen=CreatePen(PS_SOLID,1,RGB(0,0,0));
MyBrush = CreateSolidBrush(RGB(192,192,192));<br />
SelectObject(hdcMem,MyPen);
SelectObject(hdcMem,MyBrush);<br />
<br />
Rectangle(hdcMem,5,5+17,546,385+17);
<br />
MyPen=CreatePen(PS_SOLID,1,RGB(192,0,0));<br />
MyBrush=CreateSolidBrush(RGB(192,0,0));<br />
SelectObject(hdcMem,MyPen);<br />
SelectObject(hdcMem,MyBrush);<br />
<br />
Rectangle(hdcMem,10+xBuggy*40,10+(9-yBuggy)*40,20+xBuggy*40,20+(9-yBuggy)*40);
<br />
MyPen=CreatePen(PS_SOLID,1,RGB(0,0,0));
SelectObject(hdcMem,MyPen);
<br />
int xPos=15;<br />
int yPos=15;<br />
<br />
while(xPos<=570)
{<br />
MoveToEx (hdcMem, xPos, 15+17, 0);<br />
LineTo (hdcMem, xPos, 375+17);<br />
xPos=xPos+40;<br />
}<br />
<br />
<br />
while(yPos<=400)
{<br />
MoveToEx (hdcMem, 15,yPos+17, 0);<br />
LineTo (hdcMem, 535, yPos+17);<br />
yPos=yPos+40;<br />
}<br />
<br />
<br />
<br />
<br />
DeleteObject(MyPen);<br />
DeleteObject(MyBrush);<br />
<br />
<br />
<br />
BitBlt(lpPS->hdc, <br />
rc.left, rc.top,<br />
rc.right-rc.left, rc.bottom-rc.top,<br />
hdcMem,<br />
0, 0,<br />
SRCCOPY);<br />
<br />
<br />
SelectObject(hdcMem, hbmOld);<br />
DeleteObject(hbmMem);<br />
DeleteDC(hdcMem);<br />
<br />
}
|
|
|
|
|
Hi
I am writing a program to process multiple independent datas. This program is very processing intensive. So i am wondering if multi threading would help to reduce the amount of processing time.
I have doubts over it because I have only one processor. So wouldn't the time taken for the processing to be the same in multithreading case (or even more due to addition overhead)?? If it helps to cut down the time taken, how does it do it with only one processor?? Can someone please enlighten me ??
Thank you very much for the kind attention !!
|
|
|
|
|
boon kian wrote:
So wouldn't the time taken for the processing to be the same
Maybe, but your App stays responsive.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
boon kian wrote:
So i am wondering if multi threading would help to reduce the amount of processing time.
Not using a single CPU. Quite the opposite; the overhead will make the processing slower.
If the process is e.g. I/O bound the percieved speed of the application might benefit greatly from multithreading, but the total CPU time used will always be greater for a multithreading program than a singlethreded program (even if by such a small amount of time that one wouldn't even bother to try measure it).
|
|
|
|
|
I agree with the above posts, but there are some things you may want to consider...
First, the user usually despises apps that appear "frozen" and unresponsive. If you go calling a time-consuming data reduction function from the main UI thread, your app will appear to "hang" during processing. If you don't pump update messages and redraw the screen, the user can slide another window over your app, and your app will just appear blank and dead.
However, don't go off spawning 20 threads to process your stuff either! I would definately consider putting the data reduction algorithms in a seperate "worker" thread, and pumping progress messages from within it. Although you won't gain any speed (or may actually lose some), it is most likely in the best interest of the user.
This will keep your UI happy and responsive, and the world will be a better place
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
As has already been mentioned it could be slower, but you will find that the single CPU will be running at 100% all the time, whereas a single threaded app could be waiting for some input/event whilst trying to process the data.
If the data does lend it's self to multithreading then do it, you never know you may get a multi cpu machine, I do have a 2 cpu machine, but be careful as there could be an interaction between processing data on each of the cpu's that could cause the prog to hang/crash
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Ted Ferenc wrote:
whereas a single threaded app could be waiting for some input/event whilst trying to process the data.
umm, don't you mean a multi-threaded app?
A single thread will cycle through the processing algorithm and not return until complete. The multi-threaded app can process the data AND recieve messages from the user.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
What as I was trying to say was on a single CPU machine, multithreaded, the CPU usage will probably be 100% but if only one thread is used it could end up waiting for some event therefore it will not use 100% CPU time, but there is an overhead of course. But if multithreaded the likelyhood is that one thread may be waiting but another should be processing.
I fink my grammer was not correct, sorry
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
how can I capture the content of a fullscreen directx window.
I have absolutely no idea how this could be done.
thanks
widi
-
|
|
|
|
|
Is it "your" window? Then I believe it should be as simple as GetDC for the display surface and blit it to a bitmap.
|
|
|
|
|
No, it could be any (I guess mostly) fullscreen-game-windows.
-
|
|
|
|
|
|
Hy.
I'm trying to create a program that needs plugins. My problem is that i found quite a few methods of creating plugins, and i don't know wich method to use (wich one is better).
Anyway, here's what i need to be able to do:
- plugins must be able to access a list of data from the main program (for modifying it)
- plugins can show their own dialogs when executed
- i'd like to implement a Plugin Config system like Winamp3 has (there's a tree with each plugin as a treenode, and when you select one of them, the right side shows the plugin's config dialog)
- plugins should be able to add new commands to the main menu and toolbar of the application that loads them.
- also, the user should be able to select wich plugins not to load
So, if anybody has a good ideea on how can i make this all, please help me.
|
|
|
|
|
I have written a plugin system for a game launcher, and it works very fine and very similar to the one in Winamp2. The exe loads all .dll files in the plugin directory using LoadLibrary() . Of yourse you can make it selectable which files should be loaded.
In order to access data from the main program I have an exported function in my DLL that accepts a pointer parameter, here's an example:
extern "C" __declspec(dllexport) void _stdcall OnJoinServer(const hlla_SERVER* server)
Before you can user any exported functions I find their address in the DLL using GetProcAddress()
To bring up a configuration dialog I export e function in my DLL called OnConfigure ; the exe calls this function if the user clicks on "Configure" in the main app. Inside the OnConfigure function in the DLL I simply open the configuration dialog using DoModal() .
When my app finishes I close all handles to the plugins (dlls) with FreeLibrary()
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Well, i've found a system that does the loading/unloading for me (look at http://www.codeproject.com/dll/plug-in.asp).
My problem is that if i create MFC Extension DLLs, the LoadLibray and FreeLibrary functions don't work. So, i didn't find any way yet to use MFC classes in my DLLs.
I need some help with this part, as this i think is the most important one (as my DLLs will use MFC classes)
For the shared memory part (the list of data that plugins have to work with) i think i can send a pointer to that data (each plugin has a function that asks for that pointer), if anybody has a better ideea, please tell me.
For the Winamp like configuration i suppose that's not that extremly important, so i could leave it for a latter time (or leave it out completely from the project), so for now each plugin shows its own dialog with configurations.
|
|
|
|
|
LoadLibrary and FreeLibrary work like a charm for me in MFC Extension DLLs
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Then i'll have to look over it again, maybe i made some mistake.
Anyhow, i'll get back with more info (i'll have to make some tests).
Thanx anyway.
-----------------------------------
Ok, i looked it over, it didn't load the dlls as i made a mistake when i declared them, now i can load MFC extension DLLs too.
Thanx.
|
|
|
|
|
Im in the process of developing an application that requires a imilar plugin architecture. However, unlike the last response, I have chosen COM as a way of handling such things. I have not solved, or identified all of the problems associated with doing it this way, but heres the basis for my design.
- Component Categories in COM would allow my applicaiton to load any registered component on the system thats fits into my architecture.
- Using a simple, but efficiently designed interface that will allow my app to identify, and understand each component. This interface would be common across every "plugin".
- an IConfig interface could handle executing the plugins configuration, but the implementation would be specific to each plugin.
- The main applicaiton contains the list of useable and loaded plugins. It could then easily generate a tree view that lists each plugin as a node along with access to the IConfig interface.
- Almost every plugin will be presented as an child window in an MDI application.
- My applicaiton would require multiple intances of each plugin.
- I have not solved the problem of presented a common data source to each of the plugins, but im also new to COM and have a shipment of books from Amazon heading my way.
Ryan Baillargeon
|
|
|
|
|
Just remember if you allocate memory from your DLL you have to free it from your DLL. One way to get around this is to pass a function pointer to your DLL for allocating memory.
Todd Smith
|
|
|
|
|
I'm about start a new MFC project and I have fallen at the first fence! I can't decide what type of project to create.
The project will record data (from an instrument on the RS232 port) and display the data as a graph. When it is complete the user will be able to store the data as a file, and view those files at a later date. Also, they can load other files in and overlay them with the existing data.
I think I need an SDI project because I need to open files and I want the File menu, but then how can I overlay one file over another or display data 'real time'? I've only ever used the view class to display data from a file.
Or could I use a Dialog project and add my own menu, 'Open' 'Save' but that sounds messy and I don't know where to start. Any ideas / advice?
Thanks,
Ali
|
|
|
|
|
Alison Pentland wrote:
but then how can I overlay one file over another or display data 'real time'?
Sounds like SDI/multiple views or SDI/single view with a non-modal dialog for the graph.
You probably have to overwrite the open file part of your document class with your own code.
If you have ONE set of Data, shown in different ways in different views -> SDI
If you have many unrelated data sets (like documents in MS-Word) -> MDI
Just my 2c
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
jhwurmbach wrote:
Sounds like SDI/multiple views or SDI/single view with a non-modal dialog for the graph.
Thanks for answering. Yes, I have only written one app before, but it was similar and I used a modeless dialog box when the data was being recorded and displayed the files using the 'CView' class later.
The difference with this app is that they need to be able to overlay old data while they record new data, so that they can look at trends while they happen. I guess I could do this in a modeless dialog box by adding a button called 'Overlay' then calling my own File Open code.
But I still will not be able to overlay stored files together using the Doc/View architecture because you can only have one file per view can't you?
Or have I got that wrong?
Thanks,
Ali
|
|
|
|
|
Alison Pentland wrote:
The difference with this app is that they need to be able to overlay old data while they record new data
That would mean that your 'data source class' adds new data items to the CDocument -derived class and this generates UpdateAllViews() , possibly with a specific (arbitrary) Number as a Hint on witch your Views redraw itself.
Or your View update themself in fixed intervals (using a timer). Either way, Data is only to be held in the Document, and views (and non-modal dialogs) show it.
As with overlaying different files:
You would have to do the loading yourself, that is true.
But you can overwrite the OnFileOpen() -code in the Application class to allow for opening more files with one Document.
Your views have then only to iterate over the vector of loaded graphs and display all of them one after another.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
I'd go either SDI w/ modless dialogs for graphs as stated above, or go dialog-based with modless dialogs for the graphs.
If you don't have a data storage/retrieval class yet, check out my article, CDataFile[^]. I do a lot of what you're talking about.
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|