小编Ami*_*mit的帖子

不能包含这两个文件(WinSock2,Windows.h)

我遇到了包括这两个文件的问题.现在,我知道我需要首先包含Winsock2,然后是windows.h,或者简单地说:

#define WIN32_LEAN_AND_MEAN
Run Code Online (Sandbox Code Playgroud)

但是,我还有问题

我有一个调用的头文件,XS.h看起来像这样

#ifndef XS_H
#define XS_H

#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>

#endif
Run Code Online (Sandbox Code Playgroud)

XS.h在标题中包括在内Client.h. Client.hinclude看起来像这样:

#ifndef CLIENT_H
#define CLIENT_H

#include "XS.h"
Run Code Online (Sandbox Code Playgroud)

XS.h是我唯一包含的Client.h,但我仍然会得到错误(正如你所看到的,Winsock之前包括在内)windows.h

我得到了大约78个错误,以下是其中一些错误:

Error   90  error C3861: 'WSASetLastError': identifier not found    c:\program files (x86)\windows kits\8.0\include\um\ws2tcpip.h   703
Error   61  error C2375: 'WSAStartup' : redefinition; different linkage c:\program files (x86)\windows kits\8.0\include\um\winsock2.h   2296
Error   49  error C2375: 'send' : redefinition; different linkage   c:\program files (x86)\windows kits\8.0\include\um\winsock2.h   2026 …
Run Code Online (Sandbox Code Playgroud)

c sockets winapi winsock2

13
推荐指数
2
解决办法
1万
查看次数

阵列数组,大小不同

我有一个数组,每个单元格都有数组.例如,调用大数组arr:

int a[3] = {3, 2, 1};
int b[2] = {2, 1};
int *arr[2] = {a, b}
Run Code Online (Sandbox Code Playgroud)

现在问题是,如果我想在大阵列内打印小arrs.

这是我的代码:

#include <stdio.h>

void printArr(int arr [], int n)
{
    for (int i = 0 ; i < n ; i++)
    {
        printf("%d ", *(arr + i));
    }
    printf("\n");
}

int main()
{
    int a[5] = {1, 8, 4, 2, 0};
    int b[3] = {1, 4, 2};
    int *arr [2] = {a, b};

    int n = 0;

    for (int i …
Run Code Online (Sandbox Code Playgroud)

c arrays pointers

4
推荐指数
1
解决办法
7080
查看次数

如何使用WndProc作为类函数

我正在尝试创建一个包含WndProc的类,但是我收到一个错误:

Error 2 error C2440: '=' : cannot convert from 'LRESULT (__stdcall Client::* )(HWND,UINT,WPARAM,LPARAM)' to 'WNDPROC'

我在网上搜索它,看到你需要让WndProc静态,但是,它编译并且一切都很好,但如果我想改变一些东西,它不会让我:

Error 3 error C2352: 'Client::CreateMen' : illegal call of non-static member function

(CreateMen是创建菜单的类中的一个函数,使用HMENU等).

这是我的职称:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
Run Code Online (Sandbox Code Playgroud)

我能做什么?我真的很困惑......

谢谢!

c c++ winapi class

3
推荐指数
1
解决办法
1万
查看次数

如何录制麦克风直到没有声音?

我创造了两个功能: - 一个记录麦克风 - 一个播放麦克风的声音

它记录麦克风3秒钟

#include <iostream>
#include <Windows.h>
#include <vector>
using namespace std;

#pragma comment(lib, "winmm.lib")

 short int waveIn[44100 * 3];

void PlayRecord();

void StartRecord()
{
const int NUMPTS = 44100 * 3;   // 3 seconds
int sampleRate = 44100;  
// 'short int' is a 16-bit type; I request 16-bit samples below
                         // for 8-bit capture, you'd use 'unsigned char' or 'BYTE' 8-bit     types

 HWAVEIN      hWaveIn;
 MMRESULT result;

 WAVEFORMATEX pFormat;
 pFormat.wFormatTag=WAVE_FORMAT_PCM;     // simple, uncompressed format
 pFormat.nChannels=1;                    //  1=mono, …
Run Code Online (Sandbox Code Playgroud)

c++ winapi voip voice-recording

3
推荐指数
1
解决办法
3788
查看次数

ListView 项目背景

我想用颜色标记列表视图中的特殊行,所以它看起来像这样:http : //www.codeproject.com/KB/list/CColorListCtrl/rowCell.jpg (第一行 - 绿色) .

我不确定我到底该怎么做,并且对网络上的结果感到有些困惑……那么我该怎么做呢?

谢谢!

c++ winapi listview win32gui

3
推荐指数
1
解决办法
3933
查看次数

递归搜索计算机中的文件

我试图使用WinAPI递归搜索计算机中的文件:FindFirstFileFindNextFile

我不明白为什么,但我的代码不起作用.在第一次运行中,一切都很好 - 我可以看到C盘中的所有内容.例如C:\Program Files (x86),当我进入子文件夹时,我发现文件夹中的所有文件都是正确的.,而如果我使用的函数没有递归搜索,使用给定的路径C:\Program Files (x86),我会得到一个列表里面的所有文件夹.

这是我的代码:

#include <Windows.h>
#include <iostream>
#include <string>

void FindFile(std::string directory)
{
std::string tmp = directory + "\\*";
WIN32_FIND_DATA file;
HANDLE search_handle=FindFirstFile(tmp.c_str(), &file);
if (search_handle != INVALID_HANDLE_VALUE)
{
    do
    {
        std::wcout << file.cFileName << std::endl;
        directory += "\\" + std::string(file.cFileName);
        FindFile(directory);
    }while(FindNextFile(search_handle,&file));

    if (GetLastError() != 18) // Error code 18: No more files left
        CloseHandle(search_handle);
}
}

int main()
{
    FindFile("C:");
}
Run Code Online (Sandbox Code Playgroud)

该变量tmp …

c++ recursion winapi file

2
推荐指数
1
解决办法
4609
查看次数

通过静态控制绘制图像

我正在尝试在静态控件上绘制一个图片框,但图像没有出现.

图像确实存在于该位置.

这是我的代码:

    HWND hwn = CreateWindow(TEXT("static"), NULL, WS_CHILD | WS_VISIBLE, 5, 10, 470, 100, hwnd, NULL, NULL, NULL);
    HBITMAP hBmp = (HBITMAP)LoadImage(NULL, "D:\\Pic.bmp", IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);  
SendMessage(hwn, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
Run Code Online (Sandbox Code Playgroud)

首先,我正在创建一个静态控件(就像google中的指南所说的那样),然后我将图像绘制在它上面......为什么它不起作用?它只绘制静态控件,但图像根本没有加载...

谢谢!

c c++ winapi picturebox

0
推荐指数
1
解决办法
788
查看次数