|
The problem is that the thread that executes your for loop is the same thread that draws the GUI of your app. In order to solve your problem you have to create a workerthread. That thread must have a way to comunicate with your gui.
If your ussing MFC the safe way to do it is passing the HWND of the dialog box or the HWNDs of the controls you want to update and use SendMessage/PostMessage to update their contents.
To create a worker thread ( a worker thread does not handle any UI events, it does not own a window ) you can call:
CWinThread* AfxBeginThread(
AFX_THREADPROC pfnThreadProc,
LPVOID pParam,
int nPriority = THREAD_PRIORITY_NORMAL,
UINT nStackSize = 0,
DWORD dwCreateFlags = 0,
LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
pfnThreadProc - this is your thread function,it has the following proto:
UINT MyControllingFunction( LPVOID pParam );
pParam - can be anything you want, and it is what you recive in pParam in MyControllingFunction (usualy in MFC a HWND)
"I don't want to achieve immortality through my work... I want to achieve it through not dying."
Woody Allen
|
|
|
|
|
|
Hello All
I have a Win32 C++ application. The parent form has various edit boxes on it and on selection of one of these boxes a dialog box (created using DialogBox) is opened. This dialog box has a date-time picker control on it and allows the user to select a date. Once a date is selected and a button pressed on the dialog box the date is tranferred to the underlying edit box, a child control on the parent window. Now my problem is this... selection of the date works fine and the information is passed to the underlying edit control. The dialog box disappears as you would expect, but when you use the mouse to try and select one of the other edit boxes on the parent form the aforementioned dialog box reappears. This happens several times before I am finally allowed to select one of the other edit controls with the mouse. I have tried changing the focus when the dialog box closes (EndDialog) but the same still happens.
Does anyone have any ideas as to what I might be doing wrong. I am in the middle of writing a small app to try and show what is going on and I'll post this when done, but if anyone has any ideas then their help would be gratefully appreciated.
Cheers
|
|
|
|
|
Hi
Show us some code,.... where you call the dlg with the dtpicker.
Best Wishes,
ez_way
|
|
|
|
|
Hi All
This is a small application I have put together to highlight my problem. Basically it consists of a parent window with a button and RichEdit control on it. When you select the RichEdit control a dialog box appears that has a date/time picker on it and another button. Selecting the date/time picker allows you to select a date and on pressing the button on the dialog box the information is transferred to the underlying RichEdit box. The dialog box closes. However, if you then try to select one of the parent window controls with the mouse (the button for instance) the dialog box reappears... Is there something I am (or am not) doing correctly?
Heres the Applications :
#include "stdafx.h"
#include "richedit.h"
#include "resource.h"
#define WINDOW_CLASS_NAME "WINCLASS1"
HWND CreateButton(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance);
HWND CreateRichEdit(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance);
BOOL CALLBACK DateDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
HWND main_window_handle = NULL;
HINSTANCE main_hInstance = NULL;
HINSTANCE relib;
HWND eDate = NULL;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
relib = LoadLibrary("riched32.dll");
//Create a Button on the main form
HWND bDateSelect = CreateButton("Select Date",10,250,100,25,101,
hwnd,main_hInstance);
//Create a RichEdit Box on the main form
eDate = CreateRichEdit("",10,30,200,25,102,
hwnd,main_hInstance);
return (0);
} break;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return(0);
} break;
case WM_DESTROY:
{
PostQuitMessage(0);
return(0);
} break;
case WM_COMMAND:
{
switch(LOWORD(wparam))
{
case 102:
{
if(HIWORD(wparam) == EN_SETFOCUS)
{
DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_DATE),
hwnd,DateDlgProc);
}
} break;
}
} break;
default:break;
} //End of Switch
return(DefWindowProc(hwnd,msg,wparam,lparam));
}
BOOL CALLBACK DateDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
{
//Get the information from the DateTimePicker Control and Return it
HWND hwndCtrl = GetDlgItem(hwnd,IDC_DATETIMEPICKER1);
//Store the data
char date_Store[20];
int date_Length = SendMessage(hwndCtrl,WM_GETTEXTLENGTH,0,0);
SendMessage(hwndCtrl,WM_GETTEXT,(WPARAM)date_Length+1,(LPARAM)date_Store);
//Set the text in the RichEdit box for date of birth
SendMessage(eDate,WM_SETTEXT,0,(LPARAM)(LPCTSTR)date_Store);
EndDialog(hwnd,IDOK);
} break;
} break;
default:
return false;
}
return true;
}
//*******************************************************************
//* This function creates a Button
//*******************************************************************
HWND CreateButton(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance)
{
HWND hbuttonTemp; //Handle to temporary Bitmap Button
hbuttonTemp = CreateWindowEx(
WS_EX_CLIENTEDGE,
"BUTTON",
tempText,
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
x, y,
width, height,
hwnd,
(HMENU)identifier,
hInstance,
NULL);
return hbuttonTemp; //Return the handle
}
//*******************************************************************
//* This function creates a RichEdit box
//*******************************************************************
HWND CreateRichEdit(char* tempText, int x, int y, int width, int height,
int identifier, HWND hwnd, HINSTANCE hInstance)
{
HWND hrichEditTemp;
hrichEditTemp = CreateWindowEx(
NULL,
RICHEDIT_CLASS,
tempText,
WS_CHILD | WS_VISIBLE | ES_SUNKEN | ES_UPPERCASE,
x,y,
width,height,
hwnd,
(HMENU)identifier,
GetModuleHandle(NULL),
NULL);
return hrichEditTemp;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;
winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hInstance;
winclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = WINDOW_CLASS_NAME;
//Register the Window Class
if(!RegisterClass(&winclass))
return(0);
//Create the main window
if(!(hwnd=CreateWindow(WINDOW_CLASS_NAME,
"Date and Time Picker Dialog",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0,0,320,320,
NULL,NULL,
hInstance,NULL)))
return(0);
//Save the Window handle in a global
main_window_handle = hwnd;
main_hInstance = hInstance;
//Enter the main event loop
while(1)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam );
}
Any help would be gratefully appreciated.
Cheers
Billy
|
|
|
|
|
It looks as though you're getting an extra EN_SETFOCUS, then. Have you tried using SPY++ to see what messages the RichEdit window is getting, and when?
Steve S
|
|
|
|
|
hello,
i am coding in c++ (mfc) i have addded a list box to my aplication,im having torouble parsing data into my listbox,i have a preparsed buffer contaning the data i want to go into the listbox,but when i try to put it in the list box it comes out as 1 big string,but if i send the buffer data to a edit box it is parsed wonderfully,the buffer is parsed with "\r\n" can i add new lines to the listbox,without doing this again
m_strList.AddString(inBuffer);
or is there a way i can read the data line by line form the buffer and the loop the lines into the listbox 1 by 1?
thanks for your time;)
|
|
|
|
|
Hi you are not parsing the buffer just loading it.
Parse it first with a while loop.
Inside the loop load the box.
It may help also to put the buffer contents into a CString the use findrev like
char ch ='\r\n';
while.(condition){
int ix = m_strEdit.ReverseFind(ch);
grab it, stick it.
}
Best Wishes,
ez_way
|
|
|
|
|
Is there a way to send say a structure to program code and have the code tell you the variable type. This would be helpful when debugging you could do this.
send struct abc to determine_type
determine_type reports
struct abc
value 1 = int and is = 102
value 2 = char * and is = ab\0
value 3 = long and is = 190012
value 4 = char and is = R
end of structure..
This allows you to turn on some form of debugging option and report the types and values within each structure.
thanks
|
|
|
|
|
|
Hi all.
I need to make reports in VC++6.0
these reports are based on database queries or tables..
what is the starting point ? please help and note that I can't use third party components..
any tutorials, samples ?
I know SQL , ADO ,, the problem is just with reports.
thank you in advance
|
|
|
|
|
The starting point: a LOT of work!
if youre using listview controls to display your results, i have a class that outputs the entire contents of a listview control to the printer, you just add it as a member variable to your views, call a couple of its methods and it does all the work for you. Its written for use with WTL, but you shoulnt have much trouble porting it to be used with MFC (if you are using MFC). If you (or anybody) want it, e-mail me or post here, and ill be glad to send it to ya.
Hope this helps
|
|
|
|
|
wat do need help on
Game Tester
|
|
|
|
|
I need to accept XML formatted data over a socket connection and place the data into a dataset for parsing. The XML data is bracketed by a start character and an end character, but may range from 50 bytes to thousands of bytes. The app will need to be in C/C++ any thoughts
|
|
|
|
|
You can use expat[^].
pros:
-It is fast
-has a small memory footprint,
-and it comes with source code.
cons:
-it is not a validating parser. So you can't tell if the xml data is valid.
-i don't know if it can read from stream/buffers, i used it only with files.( but you have the source... )
"I don't want to achieve immortality through my work... I want to achieve it through not dying."
Woody Allen
|
|
|
|
|
HI... I wanted to know that can a dll have its own data space? well i guess i am not framing the question properly but what i am interested isn doing is storing some variable/value in a dll that can be persistant i.e i can set it during the first run of my program and then during successive runs read it or modify it .... CAN THIS BE DONE ?
~Ravi
|
|
|
|
|
I'm trying to read raw byte data off of a file. The machine which recorded the data stored them as signed 8-bit integers. I need to send the data into a function which accepts doubles. Obviously, I can't read straight into a double pointer. The values would get wrecked. I don't want to read them into a char pointer array and then cast the values into doubles as I read the values into double pointer array. Is there a better way to do this??? Thanks.
|
|
|
|
|
Anonymous wrote:
Is there a better way to do this???
No. Read them into a char array, convert them to doubles using a cast and store them in a new double array.
John
|
|
|
|
|
You might also look into word boundaries for the binary input. If you need to adjust word boundaries, then you can do this with the #pragma pack ( <args> ) statement.
|
|
|
|
|
A friend of mine is just learning how to code in C and I've been helping her a little bit along the way. There seems to be a problem with a chunk of her code, and I can't figure out how to fix it, it's been quite a while since I've looked at C so I'm a little 'fuzzy' on it.
The following bit of code is taken right from her source code.
int *suit[4];
for(int p = 0; p <= 3; p++)
{
suit[p] = &p;
}
...
then inside a loop which will execute the following loop x = 0 to x < 4 times:
printf(" %d", *suit[x]);
The program exits fine, with no errors, but the only problem is, when it prints out at the end, each entry in the suit array is set at being 4 (so the 4 will print out 4 times), when what she want to print out is 0 1 2 3, if she changes the loop to:
for(int p = 0; p <= 4; p++)
{
...
}
the print statement shows that a 5 prints out in each case. I'm sure the problem comes from this suit[p] = &p; but I don't know how to fix it.
Can anyone help us out? Thanks...
|
|
|
|
|
There's only one variable p , and every element of the array suit is made to point to that element. What exactly are you trying to do in this code?
|
|
|
|
|
What we would like to have happen is to have suit[0] = 0 and suit[1] = 1, etc... but suit[] is a pointer, int *suit[4];
So how, in that for loop, do we say that we want suit[p] = p itself, and not the address of p?
we also tried: *suit[p] = p;
and suit[p] = p;
neither of these works.
|
|
|
|
|
Generally in a loop c programmers will do this (remove the =):
int *suit[4];
for(int p = 0; p < 4; p++) This will run through all 4 suits (0..3).
John
|
|
|
|
|
essentially what you are doing is setting each of your array elements to the address of p; At the end of your loop you have an entire array of addresses to the p value. This is why you print out a bunch of 4's or 5's depending on your loop criteria.
If you are just trying to set the array locations to the value of the integers, then there is no need to use address. create your array as : int suit[4]; this is an array of integers. Now inside the for loop, suit[p]=p; will now set your array entry to the integer value of p and you will receive your expected results from your printf statement.
|
|
|
|
|
noahsarf wrote:
Now inside the for loop, suit[p]=p; will now set your array entry to the integer value of p
doing it that way gives the error:
'=' cannot convert from int to int*
that was one of the original ways we tried it.
|
|
|
|
|