Well I set it:
But how do I change it's value?Code:SetDlgItemText(hwnd, IDC_TEXT, "I'm a textbox");
Printable View
Well I set it:
But how do I change it's value?Code:SetDlgItemText(hwnd, IDC_TEXT, "I'm a textbox");
What do you mean? Change what value?
The same way you set it the first time (if I understand your question correctly).
What I meant was: After setting an edit box, how do I change it's value... Like I start an edit box with the value of "blue" how do I change it to "green"?
Does your solution works for that?
Have you tried that? It works. I promise.Quote:
Originally Posted by confuted
Well so why this dosen't work? It compiles and starts but the dialog dosen't show up...
Code:#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "clock.h"
SYSTEMTIME time;
char strtime[20];
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
while(1)
{
GetLocalTime(&time);
sprintf(strtime, "%d:%d:%d", time.wHour, time.wMinute, time.wSecond);
SetDlgItemText(hwnd, IDC_TIME, strtime);
}
break;
case WM_COMMAND:
break;
case WM_CLOSE:
EndDialog(hwnd, 0);
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);
}
Since an EDIT box is a window wouldn't the UpdateWindow function work for your purpose? Or does UpdateWindow not affect EDIT windows in the way you want?
UpdateWindow() bypasses the message que and sends the paint msg directly to the callback. Will not change the contents of the edit.
WM_INITDIALOG is called before the DLG is displayed. So putting an infinite loop here will just cause problems (IMO).
I would use a timer message. Create the timer in the init dlg msg with the required tiem interval and it will create a series of WM_TIMER msgs. In the WM_TIMER handler set the edits contents each time the timer msg arrives.
Yes. And that also leaves room for other messages to come in, meaning your window will be able to be updated, closed, etc. correctly.
Could you please show me how I would send the WM_TIMER message? And I would handle it just as any other message like the WM_INITDIALOG?
:rolleyes:
Look at SetTimer() (the timer will fire a msg until killed, not just once)
in wm_initdlg create timer
in wm_close kill timer
in WM_TIMER set you edit each time (the time msg arrives)
SetTimer()
the HWND is that of the DLG
the nIDEvent is a number you use to identify the timer (from other timers you create)
elapse is the interval in millsecs (bast possible is about 15ms)
set lpTimerFunc to NULL so the timer msg comes to your call back
Thanks a lot for beeing so descriptive and helpfull :) But it still just flashes and close... :(
Oh nevermind, I forgot a break; after the WM_TIMER message... It's working now :)Code:BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
SetDlgItemText(hwnd, IDC_TIME, FALSE);
SetTimer(hwnd, 1, 15, (TIMERPROC) NULL);
break;
case WM_TIMER:
GetLocalTime(&time);
sprintf(strtime, "%d:%d:%d", time.wHour, time.wMinute, time.wSecond);
SetDlgItemText(hwnd, IDC_TIME, strtime);
case WM_CLOSE:
KillTimer(hwnd, 1);
EndDialog(hwnd, 0);
break;
default:
return FALSE;
}
return TRUE;
}
Ahhh.....see you got it.
Just slip the cheque into the modem......