|
|
Hello there!
I have a question regarding comboboxes in winapi.
I have added a combobox to a dialog and some items in it. (look below in the code). But now I want to get feedback on the selected item in the combobox, but I don't now how do that. Lets say that I want a messagebox to come up when I select item with index 2. How would I do that? I guess that I should to it somewhere in WM_COMMAND but how..below is some of my code.
Any help would be great!
Regards
/Peter
LRESULT CALLBACK ToolboxProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
/*Add all the options to the combo box*/
char Buffer[64];
strcpy(Buffer,"Von Mises");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,0,(LPARAM)Buffer);
strcpy(Buffer,"Principal Major Z1");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,1,(LPARAM)Buffer);
strcpy(Buffer,"Principel Major Z2");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,2,(LPARAM)Buffer);
strcpy(Buffer,"Principel Minor Z1");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,3,(LPARAM)Buffer);
strcpy(Buffer,"Principel Minor Z2");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,4,(LPARAM)Buffer);
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_COMBO1:
{
MessageBox(hWndDlg, "Combobox selected ", "Notice",
MB_OK | MB_ICONINFORMATION);
}
break;
}
return 0;
}
break;
}
return FALSE;
}
|
|
|
|
|
You want to set an event on the CBN_SELCHANGE. When it returns to the OnCbnSelchangeServercombo function then check to see what was choosen and go from there.
Hope this helps.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi!
thanks for your replay Tom. But Im not quite sure how to or where to implement that, Would be great with some code examples, cause I havent found much tutorials or examples on how to handle this.
As you see in my first thread, I have given seperate indexes:
***********
strcpy(Buffer,"Principal Minor Z2");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,5,(LPARAM)Buffer);
***************
I know that when option is selected the ON_CBN_SELENDOK message is sent, but how should I use it.
So if someone could write me a code snip or recommened some tutorial I would be thankful,
Best Regards
/Peter
|
|
|
|
|
Listen when it comes to using the studios...be ti .NET or VS6, I totally believe in using the wizards. There maybe times when they create code that does not work without some tweaking...but they work great 90% of the time.
So here is how you do it. I'm not sure whether you are using the .NET studio or VS6 so I'm going to base this on the .NET studio.
Go to you dialog screen. click on the combo box that you want to add the event to. Now right click on it and choose properties. Next click on the event button on the properties box toolbar (it's the one with the lightening bolt). Now choose the CBN_SELCHANGE and click the drop down arrow or make the function name whatever you want.
This will create the function in your code. Then go to the code and do what ever you need to do when the user selects something from the combo box.
Hope this helps.
To see if this works put a message box in that function that run your program.
Tom
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hello,
Im using .Net and have done as you said, but when I click on the Lightning bulp(properties) nothing turns up,.. There is nothing to select.
I created an application Win32 Console Applicaition and I havent added any support for MFC as default. Could this have anythinh to do with.
I have selected Resources->Dialog any selected the dialog with my combobox but I cant select anything in the properties of the combobox..
/Peter
|
|
|
|
|
I found an article in MSDN - in the "books" or "partial books", maybe?
In my application I have a combo-box which allows selection of recording Primary or Secondary or both (this explains the names used in the code below!)
In my main window procedure, I use simething like:
case WM_COMMAND:<br />
switch(wParam & 0xFFFF)
{<br />
case ID_ToolbarRecordCombo:<br />
if (HIWORD(wParam) == CBN_CLOSEUP)<br />
{<br />
iComboBoxSelection = SendMessage(hWndRecordCombo,<br />
CB_GETCURSEL, 0, 0);<br />
if (iComboBoxSelection == 0 && <br />
recordingSelection != RecordPrimary)<br />
{<br />
recordingSelection = RecordPrimary;<br />
break;<br />
}<br />
else if (iComboBoxSelection == 1 && <br />
recordingSelection != RecordSecondary)<br />
{<br />
recordingSelection = RecordSecondary;<br />
break;<br />
}<br />
else if (iComboBoxSelection == 2 && <br />
recordingSelection != RecordBoth)<br />
{<br />
recordingSelection = RecordBoth;<br />
break;<br />
}<br />
}<br />
else<br />
return(DefWindowProc(hwnd, message, wParam, lParam));
I hope this helps!
|
|
|
|
|
thanks for your replay Norman,
it helped me very much but it only replys if iComboBoxSelection is =0....
Is there something wrong with my inserttion where I use CB_INSERTSTRING followed by indexing ... or do I use the COMMAND: case wrong?
/Peter
LRESULT CALLBACK ToolboxProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
LRESULT iComboBoxSelection;
switch(Msg)
{
case WM_INITDIALOG:
/*Add all the options to the combo box*/
char Buffer[64];
strcpy(Buffer,"Von Mises Z1");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,0,(LPARAM)Buffer);
strcpy(Buffer,"Von Mises Z2");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,1,(LPARAM)Buffer);
strcpy(Buffer,"Principal Major Z1");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,2,(LPARAM)Buffer);
strcpy(Buffer,"Principal Major Z2");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,3,(LPARAM)Buffer);
strcpy(Buffer,"Principal Minor Z1");
SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_INSERTSTRING,4,(LPARAM)Buffer);
strcpy(Buffer,"Principal Minor Z2");
//GetCurSel();
//iComboBoxSelection=SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_SETCURSEL, 0, 0);
// SendDlgItemMessage(hWndDlg,IDC_COMBO1,ON_CBN_SELENDOK ,0,(LPARAM)Buffer);
//SendDlgItemMessage(hWndDlg,IDC_COMBO1,CB_GETCURSEL, 0, 0);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_COMBO1:
{
if (HIWORD(wParam) == CBN_CLOSEUP)
{
iComboBoxSelection = SendMessage(hWndDlg,
CB_GETCURSEL, 0, 0);
if (iComboBoxSelection == 2)
{
MessageBox(hWnd, "iComboBoxSelection == 2", "Error",
MB_OK | MB_ICONINFORMATION);
}
if (iComboBoxSelection == 1)MessageBox(hWnd, "iComboBoxSelection == 1", "Error",
MB_OK | MB_ICONINFORMATION);
if (iComboBoxSelection == 0)MessageBox(hWnd, "iComboBoxSelection == 0", "Error",
MB_OK | MB_ICONINFORMATION);
}
break;
}
}
break;
}
return FALSE;
}
|
|
|
|
|
I found the error , thanks for all your help guys,--
/Peter
|
|
|
|
|
I'm trying to access a SQL server 2000. I will be reading data as well as updating or deleting records.
What is better; ADO, ODBC, CRecordset/ CDatabase?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
If you like STL-style programming, take a look at DTL[^].
If not, just forget about it
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Tom Wright wrote:
What is better; ADO, ODBC, CRecordset/ CDatabase?
I believe that CRecordset and CDatabase use ODBC, so those options are not mutually exclusive.
In any case, "better" is a relative term that only the application itself and the environment can dictate. I personally have used ODBC for both Access and SQL and it performed fine. That might not be the case if it were a high-volume application (e.g., several thousand transactions per second), though.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
No this app will read in one record and delete it every 20 seconds.
Easier in terms of learning and implementing in my app.
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hi guys.
I'd like to know how to retrieve if an application
was started by a user or by the operating system...
How can implemente something such this?
Thanks a lot..
bye
Jenie_net
|
|
|
|
|
Jenie_net wrote:
I'd like to know how to retrieve if an application
was started by a user or by the operating system...
All applications are started by the OS. What exactly are you trying to differentiate between?
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Sorry David..I wasn't clear in my question.
I need to know if the application was started by a user-task,such as double clik on icon,by command line,by run dialog...or was started automatically by the o.s. ,may be at start-up...such register key..may be later..planned operations,or however in another way...but automatically by the operating system...
Sorry for the english if something is incorrect...
however thanks a lot...
Jenie_net
|
|
|
|
|
I know of no way to get that level of granularity. See if the th32ParentProcessID member of PROCESSENTRY32 is of any use.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi,
Not sure if this is the right forum for this question but I didn't see a networking stuff forum...
Is there an api/method for getting the signal strength of a wireless connection (802.11b/g) programatically. Windows XP is able to display the wireless signal strength when you bring up the status dialog of a wireless network connection, I would like to do something similar in my app.
This will probably be impossible in Win2k and below since third party applications managed the wireless connections, but in windows XP it should be possible.
Does anyone have any ideas?
Thanks Tom.
|
|
|
|
|
Hi,
Here is my idea, If that wireless modem is connected to u r serial port, then u must issue some command to that port using FILE IO APIs,so that modem will respond to u r command.For command set u must refer that that modem specs.
If that is inbuilt modem then i hope there must some APIs,i am not sure about this case.
PSN
|
|
|
|
|
A wireless (802.11b/g) interface adapter would never be connected to a serial port because rs232 transfer is way too slow... Regardless of whether it is a PCMCIA, PCI or USB 802.11b/g adapter windows will display it as a Network Connection.
Win XP is able to monitor signal strength through its Network Connections sub system, this is something that Win2K and below could not do...
This is why I am wondering if there is any way to tap into this functionality programatically?
Thnx Tom.
|
|
|
|
|
Check out the Windows XP Device Driver Interface.
There should be stuff about how to Access a Wireless Network card's Hardware Interface something like a DeviceIoControl function.
http://www.microsoft.com/whdc/device/network/wireless/default.mspx[^]
This is the Link on Microsoft Driver Website if that Helps.
-Ve
-of All the things I lost, I miss my mind the most...
|
|
|
|
|
Looking for a few good tut's on making screensavers..found the old jonny castaway screensaver and would like to make one similar to it. Will be using microsoft visual studio 6, c++ or VB. Any help would be appreciated......Thanks
|
|
|
|
|
Here is one:
http://www.codeproject.com/cpp/smoovcpscreensaver.asp
Nigel Thompson created another but I was unable to find it.
"Opinions are neither right nor wrong. I cannot change your opinion of me. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hello, I had posted a question yesterday with no responses.. I figured I would give it one more shot..
I found a article on another site that talked about my problem.. here is a little blurb from the article...
If the terminating socket has been closed, calling Flush on the CArchive will raise an exception (so will calling Close). In the previous case, before the exception is handled, CArchive goes out of scope and its destructor calls Close. Close throws another exception and all hell breaks loose. Never throw exceptions from destructors.
You will need nested try / catch blocks ... [Article^]
My problem with the exceptions is fixed but I still have a memory leak.. Any ideas why??
void CMainFrame::OnSend(CClientSocket *pSocket, CString strMsg)
{ if(*pSocket != INVALID_SOCKET)
{
try
{
sendObject(pSocket, strMsg);
}
catch (CException* pEx)
{
pEx->Delete();
}
}
}
BOOL CMainFrame::sendObject(CClientSocket *pSocket, CString strMsg)
{
BOOL bRet = TRUE;
CSocketFile sf(pSocket);
CArchive ar_send(&sf, CArchive::store);
try
{
ar_send << strMsg;
ar_send.Flush();
ar_send.Close();
sf.Close();
}
catch (CException* pEx)
{
bRet = FALSE;
pEx->Delete();
}
return bRet;
}
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Hello,
The exception thrown is probably allocated using new . Try calling <delete> on pEx and see if that solves anything...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|