|
I seen this in a PHP script the other day.
switch($base){<br />
case $a == 'a' || $b == 'd':<br />
break;<br />
}
I've never seen this before in C++ development, is it valid syntax?
I could have swore I tried it once in VC++ and it failed cause CASE requested a CONSTANT?
Is this in the ANSI C/C++ spec?
I'm finding the only constant in software development is change it self.
|
|
|
|
|
this works in PHP, because there isn't anything constant, if you would use variables in C++ an multiselection can occur.
So, i didn'd know any way to use code like this in C++.
|
|
|
|
|
I remember that some years ago I worked on a project and used:
switch($base){
case $a == 'a':
case $b == 'd':
{
make your things here
break
}
case $a == ... :
}
hope this helps...
PS: I've used that in C++ but in ms-dos, I suppose that the compiler still remember this syntax...
|
|
|
|
|
case expressions in C have to be integral constants.
|
|
|
|
|
I looked into the EBNF for C/C++ and it appears (from what I can tell) that is the case (np pun intended) for both languages and apparently C# as well?
I'm finding the only constant in software development is change it self.
|
|
|
|
|
I think C# lets you use a string variable in the switch, and string literals in the case statements. But C++ doesn't allow that.
|
|
|
|
|
Hello to all,
i want to start an executable prgm, by path, and want to get the hWnd of them.
like i write "notepad.exe" and then i want to get the hWnd of the executed window.
can someone help me?!
|
|
|
|
|
If you know the window's title and class name then you can use the FindWindow() API.
You can get this information with the Spy++ utility I believe.
If you use CreateProcess() to start the app, you'll get a process ID for the new process.
Using the EnumWindows() API, you can enumerate the windows on the screen and for each top level
window, use the GetWindowThreadProcessId() API and compare the process ID to the one obtained
by CreateProcess() until you find a match.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
In the continue with Mark Salsbery after run your exe you can use of for get handle
HWND hWnd = ::FindWindow("Notepad", NULL);
::SendMessage(hWnd,WM_CLOSE,0,0);
or you can use of EnumDesktopWindows() for enumerates all windows on a desktop with a handle for each window .
|
|
|
|
|
WhiteSky wrote: HWND hWnd = ::FindWindow("Notepad", NULL); //find notepad
This will work in a perfect world, but should be considered very dangerous. FindWindow() calls EnumWindows() , and for each top-level window handle found, it calls GetWindowText() , which just sends a WM_GETTEXT message to the window handle. If the thread that owns the handle is blocked, the call to SendMessage() will also block until that thread is freed up. In the event this never happens, FindWindow() will block forever, and your application will...
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'd be more worried about the effects on such code on innocent applications that just happen to be titled "Notepad" but are not the desired target.
Steve
|
|
|
|
|
Thank you for your advice
|
|
|
|
|
if you are using CreateProcess api you will get the process id.
Then you can use the EnumWindows api function and enumerate all windows.
In the call back procedure you will get the hwnd , so calling this api GetWindowThreadProcessId you will the process id for each window. Then you can compare it , with the earlier process id from CreateProcess..
If you have any more concern , let me know..
If u can Dream... U can do it
|
|
|
|
|
Hi
How can I set a Handle to a window?For example I want to create a new dialog box when I push the first button in main dialog box.And I want to destroy the created dialog box when I push the second button in main dialog box.I wrote this code to do that:
void CMainDialog::OnButton1()
{
CDlg1 *dlg1 = new CDlg1;
dlg1->Create(IDD_DIALOG1,this);
dlg1->ShowWindow(SW_SHOW);
dlg1->Attach(hwnd);
}
void CMainDialog::OnButton2()
{
CDlg1 *dlg1 = (CDlg1 *) FromHandlePermanent(hwnd);
dlg1->DestroyWindow();
}
That doesn't work.It doesn't give a syntax error but when I push the buttons it fails.How can I attach a handle to a window and how can I use this handle?And how can I solve this problem?
Thanks
|
|
|
|
|
Make the CDlg1 object a member of CMainDialog , rather than a local variable. Then the calls to Attach() and FromHandlePermanent() can go away.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Is the only way available the one that implies to create a manifest?
If so, I'll check for that on the msdn, but I hope that there will be an easier/faster way...
As always thank you in advance.
|
|
|
|
|
If this is an MFC app, look at the bottom of stdafx.h and you find
#ifdef UNICODE
...
...
#endif
Just delete the #ifdef line and the associated #endif, but leave everything in between.
For some reason, the default only enables the V6 Common Controls if UNICODE is defined.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
Worked fine, thank you very much.
|
|
|
|
|
If I want to appeal a windows form, from another form when I push a button, what I should do? I tried this code and I have the following error: Error error C2061: syntax error : identifier 'Results'
private: System::Void ResultsButton_Click(System::Object^ sender, System::EventArgs^ e)
{
Application::Run(gcnew Results());
}
|
|
|
|
|
Wrong forum, ask to C++/CLI one.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Its better you ask in this forum[^]
|
|
|
|
|
I was wondering if there is a tool/utility that would allow me to convert (back-port) a Visual C++ .NET 2003 project (.sln MFC Application) back to Visual C++ 6 (.dsw).
Thanks
|
|
|
|
|
|
Exactly what I needed....thanks a lot!
|
|
|
|
|
Ok, so the whole transition to VC from BCB is making my head ache, so I've come here in the hopes of solving an issue.
I have an array of HBITMAP, that contain images of letters.
HBITMAP m_pBitmap[100];
This array is populated at run-time, loading in each bitmap.
CString filename;<br />
for(int i = 0; i < 100; i++)<br />
{<br />
filename.Format(_T("\\Hard Disk\\ATMT\\Aspects\\Ascii%d.bmp"), (i + 32));<br />
m_pBitmap[i] = SHLoadDIBitmap(filename);<br />
}
On my form, I have placed a CBitmap, and assigned it a Static name for reference.
What I want to be able to do, is copy some of the array bitmaps, into various locations on the form bitmap.
This is where I'm stumbling around trying to come to terms with CDCs, DIBs, BitBlt, CopyRect, etc etc
I know how to change one of the array to a CBitmap for usage:
CBitmap *bitmap = new CBitmap;<br />
BOOL bSuccess = bitmap->Attach(m_pBitmap[50]);
But I can't work out how to place the array image onto the target.
I can't seem to get a DC of the form Static Image (.GetDC( ) doesn't exist).
So, can someone please put me on track here?
|
|
|
|