|
You should enumerate top-level windows with EnumWindows. For each HWND returned, call GetProcessThreadProcessId and compare results with gived PID.
[edit]
Of course, this is GetWindowThreadProcessId, as Nish pointed out.
[/edit]
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Tomasz Sowinski wrote:
For each HWND returned, call GetProcessThreadProcessId
I think it should be GetWindowThreadProcessId
Nish
[Signature temporarily down]
|
|
|
|
|
|
|
I need to detect when my app (Win32, not MFC) is started from the command line and, if a certain switch is used, print some info and exit rather than start the GUI app.
For example, typing ``msdev'' at the C:\ prompt starts Developer Studio, but typing ``msdev /?'' just prints some usage info and exits.
I can't find anything on CodeProject. Can anyone point to some info on how to achieve this.
Thanks.
Regards,
Parish
while (!asleep)
code();
|
|
|
|
|
msdev uses a weird technique to accomlish this.
there are two files.
msdev.com -> a console program
msdev.exe -> win32 program
when you run msdev it is the com program that runs first because com has predominance over exe
If it has a /? then the msdev.com prints out all the info
If it does not then it will spawn msdev.exe
Nish
[Signature temporarily down]
|
|
|
|
|
Ah yes, I'd forgotten about that trick. Unfortunately it is not an acceptable solution in this case.
I failed to mention that this app already has some handling for outputting the info but the text only appears if the output is piped to MORE:
myapp /? | more
The app calls GetConsoleMode() and SetConsoleMode() but I suspect that these are being passed the wrong parameters (the app was originally Unix which uses a different mechanism to handle this).
while (!asleep)
code();
|
|
|
|
|
Perhaps you could compile a msdos stub into the program (using /STUB: linker input)? I don't know if this works well for NT (using cmd.exe)...
Another solution might be to check the main window class for ConsoleWindowClass.
/moliate
|
|
|
|
|
All you need is GetCommandLine(). When arguements are present, do something else.
Joel Lucsy (jjlucsy@ameritech.net)
|
|
|
|
|
I know that, and the code is there, but the problem is getting it to send the output to the correct place, i.e. the CMD window the app was started from.
I've found the reason *why* it doesn't work from reading the MSDN section about WinMain() but haven't found a solution.
When a win32 GUI app is run from the command prompt and I/O redirection is included *on the commandline*, e.g.
C:> myapp | more
C:> myapp > filename
then the apps starts with its' I/O linked to the pipe or redirect. However, if no redirection is included on the commandline then the app has no connection to the window (instance of cmd.exe) that it was started from. As the command prompt returns as soon as the app starts there appears to be no way, from within the app, of linking to the window it started from, they run as 2 unrelated tasks; even usning "START /W myapp" does not achieve the desired result.
This contrasts with Unix where the apps' I/O is connected to the shell it was started from by default, even if the app is started as a background task (so the command prompt returns immediately - normally this doesn't happen until the app exits). When starting from a menu or icon it is usual to redirect stdout and stderr to the console (myapp > /dev/console 2>&1) so you can see any messages.
If you put this simplified piece of code in WinMain() and run the app from a CMD window you will not see any output unless you redirect on the commandline:
if (__argc > 1)
{
printf("Hello, world\n");
exit(0);
}
......
I assume that, by default, std{out,err} go to NUL??
while (!asleep)
code();
|
|
|
|
|
Hi,
I would like to retreive all the file names inside some particular folder(one by one).How can i do that?
Thanks
Neha
|
|
|
|
|
FindFirstFile and FindNextFile
Nish
[Signature temporarily down]
|
|
|
|
|
Check CFindFile
Mazy
"So,so you think you can tell,
Heaven from Hell,
Blue skies from pain,...
How I wish,how I wish you were here." Wish You Were Here-Pink Floyd-1975
|
|
|
|
|
Hi all,
I have several Spinbuttons attached to Multiline Editboxes. Multiline
because I want my text right aligned on different platforms.
The problem is that I don't catch the EN_CHANGE event anymore
when I use the Spinbuttons. This only works with the Singleline property.
I just want to enable a button when something in the Editboxes change!
Thanks,
Arjan.
|
|
|
|
|
Does anybody know why a class copy constructor gets ignored by compiler when objects of the class get passed to a function with unspecified number of arguments ?
The following code illustrates this. When the test runs, the output is 2 1 2 3 4, whereas I would expect 2 0 0 0 0. Please ignore the awfulness of the implementation of the MyClass::Foo function – it is just to prove that the compiler has passed the objects by value using the default copy constructor where as the class contains user-defined copy constructor.
Thanks,
Serge
#include "stdafx.h"
class MyClass
{
public:
MyClass(int first, int second) : a(first), b(second) {}
MyClass(const MyClass& r) : a(0), b(0) {}
void Foo(int arg, ...)
{
int* pArg = &arg;
printf("%i %i %i %i %i\n", arg, *(pArg + 1), *(pArg + 2), *(pArg + 3), *(pArg + 4));
}
private:
int a, b;
};
void main()
{
MyClass mc1(1, 2);
MyClass mc2(3, 4);
mc1.Foo(2, mc1, mc2);
}
|
|
|
|
|
According to the standard (§ 5.2.2 Function call), arguments passed in the ... part of the argument list must be either primitive (arithmetic types, pointers) or POD-structs. A POD-struct is a class that behaves as a simple aggregate of data, with no user-defined constructors (you can think of POD-structs as classes where it is permissible to do bitwise copy between objects). So you're entering the realm of undefined behavior in your program.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Your copy constructor is not being called. The reason for this can be found in the partial disassembly of the line
mc1.Foo(2, mc1, mc2);
31: mc1.Foo(2, mc1, mc2);
00401090 mov eax,dword ptr [ebp-0Ch] ---->points to mc2.b and loads it to eax
00401093 push eax ----->push value to stack for function
00401094 mov ecx,dword ptr [ebp-10h] ---->points to mc2.a and loads it to eax
00401097 push ecx ----->push value to stack for function
00401098 mov edx,dword ptr [ebp-4] ---->points to mc1.b and loads it to eax
0040109B push edx ----->push value to stack for function
0040109C mov eax,dword ptr [ebp-8] ---->points to mc1.a and loads it to eax
0040109F push eax ----->push value to stack for function
004010A0 push 2 ----->This is the first arg
004010A2 lea ecx,[ebp-8]
004010A5 push ecx
004010A6 call @ILT+0(MyClass::Foo) (00401005)
004010AB add esp,18h
This seems to be compiler optimization if I am not mistaken. However if you write
MyClass mc2(mc1); then the value of mc2 members a & b are 0 i.e. your copy constructor is called.
Atul
Sonork 100.13714 netdiva
|
|
|
|
|
Thanks for the answers, now it’s clear. As the disassembly shows, the compiler generated ‘default copy constructor’ and ignored the user-defined copy constructor. Surely, in this situation, the compiler must warn about what it is doing? Interesting, what the standard says about user defined copy constructors. Does it mention that copy constructors are not applicable in some cases? And how many case are there ?
|
|
|
|
|
Hi,
I'm writing a MIDI program that will write something on an Edit control of dialog whenever there is a MIDI message input.
The callback function for handling MIDI input event needs to be either global or a static member function of such a dialog class. How can I make the callback function calls a member function of that dialog class ? (in order to change the text in the Edit control).
I have tried to make a global pointer and sets it to point to CMainFrame objects in order to access levels of members down to the dialog object. But this causes an invalid page fault in module MFC42D.DLL
Any suggestion will be highly appreciated.
T. Tanprasert (T_Tanprasert@yahoo.com)
|
|
|
|
|
this?
http://www.codeproject.com/useritems/callback_adapter.asp
t!
|
|
|
|
|
|
If I want to draw a picture (ownerdraw buttun) on a button, how can I do så that picture won't be "deleted". I mean I've tried pressing another button that painted a line on another. but when I drag the dialog outside the screen the line dissapeard. Thats ofcourse... but how to keep it there so not my WM_PAINT steal my line or picture?
Hope you understand me!
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
The draw message the button gets should always redraw, the same way that WM_PAINT always does. How are you handling the drawing of the button ?
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|
|
Is it a Big deal to do that stuff ??
See my problem is our Art director has given me a task to create a fancy shaped toolbar which is a mixture of Office2K type Flat toolbars and Mac os type round edges etc.
I tried to study some of the very good toolbar classes available on CodeProject, but it seems that I can Draw only within the buttons area. not on the edges or Title bar of the toolbar(when its floating) so I need some guidance of how to go about this kind of a stuff.
Gurus please guide me .. I dont mind working hard to write a Toolbar class from the scratch.
Abhishek Narula
"Learn to appreciate others ... World would appreciate you"
|
|
|
|
|
The NCPAINT message lets you draw around the edges. If you decide to roll your own, look through the MFC source first to see how it all works.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
"I'm thinking of getting married for companionship and so I have someone to cook and clean." - Martin Marvinski, 6/3/2002
|
|
|
|