Click here to Skip to main content
16,005,281 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Controlling Navigation in IE Pin
harder11-Feb-03 6:14
harder11-Feb-03 6:14 
GeneralRe: Controlling Navigation in IE Pin
harder11-Feb-03 9:49
harder11-Feb-03 9:49 
GeneralRegSetValueEx question Pin
ns10-Feb-03 8:13
ns10-Feb-03 8:13 
GeneralPrint with or without comments Pin
JohnnyG10-Feb-03 8:13
JohnnyG10-Feb-03 8:13 
GeneralStarting thread in OnInitDialog() Pin
raner10-Feb-03 8:04
raner10-Feb-03 8:04 
GeneralRe: Starting thread in OnInitDialog() Pin
Alvaro Mendez10-Feb-03 8:12
Alvaro Mendez10-Feb-03 8:12 
GeneralRe: Starting thread in OnInitDialog() Pin
raner10-Feb-03 19:37
raner10-Feb-03 19:37 
GeneralRe: Starting thread in OnInitDialog() Pin
Dave Bryant10-Feb-03 8:21
Dave Bryant10-Feb-03 8:21 
There is no problem starting a thread in OnInitDialog(), you just have to be very careful when using MFC objects (particularly objects derived from CWnd) in multiple threads.

Anyway, i suspect that here your code isn't compiling (i assume that's what you mean when you said that it doesn't work) because GetDlgItem() doesn't have enough parameters. Since the thread function is a global function, and not a member of CGrapDlg, it does not have access to the member functions of CGrapDlg (and CWnd from where it is derived). This means that when you call GetDlgItem() here, it is actually calling the SDK version, not the CWnd version. The SDK version of GetDlgItem() takes two parameters: the HWND of the dialog box, and then ID of the control. To get around this, you could cast the pParam parameter to a CGrapDlg, and then call the GetDlgItem() member function.

However, there are two issues here:

1) This uses CWnd-derived MFC objects in multiple threads, which is error prone. You could get around this by passing in the HWND instead, and calling the SDK directly.

2) By the sound of the thread function name, you are planning to do some drawing within this thread. In general, this is not recommended, as the dialog will also be painting itself (by handling WM_PAINT and WM_ERASEBACKGROUND), and so it is very likely that anything you draw in your thread will never be seen by the user.

Dave
GeneralRe: Starting thread in OnInitDialog() Pin
raner10-Feb-03 22:35
raner10-Feb-03 22:35 
GeneralRe: Starting thread in OnInitDialog() Pin
Abbas_Riazi10-Feb-03 8:51
professionalAbbas_Riazi10-Feb-03 8:51 
GeneralRe: Starting thread in OnInitDialog() Pin
palbano10-Feb-03 8:55
palbano10-Feb-03 8:55 
GeneralC++ and Excel via ODBC Pin
svinn10-Feb-03 7:56
svinn10-Feb-03 7:56 
GeneralRe: C++ and Excel via ODBC Pin
Joshua Nussbaum10-Feb-03 8:40
Joshua Nussbaum10-Feb-03 8:40 
GeneralRe: C++ and Excel via ODBC Pin
svinn10-Feb-03 8:45
svinn10-Feb-03 8:45 
GeneralRe: C++ and Excel via ODBC Pin
Joshua Nussbaum12-Feb-03 10:23
Joshua Nussbaum12-Feb-03 10:23 
Generalup Pin
svinn10-Feb-03 10:19
svinn10-Feb-03 10:19 
QuestionHow to send email from C++ code Pin
Shay Harel10-Feb-03 7:25
Shay Harel10-Feb-03 7:25 
AnswerRe: How to send email from C++ code Pin
Chris Meech10-Feb-03 7:38
Chris Meech10-Feb-03 7:38 
GeneralRe: How to send email from C++ code Pin
Shay Harel10-Feb-03 7:47
Shay Harel10-Feb-03 7:47 
GeneralMaximising SDI window Pin
Justin2310-Feb-03 5:56
Justin2310-Feb-03 5:56 
GeneralRe: Maximising SDI window Pin
AlexO10-Feb-03 6:41
AlexO10-Feb-03 6:41 
GeneralRe: Maximising SDI window Pin
Rage10-Feb-03 6:45
professionalRage10-Feb-03 6:45 
Generalautomatically refreshing drive views Pin
will138310-Feb-03 5:45
will138310-Feb-03 5:45 
GeneralRe: automatically refreshing drive views Pin
olivier10-Feb-03 6:04
olivier10-Feb-03 6:04 
GeneralRe: automatically refreshing drive views Pin
olivier10-Feb-03 6:28
olivier10-Feb-03 6:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.