How to Initialise a Handle

江枫思渺然 提交于 2019-12-24 03:48:15

问题


Error:

Run-Time Check Failure #3 - The variable 'TextLabelVar' is being used without 
being initialized.

Illustrative Code:

HWND VarText;
char Disps[100];
float some_number;
WINAPI WndProc(..)
{   

    switch(...) 
    case WM_CREATE:
    TextLabelVar=CreateWindowEx(WS_EX_WINDOWEDGE,TEXT("Edit"), TEXT("Val."), WS_CHILD \
                | WS_VISIBLE, 380, 50, 140, 20, hwnd, NULL, NULL, NULL);
    break;

    case WM_MESSAGEFROMANOTHERWINDOW:
    some_number=1298.123123;
    sprintf(Disps,"%f",some_number);
    SetWindowText(TextLabelVar,TEXT(Disps));

}

Question: Ok, I get the error TextLabelVar is being used without initialisation. I got similar error for var Disps. I then declared char Disps[100]; This showed no error. Now, the error moves onto a handle. I am not sure I can declare a handle as array and it makes sense. How do I solve this?


回答1:


This is a run-time error. What it is telling you is that TextLabelVar is being read before it has been initialised. And that means that the WM_MESSAGEFROMANOTHERWINDOW case statement executed before WM_CREATE.

From the comments you've assigned 0 to TextLabelVar to suppress the warning, but then of course the call to SetWindowText cannot succeed since the window handle you pass is 0.

To tackle the problem you need to understand why WM_MESSAGEFROMANOTHERWINDOW is being handled before WM_CREATE.



来源:https://stackoverflow.com/questions/17484490/how-to-initialise-a-handle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!