|
-
November 5th, 2010, 08:16 AM
#1
[RESOLVED] Dialog Performance Issue
Hi,
I have a CBN_SELCHANGE capturing some Combo Box selections. Once the combo box has an int to send to a EDITTEXT control, the application becomes very sluggish and after capturing a couple of ints, the controls do not respond. It is likely I am doing something wrong, but I do not know what that is. Any help is appreciated.
Code:
case CBN_SELCHANGE:
{
HWND hComboStr = GetDlgItem(hwndDlg, IDD_STR_COMBO);
int indexs = SendMessage(hComboStr , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexs == 0) return TRUE;
else if(indexs == 1){
int choi = GetDlgItemInt(hwndDlg, IDC_STR, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_STR, choi, FALSE);
return TRUE;
}
else if(indexs == 2){
int choi = GetDlgItemInt(hwndDlg, IDC_STR_, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_STR, choi, FALSE);
return TRUE;
}
else if(indexs == 3){
int choi = GetDlgItemInt(hwndDlg, IDC_STR__, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_STR, choi, FALSE);
return TRUE;
}
HWND hComboDex = GetDlgItem(hwndDlg, IDD_DEX_COMBO);
int indexd = SendMessage(hComboDex , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexd == 0) return TRUE;
else if(indexd == 1){
int choi = GetDlgItemInt(hwndDlg, IDC_DEX, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_DEX, choi, FALSE);
return TRUE;
}
else if(indexd == 2){
int choi = GetDlgItemInt(hwndDlg, IDC_DEX_, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_DEX, choi, FALSE);
return TRUE;
}
else if(indexd == 3){
int choi = GetDlgItemInt(hwndDlg, IDC_DEX__, NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_DEX, choi, FALSE);
return TRUE;
}
-
November 5th, 2010, 10:54 AM
#2
Re: Dialog Performance Issue
Do you process EN_UPDATE or/and EN_CHANGE messages in all these editboxes?
Victor Nijegorodov
-
November 5th, 2010, 09:00 PM
#3
Re: Dialog Performance Issue
Not at present.
I'm not exactly clear on the usage of EN_UPDATE & EN_CHANGE, or how they may be used to improve the performance of my dialog. I suppose that SendMessage will be of help but where to use it to send the notification(s)?
Last edited by Morbane; November 5th, 2010 at 10:42 PM.
Reason: Added insight
-
November 5th, 2010, 10:43 PM
#4
Re: Dialog Performance Issue
 Originally Posted by Morbane
Not at present.
I'm not exactly clear on the usage of EN_UPDATE & EN_CHANGE, or how they may be used to improve the performance of my dialog. I suppose that SendMessage will be of help but where to use it to send the notification(s)?
Where to use the notification(s) is/are my present question.
-
November 6th, 2010, 03:19 AM
#5
Re: Dialog Performance Issue
The trick I already showed you in the past:
Code:
case CBN_SELCHANGE:
{
UINT strCtrl[] = { 0, IDC_STR, IDC_STR_, IDC_STR__ };
HWND hComboStr = GetDlgItem(hwndDlg, IDD_STR_COMBO);
int indexs = SendMessage(hComboStr , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexs == 0)
return TRUE;
else if (indexs > 0 && indexs < COUNTOF(strCtrl))
{
int choi = GetDlgItemInt(hwndDlg, strCtrl[indexs], NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_STR, choi, FALSE);
return TRUE;
}
UINT dexCtrl[] = { 0, IDC_DEX, IDC_DEX_, IDC_DEX__ };
HWND hComboDex = GetDlgItem(hwndDlg, IDD_DEX_COMBO);
int indexd = SendMessage(hComboDex , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexd == 0)
return TRUE;
else if(indexd > 0 && index < COUNTOF(dexCtrl))
{
int choi = GetDlgItemInt(hwndDlg, dexCtrl[indexd], NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_DEX, choi, FALSE);
return TRUE;
}
But this code (BTW, incomplete) shows no potential performance problem so far, so the real issue is somewhere else.
Last edited by Igor Vartanov; November 6th, 2010 at 04:17 AM.
Best regards,
Igor
-
November 6th, 2010, 03:25 AM
#6
Re: Dialog Performance Issue
Where to use the notification(s) is/are my present question.
No, the question was whether you use those.
Best regards,
Igor
-
November 6th, 2010, 03:53 AM
#7
Re: Dialog Performance Issue
Is it possible that the definition numbers I am using in my resource.h which are in some cases 5 digits long could be causing the issue? Are there reserved ranges that windows uses? For example a set of definitions go thusly: 10011, 10021, 10031, 10041, 10051, 10061.
-
November 6th, 2010, 04:14 AM
#8
Re: Dialog Performance Issue
Are there reserved ranges that windows uses?
0 .. 0x7FFF is safe range for resource id, afair. Atoms use negative short values.
Your problem must be in your code you still never show.
Best regards,
Igor
-
November 6th, 2010, 04:39 AM
#9
Re: Dialog Performance Issue
Would it be appropriate to attach the files - or useful? And if I did attach them would you have a look - and if you will, which files would you want?
-
November 6th, 2010, 06:28 AM
#10
Re: Dialog Performance Issue
The most appropriate and useful would be to create a lean project that exactly reproduces your issue (or not, which fact is a great starting point to solving the issue in real program) and have no unnecessary details that would obscure the real problem, or hamper the solving. Working on this subject you'll learn a lot, get a vision to your program from another angle... and maybe you solve the issue before uploading that here.
In fact what I described above is an outline of my own standard troubleshooting process.
Best regards,
Igor
-
November 8th, 2010, 03:36 AM
#11
Re: Dialog Performance Issue
Hello,
I am posting the lean version of my main.cpp - it all works as intended save for the aforementioned performance issue which this version of code still produces. I am hoping that someone with a discerning eye might be able to identify where things could likely be jamming up and thus affecting the program form performing
Code:
#define WIN32_LEAN_AND_MEAN
#define COUNTOF(x) (sizeof(x) / sizeof(x[0]))
#include <windows.h>
#include "resource.h"
#include <cstring>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <wchar.h>
using namespace std;
string itochar(int val)
{
ostringstream strm;
strm << val;
return strm.str();
}
int d6(int mult = 1)
{
srand(time(NULL));
int iGen = rand() % (6 * mult) + (1 * mult);
if(iGen > 18)
iGen = 18;
return iGen;
}
HINSTANCE hInst;
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HWND cboxStr, cboxDex, cboxCon, cboxInt, cboxWis, cboxCha;
const char *Populate[] = {" ", "First", "Second", "Third"};
switch(uMsg)
{
case WM_INITDIALOG:
{
cboxStr = GetDlgItem(hwndDlg, IDD_STR_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxStr, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
cboxDex = GetDlgItem(hwndDlg, IDD_DEX_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxDex, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
cboxCon = GetDlgItem(hwndDlg, IDD_CON_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxCon, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
cboxInt = GetDlgItem(hwndDlg, IDD_INT_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxInt, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
cboxWis = GetDlgItem(hwndDlg, IDD_WIS_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxWis, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
cboxCha = GetDlgItem(hwndDlg, IDD_CHA_COMBO);
for(int Count = 0; Count < 4; Count++){
SendMessage(cboxCha, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>((LPCTSTR)Populate[Count]));
}
return TRUE;
}
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
return TRUE;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BTN_QUT:
{
EndDialog(hwndDlg, 0);
return TRUE;
}
//Generaters
case IDC_BTN_STR:{
static int next = 0;
UINT edCtrlId[] = { IDC_STR, IDC_STR_, IDC_STR__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_STR__, NULL, 0) > 0) return TRUE;
int nstr = d6(3); string sstr = itochar(nstr);
SetDlgItemText(hwndDlg, edCtrlId[next], sstr.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
case IDC_BTN_DEX:{
static int next = 0;
UINT edCtrlId[] = { IDC_DEX, IDC_DEX_, IDC_DEX__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_DEX__, NULL, 0) > 0) return TRUE;
int ndex = d6(3); string sdex = itochar(ndex);
SetDlgItemText(hwndDlg, edCtrlId[next], sdex.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
case IDC_BTN_CON:{
static int next = 0;
UINT edCtrlId[] = { IDC_CON, IDC_CON_, IDC_CON__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_CON__, NULL, 0) > 0) return TRUE;
int ncon = d6(3); string scon = itochar(ncon);
SetDlgItemText(hwndDlg, edCtrlId[next], scon.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
case IDC_BTN_INT:{
static int next = 0;
UINT edCtrlId[] = { IDC_INT, IDC_INT_, IDC_INT__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_INT__, NULL, 0) > 0) return TRUE;
int nint = d6(3); string sint = itochar(nint);
SetDlgItemText(hwndDlg, edCtrlId[next], sint.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
case IDC_BTN_WIS:{
static int next = 0;
UINT edCtrlId[] = { IDC_WIS, IDC_WIS_, IDC_WIS__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_WIS__, NULL, 0) > 0) return TRUE;
int nwis = d6(3); string swis = itochar(nwis);
SetDlgItemText(hwndDlg, edCtrlId[next], swis.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
case IDC_BTN_CHA:{
static int next = 0;
UINT edCtrlId[] = { IDC_CHA, IDC_CHA_, IDC_CHA__ }; // list of editboxes in order of filling
if(GetDlgItemInt(hwndDlg, IDC_CHA__, NULL, 0) > 0) return TRUE;
int ncha = d6(3); string scha = itochar(ncha);
SetDlgItemText(hwndDlg, edCtrlId[next], scha.c_str());
next = (++next) % COUNTOF(edCtrlId); // next logic must loop!
return TRUE;
}
//Resets
case IDC_BTN_RSTR:{
SetDlgItemInt(hwndDlg, IDC_STR, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_STR__, 0, FALSE);
return TRUE;
}
case IDC_BTN_RDEX:{
SetDlgItemInt(hwndDlg, IDC_DEX, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_DEX_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_DEX__, 0, FALSE);
return TRUE;
}
case IDC_BTN_RCON:{
SetDlgItemInt(hwndDlg, IDC_CON, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_CON_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_CON__, 0, FALSE);
return TRUE;
}
case IDC_BTN_RINT:{
SetDlgItemInt(hwndDlg, IDC_INT, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_INT_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_INT__, 0, FALSE);
return TRUE;
}
case IDC_BTN_RWIS:{
SetDlgItemInt(hwndDlg, IDC_WIS, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_WIS_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_WIS__, 0, FALSE);
return TRUE;
}
case IDC_BTN_RCHA:{
SetDlgItemInt(hwndDlg, IDC_CHA, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_CHA_, 0, FALSE);
SetDlgItemInt(hwndDlg, IDC_CHA__, 0, FALSE);
return TRUE;
}
}//switch(LOWORD(wParam))
case CBN_SELCHANGE:
{
UINT strCtrl[] = { 0, IDC_STR, IDC_STR_, IDC_STR__ };
HWND hComboStr = GetDlgItem(hwndDlg, IDD_STR_COMBO);
int indexs = SendMessage(hComboStr , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexs == 0)
return TRUE;
else if (indexs > 0 && indexs < 4)
{
int choi = GetDlgItemInt(hwndDlg, strCtrl[indexs], NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_STR, choi, FALSE);
return TRUE;
}
UINT dexCtrl[] = { 0, IDC_DEX, IDC_DEX_, IDC_DEX__ };
HWND hComboDex = GetDlgItem(hwndDlg, IDD_DEX_COMBO);
int indexd = SendMessage(hComboDex , CB_GETCURSEL, (WPARAM)0, 0L);
if(indexd == 0)
return TRUE;
else if(indexd > 0 && indexd < 4)
{
int choi = GetDlgItemInt(hwndDlg, dexCtrl[indexd], NULL, FALSE);
SetDlgItemInt(hwndDlg, IDB_DEX, choi, FALSE);
return TRUE;
}
return TRUE;
}//case CBN_SELCHANGE:
}//case WM_COMMAND:
}//switch(uMsg)
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
hInst = hInstance;
// The user interface is a modal dialog box
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
}
Any help in finding where the problem is starting is greatly appreciated!
-
November 8th, 2010, 07:37 AM
#12
Re: Dialog Performance Issue
CBN_SELCHANGE Notification Code
Parameters
wParam
The LOWORD contains the control identifier of the combo box. The HIWORD specifies the notification code.
In other words, to catch CBN_bla-bla you need to have this:
Code:
case WM_COMMAND:
switch (HIWORD(wParam)) // select by notification
{
case BN_CLICK:
switch (LOWORD(wParam)) // select by control id
{
case IDC_BUTTON1:
// handler for button1 click
break;
. . .
}
break;
case CBN_SELCHANGE:
switch (LOWORD(wParam)) // select by control id
{
case IDC_COMBO1:
// handler for combo1 selection change
break;
. . .
}
break;
}
break;
Last edited by Igor Vartanov; November 8th, 2010 at 07:48 AM.
Best regards,
Igor
-
November 8th, 2010, 09:25 AM
#13
Re: Dialog Performance Issue
Igor!
That, of course, works perfectly!! You're truly worth every point of the reputation you hold.
Thank you!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|