|
I have a 3x5 text box entries. Each are identified by almost the same number but with a different number attached to it. For example, row 1 control IDs are IDC_Row1_1, IDC_Row1_2, IDC_Row1_3, etc. I would like to disable/enable the boxes in a for loop without having to type out each control ID. How do I convert the string into the ControlID recognized by the system? See below.
CString str;
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= 5; j++)
{
str = "IDC_Row" + i + "_" + j;
//how do i convert the string to the control ID value to set its property?
GetDlgItem(str)->EnableWindow(TRUE);
}
}
|
|
|
|
|
Your names are actually constant values, which map to numbers in your resource file. Your best bet is to make sure they are sequential in your resource files, and then you can just use a loop.
Or you can create a vector which contains all the controls, regardless of their values, and a function object to pass to for_each.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
On the other hand, in the event that some other nitwit comes along and does not KNOW they have to be in order, you can declare a static array of UINT in your source file containing the identifiers, and use that as the basis for your looping.
static UINT s_ControlArray[] = {
IDC_CONTROL_1_1, IDC_CONTROL_1_2, IDC_CONTROL_1_3,
IDC_CONTROL_2_1, IDC_CONTROL_2_2, IDC_CONTROL_2_3
};
Use a for loop to access the elements in the array.
The GetDlgItem() would work using those identifier values, and then you can use the EnableItem as you wanted.
|
|
|
|
|
I started giving you a complicated solution (by trying to fix your code) that in the end would not work. Then thought about it for a few seconds and I have come to the conclusion that the best solution is the one Christian has provided above. I have used this method in the past (with buttons -phone dial pad) and it works great.
[EDIT]
One thing to add is I would edit the resource.h file directly.
[/EDIT]
John
|
|
|
|
|
Is there a way on how to use MFC based controls on win32?
|
|
|
|
|
You have the source code for all of MFC, if there's just one bit you want, why don't you build a control based on the source ?
I'm not sure if you can do this or not, I'd imagine it's possible, all MFC controls are Win32 controls at the end of the day, it's just a wrapper.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
I'm trying to use Video for Windows to capture images from a webcam on a timed interval (using a WM_TIMER message). To try and capture the image I'm basically using:
capFileSaveDIB(hWndC,"filename.bmp");
This works perfectly well if the application (MFC dialog) is active when the message is fired, but if the window is not active or minized, the image is not capture. I've looked through the VFW documentation on MSDN, but I can't find any mention of this problem.
Any ideas how I can capture the image while the application is minimized?
Thanks
modified 12-Jul-20 21:01pm.
|
|
|
|
|
This is what I'm getting. The code works fine when I create a seperate Windows application, but when I bring the file into my other project I get this weird error. Also it's just a .c file so how can I include it? Do I just #include <waveply1.cpp> so I can use the functions?
--------------------Configuration: 3daudio - Win32 Debug--------------------
Compiling...
WavePly1.cpp
c:\program files\microsoft visual studio\myprojects\3daudio\waveply1.cpp(328) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Error executing cl.exe.
WavePly1.obj - 1 error(s), 0 warning(s)
|
|
|
|
|
Try putting a #include "stdafx.h" at top. What is happening is that you project (as all default VC++ projects) is set to use precompiled headers. "stdafx.h" is your master precompiled header.
|
|
|
|
|
Okay that worked thanks. Now that I have a free-floating .c file, I thought I could just change main() to a regular function. This is what's happening now is that easy to figure out?
--------------------Configuration: 3daudio - Win32 Debug--------------------
Compiling...
3daudioDlg.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\3daudio\3daudioDlg.cpp(222) : error C2065: 'playmain' : undeclared identifier
Error executing cl.exe.
3daudio.exe - 1 error(s), 0 warning(s)
|
|
|
|
|
You are using "playmain" which has not been previously defined. You can't do that.
|
|
|
|
|
Hi,
I new to programming...Pls bare with me for this is really a basic question in pointers..
In my program I have a global variable
char *gz_Nos[10];
I need to assign some strings(like '000001','000002'...) to this array in one of my function and check the values in other function..
so I did as follows..ie my .cpp
char *gz_Nos[10];
mycalss::myclass(){}
mycalss::~myclass(){}
int myclass::func1()
{
char t_str[MAX_STRLEN];
for(i=0;i<2;i++)
{
wsprintf(t_str,"00000%d",i+1);
gz_Nos[i]=t_str;
}
return 1;
}
int myclass::func2()
{
char *sz_no;
int i=0;
.....
sz_no = "000001"
for(i=0;i<2;i++)
{
if(sz_no == gz_Nos[i])
{
MessageBox(0,"Error","Error",MB_OK) ;
return 0;
}
}
}
But here I couldnt see the value of gz_Nos[i] in func2..I am calling func1 first and then func2.And also in func1 if I display the value of gz_Nos[0] it displays '000002'. Where am I going wrong...
Thanks a lot.
|
|
|
|
|
Well for starters you are assigning a local variable (t_str) to your array of strings (gz_Nos), as soon as you exit the function, the compiler unwinds the stack and your left with a corrupt string. Try using something like char* t_str = new char[MAX_STRLEN], and make sure to call delete[] t_str when you no longer need it. Strings, memory and pointers are complicated beasts. Check out some good books, like Stroustrup's novel.
|
|
|
|
|
Hi everybody, i need your help. Im trying to change the desktop wallpaper, but i must use the IActiveDesktop interface, and i dont know what files i must include in the header, in the msdn help, they tell me, that i must include shlobj.h but with that it doesnt work. If some body can help me i will be gratefull.
|
|
|
|
|
|
|
|
Hi,
I'm sharing an object between 2 threads and I need to synchronize it. The following is a model of my code:
<br />
class SynchronizedObject<br />
{<br />
<pre>SynchronizedObject()
{<br />
InitializeCriticalSection(&m_ThreadSynch);<br />
}<br />
<br />
CRITICAL_SECTION m_ThreadSynch;<br />
void Lock()<br />
{<br />
::EnterCriticalSection(&m_ThreadSynch);<br />
}<br />
void Unlock()<br />
{<br />
::LeaveCriticalSection(&m_ThreadSynch);<br />
}</pre><br />
<br />
void A()<br />
{<br />
Lock();<br />
B();<br />
Unlock();<br />
}<br />
<br />
void B()<br />
{<br />
Lock();<br />
Unlock();<br />
}<br />
};<br />
For some reason when I call A() my code doesn't lock up. Am I using the Critical Section incorrectly? Or does it check which thread is trying to enter the critical section and allows the same thread to enter it multiple times (which I thought wasn't the case). What about Mutexes? Aside from synchronizing accross processes do they behave differently? What about Semaphores?
Note: I've also tried to just put a member object CCriticalSection synch; and call synch.Lock()/Unlock() where appropriate. Same result.
|
|
|
|
|
Critical sections block separate threads from entering the critical section, not the same thread.
None of the synchronization objects, near as I ever read, will block the same thread from entering them.
Mutexes behave differently because they can be 'abandoned'.
If the process owning a mutex exits before releasing the mutex, another process waiting for it will be rleased with the result WAIT_ABANDONED.
Semaphores are for controlling 'metered access' to an object.
Now, in your instance, if Thread 2 called B(), then Thread1 would not be able to enter A() until Thread2 was done processing B(). Likewise, if Thread1 entered A() first, then thread2 could not enter A() or B() until Thread1 was done with A().
|
|
|
|
|
|
If you want your thread to lock up, use a semaphore object and the WairFor... functions. They don't allow a thread to enter the critical section twice when the state of the Semaphore is non-signaled.
Behind every great black man...
... is the police. - Conspiracy brother
Blog[^]
|
|
|
|
|
Thanks for your replies. I didn't want the thread to lock up so this is perfect, but I wanted to confirm that that's how it worked and I'm not missing some small part of code.
|
|
|
|
|
Hi,
How can I show hidden folders when calling SHBrowseForFolder function?
Thanks.
Lynsen
|
|
|
|
|
|
I need to create a source to the <targetdir>data.mdb in Installshield.
I'm thinking either a function call, or directly adding Registry entries(yuck)
Can anyone help?
|
|
|
|