|
Windows forms are C#, not C++.
|
|
|
|
|
Since this is the first thing I have done in C++ I am in no position to claim to know, and I certainly know nothing about C#, but in Visual C++ 2008 Express Edition it gives various templates to choose from when you start a new project and these include
Win32 Project, Win32 Console Application and Windows Forms Application. So I don't see that Windows Forms are C#. My underdstanding of a form is simply a window.
Anyway, since I have got things working this thread should be considered closed IMO.
|
|
|
|
|
Well to be specific, Windows Forms are a .Net thing, which is most notably interfaced to with C#, but there's other ways to do it... such as C++/CLI...
Windows Forms are not simply a window, its a .Net window.
|
|
|
|
|
martinmos wrote: I couldn't add a new case because using a variable (AuMessage ) gives a compilation error.
What is the error? You need to use the UINT corresponding to your custom message. In the "case:" you need to use an int, char, boolean, or enum.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
The error I get is
"error C2051: case expression not constant"
I declared the message as UINT and I tried casting it as int for the case switch but it looks like only a constant is allowed which means I can't have a custom message in the case statement which is why I added the if clause.
|
|
|
|
|
Right, so using an "if" is correct.
What's wrong with the messaging? How are you identifying which thread/window to send messages between processes?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I know nothing about threads yet.
I identify the window of the app to send the message to using FindWindow. I do that at the start of the program before the message loop starts but after the form has been created. Then I send a message to the window and the message contains the handle of the form in my C++ program. The app receiving the message displays the handle in a label so I can see it's worked ok. Then on the other app I have a button, when I click the button to test sending a message back a message is sent back to the C++ app using the window handle that was given. My C++ app recieves the massage ok every time I press the button. But if I set a global int to some value, say 7, when I receive the message, and in my main loop I send a message back if the int is some value, say 7, then the message is sent ok but no more messages are received in my winproc although the other app thinks they are sent ok but the return value is zero whereas in my winproc function I return 76.
My main loop is like this, modified so that it continually loops and doesn't hang waiting for a message. Maybe this is a bad idea?
<pre> // Main message loop:
while (1)
{ switch (msgin)
{ case 7:
SendMessage(hAuWiiWin,wiimsg,4,6);//4, 6 has no signifance at moment, just a test
msgin = 0;
//break;//seems break not allowed on last case?
}
if (PeekMessage(&msg,NULL,0,0,0))//so loop will continue if no msg
{GetMessage(&msg,NULL,0,0);
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Sleep(20);//don't know if this is good idea
}
</pre>
My winproc is like this
<pre>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
if (message == wiToMeCommand)
{
//ignore lParam, wParam for moment
msgin = 7;//set global int which is checked in main loop
//SendMessage(hMyWind,WM_CLOSE,0,0);//that works and this app closes
return 76;//just some value to indicate we got the msg
}
else
switch (message)
{
case WM_COMMAND:</pre>
|
|
|
|
|
You should not be using SendMessage() inside your main message loop. The message loop (or pump) is just used to receive messages from the outside world and dispatch them to your message handling code inside your WndProc() procedure. Your scenario should be something like:
If SEND button is pressed
Then
SendMessage(destWnd, myPrivateMessage, ...
End If
If other message ...
Then
Take action as necessary
If myPrivateMessage is received
Then
Do whatever ...
Endif
If other ... etc
All this code should be in the WndProc() functions which will only get invoked when a message is dispatched from the message loop.
The best things in life are not things.
|
|
|
|
|
Thanks for your reply.
I changed it as you described and I have now got things to work.
The reason I could only receive a message once weas due to an error in the app sending the message and which uses a language I am very familiar with. Because I don't have a clue what I'm doing in C++ I was looking for the problem in the C++ code!!
Thanks to all who replied.
|
|
|
|
|
Hi!!
I want to write a password program that asks for a password before win os boots.
even before windows prompts for password.
and then if password is correct it boots windows.. if wrong password is entered it again asks for password.
I dont wanna use CMOS password.. After the user is asked to select the OS from boot manager, the password should be asked for n then is correct password is entered, the os boots otherwise it asks for password again.
|
|
|
|
|
Think about this: if Windows has not been booted then how will your program run? Do you have the skills to write a self-loading program that can handle memory, keyboard input, screen output etc?
The best things in life are not things.
|
|
|
|
|
You mean, you want to write a boot loader? That's out of the scope of discussion for a forum thread like this (this board is specific for asking questions on C/C++/MFC). Google on the said topic though, and you may find something that might help you.
"Real men drive manual transmission" - Rajesh.
|
|
|
|
|
Yep, boot loader is the only way to do it.
|
|
|
|
|
I guess boot manager is responsible for loading the OS files...
After the user has selected the preferred OS to boot, My program is executed..
If there is list of files that the OS loads into memory before prompting the user for password(Windows' original password), I want my program to be included into this list as the second last program to be executed..
Can i do so???
|
|
|
|
|
By that time you will have reached the Windows login prompt so there seems little point. Why do you want to duplicate what is already available in a standard Windows configuration?
The best things in life are not things.
|
|
|
|
|
i want to use my password program before win os prompts for password...
|
|
|
|
|
Hi,
Yes there is a list of native applications that execute before session manager,winlogon. You can find the list in the registry at HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\BootExecute
There is an article here on codeproject that covers the native application subject fairly well.
Three Steps Down the Stairs: From Win32 User-Land through Native API to Kernel[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thanks for that... it'll surely help...
|
|
|
|
|
A word of caution:
While this is surely doable, you should take care that your password program doesn't accidentally lock out a user who forgot his password. Since this is to run before the windows logon, 'user' in this case means everyone!. Are you really sure you want to run this before the windows logon? I mean, if a user forgets his windows password, an administrator can still log on using his own password, and reset the users password for him. But if your program fails, how then will you ever get back on your machine?
|
|
|
|
|
Thanks... Will surely take care of it... Thanks for this scenario...
|
|
|
|
|
Do you mean like writing your own gina.dll (or the replacement process post-vista)
See:http://msdn.microsoft.com/en-ca/magazine/cc163489.aspx[^]
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
listen go to bios setting and there is a hardware password option select it and then give the password which u feel like and save and exit . The next time you boot in first u will have to enter password and your windows will boot.try it i have done it 
|
|
|
|
|
DO u know this password can be bypassed... I've bypassed this password so many times... Thats why i dont want to use it..
|
|
|
|
|
I have a structure, suppose USER_INFO. When my program starts it serializes this structure from an archive file. My program uses these values, modifies few of them and when my program exists it serializes all values to that file again which it can read again on next start up. This way I stores the state of the application.
Now the problem is that when I add a new field (or structure member variable) to structure. It can not read the old values from the file because structure size is now changed. I want a solution to overcome this problem. Currently an alternative way which I am using is introducing a new structure, read the old data in old structure, copy old data from old structure to new structure and write the new structure to the file. But it is not a good solution. Can Sqlite db give a better solution because adding a new filed in db is not a big problem?
|
|
|
|
|
Are you using MFC?
"Real men drive manual transmission" - Rajesh.
|
|
|
|