动手写第一个Windows程序

用的IDE是Visual Studio 2008 中文版
创建了一个Win32 Application

// sdafsadf.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include "sdafsadf.h"
#include <stdio.h>


LRESULT CALLBACK WinSunProc(
  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,          // command line
  int nCmdShow              // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);

HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新科学技术培训中心",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 WinSunProc(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

我编译各种错误
然后我就纳闷了,难道是孙鑫的书太老了?
后来按了Alt+F7



配置属性---->常规--->字符集---->选择未设置
就可以正常运行了

结果:


----------------------------------------------------------------------------------

#include < stdio.h >
#include    <windows.h>
#include    <commctrl.h>   
#include    <shlobj.h>     
#include    <string.h>  
#include    <stdlib.h>    
#include    <memory.h>     
#include <htmlhelp.h>
#include <commctrl.h>
#include <time.h>
#include <Winbase.h>
#include <shlwapi.h>
#include    "resource.h"

#define EXTERN  extern

EXTERN HWND ghMainWnd;


// WinTest.cpp : アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include "WinTest.h"
#include "rp_Fn2lp.h"

LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL InitMainDlg(HWND);

int WINAPI WinMain(
HINSTANCE hInst,
HINSTANCE hPrev,
LPSTR lpCmdLine,
int nCmdShow
) {
    DialogBox(hInst, MAKEINTRESOURCE(IDD_MAIN),GetDesktopWindow(), (DLGPROC)MainDlgProc);

    return 0;
}

LRESULT CALLBACK MainDlgProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
              InitMainDlg(hdlg);
  return FALSE;
case WM_SYSCOMMAND:
switch( wParam ){

case SC_CLOSE :// 終了処理選択
EndDialog(hdlg, TRUE);
break;

}

return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hdlg, TRUE);
break;
}
return TRUE;
case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return FALSE;
}

return TRUE;
}

BOOL InitMainDlg(HWND hdlg)
{
return TRUE;
}


--------------------------------------------------------------------------------------------------------------------------------------------------------------------
SetFocus(hdlg);
GetFocus();
MoveWindow(hdlg,300,200,600,350,NULL);

-------------------------------------------------------------------------------

int aclState = 7;

for( int i = 0;i < 32;i++ )
{
        int temp = 1;
temp = temp << i;
temp = aclState & temp;
if(temp != 0){
   MessageBox(hdlg,"ok","weixin",0); 
}
}

你可能感兴趣的:(Win32,application,vc++)