Windows编程编译问题
下面是我的源码:
// WinExam3.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "WinCtrl.h"
OPENFILENAME ofn;
HWND hStatusBar,hToolBar;
HINSTANCE hInst;
int RightEnd[2];
LPNMHDR lpNmHdr;
LPTOOLTIPTEXT lpTText;
//Define the tool buttons
TBBUTTON tbButton[]=
{
STD_FILENEW,IDM_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
STD_FILEOPEN,IDM_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
STD_FILESAVE,IDM_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0,0,
STD_CUT,IDM_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
STD_COPY,IDM_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
STD_PASTE,IDM_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0
};
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HWND hWnd;
MSG msg;
HACCEL hAccel;
WNDCLASS wndClass;
char chMenuName[] = "MainMenu";
char chClassName[] = "WinExam3";
char chTitle[] = "The Window Example";
char chAccelName[] = "MenuAccel";
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WndProc;
wndClass.lpszClassName = chClassName;
wndClass.lpszMenuName = chMenuName;
wndClass.style = 0;
if(!RegisterClass(&wndClass))
{
MessageBeep(0);
return 0;
}
hWnd = CreateWindow(chClassName,chTitle,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
InitCommonControls();
hInst = hInstance;
hAccel = LoadAccelerators(hInstance,chAccelName);
while(GetMessage(&msg,NULL,0,0))
{
if(!TranslateAccelerator(hWnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static char chFilter[] = "Text Files(*.txt)|*.txt || All Files(*.*)|*.*||";
static char chFileName[] = "";
static RECT rectClient;
switch(message)
{
case WM_CREATE:
ofn.Flags = 0;
ofn.hInstance = NULL;
ofn.hwndOwner = hWnd;
ofn.lCustData = 0;
ofn.lpfnHook = NULL;
ofn.lpstrCustomFilter = NULL;
ofn.lpstrDefExt = NULL;
ofn.lpstrFile = NULL;
ofn.lpstrFileTitle = NULL;
ofn.lpstrFilter = chFilter;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.lpTemplateName = NULL;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.nFileOffset = 0;
ofn.nFilterIndex = 1;
ofn.nMaxCustFilter = 0;
ofn.nMaxFile = 0;
ofn.nMaxFileTitle = 0;
//Create ToolBar
hToolBar = CreateToolbarEx(hWnd,WS_CHILD | WS_BORDER |
WS_VISIBLE | TBSTYLE_TOOLTIPS,
ID_TOOLBAR,7,HINST_COMMCTRL,
IDB_STD_SMALL_COLOR,tbButton,
7,0,0,0,0,sizeof(TBBUTTON));
//Create StatusBar
hStatusBar = CreateStatusWindow(WS_CHILD | WS_VISIBLE,
"",hWnd,ID_STATUSBAR);
//Set StatusBar
GetClientRect(hWnd,&rectClient);
RightEnd[0] = rectClient.right * 2 /3;
RightEnd[1] = rectClient.right;
SendMessage(hStatusBar,SB_SETPARTS,(WPARAM)2,(LPARAM)RightEnd);
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,(LPARAM)"Welcom to use statusbar");
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)2,(LPARAM)"The Application is ready");
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_NEW:
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,(LPARAM)"");
}
break;
case WM_NOTIFY:
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}
return 0;
}
//stdafx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include <stdio.h>
#include <commdlg.h>
#include <stdlib.h>
#include <commctrl.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
编译出错信息:
--------------------Configuration: WinExam3 - Win32 Debug--------------------
Compiling...
WinExam3.cpp
Linking...
WinExam3.obj : error LNK2001: unresolved external symbol __imp__InitCommonControls@0
WinExam3.obj : error LNK2001: unresolved external symbol __imp__CreateStatusWindowA@16
WinExam3.obj : error LNK2001: unresolved external symbol __imp__CreateToolbarEx@52
Debug/WinExam3.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
WinExam3.exe - 4 error(s), 0 warning(s)
请高手指教,我的编译环境还需要设置什么?谢谢!
问题点数:50、回复次数:5Top
1 楼2ndboy(贱男春)回复于 2002-04-04 18:27:47 得分 0
commctrl.hTop
2 楼LoveTide(say no to ISO-8859-1、CVS)回复于 2002-04-04 18:34:37 得分 0
Alt+F7
Link: 加入一个 .lib 文件,具体是什么文件忘了,参考一下 msdn 吧Top
3 楼2ndboy(贱男春)回复于 2002-04-04 18:43:26 得分 50
COMCTL32.LIBTop
4 楼zhakewei(天外有天)回复于 2002-04-04 19:26:47 得分 0
老兄,继续努力吧!Top




