   strange errors - win32 based
  having 2 problems 1.how to get rid of text.  At start i have it say TextOut("Welcome to Black Jack");how would i clear that from the screen?second...is betting.  I have it get it from an edit box an dusing the atof() to switch it to float.  It works upto 999.  if you go above 1000 you get an error..and when in debugger..is comes up in diff problems.  first time i debugged it it pointed the the return DefWindowProc() then i get a error on atof() second time with no change..now when i run it i get a 00000000 in the debugger.  this change allthe time depending on value of the bet, though it works fine up to 1000.   #include <windows.h>LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);void PaintWindow();void DisplayMoney();void GetBet();void NewGameT();HDC starthdc;PAINTSTRUCT startText;HINSTANCE gl_hInstance;HWND MainWindow, StartButton, Hit, Stand, BetButton, BetWindow, Quit, DoubleDown, Split, NewGame;long double Money = 5000;char MoneyStr[] = {NULL};bool Continue = false;double TempMoney;int WINS = 0;int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){WNDCLASSEX wc;MSG Msg;;gl_hInstance = hInstance;ZeroMemory(&wc, sizeof(wc));wc.cbClsExtra = 0;wc.cbSize = sizeof(wc);wc.cbWndExtra = 0;wc.hCursor = NULL;wc.hIcon = NULL;wc.hIconSm = NULL;wc.hInstance = hInstance;wc.lpfnWndProc = WndProc;wc.lpszClassName = "Frame";wc.lpszMenuName = NULL;wc.style = CS_HREDRAW | CS_VREDRAW;wc.hbrBackground = (HBRUSH) GetStockObject (3);RegisterClassEx(&wc);MainWindow = CreateWindow("Frame", "Frame", WS_BORDER | WS_SYSMENU , 0,0,500,500,NULL, NULL, hInstance, NULL);StartButton = CreateWindow("BUTTON", "New Deal", WS_VISIBLE | WS_CHILD, 200, 250,100,25,MainWindow,NULL, hInstance, NULL);ShowWindow(MainWindow, nShowCmd);starthdc = GetWindowDC(MainWindow);BeginPaint(MainWindow, &startText);SetTextColor(starthdc, RGB(0,0,0));TextOut(starthdc,180,250,"Welcome to Black Jack", 21);EndPaint(MainWindow, &startText);while (GetMessage(&Msg, MainWindow, 0,0))    {TranslateMessage (&Msg);DispatchMessage (&Msg);    }return 0;}LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){HWND Control = (HWND) lParam;    switch (iMsg)    {case WM_CREATE:break;case WM_SIZE:break;case WM_PAINT:    break;case WM_DESTROY:UnregisterClass("Frame", gl_hInstance);PostQuitMessage(0);break;case WM_COMMAND:if(Control == StartButton){DestroyWindow(StartButton);PaintWindow();Stand = CreateWindow("BUTTON", "Stand", WS_VISIBLE | WS_CHILD, 0,200,100,25,MainWindow,NULL,gl_hInstance,NULL);Hit = CreateWindow("BUTTON", "Hit", WS_VISIBLE | WS_CHILD, 0,235, 100,25, MainWindow,NULL, gl_hInstance, NULL);DoubleDown = CreateWindow("BUTTON", "Double Down", WS_VISIBLE | WS_CHILD | WS_DISABLED,0,270,100,25, MainWindow, NULL, gl_hInstance, NULL);Split = CreateWindow("BUTTON", "Split", WS_VISIBLE | WS_CHILD | WS_DISABLED,0,305,100,25,MainWindow, NULL, gl_hInstance, NULL);BetWindow = CreateWindow("EDIT", "Bet", WS_VISIBLE | WS_CHILD | WS_BORDER, 0, 340,100,25,MainWindow,NULL, gl_hInstance, NULL);BetButton = CreateWindow("BUTTON", "Bet", WS_VISIBLE | WS_CHILD, 110,340,100,25,MainWindow, NULL, gl_hInstance, NULL);Quit = CreateWindow("BUTTON", "Quit", WS_VISIBLE | WS_CHILD, 400, 0, 100, 25, MainWindow,NULL, gl_hInstance, NULL);NewGame = CreateWindow("BUTTON", "New Game", WS_VISIBLE | WS_CHILD, 400,30,100,25,MainWindow, NULL, gl_hInstance, NULL);DisplayMoney();}else if(Control == Quit)PostQuitMessage(0);else if(Control == BetButton)GetBet();else if(Control == NewGame)NewGameT();break;}return DefWindowProc (hwnd, iMsg, wParam, lParam);}void PaintWindow(){PAINTSTRUCT Text;HDC hdc = GetWindowDC(MainWindow);BeginPaint(MainWindow, &Text);SetTextColor(hdc, RGB(0,0,0));TextOut(hdc,0,50,"Your Cards", 10);TextOut(hdc,150,50, "Opponets Cards", 14);EndPaint(MainWindow, &Text);}void DisplayMoney(){PAINTSTRUCT Text;HDC hdc = GetWindowDC(MainWindow);strcpy(MoneyStr, _gcvt(Money,10,MoneyStr));BeginPaint(MainWindow, &Text);SetTextColor(hdc, RGB(0,0,0));TextOut(hdc, 0,400, MoneyStr, strlen(MoneyStr));EndPaint(MainWindow, &Text);}void GetBet(){char GetMoney[] = {NULL};GetWindowText(BetWindow, GetMoney, 15);TempMoney = atof(GetMoney);if(TempMoney > Money){MessageBox(MainWindow, "Not Enough Money", "Not Enough Money", MB_OK);Continue = false;}else{Money-=TempMoney;Continue = true;}}void NewGameT(){Money = 500;WINS = 0;};[edited by - Rydis on February 3, 2004 10:21:44 PM]
  There are a few problems:1. The MSDN explicitly states that you should not use BeginPaint() or EndPaint() outside of the WM_PAINT message. You can fix this by moving PaintWindow() and DrawMoney() into WM_PAINT and when you need to redraw the window simply call InvalidateRect() to signal which part of the window you wish to redraw.2. The error with atof() is most likely occuring because you give GetMoney a length of only 1 char. When you call GetWindowText() you are writing past the bounds of that array (bad news!) and the atof() problem is probably a residue of that. Frankly, it''s surprising that your program doesn''t crash.   Colin Jeanne | Invader''s Realm;  well i thought the [] meant it makes it the size it needs.  Its fixed though so thanks.secondonly...the paint draws fine...its Removing the text im having trouble with. ;  To clear the window, you could probably make a call to GetClientRect to get the rectangle of the client area of the window, call GetSysColorBrush(COLOR_BTNFACE) to get a brush for the standard gray button color, and then call FillRect using the hDC you already have, and the rectangle and brush that you just got.  If you don''t want gray, you could use COLOR_WINDOW to get what is normally the white background.  MSDN has a complete list of system colors.And about the [] automatic sizing thing, that only works when initializing an array.  In your code you hadchar MoneyStr[] = {NULL};   which the compiler understands to mean "Make an array of char that has only one element, and that element''s value is 0".  Thus, it only allocates 1 byte.  That''s it.  If you wrotechar MoneyStr[] = {''A'', ''B'', ''C'', NULL};  then you would have an array with four elements, but it would remain four elements throughout the entirety of the program.Since you use the nMaxCount value 15 with GetWindowText(), then you can easily just create an array as such:char MoneyStr[15];  and then you''d be guaranteed to have a large enough amount of memory reserved for whatever GetWindowText() might try to store.  Be wary of such functions, though, since sometimes the MaxCount parameter counts the ''\0'' at the end of strings, and sometimes not.  It''s usually safest just to allocated one extra byte in your string, so make it 16, instead of 15, while still calling GetWindowText() with 15, and you sure to be fine (at least on that issue). 