+ -
当前位置:首页 → 问答吧 → 新手遇到vc++的问题

新手遇到vc++的问题

时间:2011-12-14

来源:互联网

照着书上来可以编译组建,但运行时,进程里面可以找到,就是不能产生窗口!
各位大哥帮帮忙,win32工程下,代码如下:
#include<windows.h>
#include<stdio.h>



LRESULT CALLBACK WindowProc(
  HWND hwnd, // handle to window
  UINT uMsg, // message identifier
  WPARAM wParam, // first message parameter
  LPARAM lParam // second message parameter
);




int WINAPI WinMain(
  HINSTANCE hInstance, // handle to current instance
  HINSTANCE hPrevInstance, // handle to previous instance
  LPSTR lpCmdLine, // pointer to command line
  int nCmdShow // show state of window
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_HAND);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WindowProc;
wndcls.lpszClassName="weixin";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;

RegisterClass(&wndcls);

  HWND hwnd;
  hwnd=CreateWindow("weixin","我勒个去!",WS_OVERLAPPEDWINDOW,
0,0,,600,400,NULL,NULL,hInstance,NULL);
  ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);


MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

}
return 0;
}

LRESULT CALLBACK WindowProc(
  HWND hwnd, // handle to window
  UINT uMsg, // message identifier
  WPARAM wParam, // first message parameter
  LPARAM lParam // second message parameter
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"输入字符",MB_YESNO);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse click","左键按下",MB_OK);
HDC hDC;
hDC=GetDC(hwnd);
TextOut(hDC,0,50,"我勒个去去",strlen("我勒个去去"));
  ReleaseDC(hwnd,hDC);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,"生活为了什么",strlen("生活为了什么"));
EndPaint(hwnd,&ps);
  break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否要退出程序","明明",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;

}

作者: y814192933   发布时间: 2011-12-14

太长了,学得头晕。

用 MFC 编程不更方便么?

作者: keith_cheung   发布时间: 2011-12-15

热门下载

更多