|
求助:建立一个窗口 并建三个按钮 为什么按钮不显示?
[复制链接]
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPTSTR lpCmdLine,int nCmdShow)
{
static TCHAR szAppName[]=TEXT("test");
HWND hwnd;
MSG msg;
WNDCLASS wndcls;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
wndcls.lpfnWndProc=TestProc;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hInstance=hInstance;
wndcls.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION));
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hbrBackground=(HBRUSH)GetStockObject((WHITE_BRUSH));
wndcls.lpszMenuName=NULL;
wndcls.lpszClassName=szAppName;
if(!RegisterClass(&wndcls))
{
MessageBox(NULL,TEXT("This program requires Windows NT!"),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow (szAppName, TEXT ("Test"),WS_OVERLAPPED,
0, 0,600, 600,NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK TestProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static int cxChar,cyChar;
HWND btnhwnd1,btnhwnd2,btnhwnd3;
switch(uMsg)
{
case WM_CREATE:
SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon(hInstance,(LPCTSTR)IDI_APPLICATION));
cxChar=LOWORD(GetDialogBaseUnits());
cyChar=HIWORD(GetDialogBaseUnits());
btnhwnd1=CreateWindow(TEXT("button"),TEXT("OK"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,600-cyChar,20*cxChar,cyChar,hwnd,
HMENU(0),((LPCREATESTRUCT)lParam)->hInstance,NULL);
btnhwnd2=CreateWindow(TEXT("button"),TEXT("CLEAR"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,600-cyChar,200+20*cxChar,cyChar,hwnd,
HMENU(1),((LPCREATESTRUCT)lParam)->hInstance,NULL);
btnhwnd1=CreateWindow(TEXT("button"),TEXT("CANCEL"),WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,0,600-cyChar,400+20*cxChar,cyChar,hwnd,
HMENU(2),((LPCREATESTRUCT)lParam)->hInstance,NULL);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
// TODO: 在此添加任意绘图代码...
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
运行后窗口显示出来 为什么按钮不显示呢?
还有 wndcls.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_APPLICATION)); 这里wince系统 不支持IDI_APPLICATION
怎么解决呢
|
|