Click to See Complete Forum and Search --> : What's wrong with this


SpuN
December 19th, 2004, 11:05 PM
i have a static text box on my dialog box.. and i want it to print a number that increases every time i click the button on my dlg box... what have i done wrong?


// NIGGA COUNTA

#include <windows.h>
#include <stdio.h>
#include "resource.h"

HWND hWnd;

LRESULT CALLBACK NIGGADLGPROC(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_NIGGA), hWnd, (DLGPROC)NIGGADLGPROC);
return 0;
}

LRESULT CALLBACK NIGGADLGPROC(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
int NIGGACOUNT = 0;
char cNIGGACOUNT[512];
sprintf(cNIGGACOUNT,"%i", NIGGACOUNT);

switch(Msg)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if(LOWORD(wParam) == IDC_NIGGACOUNTBUTTON)
{
NIGGACOUNT++;
}

break;

case WM_SETTEXT:
{
SetDlgItemText(hDlg, IDC_NIGGACOUNT, cNIGGACOUNT);
break;
}
}

return FALSE;
}

Krzemo
December 19th, 2004, 11:11 PM
int NIGGACOUNT = 0;

It should be defined outside NIGGADLGPROC.

Best regards,
Krzemo.

Paul Rice
December 19th, 2004, 11:12 PM
i have a static text box on my dialog box.. and i want it to print a number that increases every time i click the button on my dlg box... what have i done wrong?


// NIGGA COUNTA

#include <windows.h>
#include <stdio.h>
#include "resource.h"

HWND hWnd;

LRESULT CALLBACK NIGGADLGPROC(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_NIGGA), hWnd, (DLGPROC)NIGGADLGPROC);
return 0;
}

LRESULT CALLBACK NIGGADLGPROC(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
int NIGGACOUNT = 0;
char cNIGGACOUNT[512];
sprintf(cNIGGACOUNT,"%i", NIGGACOUNT);

switch(Msg)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if(LOWORD(wParam) == IDC_NIGGACOUNTBUTTON)
{
NIGGACOUNT++;
}

break;

case WM_SETTEXT:
{
SetDlgItemText(hDlg, IDC_NIGGACOUNT, cNIGGACOUNT);
break;
}
}

return FALSE;
}


I don't do much with dialog boxes in Win32, but, you could try making NIGGACOUNT (?) global. It looks like changing the value and updating the display take place during different message events which would rest the value of NIGGACOUNT to 0 each time the message handler is called because NIGGACOUNT is local to NIGGADLGPROC.

Krzemo
December 19th, 2004, 11:14 PM
And U have to call SetDlgItemText(hDlg, IDC_NIGGACOUNT, cNIGGACOUNT);

after "NIGGACOUNT++;" in WM_COMMAND section.

Hope it helps.

SpuN
December 19th, 2004, 11:18 PM
thanks alot got it working :)