Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Just some enquiries from a newbie

This topic is 5975 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

The questions I''m posting are related to Windows Programming. 1) Assuming that in a dialog box, can I use these: TextOut(hdwnd,1,1,str,strlen(str)); Notes : The location is occupied by a check box. Attempt : When I did this, I get a runtime error message box Advise : What is the correct way(suitable for newbie) to implement Textout() in this case? The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant

##### Share on other sites
you could use the static text control, should it need updating just send a message to update it with the new string.

edit:
  BOOL SetDlgItemText( HWND hDlg, // handle of dialog box int nIDDlgItem, // identifier of control LPCTSTR lpString // text to set);

Edited by - Bezzant on February 6, 2002 1:21:40 PM

##### Share on other sites
is hdwnd a valid HDC? you might want to change the name to "hdc" which makes more sence than hdwnd, but thats your call.

anyway, you have to initialise the HDC with GetDC, CreateCompatibleDC or CreateDC, and afterwards release it with ReleaseDC or DeleteDC depending on how you initialised it.

anyway, why would you want to do a textout over a combobox? if you want to set the text of the combobox, you should look up the CB_* windows messages, like CB_ADDSTRING,CB_SETCURSEL, CB_INSERTSTRING and such.

##### Share on other sites
Actually, sad to say that for my resource file, I am still hardcoding it and I''ve recently heard of a "Resource editor" where we may create resource file without doing much of the coding. But there''s something strange is that I have consulted my school lecturers regarding the issue and they tend to push me around the faculty like the "Tai-Chi fist" and end up getting no answer. Really regretted studying at that school.

Regarding the overlapping of CheckBox, It was a fault on my side as I did a wrong calculation of the location to drop the control and it was a painful lesson indeed. Driving me nuts for the past 2 days trying to rectify the prob.

I guess I will use static text control and try again. Tkx

The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant

##### Share on other sites
I've tried to display my text in the CTEXT static control using SendDlgItemMessage() but it failed. I've even tried displaying it in messagebox, it fails again.

I think I'm stuck

  case WM_TIMER: if(counter == 0) { KillTimer(hdwnd,IDD_TIMER); if(SendDlgItemMessage(hdwnd,IDD_CB2,BM_GETCHECK,0,0) == BST_CHECKED) { MessageBeep(MB_OK); } else { MessageBox(hdwnd,"BOOM!","Timer message",MB_OK); } } else { counter--; if(SendDlgItemMessage(hdwnd,IDD_CB1,BM_GETCHECK,0,0) == BST_CHECKED) { sprintf(str,"Number of seconds left before alert : %n",counter); MessageBox(hdwnd,str,"Test",MB_OK); //SetDlgItemText(hdwnd,IDD_CTEXT,str); } } return 1;

The error message is :
The instruction at "0x0040303f" referenced memory at
"0x00000001". The memory could not be "written".

NOTES : I'm using a modeless dialog box.
hdlg=CreateDialog(hInst,"MyDialog",hwnd,(DLGPROC)DialogFunc);

The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant

Edited by - savagerx on February 7, 2002 11:56:37 AM

Edited by - savagerx on February 7, 2002 12:03:40 PM

##### Share on other sites
again, if you are doing:

hdlg=CreateDialog(hInst,"MyDialog",hwnd,(DLGPROC)DialogFunc);

why you call:

SendDlgItemMessage(hdwnd,IDD_CB2,BM_GETCHECK,0,0)

shouldnt it be

SendDlgItemMessage(hdlg,IDD_CB2,BM_GETCHECK,0,0)

use this function:

BOOL SetDlgItemText(
HWND hDlg, // handle of dialog box
int nIDDlgItem, // identifier of control
LPCTSTR lpString // text to set
);

the error you are getting refers to a reference to a NULL pointer, or invalid memory, and I am STILL guessing one of your handles is NULL or not properly initialized.

##### Share on other sites
Below is my entire DialogFunc(), hope that may have some clues on what went wrong? At the mean time I''ll try if I have such probs with modal dialog...

Is it true that Modeless Dialog box is more restrictive compared to Modal Dialog box?

The "hdwnd" is actually the parameter for DialogFunc(), thus it should hold the handle of the Dialog Window right?
  BOOL CALLBACK DialogFunc(HWND hdwnd,UINT message, WPARAM wParam, LPARAM lParam){ static int counter; switch(message) { case WM_COMMAND: switch(LOWORD(wParam)) { case IDD_START: counter = vPos; SetTimer(hdwnd,IDD_TIMER,1000,NULL); if(SendDlgItemMessage(hdwnd,IDD_RB1,BM_GETCHECK,0,0) == BST_CHECKED) { ShowWindow(hwnd,SW_MAXIMIZE); } else if(SendDlgItemMessage(hdwnd,IDD_RB2,BM_GETCHECK,0,0) == BST_CHECKED) { ShowWindow(hwnd,SW_MINIMIZE); } break; case IDCANCEL: DestroyWindow(hdlg); break; }//close inner switch return 1; case WM_TIMER: if(counter == 0) { KillTimer(hdwnd,IDD_TIMER); if(SendDlgItemMessage(hdwnd,IDD_CB2,BM_GETCHECK,0,0) == BST_CHECKED) { MessageBeep(MB_OK); } else { MessageBox(hdwnd,"BOOM!","Timer message",MB_OK); } } else { counter--; if(SendDlgItemMessage(hdwnd,IDD_CB1,BM_GETCHECK,0,0) == BST_CHECKED) { sprintf(str,"Number of seconds left before alert : %n",counter); //MessageBox(hdwnd,str,"Test",MB_OK); SetDlgItemText(hdlg,IDD_CTEXT,str); } } return 1; case WM_INITDIALOG: si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; si.nMin = 0; si.nMax = VSCROLLMAX; SetScrollInfo(hdwnd,SB_VERT,&si,1); si.fMask = SIF_POS; si.nPos = vPos; SetScrollInfo(hdwnd,SB_VERT,&si,1); SendDlgItemMessage(hdwnd,IDD_RB3,BM_SETCHECK,BST_CHECKED,0); return 1; case WM_VSCROLL: switch(LOWORD(wParam)) { case SB_LINEDOWN: vPos++; if(vPos > VSCROLLMAX) { vPos = VSCROLLMAX; } break; case SB_LINEUP: vPos--; if(vPos < 0) { vPos = 0; } break; case SB_PAGEDOWN: vPos += 5; if(vPos > VSCROLLMAX) { vPos = VSCROLLMAX; } break; case SB_PAGEUP: vPos -= 5; if(vPos < 0) { vPos = 0; } break; case SB_THUMBTRACK: vPos = HIWORD(wParam); break; case SB_THUMBPOSITION: vPos = HIWORD(wParam); break; }//exit inner switch statement si.fMask = SIF_POS; si.nPos = vPos; SetScrollInfo(hdwnd,SB_VERT,&si,1); return 1; }//exit switch statement return 0;}

The road may be long, wind may be rough. But with a will at heart, all shall begone. ~savage chant

• 38
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631365
• Total Posts
2999589
×