【メモ】Windowsフォームの仕組みを理解する

11588 ワード

 1 #include<Windows.h>

 2 #include<stdio.h>

 3 LRESULT CALLBACK WinSunProc(     

 4     HWND hwnd,

 5     UINT uMsg,

 6     WPARAM wParam,

 7     LPARAM lParam

 8 );

 9 int WINAPI WinMain(         

10     HINSTANCE hInstance,

11     HINSTANCE hPrevInstance,

12     LPSTR lpCmdLine,

13     int nCmdShow

14 )

15 {

16     WNDCLASS wndcls;

17     wndcls.cbClsExtra=0;

18     wndcls.cbWndExtra=0;

19     wndcls.hbrBackground=(HBRUSH) GetStockObject(BLACK_BRUSH);

20     wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);

21     wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);

22     wndcls.hInstance =hInstance;

23     wndcls.lpfnWndProc=WinSunProc;

24     wndcls.lpszClassName="aa";

25     wndcls.lpszMenuName=NULL;

26     wndcls.style=CS_HREDRAW|CS_VREDRAW;

27     RegisterClass(&wndcls);

28     HWND hwnd;

29     hwnd=CreateWindow("aa"," ",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);

30     ShowWindow(hwnd,SW_SHOWNORMAL);

31     UpdateWindow(hwnd);

32     MSG msg;

33     while (GetMessage(&msg,NULL,0,0))

34     {

35         TranslateMessage(&msg);

36         DispatchMessage(&msg);

37 

38     }

39     return 0;

40 }

41 LRESULT CALLBACK WinSunProc(     

42     HWND hwnd,

43     UINT uMsg,

44     WPARAM wParam,

45     LPARAM lParam

46 )

47 {

48     switch(uMsg)

49     {

50         case WM_CHAR:

51             char szChar[20];

52             sprintf(szChar,"Char is %d",wParam);

53             MessageBox(hwnd,szChar,"aa",0);

54             break;

55         case WM_LBUTTONDOWN:

56             MessageBox(hwnd,"Mouse clicked","aa",0);

57             HDC hdc;

58             hdc=GetDC(hwnd);

59             TextOut(hdc,0,50," ",strlen(" "));

60             ReleaseDC(hwnd,hdc);

61 

62             break;

63         case WM_PAINT:

64             HDC hDC;

65             PAINTSTRUCT ps;

66             hDC=BeginPaint(hwnd,&ps);

67             TextOut(hDC,0,0,"hahahah",strlen("hahahah"));

68             EndPaint(hwnd,&ps);

69             break;

70         case WM_CLOSE:

71             if (IDYES==MessageBox(hwnd," ?","fb",MB_YESNO))

72             {

73                 DestroyWindow(hwnd);

74             }

75             break;

76         case WM_DESTROY:

77             PostQuitMessage(0);

78             break;

79         default:

80             return DefWindowProc(hwnd,uMsg,wParam,lParam);

81     }

82     return 0;

83 }

質問:error C 2664:「CreateWindowExW」:パラメータ2を「const char[7]」から「LPCWSTR」に変換できません
これにより、プロジェクト->プロパティ->構成プロパティ->C/C+->プリプロセッサ->プリプロセッサ定義->ブラウズボタンをクリックして、親およびプロジェクト設定から継承を削除できます(VS 2008).