﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-My Dream</title><link>http://www.cppblog.com/ranranyingai/</link><description /><language>zh-cn</language><lastBuildDate>Tue, 09 Jun 2026 18:58:03 GMT</lastBuildDate><pubDate>Tue, 09 Jun 2026 18:58:03 GMT</pubDate><ttl>60</ttl><item><title>新手求助！关于Windows API</title><link>http://www.cppblog.com/ranranyingai/archive/2007/09/07/31722.html</link><dc:creator>张冉冉</dc:creator><author>张冉冉</author><pubDate>Thu, 06 Sep 2007 16:03:00 GMT</pubDate><guid>http://www.cppblog.com/ranranyingai/archive/2007/09/07/31722.html</guid><wfw:comment>http://www.cppblog.com/ranranyingai/comments/31722.html</wfw:comment><comments>http://www.cppblog.com/ranranyingai/archive/2007/09/07/31722.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/ranranyingai/comments/commentRss/31722.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/ranranyingai/services/trackbacks/31722.html</trackback:ping><description><![CDATA[<p>// CH2_5.cpp : Defines the entry point for the application.<br>//</p>
<p>#include "stdafx.h"<br>#include "resource.h"</p>
<p>#define MAX_LOADSTRING 100</p>
<p>// Global Variables:<br>HINSTANCE hInst;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// current instance<br>TCHAR szTitle[MAX_LOADSTRING];&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// The title bar text<br>TCHAR szWindowClass[MAX_LOADSTRING];<br>HBITMAP hbmp;<br>HDC mdc;<br>// The title bar text</p>
<p>// Foward declarations of functions included in this code module:<br>ATOM&nbsp;&nbsp;&nbsp;&nbsp;MyRegisterClass(HINSTANCE hInstance);<br>BOOL&nbsp;&nbsp;&nbsp;&nbsp;InitInstance(HINSTANCE, int);<br>LRESULT CALLBACK&nbsp;WndProc(HWND, UINT, WPARAM, LPARAM);<br>LRESULT CALLBACK&nbsp;About(HWND, UINT, WPARAM, LPARAM);<br>void MyPaint(HDC hdc);</p>
<p>int APIENTRY WinMain(HINSTANCE hInstance,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HINSTANCE hPrevInstance,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LPSTR&nbsp;&nbsp;&nbsp;&nbsp; lpCmdLine,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nCmdShow)<br>{<br>&nbsp;&nbsp;// TODO: Place code here.<br>&nbsp;MSG msg;<br>&nbsp;HACCEL hAccelTable;</p>
<p>&nbsp;// Initialize global strings<br>&nbsp;LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);<br>&nbsp;LoadString(hInstance, IDC_CH2_5, szWindowClass, MAX_LOADSTRING);<br>&nbsp;MyRegisterClass(hInstance);</p>
<p>&nbsp;// Perform application initialization:<br>&nbsp;if (!InitInstance (hInstance, nCmdShow)) <br>&nbsp;{<br>&nbsp;&nbsp;return FALSE;<br>&nbsp;}</p>
<p>&nbsp;hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CH2_5);</p>
<p>&nbsp;// Main message loop:<br>&nbsp;while (GetMessage(&amp;msg, NULL, 0, 0)) <br>&nbsp;{<br>&nbsp;&nbsp;if (!TranslateAccelerator(msg.hwnd, hAccelTable, &amp;msg)) <br>&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;TranslateMessage(&amp;msg);<br>&nbsp;&nbsp;&nbsp;DispatchMessage(&amp;msg);<br>&nbsp;&nbsp;}<br>&nbsp;}</p>
<p>&nbsp;return msg.wParam;<br>}<br>void MyPaint(HDC hdc)<br>{<br>&nbsp;BitBlt(hdc,0,0,600,450,mdc,0,0,SRCCOPY);<br>}</p>
<p><br>//<br>//&nbsp; FUNCTION: MyRegisterClass()<br>//<br>//&nbsp; PURPOSE: Registers the window class.<br>//<br>//&nbsp; COMMENTS:<br>//<br>//&nbsp;&nbsp;&nbsp; This function and its usage is only necessary if you want this code<br>//&nbsp;&nbsp;&nbsp; to be compatible with Win32 systems prior to the 'RegisterClassEx'<br>//&nbsp;&nbsp;&nbsp; function that was added to Windows 95. It is important to call this function<br>//&nbsp;&nbsp;&nbsp; so that the application will get 'well formed' small icons associated<br>//&nbsp;&nbsp;&nbsp; with it.<br>//<br>ATOM MyRegisterClass(HINSTANCE hInstance)<br>{<br>&nbsp;WNDCLASSEX wcex;</p>
<p>&nbsp;wcex.cbSize = sizeof(WNDCLASSEX); </p>
<p>&nbsp;wcex.style&nbsp;&nbsp;&nbsp;= CS_HREDRAW | CS_VREDRAW;<br>&nbsp;wcex.lpfnWndProc&nbsp;= (WNDPROC)WndProc;<br>&nbsp;wcex.cbClsExtra&nbsp;&nbsp;= 0;<br>&nbsp;wcex.cbWndExtra&nbsp;&nbsp;= 0;<br>&nbsp;wcex.hInstance&nbsp;&nbsp;= hInstance;<br>&nbsp;wcex.hIcon&nbsp;&nbsp;&nbsp;= LoadIcon(hInstance, (LPCTSTR)IDI_CH2_5);<br>&nbsp;wcex.hCursor&nbsp;&nbsp;= LoadCursor(NULL, IDC_ARROW);<br>&nbsp;wcex.hbrBackground&nbsp;= (HBRUSH)(COLOR_WINDOW+1);<br>&nbsp;wcex.lpszMenuName&nbsp;= (LPCSTR)IDC_CH2_5;<br>&nbsp;wcex.lpszClassName&nbsp;= szWindowClass;<br>&nbsp;wcex.hIconSm&nbsp;&nbsp;= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);</p>
<p>&nbsp;return RegisterClassEx(&amp;wcex);<br>}</p>
<p>//<br>//&nbsp;&nbsp; FUNCTION: InitInstance(HANDLE, int)<br>//<br>//&nbsp;&nbsp; PURPOSE: Saves instance handle and creates main window<br>//<br>//&nbsp;&nbsp; COMMENTS:<br>//<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In this function, we save the instance handle in a global variable and<br>//&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; create and display the main program window.<br>//<br>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)<br>{<br>&nbsp;&nbsp; HWND hWnd;<br>&nbsp;&nbsp; HDC hdc;</p>
<p>&nbsp;&nbsp; hInst = hInstance; // Store instance handle in our global variable</p>
<p>&nbsp;&nbsp; hWnd = CreateWindow("ranranyingai", "绘图窗口", WS_OVERLAPPEDWINDOW,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);</p>
<p>&nbsp;&nbsp; if (!hWnd)<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FALSE;<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; MoveWindow(hWnd,10,10,600,450,true);<br>&nbsp;&nbsp; ShowWindow(hWnd, nCmdShow);<br>&nbsp;&nbsp; UpdateWindow(hWnd);</p>
<p>&nbsp;&nbsp; hdc=GetDC(hWnd);<br>&nbsp;&nbsp; mdc=CreateCompatibleDC(hdc);</p>
<p>&nbsp;&nbsp; hbmp=(HBITMAP)LoadImage(NULL,"DSC00819.bmp",IMAGE_BITMAP,600,450,LR_LOADFROMFILE);<br>&nbsp;&nbsp; SelectObject(mdc,hbmp);</p>
<p>&nbsp;&nbsp; MyPaint(hdc);<br>&nbsp;&nbsp; ReleaseDC(hWnd,hdc);</p>
<p>&nbsp;&nbsp; return TRUE;<br>}</p>
<p>//<br>//&nbsp; FUNCTION: WndProc(HWND, unsigned, WORD, LONG)<br>//<br>//&nbsp; PURPOSE:&nbsp; Processes messages for the main window.<br>//<br>//&nbsp; WM_COMMAND&nbsp;- process the application menu<br>//&nbsp; WM_PAINT&nbsp;- Paint the main window<br>//&nbsp; WM_DESTROY&nbsp;- post a quit message and return<br>//<br>//<br>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)<br>{<br>&nbsp;int wmId, wmEvent;<br>&nbsp;PAINTSTRUCT ps;<br>&nbsp;HDC hdc;<br>&nbsp;TCHAR szHello[MAX_LOADSTRING];<br>&nbsp;LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);</p>
<p>&nbsp;switch (message) <br>&nbsp;{<br>&nbsp;&nbsp;case WM_COMMAND:<br>&nbsp;&nbsp;&nbsp;wmId&nbsp;&nbsp;&nbsp; = LOWORD(wParam); <br>&nbsp;&nbsp;&nbsp;wmEvent = HIWORD(wParam); <br>&nbsp;&nbsp;&nbsp;// Parse the menu selections:<br>&nbsp;&nbsp;&nbsp;switch (wmId)<br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;case IDM_ABOUT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;case IDM_EXIT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DestroyWindow(hWnd);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return DefWindowProc(hWnd, message, wParam, lParam);<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;case WM_PAINT:<br>&nbsp;&nbsp;&nbsp;hdc = BeginPaint(hWnd, &amp;ps);<br>&nbsp;&nbsp;&nbsp;MyPaint(hdc);// TODO: Add any drawing code here...<br>&nbsp;&nbsp;&nbsp;RECT rt;<br>&nbsp;&nbsp;&nbsp;GetClientRect(hWnd, &amp;rt);<br>&nbsp;&nbsp;&nbsp;DrawText(hdc, szHello, strlen(szHello), &amp;rt, DT_CENTER);<br>&nbsp;&nbsp;&nbsp;EndPaint(hWnd, &amp;ps);<br>&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;case WM_DESTROY:<br>&nbsp;&nbsp;&nbsp;DeleteDC(mdc);<br>&nbsp;&nbsp;&nbsp;DeleteObject(hbmp);<br>&nbsp;&nbsp;&nbsp;PostQuitMessage(0);<br>&nbsp;&nbsp;&nbsp;break;<br>&nbsp;&nbsp;default:<br>&nbsp;&nbsp;&nbsp;return DefWindowProc(hWnd, message, wParam, lParam);<br>&nbsp;&nbsp; }<br>&nbsp;&nbsp; return 0;<br>}</p>
<p>// Mesage handler for about box.<br>LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)<br>{<br>&nbsp;switch (message)<br>&nbsp;{<br>&nbsp;&nbsp;case WM_INITDIALOG:<br>&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;</p>
<p>&nbsp;&nbsp;case WM_COMMAND:<br>&nbsp;&nbsp;&nbsp;if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) <br>&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;EndDialog(hDlg, LOWORD(wParam));<br>&nbsp;&nbsp;&nbsp;&nbsp;return TRUE;<br>&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;break;<br>&nbsp;}<br>&nbsp;&nbsp;&nbsp; return FALSE;<br>}<br><br><br>这是源代码，编译通过但是连接是出现错误：<br>Linking...<br>LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main<br>Debug/CH2_5.exe : fatal error LNK1120: 1 unresolved externals<br>Error executing link.exe.</p>
<p>CH2_5.exe - 2 error(s), 0 warning(s)<br>等待高手指点，不胜感激！</p>
<img src ="http://www.cppblog.com/ranranyingai/aggbug/31722.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/ranranyingai/" target="_blank">张冉冉</a> 2007-09-07 00:03 <a href="http://www.cppblog.com/ranranyingai/archive/2007/09/07/31722.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>