|
Are hbm & statBMP members of your dialog? Cause if you declare them in OnInitDialog they are destroyed and go out of scope when OnInitDialog returns.
|
|
|
|
|
Yes, they are members of the dialog!
|
|
|
|
|
hph wrote:
WS_VISIBLE | WS_CHILD | SS_CENTERIMAGE || SS_BITMAP,
You need to change this to:
WS_VISIBLE | WS_CHILD | SS_CENTERIMAGE | SS_BITMAP, You should also have your rectangle so that the right coordinate is greater than the left coordinate and the bottom coordinate is greater than the top coordinate. If you want the static to be 10x10, use
CRect(100,100,110,110) Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I have a Problem with my OLE Server.
Problem description:
I have an OLE server which is my own application (VC++ MFC).
It will be lunched in the MS Power Point, which is my OLE container.
How can I notify my container (PowerPoint) that something was done
(changed) in the server(my App)? I was thinking about Connection
Points but I'm not sure whether this will work. Can anyone tell
me what is the solution? How can I add Connection Points to the
simple application template generated by the MFC App Wizzard
(full server option)?
Thanks in advance!!!
gicio
|
|
|
|
|
I use CDC to draw some complicate figures on screen. My problem is to draw this figure only in a defined rectangle. So is the a way to define a rectangle in which CDC draw's and outside not, as when I draw outside the screen....
|
|
|
|
|
Try to create a compatible DC in memory with the 'defined rectangle' size you want. Draw your figure in this DC and copy it to the original DC.
|
|
|
|
|
What's wrong with setting the clipping region?
Steve S
|
|
|
|
|
Hi all
Convert Integer to String!
How?
Thanks
|
|
|
|
|
itoa (), ltoa () or sprintf () functions
|
|
|
|
|
_ultoa, _ultow
or
sprintf(szBuffer, "%d", 42);
or
CString strBuffer;<br />
<br />
strBuffer.Format("%d", 42);
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
Hi,
I am writing a small program that launches a third party application (a game). It extracts a few temporary, sensitive files to the hard disk, and makes sure that the user can't access them. This is the method it uses, and after trying most other avenues, I am pretty happy with it:
1) My program starts and extracts the files needed for the game to a temporary folder (and tells the system to delete these files if the system is rebooted)
2) My program then launches the game using ShellExecuteEx()
3) My program then finds the HWND handle to the game using FindWindow()
4) My program then monitors the game, checking to make sure it is the foreground window.
5) If the game (or one of its children - eg. an error box) is no longer the foreground window, my program deletes any sensitive files.
6) When the game is restored to the foreground window, my program re-extracts the necessary files. To ensure that the game doesn't try to access them before they are back on the disk, it takes these steps:
a) When the game is restored by the user, my program minimizes it again immediately.
b) My program will then show a dialog box saying "Restoring data, please wait..." with a progress bar.
c) Once the data is reloaded, my program restores the game window to the main window.
(If this sounds like an odd process, believe me that it is the best solution for what I am doing. Not necessarily the most ideal, but the best given the time I have and the little skill I have. )
So far, so good. However, because I am a relative novice, my code is far from perfect, and I am hoping someone here can show me a better way of writing the code that I am posting below, that deals with checking whether the game is in the foreground and with minimizing/restoring it accordingly. At the moment I am using a variable, int not_foreground, with GetForeGroundWindow() to check whether the game is the active window or not. However, although this works mostly, I have noticed that it doesn't work 100% of the time, which must be due to something seriously wobbly in my code (and is obviously not acceptable). Very occasionally (about 1 in 10) the game window isn't minimized by my program when the user tries to return to it, though I can't understand why. If someone could give me some pointers on how to improve this code, I would be really grateful.
Also, as I don't have access to my WinXP system for a few days and can only test this on WinMe, is there any reason the method I use for minimizing and restoring the game window wouldn't work on XP/2000 systems?
The code:
[code]
//ThirdPartyApp_hWnd = the application (game) that my program launched with ShellExecuteEx:
HWND ThirdPartyApp_hWnd = FindWindow(NULL,"Game window");
...
int not_foreground = 0;
//in main message loop:
//while the game window is active, test that it remains so:
if(not_foreground == 0)
{
if(ThirdPartyApp_hWnd != GetForegroundWindow())
{
//if the game window loses focus, make sure it's not just to a child window:
HWND checkwnd = GetForegroundWindow();
if(GetParent(checkwnd)!=ThirdPartyApp_hWnd)
{
/* My file deletion code would go here */
not_foreground = 1; //no longer foreground window
}
}
}
//while the game window is not active, check for it being restored:
if(not_foreground == 1) //not foreground
{
if(ThirdPartyApp_hWnd == GetForegroundWindow()) //game is back in foreground
{
//Minimize the program again:
SendMessage(ThirdPartyApp_hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0);
/* My file restore code would go here */
Sleep(5000); //For testing purposes, just wait 5 secs
//And now restore the game as the active window:
SetWindowPos(ThirdPartyApp_hWnd,HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW);
ShowWindow(ThirdPartyApp_hWnd,SW_RESTORE);
not_foreground = 0; //we are foreground again, so don't do this again
}
}
//message processing:
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
//If user destroys the launcher, close the game too:
SendMessage(ThirdPartyApp_hWnd,WM_CLOSE,0,0);
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
[/code]
As you can see, I'm using the straight WinAPI SDK with _no_ MFC. Any suggestions for improvements or tips as to why my code might be failing on occasion would be greatly appreciated.
May thanks,
KB
|
|
|
|
|
You could try using GetAncestor with the GA_PARENT flag instead of GetParent() because it sometimes returns an owner handle instead of a parent one (which means your foreground check would be in the wrong loop). Also, since the foreground check is only ever a 1 or 0 you should use
if(not_foreground == 1)
{
//do stuff
}
else
{
//Do stuff
}
Personally I would use SetWindowsHookEx with WH_CALLWNDPROC and a CallWndProc() CALLBACK to process the messages sent to the app for the loss of keyboard focus, window activation etc. This is event driven, much more efficient than polling the foreground window every time.
|
|
|
|
|
Thanks for the reply, this is really useful. The only problem with using SetWindowsHookEx - wouldn't that have to go in a separate DLL seeing as I am trying to get the messages that are being passed to a different application?
Many thanks,
KB
|
|
|
|
|
Kayembi wrote:
The only problem with using SetWindowsHookEx - wouldn't that have to go in a separate DLL seeing as I am trying to get the messages that are being passed to a different application?
Yes.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Correct, I'm not sure as to why this is *necessary* particularly if your not sharing any data, but the CALLBACK will need to be in the dll, perhaps you could have an initialise function that sets up the hook in the dll?
|
|
|
|
|
Dangleberry wrote:
I'm not sure as to why this is *necessary* particularly if your not sharing any data
The hook function is called in the context of the process that causes the callback, not the one that installs the hook. This means that the function must be loaded into the other process' address space. The only way this can happen is if it's in a DLL - an EXE cannot be loaded into another process' address space.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Gotcha Ryan, it makes a lot more sense now, thanks for that.
|
|
|
|
|
Thanks. Is there another way of doing this that is not so intensive as keep checking GetForegroundWindow()? Or do I definitely have to take the Windows hook DLL route?
Many thanks,
KB
|
|
|
|
|
Kayembi wrote:
Is there another way of doing this that is not so intensive as keep checking GetForegroundWindow()? Or do I definitely have to take the Windows hook DLL route?
A hook would probably be the best way to do it. You could do what you are doing - just don't do it constantly - wait for 10ms or so between checks. But I would recommend using a hook.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi !
I have an enumerated type with for instance 8 enumerations.
I would like to do a for() loop to go through each of the enumerations.
Is there a way to do it easily in C++, or do I have to use a for(int i=... ;... ;...) and cast the int into the enumerated type ?
Thanks !
Jerome
|
|
|
|
|
|
Jerome Conus wrote:
I would like to do a for() loop to go through each of the enumerations.
Unfortunately, a for loop like
enum day {Sun, Mon, Tue, Wed, Thu, Fri, Sat};
for ( day d = Sun; d <= Sat; d++)
...
will not work as you can't add 1 to d . Have you looked at Neville's suggestion.
|
|
|
|
|
I'm currently working on a videosurveillance software.
I have to display, as fast as possible, sequences of bitmaps, with
streching possibility.
I'm using VisualC++ 6.0, and I'm looking for someone who tried
different ways to display such images :
- drawdibdraw family functions
- strechdibits functions
- opengl texture mapping
- directx
- ... others ?
My goal is to find the FASTEST way to do it, whatever method.
Thanks
Mickey
|
|
|
|
|
Anyone knows how to work with 24bit pictures?
For negative it's not a problem, I just subtract every RGB value from 0xFF and it will be fine. But let's say we want to do a gray calculation like so: (3*red + 4*green + 2*blue)/9 for each RGB pixel. Since I have to use 8bytes in calculations, I get in 2pixels and 2 extra bytes which will just be there.
mm0: RR GG BB RR GG BB RR GG
and the next sequance will be:
mm0: BB RR GG BB RR GG BB RR
You see my problem?
How can I still use MMX to do this in 24bit pics?
thanks
|
|
|
|
|
Hi I am using a drag and drop to install a license file. How can I take the dropped file and save it to the install directory of the software?
I used an environmental variable to get the directory path where the file needs to be saved eg:
char *ptr;
ptr = getenv("LM_LICENSE_FILE");
I can do it using dialogs, but I need an alternative way, please help urgently!!!
|
|
|
|
|